const std::string &allargs,
char **env, int from_tty)
{
- pid_t pid;
- ptid_t ptid;
-
/* Do not change either targets above or the same target if already present.
The reason is the target stack is shared across multiple inferiors. */
int ops_already_pushed = target_is_pushed (this);
unpusher.reset (this);
}
- pid = fork_inferior (exec_file, allargs, env, inf_ptrace_me, NULL,
- NULL, NULL, NULL);
+ pid_t pid = fork_inferior (exec_file, allargs, env, inf_ptrace_me, NULL,
+ NULL, NULL, NULL);
- ptid = ptid_t (pid);
+ ptid_t ptid (pid);
/* We have something that executes now. We'll be running through
the shell at this point (if startup-with-shell is true), but the
pid shouldn't change. */
- add_thread_silent (this, ptid);
+ thread_info *thr = add_thread_silent (this, ptid);
+ switch_to_thread (thr);
unpusher.release ();
inf = current_inferior ();
inferior_appeared (inf, pid);
inf->attach_flag = 1;
- inferior_ptid = ptid_t (pid);
/* Always add a main thread. If some target extends the ptrace
target, it should decorate the ptid later with more info. */
- thread_info *thr = add_thread_silent (this, inferior_ptid);
+ thread_info *thr = add_thread_silent (this, ptid_t (pid));
+ switch_to_thread (thr);
+
/* Don't consider the thread stopped until we've processed its
initial SIGSTOP stop. */
set_executing (this, thr->ptid, true);
void
inf_ptrace_target::detach_success (inferior *inf)
{
- inferior_ptid = null_ptid;
+ switch_to_no_thread ();
detach_inferior (inf);
maybe_unpush_target ();
ptid_t
inf_ptrace_target::wait (ptid_t ptid, struct target_waitstatus *ourstatus,
- int options)
+ target_wait_flags options)
{
pid_t pid;
int status, save_errno;
}
/* Ignore terminated detached child processes. */
- if (!WIFSTOPPED (status) && pid != inferior_ptid.pid ())
+ if (!WIFSTOPPED (status) && find_inferior_pid (this, pid) == nullptr)
pid = -1;
}
while (pid == -1);
-#ifdef PT_GET_PROCESS_STATE
- if (WIFSTOPPED (status))
- {
- ptrace_state_t pe;
- pid_t fpid;
-
- if (ptrace (PT_GET_PROCESS_STATE, pid,
- (PTRACE_TYPE_ARG3)&pe, sizeof pe) == -1)
- perror_with_name (("ptrace"));
-
- switch (pe.pe_report_event)
- {
- case PTRACE_FORK:
- ourstatus->kind = TARGET_WAITKIND_FORKED;
- ourstatus->value.related_pid = ptid_t (pe.pe_other_pid);
-
- /* Make sure the other end of the fork is stopped too. */
- fpid = waitpid (pe.pe_other_pid, &status, 0);
- if (fpid == -1)
- perror_with_name (("waitpid"));
-
- if (ptrace (PT_GET_PROCESS_STATE, fpid,
- (PTRACE_TYPE_ARG3)&pe, sizeof pe) == -1)
- perror_with_name (("ptrace"));
-
- gdb_assert (pe.pe_report_event == PTRACE_FORK);
- gdb_assert (pe.pe_other_pid == pid);
- if (fpid == inferior_ptid.pid ())
- {
- ourstatus->value.related_pid = ptid_t (pe.pe_other_pid);
- return ptid_t (fpid);
- }
-
- return ptid_t (pid);
- }
- }
-#endif
-
store_waitstatus (ourstatus, status);
return ptid_t (pid);
}