aboutsummaryrefslogtreecommitdiff
path: root/gdb/utils.c
diff options
context:
space:
mode:
authorPedro Alves <palves@redhat.com>2008-09-08 21:57:42 +0000
committerPedro Alves <palves@redhat.com>2008-09-08 21:57:42 +0000
commit95e54da724be3b6673da2432d0613e163be03db3 (patch)
treebf4bbf09a3d60fb10e4c05534f61378ecc436047 /gdb/utils.c
parent414c69f7a7e241fd4a4cb85535d864d48ddbee1f (diff)
downloadfsf-binutils-gdb-95e54da724be3b6673da2432d0613e163be03db3.zip
fsf-binutils-gdb-95e54da724be3b6673da2432d0613e163be03db3.tar.gz
fsf-binutils-gdb-95e54da724be3b6673da2432d0613e163be03db3.tar.bz2
Remove global continuations in favour of a per-thread
continuations. * gdbthread.h (struct thread_info): Add comments around continuations and intermediate_continuations. (save_infrun_state, load_infrun_state): Delete continuations and intermediate_continuations arguments. * infrun.c (fetch_inferior_event): Only call normal_stop if stop_soon is NO_STOP_QUIETLY. (context_switch): Don't context-switch the continuations. * thread.c (clear_thread_inferior_resources): Discard all continuations of the thread we're clearing. (save_infrun_state, load_infrun_state): Delete continuations and intermediate_continuations arguments, and the code referencing them. * utils.c: Include "gdbthread.h". (cmd_continuation, intermediate_continuation): Delete. (add_continuation): Add thread_info* argument. Install the continuation on it. (restore_thread_cleanup): New. (do_all_continuations_ptid, do_all_continuations_thread_callback): New. (do_all_continuations): Reimplement. (discard_all_continuations_thread_callback, discard_all_continuations_thread): New. (discard_all_continuations): Reimplement. (add_intermediate_continuation): Add thread_info* argument. Install the continuation on it. (do_all_intermediate_continuations_thread_callback) (do_all_intermediate_continuations_thread): New. (do_all_intermediate_continuations): Reimplement. (discard_all_intermediate_continuations_thread_callback): New. (discard_all_intermediate_continuations_thread): New. (discard_all_intermediate_continuations): Reimplement. * breakpoint.c (until_break_command): Install the continuation on the current thread. * defs.h (cmd_continuation, intermediate_continuation): Delete. (struct thread_info): Forward declare. (add_continuation, add_intermediate_continuation): Add thread_info* argument. (do_all_continuations_thread, discard_all_continuations_thread) (do_all_intermediate_continuations_thread) (discard_all_intermediate_continuations_thread): Declare. * inf-loop.c (inferior_event_handler): In non-stop only run continuations on the thread that stopped. In all-stop, run continuations on all threads. * infcmd.c (step_once, finish_command): Adjust.
Diffstat (limited to 'gdb/utils.c')
-rw-r--r--gdb/utils.c190
1 files changed, 137 insertions, 53 deletions
diff --git a/gdb/utils.c b/gdb/utils.c
index 4aa3367..ce05909 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -25,6 +25,7 @@
#include "gdb_string.h"
#include "event-top.h"
#include "exceptions.h"
+#include "gdbthread.h"
#ifdef TUI
#include "tui/tui.h" /* For tui_get_command_dimension. */
@@ -105,13 +106,6 @@ static int debug_timestamp = 0;
static struct cleanup *cleanup_chain; /* cleaned up after a failed command */
static struct cleanup *final_cleanup_chain; /* cleaned up when gdb exits */
-/* Pointer to what is left to do for an execution command after the
- target stops. Used only in asynchronous mode, by targets that
- support async execution. The finish and until commands use it. So
- does the target extended-remote command. */
-struct continuation *cmd_continuation;
-struct continuation *intermediate_continuation;
-
/* Nonzero if we have job control. */
int job_control;
@@ -477,14 +471,14 @@ struct continuation
struct cleanup base;
};
-/* Add a continuation to the continuation list, the global list
- cmd_continuation. The new continuation will be added at the
- front. */
+/* Add a continuation to the continuation list of THREAD. The new
+ continuation will be added at the front. */
void
-add_continuation (void (*continuation_hook) (void *), void *args,
+add_continuation (struct thread_info *thread,
+ void (*continuation_hook) (void *), void *args,
void (*continuation_free_args) (void *))
{
- struct cleanup *as_cleanup = &cmd_continuation->base;
+ struct cleanup *as_cleanup = &thread->continuations->base;
make_cleanup_ftype *continuation_hook_fn = continuation_hook;
make_my_cleanup2 (&as_cleanup,
@@ -492,53 +486,122 @@ add_continuation (void (*continuation_hook) (void *), void *args,
args,
continuation_free_args);
- cmd_continuation = (struct continuation *) as_cleanup;
+ thread->continuations = (struct continuation *) as_cleanup;
}
-/* Walk down the cmd_continuation list, 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. */
-void
-do_all_continuations (void)
+static void
+restore_thread_cleanup (void *arg)
{
- struct cleanup *continuation_ptr;
+ 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, &current_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. */
- continuation_ptr = &cmd_continuation->base;
- cmd_continuation = NULL;
+ as_cleanup = &(*continuations_p)->base;
+ *continuations_p = NULL;
/* Work now on the list we have set aside. */
- do_my_cleanups (&continuation_ptr, NULL);
+ do_my_cleanups (&as_cleanup, NULL);
+
+ do_cleanups (old_chain);
}
-/* Walk down the cmd_continuation list, and get rid of all the
- continuations. */
+/* 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
-discard_all_continuations (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)
{
- struct cleanup *continuation_ptr = &cmd_continuation->base;
+ struct cleanup *continuation_ptr = &thread->continuations->base;
discard_my_cleanups (&continuation_ptr, NULL);
- cmd_continuation = NULL;
+ thread->continuations = NULL;
+ return 0;
+}
+
+/* Get rid of all the continuations of THREAD. */
+void
+discard_all_continuations_thread (struct thread_info *thread)
+{
+ discard_all_continuations_thread_callback (thread, NULL);
+}
+
+/* Get rid of all the continuations of all threads. */
+void
+discard_all_continuations (void)
+{
+ iterate_over_threads (discard_all_continuations_thread_callback, NULL);
}
-/* Add a continuation to the continuation list, the global list
- intermediate_continuation. The new continuation will be added at
- the front. */
+
+/* Add a continuation to the intermediate continuation list of THREAD.
+ The new continuation will be added at the front. */
void
-add_intermediate_continuation (void (*continuation_hook)
+add_intermediate_continuation (struct thread_info *thread,
+ void (*continuation_hook)
(void *), void *args,
void (*continuation_free_args) (void *))
{
- struct cleanup *as_cleanup = &intermediate_continuation->base;
+ struct cleanup *as_cleanup = &thread->intermediate_continuations->base;
make_cleanup_ftype *continuation_hook_fn = continuation_hook;
make_my_cleanup2 (&as_cleanup,
@@ -546,7 +609,7 @@ add_intermediate_continuation (void (*continuation_hook)
args,
continuation_free_args);
- intermediate_continuation = (struct continuation *) as_cleanup;
+ thread->intermediate_continuations = (struct continuation *) as_cleanup;
}
/* Walk down the cmd_continuation list, and execute all the
@@ -557,31 +620,52 @@ add_intermediate_continuation (void (*continuation_hook)
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 int
+do_all_intermediate_continuations_thread_callback (struct thread_info *thread,
+ void *data)
+{
+ do_all_continuations_ptid (thread->ptid,
+ &thread->intermediate_continuations);
+ return 0;
+}
+
+/* Do all intermediate continuations of thread THREAD. */
void
-do_all_intermediate_continuations (void)
+do_all_intermediate_continuations_thread (struct thread_info *thread)
{
- struct cleanup *continuation_ptr;
+ do_all_intermediate_continuations_thread_callback (thread, NULL);
+}
- /* 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. */
+/* Do all intermediate continuations of all threads. */
+void
+do_all_intermediate_continuations (void)
+{
+ iterate_over_threads (do_all_intermediate_continuations_thread_callback, NULL);
+}
- continuation_ptr = &intermediate_continuation->base;
- intermediate_continuation = NULL;
+/* Callback for iterate over threads. */
+static int
+discard_all_intermediate_continuations_thread_callback (struct thread_info *thread,
+ void *data)
+{
+ struct cleanup *continuation_ptr = &thread->intermediate_continuations->base;
+ discard_my_cleanups (&continuation_ptr, NULL);
+ thread->intermediate_continuations = NULL;
+ return 0;
+}
- /* Work now on the list we have set aside. */
- do_my_cleanups (&continuation_ptr, NULL);
+/* Get rid of all the intermediate continuations of THREAD. */
+void
+discard_all_intermediate_continuations_thread (struct thread_info *thread)
+{
+ discard_all_intermediate_continuations_thread_callback (thread, NULL);
}
-/* Walk down the cmd_continuation list, and get rid of all the
- continuations. */
+/* Get rid of all the intermediate continuations of all threads. */
void
discard_all_intermediate_continuations (void)
{
- struct cleanup *continuation_ptr = &intermediate_continuation->base;
- discard_my_cleanups (&continuation_ptr, NULL);
- continuation_ptr = NULL;
+ iterate_over_threads (discard_all_intermediate_continuations_thread_callback, NULL);
}