aboutsummaryrefslogtreecommitdiff
path: root/gdb/procfs.c
diff options
context:
space:
mode:
authorPedro Alves <palves@redhat.com>2020-06-22 10:54:08 +0100
committerPedro Alves <palves@redhat.com>2020-06-22 11:10:49 +0100
commitf809832224cc45eb58812f6d4bb03cbf52fad980 (patch)
tree18c54e3f54aeb3178283c2407617f17bc4386726 /gdb/procfs.c
parent39ff0b812324f4b050bb0b367b269db6d4d0cb8b (diff)
downloadbinutils-f809832224cc45eb58812f6d4bb03cbf52fad980.zip
binutils-f809832224cc45eb58812f6d4bb03cbf52fad980.tar.gz
binutils-f809832224cc45eb58812f6d4bb03cbf52fad980.tar.bz2
Solaris, target_wait(), don't rely on inferior_ptid
Debugging on Solaris is broken, with the procfs target backend failing with: procfs: couldn't find pid 0 in procinfo list. as soon as you start a program. The problem is procfs_target::wait assuming that inferior_ptid is meaningful on entry, but, since the multi-target series, inferior_ptid is null_ptid before we call target_wait, in infrun.c: static ptid_t do_target_wait_1 (inferior *inf, ptid_t ptid, target_waitstatus *status, int options) { ... /* We know that we are looking for an event in the target of inferior INF, but we don't know which thread the event might come from. As such we want to make sure that INFERIOR_PTID is reset so that none of the wait code relies on it - doing so is always a mistake. */ switch_to_inferior_no_thread (inf); This patch tweaks the backend to remove the assumption that inferior_ptid points at something. sol-thread.c (the thread_stratum that sits on top of procfs.c) also has the same issue. Some spots in procfs_target::wait were returning TARGET_WAITKIND_SPURIOUS+inferior_ptid. This commit replaces those with waiting again without returning to the core. This fixes the relying on inferior_ptid, and also should fix the issue discussed here: https://sourceware.org/pipermail/gdb/2020-May/048616.html https://sourceware.org/pipermail/gdb/2020-June/048660.html gdb/ChangeLog: 2020-06-22 Pedro Alves <palves@redhat.com> PR gdb/25939 * procfs.c (procfs_target::wait): Don't reference inferior_ptid. Use the current inferior instead. Don't return TARGET_WAITKIND_SPURIOUS/inferior_ptid -- instead continue and wait again. * sol-thread.c (sol_thread_target::wait): Don't reference inferior_ptid. (ps_lgetregs, ps_lsetregs, ps_lgetfpregs, ps_lsetfpregs) (sol_update_thread_list_callback): Use the current inferior's pid instead of inferior_ptid.
Diffstat (limited to 'gdb/procfs.c')
-rw-r--r--gdb/procfs.c45
1 files changed, 17 insertions, 28 deletions
diff --git a/gdb/procfs.c b/gdb/procfs.c
index 6360436..65243b1 100644
--- a/gdb/procfs.c
+++ b/gdb/procfs.c
@@ -2052,7 +2052,11 @@ wait_again:
retval = ptid_t (-1);
/* Find procinfo for main process. */
- pi = find_procinfo_or_die (inferior_ptid.pid (), 0);
+
+ /* procfs_target currently only supports one inferior. */
+ inferior *inf = current_inferior ();
+
+ pi = find_procinfo_or_die (inf->pid, 0);
if (pi)
{
/* We must assume that the status is stale now... */
@@ -2079,10 +2083,10 @@ wait_again:
wait_retval = ::wait (&wstat); /* "wait" for the child's exit. */
/* Wrong child? */
- if (wait_retval != inferior_ptid.pid ())
+ if (wait_retval != inf->pid)
error (_("procfs: couldn't stop "
"process %d: wait returned %d."),
- inferior_ptid.pid (), wait_retval);
+ inf->pid, wait_retval);
/* FIXME: might I not just use waitpid?
Or try find_procinfo to see if I know about this child? */
retval = ptid_t (wait_retval);
@@ -2137,13 +2141,11 @@ wait_again:
printf_unfiltered (_("[%s exited]\n"),
target_pid_to_str (retval).c_str ());
delete_thread (find_thread_ptid (this, retval));
- status->kind = TARGET_WAITKIND_SPURIOUS;
- return retval;
+ target_continue_no_signal (ptid);
+ goto wait_again;
}
else if (what == SYS_exit)
{
- struct inferior *inf;
-
/* Handle SYS_exit call only. */
/* Stopped at entry to SYS_exit.
Make it runnable, resume it, then use
@@ -2158,14 +2160,13 @@ wait_again:
if (!proc_run_process (pi, 0, 0))
proc_error (pi, "target_wait, run_process", __LINE__);
- inf = find_inferior_pid (this, pi->pid);
if (inf->attach_flag)
{
/* Don't call wait: simulate waiting for exit,
return a "success" exit code. Bogus: what if
it returns something else? */
wstat = 0;
- retval = inferior_ptid; /* ? ? ? */
+ retval = ptid_t (inf->pid); /* ? ? ? */
}
else
{
@@ -2204,19 +2205,9 @@ wait_again:
i, sysargs[i]);
}
- if (status)
- {
- /* How to exit gracefully, returning "unknown
- event". */
- status->kind = TARGET_WAITKIND_SPURIOUS;
- return inferior_ptid;
- }
- else
- {
- /* How to keep going without returning to wfi: */
- target_continue_no_signal (ptid);
- goto wait_again;
- }
+ /* How to keep going without returning to wfi: */
+ target_continue_no_signal (ptid);
+ goto wait_again;
}
break;
case PR_SYSEXIT:
@@ -2248,9 +2239,8 @@ wait_again:
if (!in_thread_list (this, temp_ptid))
add_thread (this, temp_ptid);
- /* Return to WFI, but tell it to immediately resume. */
- status->kind = TARGET_WAITKIND_SPURIOUS;
- return inferior_ptid;
+ target_continue_no_signal (ptid);
+ goto wait_again;
}
else if (what == SYS_lwp_exit)
{
@@ -2281,8 +2271,8 @@ wait_again:
i, sysargs[i]);
}
- status->kind = TARGET_WAITKIND_SPURIOUS;
- return inferior_ptid;
+ target_continue_no_signal (ptid);
+ goto wait_again;
}
break;
case PR_REQUESTED:
@@ -2333,7 +2323,6 @@ wait_again:
/* Got this far without error: If retval isn't in the
threads database, add it. */
if (retval.pid () > 0
- && retval != inferior_ptid
&& !in_thread_list (this, retval))
{
/* We have a new thread. We need to add it both to