-ptid_t
-linux_handle_extended_wait (int pid, int status,
- struct target_waitstatus *ourstatus)
-{
- int event = status >> 16;
-
- if (event == PTRACE_EVENT_FORK || event == PTRACE_EVENT_VFORK
- || event == PTRACE_EVENT_CLONE)
- {
- unsigned long new_pid;
- int ret;
-
- ptrace (PTRACE_GETEVENTMSG, pid, 0, &new_pid);
-
- /* If we haven't already seen the new PID stop, wait for it now. */
- if (! pull_pid_from_list (&stopped_pids, new_pid))
- {
- /* The new child has a pending SIGSTOP. We can't affect it until it
- hits the SIGSTOP, but we're already attached. */
- ret = my_waitpid (new_pid, &status,
- (event == PTRACE_EVENT_CLONE) ? __WCLONE : 0);
- if (ret == -1)
- perror_with_name (_("waiting for new child"));
- else if (ret != new_pid)
- internal_error (__FILE__, __LINE__,
- _("wait returned unexpected PID %d"), ret);
- else if (!WIFSTOPPED (status) || WSTOPSIG (status) != SIGSTOP)
- internal_error (__FILE__, __LINE__,
- _("wait returned unexpected status 0x%x"), status);
- }
-
- if (event == PTRACE_EVENT_FORK)
- ourstatus->kind = TARGET_WAITKIND_FORKED;
- else if (event == PTRACE_EVENT_VFORK)
- ourstatus->kind = TARGET_WAITKIND_VFORKED;
- else
- ourstatus->kind = TARGET_WAITKIND_SPURIOUS;
-
- ourstatus->value.related_pid = new_pid;
- return inferior_ptid;
- }
-
- if (event == PTRACE_EVENT_EXEC)
- {
- ourstatus->kind = TARGET_WAITKIND_EXECD;
- ourstatus->value.execd_pathname
- = xstrdup (child_pid_to_exec_file (pid));
-
- if (linux_parent_pid)
- {
- detach_breakpoints (linux_parent_pid);
- ptrace (PTRACE_DETACH, linux_parent_pid, 0, 0);
-
- linux_parent_pid = 0;
- }
-
- return inferior_ptid;
- }
-
- internal_error (__FILE__, __LINE__,
- _("unknown ptrace event %d"), event);
-}
-