diff options
author | Pedro Alves <palves@redhat.com> | 2020-06-22 10:54:08 +0100 |
---|---|---|
committer | Pedro Alves <palves@redhat.com> | 2020-06-22 11:10:49 +0100 |
commit | f809832224cc45eb58812f6d4bb03cbf52fad980 (patch) | |
tree | 18c54e3f54aeb3178283c2407617f17bc4386726 /gdb/sol-thread.c | |
parent | 39ff0b812324f4b050bb0b367b269db6d4d0cb8b (diff) | |
download | gdb-f809832224cc45eb58812f6d4bb03cbf52fad980.zip gdb-f809832224cc45eb58812f6d4bb03cbf52fad980.tar.gz gdb-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/sol-thread.c')
-rw-r--r-- | gdb/sol-thread.c | 30 |
1 files changed, 10 insertions, 20 deletions
diff --git a/gdb/sol-thread.c b/gdb/sol-thread.c index 9addf8d..a24d51d 100644 --- a/gdb/sol-thread.c +++ b/gdb/sol-thread.c @@ -427,16 +427,6 @@ ptid_t sol_thread_target::wait (ptid_t ptid, struct target_waitstatus *ourstatus, int options) { - ptid_t rtnval; - ptid_t save_ptid; - - save_ptid = inferior_ptid; - scoped_restore save_inferior_ptid = make_scoped_restore (&inferior_ptid); - - inferior_ptid = thread_to_lwp (inferior_ptid, main_ph.ptid.pid ()); - if (inferior_ptid.pid () == -1) - inferior_ptid = procfs_first_available (); - if (ptid.pid () != -1) { ptid_t ptid_for_warning = ptid; @@ -449,17 +439,17 @@ sol_thread_target::wait (ptid_t ptid, struct target_waitstatus *ourstatus, ptid_for_warning.tid ()); } - rtnval = beneath ()->wait (ptid, ourstatus, options); + ptid_t rtnval = beneath ()->wait (ptid, ourstatus, options); if (ourstatus->kind != TARGET_WAITKIND_EXITED) { /* Map the LWP of interest back to the appropriate thread ID. */ - rtnval = lwp_to_thread (rtnval); - if (rtnval.pid () == -1) - rtnval = save_ptid; + ptid_t thr_ptid = lwp_to_thread (rtnval); + if (thr_ptid.pid () != -1) + rtnval = thr_ptid; /* See if we have a new thread. */ - if (rtnval.tid_p () && rtnval != save_ptid) + if (rtnval.tid_p ()) { thread_info *thr = find_thread_ptid (current_inferior (), rtnval); if (thr == NULL || thr->state == THREAD_EXITED) @@ -855,7 +845,7 @@ ps_ptwrite (struct ps_prochandle *ph, psaddr_t addr, ps_err_e ps_lgetregs (struct ps_prochandle *ph, lwpid_t lwpid, prgregset_t gregset) { - ptid_t ptid = ptid_t (inferior_ptid.pid (), lwpid, 0); + ptid_t ptid = ptid_t (current_inferior ()->pid, lwpid, 0); struct regcache *regcache = get_thread_arch_regcache (current_inferior ()->process_target (), ptid, target_gdbarch ()); @@ -872,7 +862,7 @@ ps_err_e ps_lsetregs (struct ps_prochandle *ph, lwpid_t lwpid, const prgregset_t gregset) { - ptid_t ptid = ptid_t (inferior_ptid.pid (), lwpid, 0); + ptid_t ptid = ptid_t (current_inferior ()->pid, lwpid, 0); struct regcache *regcache = get_thread_arch_regcache (current_inferior ()->process_target (), ptid, target_gdbarch ()); @@ -925,7 +915,7 @@ ps_err_e ps_lgetfpregs (struct ps_prochandle *ph, lwpid_t lwpid, prfpregset_t *fpregset) { - ptid_t ptid = ptid_t (inferior_ptid.pid (), lwpid, 0); + ptid_t ptid = ptid_t (current_inferior ()->pid, lwpid, 0); struct regcache *regcache = get_thread_arch_regcache (current_inferior ()->process_target (), ptid, target_gdbarch ()); @@ -942,7 +932,7 @@ ps_err_e ps_lsetfpregs (struct ps_prochandle *ph, lwpid_t lwpid, const prfpregset_t * fpregset) { - ptid_t ptid = ptid_t (inferior_ptid.pid (), lwpid, 0); + ptid_t ptid = ptid_t (current_inferior ()->pid, lwpid, 0); struct regcache *regcache = get_thread_arch_regcache (current_inferior ()->process_target (), ptid, target_gdbarch ()); @@ -1012,7 +1002,7 @@ sol_update_thread_list_callback (const td_thrhandle_t *th, void *ignored) if (retval != TD_OK) return -1; - ptid_t ptid = ptid_t (inferior_ptid.pid (), 0, ti.ti_tid); + ptid_t ptid = ptid_t (current_inferior ()->pid, 0, ti.ti_tid); thread_info *thr = find_thread_ptid (current_inferior (), ptid); if (thr == NULL || thr->state == THREAD_EXITED) { |