diff --git a/gdb/aix-thread.c b/gdb/aix-thread.c index ecd8200b692..d47f5132592 100644 --- a/gdb/aix-thread.c +++ b/gdb/aix-thread.c @@ -701,14 +701,14 @@ gcmp (const void *t1v, const void *t2v) Return 0 if none found. */ static pthdb_tid_t -get_signaled_thread (void) +get_signaled_thread (int pid) { struct thrdsinfo64 thrinf; tid_t ktid = 0; while (1) { - if (getthrds (inferior_ptid.pid (), &thrinf, + if (getthrds (pid, &thrinf, sizeof (thrinf), &ktid, 1) != 1) break; @@ -734,9 +734,9 @@ get_signaled_thread (void) have difficulty with certain call patterns */ static void -sync_threadlists (void) +sync_threadlists (int pid) { - int cmd, status, infpid; + int cmd, status; int pcount, psize, pi, gcount, gi; struct pd_thread *pbuf; struct thread_info **gbuf, **g, *thread; @@ -790,8 +790,6 @@ sync_threadlists (void) qsort (gbuf, gcount, sizeof *gbuf, gcmp); /* Apply differences between the two arrays to GDB's thread list. */ - - infpid = inferior_ptid.pid (); for (pi = gi = 0; pi < pcount || gi < gcount;) { if (pi == pcount) @@ -808,7 +806,7 @@ sync_threadlists (void) process_stratum_target *proc_target = current_inferior ()->process_target (); thread = add_thread_with_info (proc_target, - ptid_t (infpid, 0, pbuf[pi].pthid), + ptid_t (pid, 0, pbuf[pi].pthid), priv); pi++; @@ -818,7 +816,7 @@ sync_threadlists (void) ptid_t pptid, gptid; int cmp_result; - pptid = ptid_t (infpid, 0, pbuf[pi].pthid); + pptid = ptid_t (pid, 0, pbuf[pi].pthid); gptid = gbuf[gi]->ptid; pdtid = pbuf[pi].pdtid; tid = pbuf[pi].tid; @@ -872,10 +870,11 @@ iter_tid (struct thread_info *thread, void *tidp) /* Synchronize libpthdebug's state with the inferior and with GDB, generate a composite process/thread for the current thread, - set inferior_ptid to if SET_INFPID, and return . */ + Return the ptid of the event thread if one can be found, else + return a pid-only ptid with PID. */ static ptid_t -pd_update (int set_infpid) +pd_update (int pid) { int status; ptid_t ptid; @@ -883,36 +882,33 @@ pd_update (int set_infpid) struct thread_info *thread = NULL; if (!pd_active) - return inferior_ptid; + return ptid_t (pid); status = pthdb_session_update (pd_session); if (status != PTHDB_SUCCESS) - return inferior_ptid; + return ptid_t (pid); - sync_threadlists (); + sync_threadlists (pid); /* Define "current thread" as one that just received a trap signal. */ - tid = get_signaled_thread (); + tid = get_signaled_thread (pid); if (tid != 0) thread = iterate_over_threads (iter_tid, &tid); if (!thread) - ptid = inferior_ptid; + ptid = ptid_t (pid); else - { - ptid = thread->ptid; - if (set_infpid) - switch_to_thread (thread); - } + ptid = thread->ptid; + return ptid; } /* Try to start debugging threads in the current process. - If successful and SET_INFPID, set inferior_ptid to reflect the - current thread. */ + If successful and there exists and we can find an event thread, return a ptid + for that thread. Otherwise, return a ptid-only ptid using PID. */ static ptid_t -pd_activate (int set_infpid) +pd_activate (int pid) { int status; @@ -921,10 +917,10 @@ pd_activate (int set_infpid) &pd_session); if (status != PTHDB_SUCCESS) { - return inferior_ptid; + return ptid_t (pid); } pd_active = 1; - return pd_update (set_infpid); + return pd_update (pid); } /* Undo the effects of pd_activate(). */ @@ -1080,17 +1076,18 @@ aix_thread_target::wait (ptid_t ptid, struct target_waitstatus *status, target_wait_flags options) { { - scoped_restore save_inferior_ptid = make_scoped_restore (&inferior_ptid); - pid_to_prc (&ptid); - inferior_ptid = ptid_t (inferior_ptid.pid ()); ptid = beneath ()->wait (ptid, status, options); } if (ptid.pid () == -1) return ptid_t (-1); + /* The target beneath does not deal with threads, so it should only return + pid-only ptids. */ + gdb_assert (ptid.is_pid ()); + /* Check whether libpthdebug might be ready to be initialized. */ if (!pd_active && status->kind () == TARGET_WAITKIND_STOPPED && status->sig () == GDB_SIGNAL_TRAP) @@ -1102,10 +1099,10 @@ aix_thread_target::wait (ptid_t ptid, struct target_waitstatus *status, if (regcache_read_pc (regcache) - gdbarch_decr_pc_after_break (gdbarch) == pd_brk_addr) - return pd_activate (0); + return pd_activate (ptid.pid ()); } - return pd_update (0); + return pd_update (ptid.pid ()); } /* Record that the 64-bit general-purpose registers contain VALS. */ @@ -1765,7 +1762,7 @@ aix_thread_target::pid_to_str (ptid_t ptid) if (!PD_TID (ptid)) return beneath ()->pid_to_str (ptid); - return string_printf (_("Thread %ld"), ptid.tid ()); + return string_printf (_("Thread %s"), pulongest (ptid.tid ())); } /* Return a printable representation of extra information about diff --git a/gdb/rs6000-aix-nat.c b/gdb/rs6000-aix-nat.c index 8563aea313a..f604f7d503e 100644 --- a/gdb/rs6000-aix-nat.c +++ b/gdb/rs6000-aix-nat.c @@ -523,13 +523,12 @@ rs6000_nat_target::wait (ptid_t ptid, struct target_waitstatus *ourstatus, _("Child process unexpectedly missing: %s.\n"), safe_strerror (save_errno)); - /* Claim it exited with unknown signal. */ - ourstatus->set_signalled (GDB_SIGNAL_UNKNOWN); - return inferior_ptid; + ourstatus->set_ignore (); + return minus_one_ptid; } /* 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);