From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14727 invoked by alias); 27 Jun 2007 16:01:41 -0000 Received: (qmail 14697 invoked by uid 22791); 27 Jun 2007 16:01:36 -0000 X-Spam-Check-By: sourceware.org Received: from sibelius.xs4all.nl (HELO brahms.sibelius.xs4all.nl) (82.92.89.47) by sourceware.org (qpsmtpd/0.31) with ESMTP; Wed, 27 Jun 2007 16:01:32 +0000 Received: from brahms.sibelius.xs4all.nl (kettenis@localhost.sibelius.xs4all.nl [127.0.0.1]) by brahms.sibelius.xs4all.nl (8.14.0/8.14.0) with ESMTP id l5RG1Klb012737; Wed, 27 Jun 2007 18:01:20 +0200 (CEST) Received: (from kettenis@localhost) by brahms.sibelius.xs4all.nl (8.14.0/8.14.0/Submit) id l5RG1KoT030784; Wed, 27 Jun 2007 18:01:20 +0200 (CEST) Date: Wed, 27 Jun 2007 18:30:00 -0000 Message-Id: <200706271601.l5RG1KoT030784@brahms.sibelius.xs4all.nl> From: Mark Kettenis To: jan.kratochvil@redhat.com CC: gdb-patches@sourceware.org In-reply-to: <20070627065203.GA9427@host0.dyn.jankratochvil.net> (message from Jan Kratochvil on Wed, 27 Jun 2007 08:52:03 +0200) Subject: Re: [patch] Fix Linux attach to signalled/stopped processes References: <20070606143432.GA11555@host0.dyn.jankratochvil.net> <200706151801.l5FI1xH6022843@brahms.sibelius.xs4all.nl> <20070626210341.GA1406@host0.dyn.jankratochvil.net> <200706262254.l5QMsrPn007445@brahms.sibelius.xs4all.nl> <20070627065203.GA9427@host0.dyn.jankratochvil.net> Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2007-06/txt/msg00481.txt.bz2 > Date: Wed, 27 Jun 2007 08:52:03 +0200 > From: Jan Kratochvil > > On Wed, 27 Jun 2007 00:54:54 +0200, Mark Kettenis wrote: > ... > > This is what I get on OpenBSD: > > > > $ ./ptrace-test > > .assertion "!WIFSIGNALED (status)" failed: file "ptrace-test.c", line 122, function "main" > > Abort trap (core dumped) > > > > This is sort of odd, > > Thanks for the test - it is now confirmed the code is not crossplatform and > different hacks may be needed on different ptrace(2)-using OSes. > OK, going to move it to linux-nat.c. > > > but then your test program has a serious problem. > > It doesn't wait(2) after ptrace(PT_ATTACH, ...). That's asking for trouble. > > It does wait(2) right after a preventive `PT_CONT (SIGSTOP)' as otherwise > wait(2) would hang if the original process was already stopped ... That's a kernel bug in my book; wait(2) should always report a SIGSTOP after a PT_ATTACH as soon as the traced process has been stopped. If the process was already stopped, wait(2) should simply report that SIGSTOP immediately. > > > How does currently GDB behave there while attaching to a SIGSTOPped process? > > > > I don't think it matters whether the process is stopped or not. > > ... the same way the current GDB hangs. SIGSTOP is already delivered before > and the new SIGSTOP from PTRACE_ATTACH does not stack as SIGSTOP is already > active. If the original SIGSTOP was already wait(2)ed by the pre-ptrace(2) > parent the new ptrace(2)-parent (the debugger) will not get the new SIGSTOP > caught and thus wait(2) hangs for it. > [ Info originally from Roland McGrath. ] So it seems that Linux completely ignores SIGSTOP if a process is already stopped. That's the right thing to do for "normal" processes, but not ok for traced processes. Looks like fixing that would solve a lot of problems. Wouldn't surprise me if that would also make lots of the workarounds we put in for debugging multi-threaded programs unnecessary. Mark