+discard_all_inferior_continuations (struct inferior *inf)
+{
+ struct cleanup *continuation_ptr = &inf->continuations->base;
+ discard_my_cleanups (&continuation_ptr, NULL);
+ inf->continuations = NULL;
+}
+
+static void
+restore_thread_cleanup (void *arg)
+{
+ ptid_t *ptid_p = arg;
+ switch_to_thread (*ptid_p);
+}
+
+/* Walk down the continuation list of PTID, and execute all the
+ continuations. There is a problem though. In some cases new
+ continuations may be added while we are in the middle of this loop.
+ If this happens they will be added in the front, and done before we
+ have a chance of exhausting those that were already there. We need
+ to then save the beginning of the list in a pointer and do the
+ continuations from there on, instead of using the global beginning
+ of list as our iteration pointer. */
+static void
+do_all_continuations_ptid (ptid_t ptid,
+ struct continuation **continuations_p)
+{
+ struct cleanup *old_chain;
+ ptid_t current_thread;
+ struct cleanup *as_cleanup;
+
+ if (*continuations_p == NULL)
+ return;
+
+ current_thread = inferior_ptid;
+
+ /* Restore selected thread on exit. Don't try to restore the frame
+ as well, because:
+
+ - When running continuations, the selected frame is always #0.
+
+ - The continuations may trigger symbol file loads, which may
+ change the frame layout (frame ids change), which would trigger
+ a warning if we used make_cleanup_restore_current_thread. */
+
+ old_chain = make_cleanup (restore_thread_cleanup, ¤t_thread);
+
+ /* Let the continuation see this thread as selected. */
+ switch_to_thread (ptid);
+
+ /* Copy the list header into another pointer, and set the global
+ list header to null, so that the global list can change as a side
+ effect of invoking the continuations and the processing of the
+ preexisting continuations will not be affected. */
+
+ as_cleanup = &(*continuations_p)->base;
+ *continuations_p = NULL;
+
+ /* Work now on the list we have set aside. */
+ do_my_cleanups (&as_cleanup, NULL);
+
+ do_cleanups (old_chain);
+}
+
+/* Callback for iterate over threads. */
+static int
+do_all_continuations_thread_callback (struct thread_info *thread, void *data)
+{
+ do_all_continuations_ptid (thread->ptid, &thread->continuations);
+ return 0;
+}
+
+/* Do all continuations of thread THREAD. */
+void
+do_all_continuations_thread (struct thread_info *thread)
+{
+ do_all_continuations_thread_callback (thread, NULL);
+}
+
+/* Do all continuations of all threads. */
+void
+do_all_continuations (void)
+{
+ iterate_over_threads (do_all_continuations_thread_callback, NULL);
+}
+
+/* Callback for iterate over threads. */
+static int
+discard_all_continuations_thread_callback (struct thread_info *thread,
+ void *data)