diff options
author | Don Breazeal <donb@codesourcery.com> | 2015-05-12 09:52:43 -0700 |
---|---|---|
committer | Don Breazeal <donb@codesourcery.com> | 2015-05-12 09:52:43 -0700 |
commit | de0d863ec3fda88e488cee568f943c7998b68862 (patch) | |
tree | ba0c782f7e34cc80b37f9a704f71e897364f364c /gdb/linux-nat.c | |
parent | ddcbc3975fffffdb5bb3bfb05b1f0ef3d67be3ee (diff) | |
download | gdb-de0d863ec3fda88e488cee568f943c7998b68862.zip gdb-de0d863ec3fda88e488cee568f943c7998b68862.tar.gz gdb-de0d863ec3fda88e488cee568f943c7998b68862.tar.bz2 |
Extended-remote Linux follow fork
This patch implements basic support for follow-fork and detach-on-fork on
extended-remote Linux targets. Only 'fork' is supported in this patch;
'vfork' support is added n a subsequent patch. This patch depends on
the previous patches in the patch series.
Sufficient extended-remote functionality has been implemented here to pass
gdb.base/multi-forks.exp, as well as gdb.base/foll-fork.exp with the
catchpoint tests commented out. Some other fork tests fail with this
patch because it doesn't provide the architecture support needed for
watchpoint inheritance or fork catchpoints.
The implementation follows the same general structure as for the native
implementation as much as possible.
This implementation includes:
* enabling fork events in linux-low.c in initialize_low and
linux_enable_extended_features
* handling fork events in gdbserver/linux-low.c:handle_extended_wait
- when a fork event occurs in gdbserver, we must do the full creation
of the new process, thread, lwp, and breakpoint lists. This is
required whether or not the new child is destined to be
detached-on-fork, because GDB will make target calls that require all
the structures. In particular we need the breakpoint lists in order
to remove the breakpoints from a detaching child. If we are not
detaching the child we will need all these structures anyway.
- as part of this event handling we store the target_waitstatus in a new
member of the parent lwp_info structure, 'waitstatus'. This
is used to store extended event information for reporting to GDB.
- handle_extended_wait is given a return value, denoting whether the
handled event should be reported to GDB. Previously it had only
handled clone events, which were never reported.
* using a new predicate in gdbserver to control handling of the fork event
(and eventually all extended events) in linux_wait_1. The predicate,
extended_event_reported, checks a target_waitstatus.kind for an
extended ptrace event.
* implementing a new RSP 'T' Stop Reply Packet stop reason: "fork", in
gdbserver/remote-utils.c and remote.c.
* implementing new target and RSP support for target_follow_fork with
target extended-remote. (The RSP components were actually defined in
patch 1, but they see their first use here).
- remote target routine remote_follow_fork, which just sends the 'D;pid'
detach packet to detach the new fork child cleanly. We can't just
call target_detach because the data structures for the forked child
have not been allocated on the host side.
Tested on x64 Ubuntu Lucid, native, remote, extended-remote.
gdb/gdbserver/ChangeLog:
* linux-low.c (handle_extended_wait): Implement return value,
rename argument 'event_child' to 'event_lwp', handle
PTRACE_EVENT_FORK, call internal_error for unrecognized event.
(linux_low_ptrace_options): New function.
(linux_low_filter_event): Call linux_low_ptrace_options,
use different argument fo linux_enable_event_reporting,
use return value from handle_extended_wait.
(extended_event_reported): New function.
(linux_wait_1): Call extended_event_reported and set
status to report fork events.
(linux_write_memory): Add pid to debug message.
(reset_lwp_ptrace_options_callback): New function.
(linux_handle_new_gdb_connection): New function.
(linux_target_ops): Initialize new structure member.
* linux-low.h (struct lwp_info) <waitstatus>: New member.
* lynx-low.c: Initialize new structure member.
* remote-utils.c (prepare_resume_reply): Implement stop reason
"fork" for "T" stop message.
* server.c (handle_query): Call handle_new_gdb_connection.
* server.h (report_fork_events): Declare global flag.
* target.h (struct target_ops) <handle_new_gdb_connection>:
New member.
(target_handle_new_gdb_connection): New macro.
* win32-low.c: Initialize new structure member.
gdb/ChangeLog:
* linux-nat.c (linux_nat_ptrace_options): New function.
(linux_init_ptrace, wait_lwp, linux_nat_filter_event):
Call linux_nat_ptrace_options and use different argument to
linux_enable_event_reporting.
(_initialize_linux_nat): Delete call to
linux_ptrace_set_additional_flags.
* nat/linux-ptrace.c (current_ptrace_options): Rename to
supported_ptrace_options.
(additional_flags): Delete variable.
(linux_check_ptrace_features): Use supported_ptrace_options.
(linux_test_for_tracesysgood, linux_test_for_tracefork):
Likewise, and remove additional_flags check.
(linux_enable_event_reporting): Change 'attached' argument to
'options'. Use supported_ptrace_options.
(ptrace_supports_feature): Change comment. Use
supported_ptrace_options.
(linux_ptrace_set_additional_flags): Delete function.
* nat/linux-ptrace.h (linux_ptrace_set_additional_flags):
Delete function prototype.
* remote.c (remote_fork_event_p): New function.
(remote_detach_pid): New function.
(remote_detach_1): Call remote_detach_pid, don't mourn inferior
if doing detach-on-fork.
(remote_follow_fork): New function.
(remote_parse_stop_reply): Handle new "T" stop reason "fork".
(remote_pid_to_str): Print "process" strings for pid/0/0 ptids.
(init_extended_remote_ops): Initialize to_follow_fork.
Diffstat (limited to 'gdb/linux-nat.c')
-rw-r--r-- | gdb/linux-nat.c | 37 |
1 files changed, 26 insertions, 11 deletions
diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c index b04aa68..f95e76c 100644 --- a/gdb/linux-nat.c +++ b/gdb/linux-nat.c @@ -368,6 +368,25 @@ pull_pid_from_list (struct simple_pid_list **listp, int pid, int *statusp) return 0; } +/* Return the ptrace options that we want to try to enable. */ + +static int +linux_nat_ptrace_options (int attached) +{ + int options = 0; + + if (!attached) + options |= PTRACE_O_EXITKILL; + + options |= (PTRACE_O_TRACESYSGOOD + | PTRACE_O_TRACEVFORKDONE + | PTRACE_O_TRACEVFORK + | PTRACE_O_TRACEFORK + | PTRACE_O_TRACEEXEC); + + return options; +} + /* Initialize ptrace warnings and check for supported ptrace features given PID. @@ -376,7 +395,9 @@ pull_pid_from_list (struct simple_pid_list **listp, int pid, int *statusp) static void linux_init_ptrace (pid_t pid, int attached) { - linux_enable_event_reporting (pid, attached); + int options = linux_nat_ptrace_options (attached); + + linux_enable_event_reporting (pid, options); linux_ptrace_init_warnings (); } @@ -2301,8 +2322,9 @@ wait_lwp (struct lwp_info *lp) if (lp->must_set_ptrace_flags) { struct inferior *inf = find_inferior_pid (ptid_get_pid (lp->ptid)); + int options = linux_nat_ptrace_options (inf->attach_flag); - linux_enable_event_reporting (ptid_get_lwp (lp->ptid), inf->attach_flag); + linux_enable_event_reporting (ptid_get_lwp (lp->ptid), options); lp->must_set_ptrace_flags = 0; } @@ -3102,8 +3124,9 @@ linux_nat_filter_event (int lwpid, int status) if (WIFSTOPPED (status) && lp->must_set_ptrace_flags) { struct inferior *inf = find_inferior_pid (ptid_get_pid (lp->ptid)); + int options = linux_nat_ptrace_options (inf->attach_flag); - linux_enable_event_reporting (ptid_get_lwp (lp->ptid), inf->attach_flag); + linux_enable_event_reporting (ptid_get_lwp (lp->ptid), options); lp->must_set_ptrace_flags = 0; } @@ -5028,14 +5051,6 @@ Enables printf debugging output."), sigdelset (&suspend_mask, SIGCHLD); sigemptyset (&blocked_mask); - - /* Do not enable PTRACE_O_TRACEEXIT until GDB is more prepared to - support read-only process state. */ - linux_ptrace_set_additional_flags (PTRACE_O_TRACESYSGOOD - | PTRACE_O_TRACEVFORKDONE - | PTRACE_O_TRACEVFORK - | PTRACE_O_TRACEFORK - | PTRACE_O_TRACEEXEC); } |