binutils-gdb/gdb/python
Jan Vrany a2757c4ed6 gdb/mi: consistently notify user when GDB/MI client uses -thread-select
GDB notifies users about user selected thread changes somewhat
inconsistently as mentioned on gdb-patches mailing list here:

  https://sourceware.org/pipermail/gdb-patches/2022-February/185989.html

Consider GDB debugging a multi-threaded inferior with both CLI and GDB/MI
interfaces connected to separate terminals.

Assuming inferior is stopped and thread 1 is selected, when a thread
2 is selected using '-thread-select 2' command on GDB/MI terminal:

    -thread-select 2
    ^done,new-thread-id="2",frame={level="0",addr="0x00005555555551cd",func="child_sub_function",args=[],file="/home/jv/Projects/gdb/users_jv_patches/gdb/testsuite/gdb.mi/user-selected-context-sync.c",fullname="/home/uuu/gdb/gdb/testsuite/gdb.mi/user-selected-context-sync.c",line="30",arch="i386:x86-64"}
    (gdb)

and on CLI terminal we get the notification (as expected):

    [Switching to thread 2 (Thread 0x7ffff7daa640 (LWP 389659))]
    #0  child_sub_function () at /home/uuu/gdb/gdb/testsuite/gdb.mi/user-selected-context-sync.c:30
    30        volatile int dummy = 0;

However, now that thread 2 is selected, if thread 1 is selected
using 'thread-select --thread 1 1' command on GDB/MI terminal
terminal:

   -thread-select --thread 1 1
   ^done,new-thread-id="1",frame={level="0",addr="0x0000555555555294",func="main",args=[],file="/home/jv/Projects/gdb/users_jv_patches/gdb/testsuite/gdb.mi/user-selected-context-sync.c",fullname="/home/jv/Projects/gdb/users_jv_patches/gdb/testsuite/gdb.mi/user-selected-context-sync.c",line="66",arch="i386:x86-64"}
   (gdb)

but no notification is printed on CLI terminal, despite the fact
that user selected thread has changed.

The problem is that when `-thread-select --thread 1 1` is executed
then thread is switched to thread 1 before mi_cmd_thread_select () is
called, therefore the condition "inferior_ptid != previous_ptid"
there does not hold.

To address this problem, we have to move notification logic up to
mi_cmd_execute () where --thread option is processed and notify
user selected contents observers there if context changes.

However, this in itself breaks GDB/MI because it would cause context
notification to be sent on MI channel. This is because by the time
we notify, MI notification suppression is already restored (done in
mi_command::invoke(). Therefore we had to lift notification suppression
logic also up to mi_cmd_execute (). This change in made distinction
between mi_command::invoke() and mi_command::do_invoke() unnecessary
as all mi_command::invoke() did (after the change) was to call
do_invoke(). So this patches removes do_invoke() and moves the command
execution logic directly to invoke().

With this change, all gdb.mi tests pass, tested on x86_64-linux.

Co-authored-by: Andrew Burgess <aburgess@redhat.com>
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=20631
2022-03-16 15:08:22 +00:00
..
lib/gdb gdb/python/mi: create MI commands using python 2022-03-14 14:09:09 +00:00
py-all-events.def Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
py-arch.c Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
py-auto-load.c Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
py-block.c Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
py-bpevent.c Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
py-breakpoint.c Change how Python architecture and language are handled 2022-01-26 06:49:51 -07:00
py-cmd.c Change how Python architecture and language are handled 2022-01-26 06:49:51 -07:00
py-connection.c Change how Python architecture and language are handled 2022-01-26 06:49:51 -07:00
py-continueevent.c Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
py-event-types.def Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
py-event.c Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
py-event.h Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
py-events.h Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
py-evtregistry.c Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
py-evts.c Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
py-exitedevent.c Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
py-finishbreakpoint.c gdb: add a symbol* argument to get_return_value 2022-02-15 09:52:37 +00:00
py-frame.c Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
py-framefilter.c gdb: remove SYMBOL_IS_ARGUMENT macro 2022-02-06 16:03:46 -05:00
py-function.c Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
py-gdb-readline.c Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
py-inferior.c Change how Python architecture and language are handled 2022-01-26 06:49:51 -07:00
py-infevents.c Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
py-infthread.c Fix maybe-uninitialized warning in py-infthread.c 2022-02-28 10:53:13 -07:00
py-instruction.c Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
py-instruction.h Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
py-lazy-string.c Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
py-linetable.c gdb: remove SYMTAB_LINETABLE macro, add getter/setter 2022-02-06 15:48:19 -05:00
py-membuf.c Change how Python architecture and language are handled 2022-01-26 06:49:51 -07:00
py-micmd.c gdb/mi: consistently notify user when GDB/MI client uses -thread-select 2022-03-16 15:08:22 +00:00
py-newobjfileevent.c Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
py-objfile.c Remove host_hex_value 2022-02-04 07:37:22 -07:00
py-param.c gdb/python: improve the auto help text for gdb.Parameter 2022-01-26 22:00:20 +00:00
py-prettyprint.c Always call the wrap_here method 2022-01-26 15:19:13 -07:00
py-progspace.c gdb: remove COMPUNIT_OBJFILE macro 2022-02-06 15:48:18 -05:00
py-record-btrace.c Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
py-record-btrace.h Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
py-record-full.c Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
py-record-full.h Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
py-record.c Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
py-record.h Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
py-ref.h Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
py-registers.c Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
py-signalevent.c Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
py-stopevent.c Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
py-stopevent.h Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
py-symbol.c gdb: remove SYMBOL_LINE macro 2022-02-06 16:03:47 -05:00
py-symtab.c gdb: remove SYMTAB_OBJFILE macro 2022-02-06 16:03:46 -05:00
py-threadevent.c Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
py-tui.c Change how Python architecture and language are handled 2022-01-26 06:49:51 -07:00
py-type.c gdb/python: add Type.is_signed property 2022-03-07 19:42:08 +00:00
py-unwind.c Change how Python architecture and language are handled 2022-01-26 06:49:51 -07:00
py-utils.c gdb/python/mi: create MI commands using python 2022-03-14 14:09:09 +00:00
py-value.c gdb/python: allow Value.format_string to return styled output 2022-02-07 16:52:47 +00:00
py-varobj.c Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
py-xmethods.c Change how Python architecture and language are handled 2022-01-26 06:49:51 -07:00
python-config.py gdb: re-format Python files using black 21.4b0 2021-05-07 10:56:20 -04:00
python-internal.h gdb/python/mi: create MI commands using python 2022-03-14 14:09:09 +00:00
python.c gdb/python/mi: create MI commands using python 2022-03-14 14:09:09 +00:00
python.h Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00