+struct thread_info *
+add_thread_silent (ptid_t ptid)
+{
+ struct thread_info *tp;
+
+ tp = find_thread_ptid (ptid);
+ if (tp)
+ /* Found an old thread with the same id. It has to be dead,
+ otherwise we wouldn't be adding a new thread with the same id.
+ The OS is reusing this id --- delete it, and recreate a new
+ one. */
+ {
+ /* In addition to deleting the thread, if this is the current
+ thread, then we need to take care that delete_thread doesn't
+ really delete the thread if it is inferior_ptid. Create a
+ new template thread in the list with an invalid ptid, switch
+ to it, delete the original thread, reset the new thread's
+ ptid, and switch to it. */
+
+ if (ptid_equal (inferior_ptid, ptid))
+ {
+ tp = new_thread (ptid);
+
+ /* Make switch_to_thread not read from the thread. */
+ tp->state_ = THREAD_EXITED;
+ switch_to_thread (minus_one_ptid);
+
+ /* Now we can delete it. */
+ delete_thread (ptid);
+
+ /* Now reset its ptid, and reswitch inferior_ptid to it. */
+ tp->ptid = ptid;
+ tp->state_ = THREAD_STOPPED;
+ switch_to_thread (ptid);
+
+ observer_notify_new_thread (tp);
+
+ /* All done. */
+ return tp;
+ }
+ else
+ /* Just go ahead and delete it. */
+ delete_thread (ptid);
+ }
+
+ tp = new_thread (ptid);
+ observer_notify_new_thread (tp);
+
+ return tp;
+}
+
+struct thread_info *
+add_thread_with_info (ptid_t ptid, struct private_thread_info *private)
+{
+ struct thread_info *result = add_thread_silent (ptid);
+
+ result->private = private;
+
+ if (print_thread_events)
+ printf_unfiltered (_("[New %s]\n"), target_pid_to_str (ptid));
+
+ annotate_new_thread ();
+ return result;
+}
+
+struct thread_info *
+add_thread (ptid_t ptid)
+{
+ return add_thread_with_info (ptid, NULL);
+}
+
+/* Delete thread PTID. If SILENT, don't notify the observer of this
+ exit. */
+static void
+delete_thread_1 (ptid_t ptid, int silent)