This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [patch] Fix Linux attach to signalled/stopped processes
- From: Pedro Alves <pedro at codesourcery dot com>
- To: gdb-patches at sourceware dot org
- Cc: Daniel Jacobowitz <drow at false dot org>, Roland McGrath <roland at redhat dot com>, Jan Kratochvil <jan dot kratochvil at redhat dot com>, Doug Evans <dje at google dot com>, mark dot kettenis at xs4all dot nl
- Date: Fri, 11 Apr 2008 23:54:48 +0100
- Subject: Re: [patch] Fix Linux attach to signalled/stopped processes
- References: <e394668d0803311218x35c802c1g7dba5f3b48b38bc8@mail.gmail.com> <200804112300.38076.pedro@codesourcery.com> <20080411221958.GA21910@caradoc.them.org>
A Friday 11 April 2008 23:19:58, Daniel Jacobowitz wrote:
> On Fri, Apr 11, 2008 at 11:00:37PM +0100, Pedro Alves wrote:
> > ?> + ?/* Pass on the last signal, if appropriate. ?*/
> >
> > > + ?if (lp->status == 0 && GET_LWP (lp->ptid) == GET_LWP (inferior_ptid)
> > > + ? ? ?&& stop_signal != TARGET_SIGNAL_0 && signal_pass_state
> > > (stop_signal)) + ? ?lp->status = 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?).
>
> I want the ptid associated with the global variable stop_signal. It's
> deliberately not the ptid of the main thread but I hadn't thought
> about the thread command.
Ok, but the last lwp in detach_command is always the main lwp, not
inferior_ptid, even if the user doesn't use the "thread" command.
That is, this is the main thread:
>+ ?/* Pass on any pending signal for the last LWP. ?*/
>+ ?status = lwp_list->status;
but back in detach_callback, if the inferior_ptid's lwp is not the main
thread, you're writing the lp->status to an lwp that is going to
be deleted right afterwards:
/* We don't actually detach from the LWP that has an id equal to the
overall process id just yet. */
if (GET_LWP (lp->ptid) != GET_PID (lp->ptid))
{
(...)
delete_lwp (lp->ptid);
}
> Is that variable context-switched (or should it be)?
Not currently. One of my non-stop patches makes it so.
Currently, in all-stop mode, if the user switches threads
after getting a signal, when resuming, GDB will pass
the signal to the current thread, not the one that got
it in the first place...
> Any idea how to do this?
Not really. I'm don't think we can context-switch
stop_signal in all-stop mode. At least not without more work
in infrun.c. I'd have to think and try a bit more. My current
patch leaves it global in all-stop mode. Maybe you just
need a event_ptid, similar to trap_ptid, or just resend the signal
to the main thread.
--
Pedro Alves