public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Jan Vrany <jan.vrany@labware.com>
To: Simon Marchi <simark@simark.ca>, gdb-patches@sourceware.org
Cc: Andrew Burgess <aburgess@redhat.com>
Subject: Re: [pushed] gdb/mi: consistently notify user when GDB/MI client uses -thread-select
Date: Mon, 21 Mar 2022 21:01:50 +0000	[thread overview]
Message-ID: <897bd508133687e4d30994deecdd87786d71334d.camel@labware.com> (raw)
In-Reply-To: <78570a7f-f6c0-5e1b-4178-c9ce401feab7@simark.ca>

On Mon, 2022-03-21 at 16:35 -0400, Simon Marchi wrote:
> On 2022-03-16 11:09, Jan Vrany via Gdb-patches wrote:
> > GDB notifies users about user selected thread changes somewhat
> > inconsistently as mentioned on gdb-patches mailing list here:
> > 
> >   https://urldefense.proofpoint.com/v2/url?u=https-3A__sourceware.org_pipermail_gdb-2Dpatches_2022-2DFebruary_185989.html&d=DwICaQ&c=sPZ6DeHLiehUHQWKIrsNwWp3t7snrE-az24ztT0w7Jc&r=WpFFGgYa98Yp-c29WHTCwU1wAGFBvszA6a4RzgpMSqc&m=qn1ryn0GnzccCli0TKe7kc6WpMiz1opcXfyT-fLWkIk&s=XoLasKCD9agRgS73PoGDnzPlKbo4_lL616HCUvldty0&e= 
> > 
> > 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://urldefense.proofpoint.com/v2/url?u=https-3A__sourceware.org_bugzilla_show-5Fbug.cgi-3Fid-3D20631&d=DwICaQ&c=sPZ6DeHLiehUHQWKIrsNwWp3t7snrE-az24ztT0w7Jc&r=WpFFGgYa98Yp-c29WHTCwU1wAGFBvszA6a4RzgpMSqc&m=qn1ryn0GnzccCli0TKe7kc6WpMiz1opcXfyT-fLWkIk&s=_9JOeNLk-p5CQtAtasdJbRyV5KK5tq1qLb_IxeKdmMw&e= 
> 
> Hi,
> 
> I see this on Ubuntu 20.04, am I the only one?

Weird. I just compiled GDB commit f55649cc and see no such failures:

> make check RUNTESTFLAGS='TRANSCRIPT=y  gdb.mi/user-select*.exp'
...
Running /home/jv/Projects/gdb/origin_master/gdb/testsuite/gdb.mi/user-selected-context-sync.exp ...

		=== gdb Summary ===

# of expected passes		419

I'll try on Ubuntu 20.04 tomorrow. 

Jan

> 
> FAIL: gdb.mi/user-selected-context-sync.exp: mode=all-stop: test_mi_thread_select: thread 1.2: -thread-select again, event on CLI, ensure no output CLI
> FAIL: gdb.mi/user-selected-context-sync.exp: mode=all-stop: test_mi_thread_select: thread 1.3: -thread-select again, event on CLI, ensure no output CLI
> FAIL: gdb.mi/user-selected-context-sync.exp: mode=non-stop: test_mi_thread_select: thread 1.2: -thread-select again, event on CLI, ensure no output CLI
> 
> Just the first one here:
> 
> -thread-select 2
> ^done,new-thread-id="2",frame={level="0",addr="0x00005555555551b8",func="child_sub_function",args=[],file="/home/smarchi/src/binutils-gdb/gdb/testsuite/gdb.mi/user-selected-context-
> sync.c",fullname="/home/smarchi/src/binutils-gdb/gdb/testsuite/gdb.mi/user-selected-context-sync.c",line="33",arch="i386:x86-64"}
> (gdb)
> PASS: gdb.mi/user-selected-context-sync.exp: mode=all-stop: test_mi_thread_select: thread 1.2: -thread-select again
> [Switching to thread 1.2 (Thread 0x7ffff7d99700 (LWP 1763981))]
> #0  child_sub_function () at /home/smarchi/src/binutils-gdb/gdb/testsuite/gdb.mi/user-selected-context-sync.c:33
> 33          dummy = !dummy; /* thread loop line */
> print 666
> $9 = 666
> (gdb) FAIL: gdb.mi/user-selected-context-sync.exp: mode=all-stop: test_mi_thread_select: thread 1.2: -thread-select again, event on CLI, ensure no output CLI
> 
> Simon


  reply	other threads:[~2022-03-21 21:01 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-16 15:09 Jan Vrany
2022-03-21 20:35 ` Simon Marchi
2022-03-21 21:01   ` Jan Vrany [this message]
2022-03-22 14:37     ` Jan Vrany
2022-03-23 12:36       ` Simon Marchi
2022-03-23 15:13         ` Jan Vrany
2022-03-23 15:16           ` Simon Marchi
2022-03-23 16:09             ` Jan Vrany
2022-03-23 19:09               ` Andrew Burgess
2022-03-23 19:11                 ` Andrew Burgess
2022-03-23 20:33                 ` Jan Vrany
2022-03-24 14:47                 ` Simon Marchi
2022-03-24 18:52                   ` [PATCHv2] gdb/mi: fix use after free of frame_info causing spurious notifications Andrew Burgess
2022-03-24 20:32                     ` Simon Marchi
2022-03-29 10:10                       ` Andrew Burgess
2022-03-24 15:00               ` [pushed] gdb/mi: consistently notify user when GDB/MI client uses -thread-select Simon Marchi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=897bd508133687e4d30994deecdd87786d71334d.camel@labware.com \
    --to=jan.vrany@labware.com \
    --cc=aburgess@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=simark@simark.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).