Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Andrew Burgess <andrew.burgess@embecosm.com>
To: Pedro Alves <palves@redhat.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCHv3 2/2] gdb/remote: Restore support for 'S' stop reply packet
Date: Mon, 02 Mar 2020 19:25:00 -0000	[thread overview]
Message-ID: <20200302192450.GU3317@embecosm.com> (raw)
In-Reply-To: <9af55184-812e-ecb6-a3ba-bb89106b82fb@redhat.com>

* Pedro Alves <palves@redhat.com> [2020-03-02 19:07:33 +0000]:

> On 3/2/20 3:19 PM, Andrew Burgess wrote:
> > * Pedro Alves <palves@redhat.com> [2020-03-02 12:25:12 +0000]:
> 
> >> "inferior" -> "target".
> >>
> >> The "inferior" -> "target" distinction I'm making in these
> >> small remarks above matters, because say the remote server
> >> is debugging two single-threaded inferiors.  We still want to
> >> (and do) warn.
> > 
> > I hadn't really considered this case, however, this raises a
> > follow on question:
> > 
> > Before entering the target wait code we call
> > switch_to_inferior_no_thread, partly, as I understand it because
> > having inferior_ptid pointing at a thread leads to invalid code
> > that relies on this thread being _the_ event thread, when really we
> > need to extract the inferior and thread-id from the stop event.
> 
> The main reason we switch the inferior is that the target stack is a
> property of the inferior now.  Each inferior has its own target stack
> (see inferior::m_target_stack).  Note, target stack, not target.
> A single target may be used by different inferiors.  E.g.,
> when remote debugging, if you're debugging two inferiors under control
> of the same gdbserver, each inferior will have a pointer to the
> same remote target instance in its target stack.
> 
> To call any target method, we must be sure to make the relevant
> inferior current, because target methods consult the inferior's
> target stack to know which target to call.  When target methods
> defer to the target beneath, they'll again consult the target stack
> stored in the current inferior (the "this->beneath ()->foo()" calls
> in target-delegates.c).
> 
> So to call the target_wait method to poll events out of some target,
> you need to switch to some representative inferior that uses the
> process_stratum target you want to poll.
> 
> However, a reason we need to switch to all inferiors in turn and not
> just a subset sufficient to cover all instantiated process_stratum
> targets, is the strata above process_stratum, like record_stratum.
> Those targets aren't shared between inferiors, and they generate
> target events as well.
> 
> I suspect it may be possible to come up with a cleaner design here,
> but I haven't been able to come up with one that's as simple as the
> current one, given all the constraints of the rest of current
> gdb's design.  I didn't try very hard though.
> 
> Since we're switching the inferior around, the question 
> of -- which thread in the inferior should we pick? -- immediately
> arises.  And the best answer is "none".  Switching to no-thread also
> has the property that it "catches" target backends relying on
> inferior_ptid to infer things about the next stopping event,
> when they should not.  (Another point that helps with seeing how that's
> wrong is to consider that inferior_ptid includes no field
> that would indicate which target instance the ptid came from.
> So e.g., if you're debugging against two remote stubs, it could well
> be the case that when you get to target_wait, inferior_ptid points at
> a thread of the other target, even though it seemingly looks
> like a valid thread in the current target.)
> 
> > 
> > So, why do we allow the current_inferior to remain valid while we
> > perform the wait?  Instead, why don't we clear both current_inferior
> > and inferior_ptid, and then enter the wait code?
> 
> It's impossible to clear current_inferior with the current design.
> There must always be a current inferior.

Thanks for the explanation.

Andrew


  reply	other threads:[~2020-03-02 19:25 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-31  7:35 [PATCH] gdb/remote: Ask target for current thread if it doesn't tell us Andrew Burgess
2020-02-26 18:52 ` Andrew Burgess
2020-02-26 19:28 ` Pedro Alves
2020-02-27 16:17   ` [PATCHv2] gdb/remote: Restore support for 'S' stop reply packet Andrew Burgess
2020-02-27 19:46     ` Pedro Alves
2020-02-28 14:03       ` Andrew Burgess
2020-02-28 17:46         ` Pedro Alves
2020-03-02 11:54           ` [PATCHv3 0/2] " Andrew Burgess
     [not found]             ` <27befec6c761c43f2e1a9e59403644c198cbd75b.1583149853.git.andrew.burgess@embecosm.com>
2020-03-02 12:24               ` [PATCHv3 1/2] gdbserver: Add mechanism to prevent sending T stop packets Pedro Alves
2020-03-02 11:54           ` [PATCHv3 2/2] gdb/remote: Restore support for 'S' stop reply packet Andrew Burgess
2020-03-02 12:25             ` Pedro Alves
2020-03-02 15:19               ` Andrew Burgess
2020-03-02 19:07                 ` Pedro Alves
2020-03-02 19:25                   ` Andrew Burgess [this message]
2020-03-09 17:35             ` Tom Tromey
2020-03-10 19:05               ` Andrew Burgess
2020-03-11 16:23               ` Andrew Burgess
2020-03-11 18:02                 ` Tom Tromey

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=20200302192450.GU3317@embecosm.com \
    --to=andrew.burgess@embecosm.com \
    --cc=gdb-patches@sourceware.org \
    --cc=palves@redhat.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