public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: Doug Evans <dje@google.com>
Cc: gdb-patches <gdb-patches@sourceware.org>,
	       Stan Shebs <stanshebs@earthlink.net>
Subject: Re: Questions on commit 6c95b8df7fef5273da71c34775918c554aae0ea8
Date: Fri, 03 Oct 2014 17:14:00 -0000	[thread overview]
Message-ID: <542ED988.8050407@redhat.com> (raw)
In-Reply-To: <21547.2428.934404.571592@ruffy2.mtv.corp.google.com>

On 09/30/2014 08:50 PM, Doug Evans wrote:
> Pedro Alves writes:
>  > On 09/20/2014 07:39 PM, Doug Evans wrote:
>  > > [Ugh, bad To address on first try.]
>  > > 
>  > > Hi.
>  > > 
>  > > While looking into removing lwp_list from gdb (akin to what I did for
>  > > gdbserver) I found that several bits of target code are calling
>  > > init_thread_list
>  > > (grep init_thread_list *.c).
>  > > Maybe there's the odd case where target code would need to do this,
>  > > but normally when should target code *ever* do this?
>  > 
>  > > To try to assist you with getting a handle on my confusion, consider
>  > > remote.c:extended_remote_create_inferior_1 from gdb 6.8:
>  > > 
>  > >   /* Clean up from the last time we were running.  */
>  > >   init_thread_list ();
>  > >   init_wait_for_inferior ();
>  > > 
>  > > Now look at what's there today:
>  > > 
>  > >   if (!have_inferiors ())
>  > >     {
>  > >       /* Clean up from the last time we ran, before we mark the target
>  > >          running again.  This will mark breakpoints uninserted, and
>  > >          get_offsets may insert breakpoints.  */
>  > >       init_thread_list ();
>  > >       init_wait_for_inferior ();
>  > >     }
>  > 
>  > > 
>  > > I think(!) there may be multiple ways to look at all of this as being
>  > > wrong, so pick your favorite, but here's one way: What does it matter
>  > > whether there are other inferiors as to whether
>  > > remote.c:extended_remote_create_inferior has to "clean up from the
>  > > last time we were running"?
>  > > 
>  > > Obviously we can't call init_thread_list if there are other inferiors,
>  > > but why are we calling init_thread_list here at all?  Why isn't this
>  > > state being managed by gdb itself (inf*.c or some such)?  I can
>  > > imagine one can look at this as just being still a work in progress on
>  > > the way to proper multi-target support.  It's stil a bit odd though to
>  > > have taken this step this way, so I'm hoping for some clarification.
>  > 
>  > Really not sure what sort of answer you're looking for.
> 
> The most succinct way of expressing what I'm looking for that I can
> think of is that I want to understand this code, and I don't.
> There are several instances of the !have_inferiors() check, I picked
> this one because it seemed like as good a choice as any.

init_thread_list does two things:

 - wipes all threads.
 - resets the thread id counter back to 0, so the next
   thread is gdb thread number 1.

The main point of calling init_thread_list if there are
no live inferiors, is to reset the thread id counter.
That is so that with "run; kill; run", you end up with
the main thread being gdb thread number 1, in both
runs.

Now, if there are other live inferiors, then we shouldn't wipe
their threads.  And as gdb thread ids are global currently,
not private per-inferior/process, then we obviously shouldn't
reset the  thread id counter either.

The reason this isn't managed by the core itself, is I believe
that nobody has tried to do that yet.

>  > > Maybe it's a simple
>  > > oversight, but I think (emphasis on THINK, I could certainly be
>  > > missing something) we need to take a step back and ask why this code
>  > > is there at all.  Putting this code in target routines gives us a lot
>  > > of flexibility, but the cost is more mental load (for lack of a better
>  > > phrase) and more touch points when trying to fix/improve core gdb, and
>  > > I'm getting the impression that the pendulum has swung too far towards
>  > > putting general housekeeping operations in target code.
>  > 
>  > Huh?  I think you're getting this backwards.  You make it sound like
>  > we've been adding more of this stuff in target code ("putting"),
>  > while instead these are _ancient_ code that over the years we've
>  > been cleaning up.
> 
> Well, yes we have been adding non-target-specific code to target files.
> E.g., I don't see how the trustability of compilers to emit good
> data for prologues varies by target, and yet we're doing different things
> in amd64_skip_prologue vs arm_skip_prologue w.r.t. gcc vs clang.

Well, on the compiler side, prologue emission
is tied to the backend.  Certainly it's easy to picture that different
backends on the compiler side vary in quality.

For example, I recall that on GCC,
there was a long term conversion of prologue emission from text
to rtl.  A quick google search finds:

 https://gcc.gnu.org/ml/gcc/2011-06/msg00222.html
and
 https://gcc.gnu.org/ml/gcc-patches/2011-07/msg00685.html

for example.

I don't know whether something like that affects the cases
in question or not.  I'm just saying that I could see there
being a reason.

> I could certainly be wrong here, but I don't think so.
> Can gcc get this right for ARM enough that we accept the risk of the
> odd bug whereas with AMD64 we've chosen to not accept this risk?
> Here's a case where some cleanup is needed, but this is relatively
> freshly added code.
> [From one perspective *-tdep files are different than
> target files like remote.c. But it's still a case of balancing
> target-specific and non-target-specific code.]
> 
> Plus, pending an understanding of the !have_inferiors() check above (and
> elsewhere), it's not clear to me we have always been cleaning up. 

I honestly fail to see the relation and I don't think it's useful
to try to generalize like that.  Each case is a different case.

If you find patterns that can be factored out, and find ways to
clean things up, then please go for it.

Thanks,
Pedro Alves

  reply	other threads:[~2014-10-03 17:14 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-20 18:39 Doug Evans
2014-09-26 16:51 ` Pedro Alves
2014-09-30 19:50   ` Doug Evans
2014-10-03 17:14     ` Pedro Alves [this message]
2014-10-19 22:57       ` Doug Evans
2014-10-24 16:54         ` Pedro Alves

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=542ED988.8050407@redhat.com \
    --to=palves@redhat.com \
    --cc=dje@google.com \
    --cc=gdb-patches@sourceware.org \
    --cc=stanshebs@earthlink.net \
    /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).