This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH 1/2] mi: Restore original thread/frame when specifying --thread or --thread-group
On 08/02/2016 11:14 PM, Simon Marchi wrote:
> On 16-08-02 01:38 PM, Simon Marchi wrote:
>> Ok, I kinda had the same design idea, but it was blurry. Now that you explain it
>> (I didn't know what previous_inferior_ptid was), it's clear. I'll try to prototype it
>> quickly to see if it's viable.
>
> I started to prototype what you described, but it's definitely not a small job. It would
> also be too big of a change to put in 7.12. I'd be really interested to work on that for
> the next development cycle though.
>
> In the mean time, here is a new version of the patch that implements what I had described
> (with the global flag), which I think is less risky.
I think you need to consider infcalls, and canned sequence of commands
Python/Scheme, etc., basically any place that sets ui->async = 0 ...
guile/guile.c:169: current_ui->async = 0;
guile/guile.c:202: current_ui->async = 0;
guile/guile.c:332: current_ui->async = 0;
guile/scm-ports.c:521: current_ui->async = 0;
top.c:700: current_ui->async = 0;
compile/compile.c:95: current_ui->async = 0;
compile/compile.c:137: current_ui->async = 0;
compile/compile.c:191: current_ui->async = 0;
infcall.c:586: current_ui->async = 0;
python/python.c:326: current_ui->async = 0;
python/python.c:471: current_ui->async = 0;
python/python.c:655: current_ui->async = 0;
cli/cli-script.c:384: current_ui->async = 0;
cli/cli-script.c:666: current_ui->async = 0;
cli/cli-script.c:690: current_ui->async = 0;
cli/cli-script.c:1697: current_ui->async = 0;
... because these will only return when execution next stops,
so the cleanup runs after, and undoes the thread change.
E.g., this infcall stops due to a breakpoint on another
thread, but MI still reverts back to the "--thread" thread:
(gdb)
b usleep
[...]
^done
(gdb)
thread 1
[...]
^done
=thread-selected,id="1"
(gdb)
-interpreter-exec --thread 1 console "print sleep (10)"
[...]
~"[Switching to Thread 0x7ffff6ffb700 (LWP 7818)]\n"
~"\n"
~"Thread 3 \"threads\" hit Breakpoint 2, usleep (useconds=1) at ../sysdeps/posix/usleep.c:26\n"
~"26\t struct timespec ts = { .tv_sec = (long int) (useconds / 1000000),\n"
*stopped,reason="breakpoint-hit",disp="keep",bkptno="2",frame={addr="0x00007ffff78f6030",func="usleep",args=[{name="useconds",value="1"}],file="../sysdeps/posix/usleep.c",fullname="/usr/src/debug/glibc-2.22/sysdeps/posix/usleep.c",line="26"},thread-id="3",stopped-threads="all",core="2"
&"The program stopped in another thread while making a function call from GDB.\n"
&"Evaluation of the expression containing the function\n"
&"(__sleep) will be abandoned.\n"
&"When the function is done executing, GDB will silently stop.\n"
^error,msg="The program stopped in another thread while making a function call from GDB.\nEvaluation of the expression containing the function\n(__sleep) will be abandoned.\nWhen the function is done executing, GDB will silently stop."
(gdb)
thread
[...]
~"[Current thread is 1 (Thread 0x7ffff7fc8700 (LWP 7813))]\n"
^done
(gdb)
Above should have been 3.
E.g., this user-defined command starts the program and stops in
thread 2.1, but MI still reverts back to the "--thread" thread:
(gdb) define foo
~">" inferior 2
~">" start
~">" end
(gdb)
info inferiors
~" Num Description Executable \n"
~"* 1 process 8216 /home/pedro/brno/pedro/gdb/tests/threads \n"
~" 2 <null> /home/pedro/brno/pedro/gdb/tests/threads \n"
^done
(gdb)
info threads
~" Id Target Id Frame \n"
~"* 1.1 Thread 0x7ffff7fc8700 (LWP 8216) \"threads\" main () at threads.c:54\n"
^done
(gdb)
-interpreter-exec --thread 1 console "foo"
~"[Switching to inferior 2 [<null>] (/home/pedro/brno/pedro/gdb/tests/threads)]\n"
[...]
~"\n"
~"Thread 2.1 \"threads\" hit Temporary breakpoint 3, main () at threads.c:54\n"
~"54\t long i = 0;\n"
*stopped,reason="breakpoint-hit",disp="del",bkptno="3",frame={addr="0x000000000040076e",func="main",args=[],file="threads.c",fullname="/home/pedro/brno/pedro/gdb/tests/threads.c",line="54"},thread-id="3",stopped-threads="all",core="7"
=breakpoint-deleted,id="3"
(gdb)
thread
&"thread\n"
~"[Current thread is 1.1 (Thread 0x7ffff7fc8700 (LWP 8216))]\n"
^done
(gdb)
While at it, "inferior 2" is a command that explicitly changes
the thread, but misses setting the new flag:
-interpreter-exec --thread 1 console "inferior 2"
~"[Switching to inferior 2 [process 8603] (/home/pedro/brno/pedro/gdb/tests/threads)]\n"
~"[Switching to thread 2.1 (Thread 0x7ffff7fc8700 (LWP 8603))] \n"
~"#0 main () at threads.c:54\n"
~"54\t long i = 0;\n"
^done
(gdb)
thread
&"thread \n"
~"[Current thread is 1.1 (Thread 0x7ffff7fc8700 (LWP 8599))]\n"
^done
(gdb)
It may be this requires setting the flag in most of the places
that we'd set the user-selected thread in the other approach,
not sure.
Thanks,
Pedro Alves