public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Andrew Burgess <andrew.burgess@embecosm.com>
To: "Saiapova, Natalia" <natalia.saiapova@intel.com>
Cc: 'Kevin Buettner' <kevinb@redhat.com>,
	Natalia Saiapova via Gdb-patches <gdb-patches@sourceware.org>
Subject: Re: [PATCH v2 4/6] gdb/infrun: in condition evaluation wait only for the current inferior.
Date: Tue, 2 Mar 2021 12:17:51 +0000	[thread overview]
Message-ID: <20210302121751.GR265215@embecosm.com> (raw)
In-Reply-To: <SN6PR11MB34061638A30BD2ABA282CCD38D190@SN6PR11MB3406.namprd11.prod.outlook.com>

* Saiapova, Natalia via Gdb-patches <gdb-patches@sourceware.org> [2020-10-26 12:11:06 +0000]:

> Hi Kevin,
> 
> Thank you for looking into this! See my answer below.
> 
> Regards,
> Natalia
> > -----Original Message-----
> > From: Kevin Buettner <kevinb@redhat.com>
> > Sent: Monday, October 19, 2020 4:44 AM
> > To: Natalia Saiapova via Gdb-patches <gdb-patches@sourceware.org>
> > Cc: Saiapova, Natalia <natalia.saiapova@intel.com>
> > Subject: Re: [PATCH v2 4/6] gdb/infrun: in condition evaluation wait only for the
> > current inferior.
> > 
> > Hi Natalia,
> > 
> > I have a question about this commit.  See below.
> > 
> > On Fri,  9 Oct 2020 13:27:16 +0200
> > Natalia Saiapova via Gdb-patches <gdb-patches@sourceware.org> wrote:
> > 
> > > In the middle of a condition evaluation, to successfully finish the
> > > inferior call we need to wait for events from the current thread.
> > > Otherwise, a pending event from another thread might be taken and
> > > the inferior call is abandoned.
> > >
> > > gdb/ChangeLog:
> > > 2020-08-26  Natalia Saiapova  <natalia.saiapova@intel.com>
> > > 	    Tankut Baris Aktemur <tankut.baris.aktemur@intel.com>
> > >
> > > 	* infrun.c (do_target_wait): Match an inferior PID with the
> > > 	expected PID.
> > > 	(fetch_inferior_event): In condition evaluation, wait for the
> > > 	event from the current inferior.
> > >
> > > Co-authored-by: Natalia Saiapova <natalia.saiapova@intel.com>
> > > Co-authored-by: Tankut Baris Aktemur <tankut.baris.aktemur@intel.com>
> > >
> > > Signed-off-by: Natalia Saiapova <natalia.saiapova@intel.com>
> > > ---
> > >  gdb/infrun.c | 17 +++++++++++++----
> > >  1 file changed, 13 insertions(+), 4 deletions(-)
> > >
> > > diff --git a/gdb/infrun.c b/gdb/infrun.c
> > > index 91271c2ddbe..d260eb6e3a7 100644
> > > --- a/gdb/infrun.c
> > > +++ b/gdb/infrun.c
> > > @@ -3565,10 +3565,11 @@ do_target_wait (ptid_t wait_ptid,
> > execution_control_state *ecs,
> > >       polling the rest of the inferior list starting from that one in a
> > >       circular fashion until the whole list is polled once.  */
> > >
> > > -  auto inferior_matches = [&wait_ptid] (inferior *inf)
> > > +  ptid_t wait_pid_ptid {wait_ptid.pid ()};
> > > +  auto inferior_matches = [&wait_pid_ptid] (inferior *inf)
> > >      {
> > > -      return (inf->process_target () != NULL
> > > -	      && ptid_t (inf->pid).matches (wait_ptid));
> > > +      return (inf->process_target () != nullptr
> > > +	      && ptid_t (inf->pid).matches (wait_pid_ptid));
> > >      };
> > 
> > I'm puzzled by the changes above.  Can you explain what this is
> > about?  (And perhaps add a comment...)
> 
> When we come here from the infcall inside the condition, the
> wait_ptid has a form {non-zero, non-zero, zero}, which corresponds
> to the thread started the infcall. So, when we construct a ptid via
> ptid_t (inf->pid) in inferior_matches function, it does not match
> the wait_ptid. That leads to ecs->ws.kind = TARGET_WAITKIND_IGNORE
> and we are not getting the event. But we wait for an event from the
> thread which has started the infcall, so until we get one we are in
> an infinite loop.
> 
> This code looks like the intention here is to find a matching
> inferior, so we are interested only in the PID part of the
> wait_ptid. Thus, I made the change. Does this make sense to you?

This describes what, but not why.  You earlier change in
user_visible_resume_ptid, which I'm guessing relates to this change
returned the inferior_ptid.  But that's not the only path by which we
might return inferior_ptid.  So its not clear why this change runs
into problems, but other cases don't.

Also I agree with Kevin that this probably needs explaining with
comments in the code.

Thanks,
Andrew


> 
> > 
> > >
> > >    /* First see how many matching inferiors we have.  */
> > > @@ -3906,7 +3907,15 @@ fetch_inferior_event ()
> > >        = make_scoped_restore (&execution_direction,
> > >  			     target_execution_direction ());
> > >
> > > -    if (!do_target_wait (minus_one_ptid, ecs, TARGET_WNOHANG))
> > > +    ptid_t waiton_ptid = minus_one_ptid;
> > > +
> > > +    /* If the thread is in the middle of the condition evaluation,
> > > +       wait for the event from the current inferior.  */
> > > +    if (inferior_ptid != null_ptid
> > > +	&& inferior_thread ()->control.in_cond_eval)
> > > +      waiton_ptid = inferior_ptid;
> > > +
> > > +    if (!do_target_wait (waiton_ptid, ecs, TARGET_WNOHANG))
> > >        return;
> > >
> > >      gdb_assert (ecs->ws.kind != TARGET_WAITKIND_IGNORE);
> > > --
> > > 2.17.1
> > >
> > > Intel Deutschland GmbH
> > > Registered Address: Am Campeon 10-12, 85579 Neubiberg, Germany
> > > Tel: +49 89 99 8853-0, www.intel.de
> > > Managing Directors: Christin Eisenschmid, Gary Kershaw
> > > Chairperson of the Supervisory Board: Nicole Lau
> > > Registered Office: Munich
> > > Commercial Register: Amtsgericht Muenchen HRB 186928
> > >
> 
> Intel Deutschland GmbH
> Registered Address: Am Campeon 10-12, 85579 Neubiberg, Germany
> Tel: +49 89 99 8853-0, www.intel.de
> Managing Directors: Christin Eisenschmid, Gary Kershaw
> Chairperson of the Supervisory Board: Nicole Lau
> Registered Office: Munich
> Commercial Register: Amtsgericht Muenchen HRB 186928
> 

  reply	other threads:[~2021-03-02 12:17 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20200831123519.16232-1-natalia.saiapova () intel ! com>
2020-10-09 11:27 ` [PATCH v2 0/6] Fix inferior calls from breakpoint condition Natalia Saiapova
2020-10-09 11:27   ` [PATCH v2 1/6] gdb: add in_cond_eval field to thread_control_state struct Natalia Saiapova
2021-03-02 10:43     ` Andrew Burgess
2020-10-09 11:27   ` [PATCH v2 2/6] gdb/infrun: in condition evaluation resume only current thread Natalia Saiapova
2021-03-02 11:15     ` Andrew Burgess
2020-10-09 11:27   ` [PATCH v2 3/6] gdb/infcall: in condition evaluation register target back after infcall Natalia Saiapova
2020-10-19  0:53     ` Kevin Buettner
2021-03-02 11:26     ` Andrew Burgess
2020-10-09 11:27   ` [PATCH v2 4/6] gdb/infrun: in condition evaluation wait only for the current inferior Natalia Saiapova
2020-10-19  1:44     ` Kevin Buettner
2020-10-26 12:11       ` Saiapova, Natalia
2021-03-02 12:17         ` Andrew Burgess [this message]
2020-10-09 11:27   ` [PATCH v2 5/6] gdb/infrun: in condition evaluation do not stop all threads Natalia Saiapova
2020-10-09 11:27   ` [PATCH v2 6/6] gdb/testsuite: add tests for inferior calls in breakpoint conditions Natalia Saiapova
2020-10-12  0:49   ` [PATCH v2 0/6] Fix inferior calls from breakpoint condition Kevin Buettner

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=20210302121751.GR265215@embecosm.com \
    --to=andrew.burgess@embecosm.com \
    --cc=gdb-patches@sourceware.org \
    --cc=kevinb@redhat.com \
    --cc=natalia.saiapova@intel.com \
    /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).