From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5943 invoked by alias); 23 Feb 2011 20:25:04 -0000 Mailing-List: contact archer-help@sourceware.org; run by ezmlm Sender: Precedence: bulk List-Post: List-Help: List-Subscribe: List-Id: Received: (qmail 5924 invoked by uid 22791); 23 Feb 2011 20:25:03 -0000 X-SWARE-Spam-Status: No, hits=-6.3 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Date: Wed, 23 Feb 2011 20:25:00 -0000 From: Jan Kratochvil To: Roland McGrath Cc: Oleg Nesterov , archer@sourceware.org Subject: [patch] Re: [BUG] gdb: quit hangs after step into signal handler Message-ID: <20110223202454.GA4687@host1.dyn.jankratochvil.net> References: <20100920211715.GA10574@redhat.com> <20100921235356.BB1F340614@magilla.sf.frob.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20100921235356.BB1F340614@magilla.sf.frob.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-SW-Source: 2011-q1/txt/msg00102.txt.bz2 On Wed, 22 Sep 2010 01:53:56 +0200, Roland McGrath wrote: > Even if you were paranoid about some old kernel where PTRACE_KILL might work > better (dubious if there are any such, but that's why it's paranoia), you > could do this before PTRACE_KILL and it should certainly be fine everywhere. Problem is the inferior will start running after PTRACE_KILL. Current GDB: Quit anyway? (y or n) y read(0, "y\n", 1024) = 2 ptrace(PTRACE_KILL, 32336, 0, 0) = 0 wait4(32336, Before kill (SIGKILL) gets applied the code may do something unexpected. Why do you consider SIGKILL first, PTRACE_KILL second as worse? (Probably not so important now.) Thanks, Jan gdb/ 2011-02-23 Jan Kratochvil * linux-nat.c (kill_callback): Use SIGKILL first. gdb/testsuite/ 2011-02-23 Jan Kratochvil * gdb.base/kill-after-signal.c: New file. * gdb.base/kill-after-signal.exp: New file. --- a/gdb/linux-nat.c +++ b/gdb/linux-nat.c @@ -3802,6 +3802,18 @@ linux_nat_wait (struct target_ops *ops, static int kill_callback (struct lwp_info *lp, void *data) { + /* PTRACE_KILL may resume the inferior. Send SIGKILL first. */ + + errno = 0; + kill (GET_LWP (lp->ptid), SIGKILL); + if (debug_linux_nat) + fprintf_unfiltered (gdb_stdlog, + "KC: kill (SIGKILL) %s, 0, 0 (%s)\n", + target_pid_to_str (lp->ptid), + errno ? safe_strerror (errno) : "OK"); + + /* Some kernels ignore even SIGKILL for processes under ptrace. */ + errno = 0; ptrace (PTRACE_KILL, GET_LWP (lp->ptid), 0, 0); if (debug_linux_nat) --- /dev/null +++ b/gdb/testsuite/gdb.base/kill-after-signal.c @@ -0,0 +1,37 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2011 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 3 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, see . */ + +#include +#include +#include +#include + +void +handler (int signo) +{ + sleep (600); + assert (0); +} + +int +main (void) +{ + signal (SIGUSR1, handler); + raise (SIGUSR1); + assert (0); + return 0; +} --- /dev/null +++ b/gdb/testsuite/gdb.base/kill-after-signal.exp @@ -0,0 +1,29 @@ +# Copyright (C) 2011 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 3 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, see . + +set testfile "kill-after-signal" +if [prepare_for_testing ${testfile}.exp ${testfile}] { + return -1 +} + +gdb_test "handle SIGUSR1 stop print pass" "SIGUSR1\[ \t\]+Yes\[ \t\]+Yes\[ \t\]+Yes\[ \t\]+.*" + +if ![runto_main] { + return -1 +} + +gdb_test "continue" "Program received signal SIGUSR1, .*" +gdb_test "stepi" "\r\nhandler .*" +gdb_test "kill" "^y" "kill" "Kill the program being debugged\\? \\(y or n\\) $" "y"