From: Jan Kratochvil <jan.kratochvil@redhat.com>
To: Mark Kettenis <mark.kettenis@xs4all.nl>
Cc: gdb-patches@sourceware.org
Subject: Re: [patch] Fix Linux attach to signalled/stopped processes
Date: Tue, 26 Jun 2007 22:40:00 -0000 [thread overview]
Message-ID: <20070626210341.GA1406@host0.dyn.jankratochvil.net> (raw)
In-Reply-To: <200706151801.l5FI1xH6022843@brahms.sibelius.xs4all.nl>
[-- Attachment #1: Type: text/plain, Size: 1251 bytes --]
On Fri, 15 Jun 2007 20:01:59 +0200, Mark Kettenis wrote:
> > Date: Wed, 6 Jun 2007 16:34:32 +0200
> > From: Jan Kratochvil <jan.kratochvil@redhat.com>
> >
> > 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
[-- Attachment #2: ptrace-test.c --]
[-- Type: text/plain, Size: 2926 bytes --]
/* 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 <signal.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/wait.h>
#include <sys/ptrace.h>
#include <assert.h>
#include <fcntl.h>
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;
}
next prev parent reply other threads:[~2007-06-26 21:04 UTC|newest]
Thread overview: 52+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
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
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
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=20070626210341.GA1406@host0.dyn.jankratochvil.net \
--to=jan.kratochvil@redhat.com \
--cc=gdb-patches@sourceware.org \
--cc=mark.kettenis@xs4all.nl \
/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