binutils-gdb/gdb/nat
Don Breazeal de0d863ec3 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.
2015-05-12 09:52:43 -07:00
..
gdb_thread_db.h Move shared native target specific code to gdb/nat 2014-06-20 14:06:48 +01:00
glibc_thread_db.h Move shared native target specific code to gdb/nat 2014-06-20 14:06:48 +01:00
linux-btrace.c btrace: support 32-bit inferior on 64-bit host 2015-03-03 12:47:41 +01:00
linux-btrace.h record btrace: add configuration struct 2015-02-09 09:38:55 +01:00
linux-nat.h Make lwp_info.arch_private handling shared 2015-03-24 14:05:44 +00:00
linux-osdata.c Add cpu information to the info os command on linux. 2015-03-31 09:31:52 -04:00
linux-osdata.h Update year range in copyright notice of all files owned by the GDB project. 2015-01-01 13:32:14 +04:00
linux-personality.c Fix nat/linux-personality.c regression on RHEL-5 2015-01-16 11:42:28 -05:00
linux-personality.h Move code to disable ASR to nat/ 2015-01-15 15:10:49 -05:00
linux-procfs.c Introduce linux_proc_pid_to_exec_file 2015-04-17 09:47:30 +01:00
linux-procfs.h Introduce linux_proc_pid_to_exec_file 2015-04-17 09:47:30 +01:00
linux-ptrace.c Extended-remote Linux follow fork 2015-05-12 09:52:43 -07:00
linux-ptrace.h Extended-remote Linux follow fork 2015-05-12 09:52:43 -07:00
linux-waitpid.c Update year range in copyright notice of all files owned by the GDB project. 2015-01-01 13:32:14 +04:00
linux-waitpid.h Update year range in copyright notice of all files owned by the GDB project. 2015-01-01 13:32:14 +04:00
mips-linux-watch.c Update year range in copyright notice of all files owned by the GDB project. 2015-01-01 13:32:14 +04:00
mips-linux-watch.h Update year range in copyright notice of all files owned by the GDB project. 2015-01-01 13:32:14 +04:00
ppc-linux.c Detect 64-bit-ness in PowerPC Book III-E 2015-01-14 22:28:27 +08:00
ppc-linux.h Detect 64-bit-ness in PowerPC Book III-E 2015-01-14 22:28:27 +08:00
x86-cpuid.h Update year range in copyright notice of all files owned by the GDB project. 2015-01-01 13:32:14 +04:00
x86-dregs.c C++ keyword cleanliness, mostly auto-generated 2015-02-27 16:33:07 +00:00
x86-dregs.h Add x86_debug_reg_state to gdbserver 2015-03-24 14:05:43 +00:00
x86-gcc-cpuid.h Update year range in copyright notice of all files owned by the GDB project. 2015-01-01 13:32:14 +04:00
x86-linux-dregs.c Move low-level Linux x86 debug register code to a shared file 2015-03-24 14:05:45 +00:00
x86-linux-dregs.h Move low-level Linux x86 debug register code to a shared file 2015-03-24 14:05:45 +00:00
x86-linux.c Move duplicated Linux x86 code to nat/x86-linux.c 2015-03-24 14:05:45 +00:00
x86-linux.h Move duplicated Linux x86 code to nat/x86-linux.c 2015-03-24 14:05:45 +00:00