- /* Next in list of currently installed 'struct
- current_thread_cleanup' cleanups. See
- 'current_thread_cleanup_chain' below. */
- struct current_thread_cleanup *next;
-
- ptid_t inferior_ptid;
- struct frame_id selected_frame_id;
- int selected_frame_level;
- int was_stopped;
- int inf_id;
- int was_removable;
-};
-
-/* A chain of currently installed 'struct current_thread_cleanup'
- cleanups. Restoring the previously selected thread looks up the
- old thread in the thread list by ptid. If the thread changes ptid,
- we need to update the cleanup's thread structure so the look up
- succeeds. */
-static struct current_thread_cleanup *current_thread_cleanup_chain;
-
-/* A thread_ptid_changed observer. Update all currently installed
- current_thread_cleanup cleanups that want to switch back to
- OLD_PTID to switch back to NEW_PTID instead. */
-
-static void
-restore_current_thread_ptid_changed (ptid_t old_ptid, ptid_t new_ptid)
-{
- struct current_thread_cleanup *it;
-
- for (it = current_thread_cleanup_chain; it != NULL; it = it->next)
- {
- if (ptid_equal (it->inferior_ptid, old_ptid))
- it->inferior_ptid = new_ptid;
- }
-}
-
-static void
-do_restore_current_thread_cleanup (void *arg)
-{
- struct thread_info *tp;
- struct current_thread_cleanup *old = (struct current_thread_cleanup *) arg;
-
- tp = find_thread_ptid (old->inferior_ptid);
-
- /* If the previously selected thread belonged to a process that has
- in the mean time been deleted (due to normal exit, detach, etc.),
- then don't revert back to it, but instead simply drop back to no
- thread selected. */
- if (tp
- && find_inferior_ptid (tp->ptid) != NULL)
- restore_current_thread (old->inferior_ptid);
+ /* If an entry of thread_info was previously selected, it won't be
+ deleted because we've increased its refcount. The thread represented
+ by this thread_info entry may have already exited (due to normal exit,
+ detach, etc), so the thread_info.state is THREAD_EXITED. */
+ if (m_thread != NULL
+ /* If the previously selected thread belonged to a process that has
+ in the mean time exited (or killed, detached, etc.), then don't revert
+ back to it, but instead simply drop back to no thread selected. */
+ && m_inf->pid != 0)
+ switch_to_thread (m_thread);