binutils-gdb/gdb/nat
Joel Brobecker beed38b827 [Linux] Ask kernel to kill inferior when GDB terminates
This patch enhances GDB on GNU/Linux systems in the situation where
we are debugging an inferior that was created from GDB (as opposed
to attached to), by asking the kernel to kill the inferior if GDB
terminates without doing it itself.

This would typically happen when GDB encounters a problem and
crashes, or when it gets killed by an external process. This can
be observed by starting a program under GDB, and then killing
GDB with signal 9. After GDB is killed, the inferior still remains.

This patch also fixes GDBserver similarly.

This fix is conditional on the kernel supporting the PTRACE_O_EXITKILL
feature.  On older kernels, the behavior remains unchanged.

gdb/ChangeLog:

        * nat/linux-ptrace.h (PTRACE_O_EXITKILL): Define if not
        already defined.
        (linux_enable_event_reporting): Add parameter "attached".
        * nat/linux-ptrace.c (linux_test_for_exitkill): New forward
        declaration.  New function.
        (linux_check_ptrace_features): Add linux_test_for_exitkill call.
        (linux_enable_event_reporting): Add new parameter "attached".
        Do not call ptrace with the PTRACE_O_EXITKILL if ATTACHED is
        nonzero.
        * linux-nat.c (linux_init_ptrace): Add parameter "attached".
        Use it.  Update function description.
        (linux_child_post_attach, linux_child_post_startup_inferior):
        Update call to linux_enable_event_reporting.

gdb/gdbserver/ChangeLog:

        * linux-low.c (linux_low_filter_event): Update call to
        linux_enable_event_reporting following the addition of
        a new parameter to that function.

Tested on x86_64-linux, native and native-gdbserver.

I also verified by hand that the inferior gets killed when killing
GDB in the "run" case, while the inferior remains in the "attach"
case. Same for GDBserver.
2014-12-16 07:56:46 -05:00
..
gdb_thread_db.h
glibc_thread_db.h
linux-btrace.c Remove GDBSERVER uses from linux-btrace.c 2014-09-12 10:11:42 +01:00
linux-btrace.h Remove GDBSERVER uses from linux-btrace.c 2014-09-12 10:11:42 +01:00
linux-nat.h
linux-osdata.c Include common-defs.h instead of defs.h/server.h in shared code 2014-09-12 10:11:42 +01:00
linux-osdata.h Move ptid.h to common-defs.h 2014-08-07 09:06:44 +01:00
linux-procfs.c Warn users about mismatched PID namespaces 2014-11-11 14:18:23 +00:00
linux-procfs.h Warn users about mismatched PID namespaces 2014-11-11 14:18:23 +00:00
linux-ptrace.c [Linux] Ask kernel to kill inferior when GDB terminates 2014-12-16 07:56:46 -05:00
linux-ptrace.h [Linux] Ask kernel to kill inferior when GDB terminates 2014-12-16 07:56:46 -05:00
linux-waitpid.c Clarify GDBSERVER use in linux-waitpid.c 2014-09-12 11:03:49 +01:00
linux-waitpid.h
mips-linux-watch.c Include common-defs.h instead of defs.h/server.h in shared code 2014-09-12 10:11:42 +01:00
mips-linux-watch.h Do not include defs.h or server.h in any header file 2014-07-31 13:25:01 +01:00
x86-cpuid.h Rename 32- and 64-bit Intel files from "i386" to "x86" 2014-09-02 16:54:08 +01:00
x86-dregs.c Remove GDBSERVER uses from x86-dregs.c 2014-09-12 10:11:42 +01:00
x86-dregs.h x86 debug address register clarifications 2014-09-03 12:40:49 +01:00
x86-gcc-cpuid.h Rename 32- and 64-bit Intel files from "i386" to "x86" 2014-09-02 16:54:08 +01:00