This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [RFA/Linux] Ask kernel to kill inferior when GDB terminates
- From: Pedro Alves <palves at redhat dot com>
- To: Joel Brobecker <brobecker at adacore dot com>
- Cc: gdb-patches at sourceware dot org
- Date: Mon, 15 Dec 2014 21:17:48 +0000
- Subject: Re: [RFA/Linux] Ask kernel to kill inferior when GDB terminates
- Authentication-results: sourceware.org; auth=none
- References: <1415984034-27122-1-git-send-email-brobecker at adacore dot com> <54663729 dot 6010708 at redhat dot com> <20141114173255 dot GD5774 at adacore dot com> <20141119092547 dot GP5774 at adacore dot com> <546C69D4 dot 5090300 at redhat dot com> <20141213162757 dot GL5457 at adacore dot com> <548EE088 dot 20506 at redhat dot com> <20141215204323 dot GE5457 at adacore dot com>
On 12/15/2014 08:43 PM, Joel Brobecker wrote:
> GDB with signal 9. After GDB is killed, the inferior still remains
> in "interruptible sleep (waiting for an event to complete)" state.
This makes it sound like "interruptible sleep" is some kind of wedged
state waiting for a debugger. But, this simply means your process is just
running as normal, and your test's case, normal means idling. Most likely,
your test program had a "sleep" call in it. IOW, it'd be in sleep state
even if had been started outside gdb. Another test program could go
to "T (stopped)", "R (running)", etc.
> -/* Determine ptrace features available on this target. */
> +/* Determine ptrace features available on this target.
> + ATTACHED should be nonzero iff we've attached to the inferior. */
>
> static void
> -linux_check_ptrace_features (void)
> +linux_check_ptrace_features (int attached)
> {
> int child_pid, ret, status;
>
> @@ -338,6 +340,9 @@ linux_check_ptrace_features (void)
>
> linux_test_for_tracefork (child_pid);
>
> + if (!attached)
> + linux_test_for_exitkill (child_pid);
This test must be called unconditionally. current_ptrace_options is
only initialized once:
void
linux_enable_event_reporting (pid_t pid)
{
/* Check if we have initialized the ptrace features for this
target. If not, do it now. */
if (current_ptrace_options == -1)
linux_check_ptrace_features ();
so if the first process gdbserver debugs is an "attach" process,
but the second one is not, you'll miss setting PTRACE_O_EXITKILL on
the second process.
Instead, always call linux_test_for_exitkill, and then in
linux_enable_event_reporting mask out PTRACE_O_EXITKILL
from current_ptrace_options if 'attached' is false.
Thanks,
Pedro Alves