aboutsummaryrefslogtreecommitdiff
path: root/gdb/inf-ptrace.c
diff options
context:
space:
mode:
authorDon Breazeal <donb@codesourcery.com>2014-09-30 11:01:57 -0700
committerDon Breazeal <donb@codesourcery.com>2014-09-30 11:01:57 -0700
commitd83ad864a285fe3127e1a98830197e8461ad2745 (patch)
tree17fc116484b87e08c0a992063513490208c3e1ef /gdb/inf-ptrace.c
parent63b434a4374b61aa34b095a789cd0d03b2a5a526 (diff)
downloadgdb-d83ad864a285fe3127e1a98830197e8461ad2745.zip
gdb-d83ad864a285fe3127e1a98830197e8461ad2745.tar.gz
gdb-d83ad864a285fe3127e1a98830197e8461ad2745.tar.bz2
Refactor native follow-fork.
This patch reorganizes the code that implements follow-fork and detach-on-fork in preparation for implementation of those features for the extended-remote target. The function linux-nat.c:linux_child_follow_fork contained target-independent code mixed in with target-dependent code. The target-independent pieces need to be accessible for the host-side implementation of follow-fork for extended-remote Linux targets. The changes are fairly mechanical. A new routine, follow_fork_inferior, is implemented in infrun.c, containing those parts of linux_child_follow_fork that manage inferiors and the inferior list. The parts of linux_child_follow_fork that deal with LWPs and target-specifics were left in-place. Although the order of some operations was changed, the resulting functionality was not. Modifications were made to the other native target follow-fork functions, inf_ttrace_follow_fork and inf_ptrace_follow_fork, that should allow them to work with follow_fork_inferior. Some other adjustments were necessary in inf-ttrace.c. The changes to inf-ttrace.c and inf-ptrace.c were not tested. gdb/ChangeLog: * inf-ptrace.c (inf_ptrace_follow_fork): Remove target-independent code so as to work with follow_fork_inferior. * inf-ttrace.c (inf_ttrace_follow_fork): Ditto. (inf_ttrace_create_inferior): Remove reference to inf_ttrace_vfork_ppid. (inf_ttrace_attach): Ditto. (inf_ttrace_detach): Ditto. (inf_ttrace_kill): Use current_inferior instead of inf_ttrace_vfork_ppid. (inf_ttrace_wait): Eliminate use of inf_ttrace_vfork_ppid, report TARGET_WAITKIND_VFORK_DONE event, delete HACK that switched the inferior away from the parent. * infrun.c (follow_fork): Call follow_fork_inferior instead of target_follow_fork. (follow_fork_inferior): New function. (follow_inferior_reset_breakpoints): Make function static. * infrun.h (follow_inferior_reset_breakpoints): Remove declaration. * linux-nat.c (linux_child_follow_fork): Move target-independent code to infrun.c:follow_fork_inferior.
Diffstat (limited to 'gdb/inf-ptrace.c')
-rw-r--r--gdb/inf-ptrace.c48
1 files changed, 6 insertions, 42 deletions
diff --git a/gdb/inf-ptrace.c b/gdb/inf-ptrace.c
index dd71b3a..6eb8080 100644
--- a/gdb/inf-ptrace.c
+++ b/gdb/inf-ptrace.c
@@ -36,57 +36,21 @@
#ifdef PT_GET_PROCESS_STATE
+/* Target hook for follow_fork. On entry and at return inferior_ptid is
+ the ptid of the followed inferior. */
+
static int
inf_ptrace_follow_fork (struct target_ops *ops, int follow_child,
int detach_fork)
{
- pid_t pid, fpid;
- ptrace_state_t pe;
-
- pid = ptid_get_pid (inferior_ptid);
-
- if (ptrace (PT_GET_PROCESS_STATE, pid,
- (PTRACE_TYPE_ARG3)&pe, sizeof pe) == -1)
- perror_with_name (("ptrace"));
-
- gdb_assert (pe.pe_report_event == PTRACE_FORK);
- fpid = pe.pe_other_pid;
-
- if (follow_child)
+ if (!follow_child)
{
- struct inferior *parent_inf, *child_inf;
- struct thread_info *tp;
-
- parent_inf = find_inferior_pid (pid);
-
- /* Add the child. */
- child_inf = add_inferior (fpid);
- child_inf->attach_flag = parent_inf->attach_flag;
- copy_terminal_info (child_inf, parent_inf);
- child_inf->pspace = parent_inf->pspace;
- child_inf->aspace = parent_inf->aspace;
+ pid_t child_pid = inferior_thread->pending_follow.value.related_pid;
- /* Before detaching from the parent, remove all breakpoints from
- it. */
- remove_breakpoints ();
-
- if (ptrace (PT_DETACH, pid, (PTRACE_TYPE_ARG3)1, 0) == -1)
- perror_with_name (("ptrace"));
-
- /* Switch inferior_ptid out of the parent's way. */
- inferior_ptid = pid_to_ptid (fpid);
-
- /* Delete the parent. */
- detach_inferior (pid);
-
- add_thread_silent (inferior_ptid);
- }
- else
- {
/* Breakpoints have already been detached from the child by
infrun.c. */
- if (ptrace (PT_DETACH, fpid, (PTRACE_TYPE_ARG3)1, 0) == -1)
+ if (ptrace (PT_DETACH, child_pid, (PTRACE_TYPE_ARG3)1, 0) == -1)
perror_with_name (("ptrace"));
}