Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Daniel Jacobowitz <drow@false.org>
To: Roland McGrath <roland@redhat.com>
Cc: Jan Kratochvil <jan.kratochvil@redhat.com>,
	Doug Evans <dje@google.com>,
		GDB Patches <gdb-patches@sourceware.org>,
	mark.kettenis@xs4all.nl
Subject: Re: [patch] Fix Linux attach to signalled/stopped processes
Date: Mon, 14 Apr 2008 15:09:00 -0000	[thread overview]
Message-ID: <20080414143448.GA32227@caradoc.them.org> (raw)
In-Reply-To: <20080412000155.7F07A26FA5E@magilla.localdomain>

On Fri, Apr 11, 2008 at 05:01:55PM -0700, Roland McGrath wrote:
> Ah, right.  You can also do:
> 
> 	PTRACE_ATTACH		-> pending SIGSTOP
> 	... if running		-> stopped, no pending SIGSTOP
> 	... if stopped		-> still stopped, pending SIGSTOP
> 	tkill (SIGSTOP, tid)	-> pending SIGSTOP
> 
> 	PTRACE_CONT, tid, 0	-> if not stopped the first time yet, ESRCH
> 				-> if stopped, wakes up, dequeues SIGSTOP
> 	wait			-> always see it stop
> 
> You just don't know whether you'll see one more spurious SIGSTOP or not.
> (Once you've waited, you can synchronously check /proc, but that doesn't
> tell you whether it was your spurious one or just an outside one sent
> right now.)

Isn't this still racy?  SIGCONT wakeups happen synchronously, but
SIGSTOP stops do not.  After the PTRACE_ATTACH the thread might be
running with a pending SIGSTOP.  Then the tkill has no effect, and
if the thread stops between the tkill and the PTRACE_CONT it will have
no reason to stop again.

Fixing the race is not hard though: grub around in /proc for status.
First PTRACE_ATTACH, which sends a SIGSTOP.  Then check /proc.  If it
is running, it must have a pending SIGSTOP; we can wait for it so skip
the tkill and the PTRACE_CONT.  If it is not running, it may or may
not have a pending SIGSTOP.  So do as you described above with tkill
and PTRACE_CONT.

This has the same problem of using SIGSTOP in that it may stop other
threads of the process.  But it avoids using SIGCONT, so it will not
wake up other threads of the process.  For GDB's purposes, that is
currently good enough - strictly better than before, while the
SIGCONT approach could cause other threads to run before we attached
to them.

Thanks again for the assistance.  This conversation gave me a useful
insight into one of those things you already probably know: GDB's use
of SIGSTOP instead of another signal is not significant.  We want the
process to be signalled, that's all.  Since each SIGSTOP we send stops
the whole group, I suspect if I checked using PTRACE_GETSIGINFO I
would find most of the threads in finish_stop and not fully ptrace
controllable.  To preserve our last vestiges of LinuxThreads support
we have to continue sending SIGSTOP once per thread, or else use a
different signal.

I'm not going to make that change right now, but I will add some
comments about it.  We could probably use an RT signal at each point
we want a stop.

-- 
Daniel Jacobowitz
CodeSourcery


  reply	other threads:[~2008-04-14 14:35 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-31 22:07 Doug Evans
2008-04-02  0:01 ` Jan Kratochvil
2008-04-02  0:07   ` Roland McGrath
2008-04-10 15:30     ` Daniel Jacobowitz
2008-04-10 15:37       ` Jan Kratochvil
2008-04-10 15:49         ` Daniel Jacobowitz
2008-04-10 16:00           ` Jan Kratochvil
2008-04-10 19:59             ` Daniel Jacobowitz
2008-04-10 15:39   ` Daniel Jacobowitz
2008-04-10 16:00     ` Jan Kratochvil
2008-04-10 19:48       ` Daniel Jacobowitz
2008-04-11  8:46       ` Roland McGrath
2008-04-11 17:46         ` Jan Kratochvil
2008-04-11 19:01           ` Daniel Jacobowitz
2008-04-12  7:58           ` Roland McGrath
2008-04-14 15:09             ` Daniel Jacobowitz [this message]
2008-04-14 15:31               ` Daniel Jacobowitz
2008-04-15 22:14                 ` Jan Kratochvil
2008-05-01 18:50                   ` Daniel Jacobowitz
2008-07-05  8:48                     ` Jan Kratochvil
2008-07-05 13:48                       ` Daniel Jacobowitz
2008-09-24 12:46                 ` Andreas Schwab
2008-09-26  3:52                   ` Jan Kratochvil
2008-09-26 13:00                     ` Daniel Jacobowitz
2008-09-28 11:43                       ` Jan Kratochvil
2008-09-28 14:58                         ` Daniel Jacobowitz
2008-04-15  8:14               ` Roland McGrath
2008-04-15 13:02                 ` Daniel Jacobowitz
2008-04-16  7:01                   ` Roland McGrath
2008-04-11 22:20         ` Daniel Jacobowitz
2008-04-11 22:21           ` Pedro Alves
2008-04-11 22:25             ` Daniel Jacobowitz
2008-04-12  0:02               ` Pedro Alves
2008-04-12  0:19                 ` Pedro Alves
2008-04-13  9:35                   ` Pedro Alves
2008-04-13 13:40                     ` Pedro Alves
2008-04-12 16:38           ` Roland McGrath
2008-04-12 16:43           ` Eli Zaretskii
  -- strict thread matches above, loose matches on Subject: below --
2007-06-06 14:34 Jan Kratochvil
2007-06-11 13:44 ` Jan Kratochvil
2007-06-15 18:02 ` Mark Kettenis
2007-06-26 22:40   ` Jan Kratochvil
2007-06-27  0:13     ` Mark Kettenis
2007-06-27 11:59       ` Jan Kratochvil
2007-06-27 18:30         ` Mark Kettenis
2007-06-30 11:45         ` Jan Kratochvil
2007-06-30 11:57           ` Eli Zaretskii
2007-06-30 17:15             ` Jan Kratochvil
2007-06-30 18:52               ` Eli Zaretskii
     [not found]               ` <200706301852.l5UIq8ek010536@brahms.sibelius.xs4all.nl>
2007-07-01  3:17                 ` Eli Zaretskii
2007-07-01  9:34                   ` Mark Kettenis
2007-07-01 10:03                     ` Jan Kratochvil

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=20080414143448.GA32227@caradoc.them.org \
    --to=drow@false.org \
    --cc=dje@google.com \
    --cc=gdb-patches@sourceware.org \
    --cc=jan.kratochvil@redhat.com \
    --cc=mark.kettenis@xs4all.nl \
    --cc=roland@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