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, Richard Bunt <Richard.Bunt@arm.com>
Subject: Re: [PATCH] gdb: Don't ignore all SIGSTOP when the signal handler is set to pass
Date: Thu, 03 Oct 2019 15:14:00 -0000	[thread overview]
Message-ID: <20191003151434.GI4962@embecosm.com> (raw)
In-Reply-To: <87066547-f991-9597-0ead-7a52b05ee2c3@redhat.com>

* Pedro Alves <palves@redhat.com> [2019-10-03 13:59:14 +0100]:

> On 9/10/19 6:37 PM, Andrew Burgess wrote:
> > It was observed that in a multi-threaded application on GNU/Linux,
> > that if the user has set the SIGSTOP to be pass (using GDB's handle
> > command) then the inferior would hang upon hitting a breakpoint.
> > 
> > What happens is that when a thread hits the breakpoint GDB tries to
> > stop all of the other threads by sending them a SIGSTOP and setting
> > the stop_requested flag in the target_ops structure - this can be seen
> > in infrun.c:stop_all_threads.
> > 
> > GDB then waits for all of the other threads to stop.
> > 
> > When the SIGSTOP event arrives we eventually end up in
> > linux-nat.c:linux_nat_filter_event, which has the job of deciding if
> > the event we're looking at (the SIGSTOP arriving in this case) is
> > something that should be reported back to the core of GDB.
> > 
> > One of the final actions of this function is to check if we stopped
> > due to a signal, and if we did, and the signal has been set to 'pass'
> > by the user then we ignore the event and resume the thread.
> > 
> > This code already has some conditions in place that mean the event is
> > reported to GDB even if the signal is in the set of signals to be
> > passed to the inferior.
> > 
> > In this commit I extend this condition to such that:
> > 
> >   If the signal is a SIGSTOP, and the thread's stop_requested flag is
> >   set (indicating we're waiting for the thread to stop with a SIGSTOP)
> >   then we should report this SIGSTOP to GDB and not pass it to the
> >   inferior.
> > 
> > With this change in place the test now passes.  Regression tested on
> > x86-64 GNU/Linux with no regressions.
> 
> Indeed, makes sense.  
> 
> I checked that gdbserver passes the new test too.  (It knows to always
> report an event when gdb tries to stop a thread with 'vCont;t'.)
> 
> > +/* The worker thread just spins forever.  */
> > +void*
> > +thread_worker (void *payload)
> > +{
> > +  while (1)
> > +    {
> > +      sleep (1);
> > +    }
> > +
> > +  return NULL;
> > +}
> > +
> 
> > +/* A place for GDB to place a breakpoint.   */
> > +void
> > +breakpt ()
> > +{
> > +  asm ("" ::: "memory");
> 
> I wonder whether this barrier is a good idea, given
> that it limits portability to gcc and clang.
> 
> I checked that both clang and gcc still manage to
> eliminate the function with "-flto -O2", the barrier
> didn't help then.  '__attribute__((used))' instead
> of the barrier works though.
> 
> > +}
> 
> > +
> > +/* Create a worker thread that just spins forever, then enter a loop
> > +   periodically calling the BREAKPT function.  */
> > +int main() {
> 
> GNU formatting.
> 
> > +  spawn_thread ();
> > +
> > +  while (1)
> > +    {
> > +      sleep (1);
> > +
> > +      breakpt ();
> > +    }
> > +
> > +  return 0;
> > +}
> 
> It's better to avoid that the testcase really runs forever, in case GDB
> crashes and the system doesn't kill the process.  Easily fixed with
> an "alarm" call at the top of main.
> 
> LGTM otherwise.
> 
> BTW, FYI, I saw this:
> 
> $ git am /tmp/sigstop.mbox
> Applying: gdb: Don't ignore all SIGSTOP when the signal handler is set to pass
> .git/rebase-apply/patch:104: new blank line at EOF.
> +
> .git/rebase-apply/patch:162: new blank line at EOF.
> +
> warning: 2 lines add whitespace errors.
> 

I pushed this patch with the fixes you identified above.

Thanks,
Andrew


      reply	other threads:[~2019-10-03 15:14 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-10 17:38 Andrew Burgess
2019-09-26 23:06 ` Andrew Burgess
2019-10-03 11:55   ` Andrew Burgess
2019-10-03 12:59 ` Pedro Alves
2019-10-03 15:14   ` Andrew Burgess [this message]

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=20191003151434.GI4962@embecosm.com \
    --to=andrew.burgess@embecosm.com \
    --cc=Richard.Bunt@arm.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