From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4995 invoked by alias); 26 Jun 2007 21:04:09 -0000 Received: (qmail 4987 invoked by uid 22791); 26 Jun 2007 21:04:08 -0000 X-Spam-Check-By: sourceware.org Received: from pauline.vellum.cz (HELO pauline.vellum.cz) (89.250.243.234) by sourceware.org (qpsmtpd/0.31) with ESMTP; Tue, 26 Jun 2007 21:04:04 +0000 Received: from host0.dyn.jankratochvil.net (localhost.localdomain [127.0.0.1]) by pauline.vellum.cz (8.12.11.20060308/8.12.11) with ESMTP id l5QL3fJk014139; Tue, 26 Jun 2007 23:03:41 +0200 Received: from host0.dyn.jankratochvil.net (localhost [127.0.0.1]) by host0.dyn.jankratochvil.net (8.14.1/8.13.8) with ESMTP id l5QL3fjb001571; Tue, 26 Jun 2007 23:03:41 +0200 Received: (from jkratoch@localhost) by host0.dyn.jankratochvil.net (8.14.1/8.14.1/Submit) id l5QL3fPm001570; Tue, 26 Jun 2007 23:03:41 +0200 Date: Tue, 26 Jun 2007 22:40:00 -0000 From: Jan Kratochvil To: Mark Kettenis Cc: gdb-patches@sourceware.org Subject: Re: [patch] Fix Linux attach to signalled/stopped processes Message-ID: <20070626210341.GA1406@host0.dyn.jankratochvil.net> References: <20070606143432.GA11555@host0.dyn.jankratochvil.net> <200706151801.l5FI1xH6022843@brahms.sibelius.xs4all.nl> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="mP3DRpeJDSE+ciuQ" Content-Disposition: inline In-Reply-To: <200706151801.l5FI1xH6022843@brahms.sibelius.xs4all.nl> User-Agent: Mutt/1.5.14 (2007-02-12) X-IsSubscribed: yes 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/msg00474.txt.bz2 --mP3DRpeJDSE+ciuQ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 1251 On Fri, 15 Jun 2007 20:01:59 +0200, Mark Kettenis wrote: > > Date: Wed, 6 Jun 2007 16:34:32 +0200 > > From: Jan Kratochvil > > > > The patch changes the functionality of TO_ATTACH. The former > > functionality was too UNIX centric. I was reading all the TO_ATTACH > > OS-flavor implementations and I believe the non-"inf-ptrace.c" ones > > do not need update. The code was tested only on Linux kernel, > > though. > > I disagree here. You're adding all sorts of goo to work around > Linux-specific problems. Please put this stuff in linux-nat.c While that "/proc/PID/status" reading part looks definitely Linux specific I would guess that the first waitpid(2) after PTRACE_ATTACH may not return SIGSTOP even on other ptrace(2)-using OSes (BSD?). Attaching a testcase for a possible non-Linux kernel test which: Should print approx. 1x '.' per second (on each caught pending SIGALRM signal). At least Linux 2.6.22-rc5.x86_64 prints '!' which looks as a kernel bug to me. How does currently GDB behave there while attaching to a SIGSTOPped process? This waitpid(2)-after-ptrace(2) signals redelivery looks as ptrace(2) specific and not Linux specific to me. And so it would belong to inf-ptrace.c. Regards, Jan --mP3DRpeJDSE+ciuQ Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="ptrace-test.c" Content-length: 2926 /* This testcase is part of GDB, the GNU debugger. Copyright 2007 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include static void action(int sig, siginfo_t * info, void *uc) { raise (SIGALRM); } static void loop (void) { struct sigaction act; memset (&act, 0, sizeof(struct sigaction)); act.sa_sigaction = action; act.sa_flags = SA_RESTART; sigaction (SIGALRM, &act, 0); raise (SIGALRM); putchar ('!'); for (;;) pause (); /* NOTREACHED */ abort (); } static pid_t child; static void cleanup (void) { kill (child, SIGKILL); } static void handler (int signo) { cleanup (); } int main (void) { void (*handler_orig) (int signo); setbuf (stdout, NULL); child = fork (); switch (child) { case -1: abort (); case 0: loop (); /* NOTREACHED */ abort (); default: break; } atexit (cleanup); handler_orig = signal (SIGABRT, handler); assert (handler_orig == SIG_DFL); for (;;) { errno = 0; ptrace (PTRACE_ATTACH, child, NULL, NULL); assert_perror (errno); unsigned long sig; /* Deliver one SIGSTOP just for sure. If the process was already stopped AND some other process (like shell) has already waited for it we would get stuck in waitpid (). */ sig = SIGSTOP; do { pid_t got_pid; int status; errno = 0; ptrace (PT_CONTINUE, child, (void *) 1UL, (void *) sig); /* For unstopped processes the preventive signal may ESRCH. */ if (sig != SIGSTOP) { assert_perror (errno); putchar ('.'); } got_pid = waitpid (child, &status, 0); assert (got_pid == child); /* Check if the thread has exited. */ assert (!WIFEXITED (status)); assert (!WIFSIGNALED (status)); assert (WIFSTOPPED (status)); sig = WSTOPSIG (status); assert (sig != 0); } while (sig != SIGSTOP); errno = 0; ptrace (PTRACE_DETACH, child, (void *) 1UL, (void *) 0UL); assert_perror (errno); } return 0; } --mP3DRpeJDSE+ciuQ--