From 3e74e146f297ec074e10c2b9a9e5869ec536649d Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Fri, 22 Mar 2013 14:52:26 +0000 Subject: [PATCH] Linux: No need to set ptrace event options in fork/clone children. Oleg Nesterov told me that the Linux kernel copies the parent's ptrace options to fork/clone children, so there's no need for GDB to do that manually. I was actually a bit surprised, since I thought the ptracer had to always set the ptrace options itself, and GDB is indeed calling PTRACE_SETOPTIONS for each new fork child, if it'll stay attached. Looking at the history of that code, I found that is was actually I who added that set-ptrace-options-in-children bit, back in http://sourceware.org/ml/gdb-patches/2009-05/msg00656.html. But, honestly, I don't recall why I needed that. I think I may have just blindly believed it was necessary. I then looked back at the history of all the PTRACE_SETOPTIONS code we have, and found that gdb never did copy the ptrace options before my patch. But, when gdbserver learnt to use PTRACE_EVENT_CLONE, at http://sourceware.org/ml/gdb-patches/2007-10/msg00547.html, it was made to do 'ptrace (PTRACE_SETOPTIONS, new_pid, 0, PTRACE_O_TRACECLONE)' for all new clones. Hmmm. But, GDB itself never did that, so it can't really ever have been necessary, I believe, otherwise GDB should have been doing it too. (GDBserver doesn't support following forks, and so naturally doesn't do any PTRACE_SETOPTIONS on fork children.) So this patch removes the -I believe- unnecessary ptrace syscalls. Tested on x86_64 Fedora 17, native/gdbserver, and on x86_64 RHEL5 native/gdbserver (Linux 2.6.18, I think a ptrace-on-utrace kernel). No regressions. gdb/ 2013-03-22 Pedro Alves * linux-nat.c (linux_child_follow_fork): Don't call linux_enable_event_reporting. (linux_handle_extended_wait): Don't call linux_enable_event_reporting. gdb/gdbserver/ 2013-03-22 Pedro Alves * linux-low.c (handle_extended_wait): Don't call linux_enable_event_reporting. --- gdb/ChangeLog | 7 +++++++ gdb/gdbserver/ChangeLog | 5 +++++ gdb/gdbserver/linux-low.c | 2 -- gdb/linux-nat.c | 4 ---- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 7b5bb6c22ea..13d061197ff 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,10 @@ +2013-03-22 Pedro Alves + + * linux-nat.c (linux_child_follow_fork): Don't call + linux_enable_event_reporting. + (linux_handle_extended_wait): Don't call + linux_enable_event_reporting. + 2013-03-22 Pedro Alves * hppa-hpux-tdep.c (hppa_hpux_push_dummy_code): Define INSN macro, diff --git a/gdb/gdbserver/ChangeLog b/gdb/gdbserver/ChangeLog index 18355b4be7b..b1f5f0f02ab 100644 --- a/gdb/gdbserver/ChangeLog +++ b/gdb/gdbserver/ChangeLog @@ -1,3 +1,8 @@ +2013-03-22 Pedro Alves + + * linux-low.c (handle_extended_wait): Don't call + linux_enable_event_reporting. + 2013-03-15 Tony Theodore PR build/9098: diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c index 523926d1790..72c51e0e9cc 100644 --- a/gdb/gdbserver/linux-low.c +++ b/gdb/gdbserver/linux-low.c @@ -468,8 +468,6 @@ handle_extended_wait (struct lwp_info *event_child, int wstat) warning ("wait returned unexpected status 0x%x", status); } - linux_enable_event_reporting (new_pid); - ptid = ptid_build (pid_of (event_child), new_pid, 0); new_lwp = (struct lwp_info *) add_lwp (ptid); add_thread (ptid, new_lwp); diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c index 3cbd126807e..5631e9ed635 100644 --- a/gdb/linux-nat.c +++ b/gdb/linux-nat.c @@ -643,9 +643,6 @@ linux_child_follow_fork (struct target_ops *ops, int follow_child) parent_pid = ptid_get_pid (inferior_ptid); child_pid = PIDGET (inferior_thread ()->pending_follow.value.related_pid); - if (!detach_fork) - linux_enable_event_reporting (pid_to_ptid (child_pid)); - if (has_vforked && !non_stop /* Non-stop always resumes both branches. */ && (!target_is_async_p () || sync_execution) @@ -2316,7 +2313,6 @@ linux_handle_extended_wait (struct lwp_info *lp, int status, this fork. We're actually doing an infcall in linux-fork.c. */ ourstatus->kind = TARGET_WAITKIND_SPURIOUS; - linux_enable_event_reporting (pid_to_ptid (new_pid)); /* Report the stop to the core. */ return 0;