+\f
+
+#ifdef PT_GET_PROCESS_STATE
+
+static int
+inf_ptrace_follow_fork (struct target_ops *ops, int follow_child)
+{
+ 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)
+ {
+ 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;
+
+ /* 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)
+ perror_with_name (("ptrace"));
+ }
+
+ return 0;
+}
+
+#endif /* PT_GET_PROCESS_STATE */