From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16656 invoked by alias); 11 Apr 2008 22:01:03 -0000 Received: (qmail 16624 invoked by uid 22791); 11 Apr 2008 22:00:59 -0000 X-Spam-Check-By: sourceware.org Received: from mail.codesourcery.com (HELO mail.codesourcery.com) (65.74.133.4) by sourceware.org (qpsmtpd/0.31) with ESMTP; Fri, 11 Apr 2008 22:00:40 +0000 Received: (qmail 25331 invoked from network); 11 Apr 2008 22:00:38 -0000 Received: from unknown (HELO orlando.local) (pedro@127.0.0.2) by mail.codesourcery.com with ESMTPA; 11 Apr 2008 22:00:38 -0000 From: Pedro Alves To: gdb-patches@sourceware.org Subject: Re: [patch] Fix Linux attach to signalled/stopped processes Date: Fri, 11 Apr 2008 22:21:00 -0000 User-Agent: KMail/1.9.6 (enterprise 0.20070907.709405) Cc: Daniel Jacobowitz , Roland McGrath , Jan Kratochvil , Doug Evans , mark.kettenis@xs4all.nl References: <20080410231205.2DBFD26F992@magilla.localdomain> <20080411210221.GA13599@caradoc.them.org> In-Reply-To: <20080411210221.GA13599@caradoc.them.org> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Message-Id: <200804112300.38076.pedro@codesourcery.com> 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: 2008-04/txt/msg00227.txt.bz2 Some quick comments, A Friday 11 April 2008 22:02:21, Daniel Jacobowitz wrote: =A0> + =A0/* Pass on the last signal, if appropriate. =A0*/ > + =A0if (lp->status =3D=3D 0 && GET_LWP (lp->ptid) =3D=3D GET_LWP (inferi= or_ptid) > + =A0 =A0 =A0&& stop_signal !=3D TARGET_SIGNAL_0 && signal_pass_state (st= op_signal)) > + =A0 =A0lp->status =3D W_STOPCODE (target_signal_to_host (stop_signal)); You're writing to lp->status of inferior_ptid, which isn't garantied to be the main thread or the thread that got the last signal (user may have used the "thread" command to switch threads, or we're stopped at a breakpoint in some other thread not the main one, for example, or the kernel decided to send the signal to some other thread because the main one was already stopped?). >=A0 =A0/* We don't actually detach from the LWP that has an id equal to the >=A0 =A0 =A0 overall process id just yet. =A0*/ >=A0 =A0if (GET_LWP (lp->ptid) !=3D GET_PID (lp->ptid)) >@@ -1263,14 +1343,29 @@ static void >=A0linux_nat_detach (char *args, int from_tty) >=A0{ >=A0 =A0int pid; >+ =A0int status; >+ =A0enum target_signal sig; >+ >=A0 =A0if (target_can_async_p ()) >=A0 =A0 =A0linux_nat_async (NULL, 0); >=A0 >- =A0iterate_over_lwps (detach_callback, NULL); >+ =A0iterate_over_lwps (detach_callback, &status); > Passing &status seems bogus, since you're passing the status in lp->status ? =A0 >=A0 =A0/* Only the initial process should be left right now. =A0*/ >=A0 =A0gdb_assert (num_lwps =3D=3D 1); >=A0 >+ =A0/* Pass on any pending signal for the last LWP. =A0*/ >+ =A0status =3D lwp_list->status; >+ =A0if (WIFSTOPPED (status) && (args =3D=3D NULL || *args =3D=3D '\0')) >+ =A0 =A0{ >+ =A0 =A0 =A0args =3D alloca (8); >+ =A0 =A0 =A0sprintf (args, "%d", (int) WSTOPSIG (status)); >+ =A0 =A0 =A0fprintf_unfiltered (gdb_stdlog, >+=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 =A0= "LND: Sending signal %s to %s\n", >+=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 =A0= args, >+=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 =A0= target_pid_to_str (lwp_list->ptid)); >+ =A0 =A0} >+ > I don't see where you're actually sending the signal. Even if you did, it isn't guarantied you are passing this signal. It will miss it if inferior_ptid isn't the main thread. See comments above. Also, why the alloca dance instead of using "Sending signal %d to %s\n" directly, if you're not doing anything else with args? AKA, what's the plan for args? What's supposed to happen if stop_signal was a SIGTRAP ? --=20 Pedro Alves