This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFA/Linux] Ask kernel to kill inferior when GDB terminates


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]