+ /* It can happen that what we knew as the target inferior id
+ changes. E.g, target remote may only discover the remote process
+ pid after adding the inferior to GDB's list. */
+ inf = find_inferior_ptid (old_ptid);
+ inf->pid = ptid_get_pid (new_ptid);
+
+ tp = find_thread_ptid (old_ptid);
+ tp->ptid = new_ptid;
+
+ observer_notify_thread_ptid_changed (old_ptid, new_ptid);
+}
+
+/* See gdbthread.h. */
+
+void
+set_resumed (ptid_t ptid, int resumed)
+{
+ struct thread_info *tp;
+ int all = ptid == minus_one_ptid;
+
+ if (all || ptid_is_pid (ptid))
+ {
+ for (tp = thread_list; tp; tp = tp->next)
+ if (all || ptid_get_pid (tp->ptid) == ptid_get_pid (ptid))
+ tp->resumed = resumed;
+ }
+ else
+ {
+ tp = find_thread_ptid (ptid);
+ gdb_assert (tp != NULL);
+ tp->resumed = resumed;
+ }
+}
+
+/* Helper for set_running, that marks one thread either running or
+ stopped. */
+
+static int
+set_running_thread (struct thread_info *tp, int running)
+{
+ int started = 0;
+
+ if (running && tp->state == THREAD_STOPPED)
+ started = 1;
+ tp->state = running ? THREAD_RUNNING : THREAD_STOPPED;
+
+ if (!running)
+ {
+ /* If the thread is now marked stopped, remove it from
+ the step-over queue, so that we don't try to resume
+ it until the user wants it to. */
+ if (tp->step_over_next != NULL)
+ thread_step_over_chain_remove (tp);
+ }
+
+ return started;
+}
+
+void
+set_running (ptid_t ptid, int running)
+{
+ struct thread_info *tp;
+ int all = ptid == minus_one_ptid;
+ int any_started = 0;
+
+ /* We try not to notify the observer if no thread has actually changed
+ the running state -- merely to reduce the number of messages to
+ frontend. Frontend is supposed to handle multiple *running just fine. */
+ if (all || ptid_is_pid (ptid))
+ {
+ for (tp = thread_list; tp; tp = tp->next)
+ if (all || ptid_get_pid (tp->ptid) == ptid_get_pid (ptid))
+ {
+ if (tp->state == THREAD_EXITED)
+ continue;
+
+ if (set_running_thread (tp, running))
+ any_started = 1;
+ }
+ }
+ else
+ {
+ tp = find_thread_ptid (ptid);
+ gdb_assert (tp != NULL);
+ gdb_assert (tp->state != THREAD_EXITED);
+ if (set_running_thread (tp, running))
+ any_started = 1;
+ }
+ if (any_started)
+ observer_notify_target_resumed (ptid);
+}
+
+static int
+is_thread_state (ptid_t ptid, enum thread_state state)
+{
+ struct thread_info *tp;
+
+ tp = find_thread_ptid (ptid);
+ gdb_assert (tp);
+ return tp->state == state;
+}
+
+int
+is_stopped (ptid_t ptid)
+{
+ return is_thread_state (ptid, THREAD_STOPPED);
+}
+
+int
+is_exited (ptid_t ptid)
+{
+ return is_thread_state (ptid, THREAD_EXITED);
+}
+
+int
+is_running (ptid_t ptid)
+{
+ return is_thread_state (ptid, THREAD_RUNNING);
+}
+
+int
+is_executing (ptid_t ptid)
+{
+ struct thread_info *tp;
+
+ tp = find_thread_ptid (ptid);
+ gdb_assert (tp);
+ return tp->executing;
+}
+
+void
+set_executing (ptid_t ptid, int executing)
+{
+ struct thread_info *tp;
+ int all = ptid == minus_one_ptid;
+
+ if (all || ptid_is_pid (ptid))
+ {