aboutsummaryrefslogtreecommitdiff
path: root/gdb/linux-nat.c
diff options
context:
space:
mode:
authorJoel Brobecker <brobecker@adacore.com>2014-11-11 10:07:21 +0400
committerJoel Brobecker <brobecker@adacore.com>2014-12-16 07:56:46 -0500
commitbeed38b8273fa18be574a7e84d5d2ee1f563ed48 (patch)
treeacb445cc66a01354c72052c9231042b0096e8f79 /gdb/linux-nat.c
parentbf330350c212fb8880faab663f5b3565319d0a95 (diff)
downloadgdb-beed38b8273fa18be574a7e84d5d2ee1f563ed48.zip
gdb-beed38b8273fa18be574a7e84d5d2ee1f563ed48.tar.gz
gdb-beed38b8273fa18be574a7e84d5d2ee1f563ed48.tar.bz2
[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.
Diffstat (limited to 'gdb/linux-nat.c')
-rw-r--r--gdb/linux-nat.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c
index 29133f9..845d566 100644
--- a/gdb/linux-nat.c
+++ b/gdb/linux-nat.c
@@ -321,25 +321,27 @@ pull_pid_from_list (struct simple_pid_list **listp, int pid, int *statusp)
}
/* Initialize ptrace warnings and check for supported ptrace
- features given PID. */
+ features given PID.
+
+ ATTACHED should be nonzero iff we attached to the inferior. */
static void
-linux_init_ptrace (pid_t pid)
+linux_init_ptrace (pid_t pid, int attached)
{
- linux_enable_event_reporting (pid);
+ linux_enable_event_reporting (pid, attached);
linux_ptrace_init_warnings ();
}
static void
linux_child_post_attach (struct target_ops *self, int pid)
{
- linux_init_ptrace (pid);
+ linux_init_ptrace (pid, 1);
}
static void
linux_child_post_startup_inferior (struct target_ops *self, ptid_t ptid)
{
- linux_init_ptrace (ptid_get_pid (ptid));
+ linux_init_ptrace (ptid_get_pid (ptid), 0);
}
/* Return the number of known LWPs in the tgid given by PID. */