aboutsummaryrefslogtreecommitdiff
path: root/gdb/thread.c
diff options
context:
space:
mode:
authorPedro Alves <palves@redhat.com>2015-08-07 17:23:57 +0100
committerPedro Alves <palves@redhat.com>2015-08-07 17:23:57 +0100
commitc2829269f5af8a860b54ceac3596610b1f51fee5 (patch)
tree83f1eb93f9a22910a95b423efa93429199b8d74d /gdb/thread.c
parent6c4cfb244b408f980be24ea2175bc58baf74a6f9 (diff)
downloadfsf-binutils-gdb-c2829269f5af8a860b54ceac3596610b1f51fee5.zip
fsf-binutils-gdb-c2829269f5af8a860b54ceac3596610b1f51fee5.tar.gz
fsf-binutils-gdb-c2829269f5af8a860b54ceac3596610b1f51fee5.tar.bz2
Embed the pending step-over chain in thread_info objects
In order to teach non-stop mode to do in-line step-overs (pause all threads, remove breakpoint, single-step, reinsert breakpoint, restart threads), we'll need to be able to queue in-line step over requests, much like we queue displaced stepping (out-of-line) requests. Actually, the queue should be the same -- threads wait for their turn to step past something (breakpoint, watchpoint), doesn't matter what technique we end up using when the step over actually starts. I found that the queue management ends up simpler and more efficient if embedded in the thread objects themselves. This commit converts the existing displaced stepping queue to that. Later patches will make the in-line step-overs code paths use it too. gdb/ChangeLog: 2015-08-07 Pedro Alves <palves@redhat.com> * gdbthread.h (struct thread_info) <step_over_prev, step_over_next>: New fields. (thread_step_over_chain_enqueue, thread_step_over_chain_remove) (thread_step_over_chain_next, thread_is_in_step_over_chain): New declarations. * infrun.c (struct displaced_step_request): Delete. (struct displaced_step_inferior_state) <step_request_queue>: Delete field. (displaced_step_prepare): Assert that trap_expected is set. Use thread_step_over_chain_enqueue. Split starting a new displaced step to ... (start_step_over): ... this new function. (resume): Assert the thread isn't waiting for a step over already. (proceed): Assert the thread isn't waiting for a step over already. (infrun_thread_stop_requested): Adjust to remove threads from the embedded step-over chain. (handle_inferior_event) <fork/vfork>: Call start_step_over after displaced_step_fixup. (handle_signal_stop): Call start_step_over after displaced_step_fixup. * infrun.h (step_over_queue_head): New declaration. * thread.c (step_over_chain_enqueue, step_over_chain_remove) (thread_step_over_chain_next, thread_is_in_step_over_chain) (thread_step_over_chain_enqueue) (thread_step_over_chain_remove): New functions. (delete_thread_1): Remove thread from the step-over chain.
Diffstat (limited to 'gdb/thread.c')
-rw-r--r--gdb/thread.c84
1 files changed, 84 insertions, 0 deletions
diff --git a/gdb/thread.c b/gdb/thread.c
index 46b5947..28e5ef8 100644
--- a/gdb/thread.c
+++ b/gdb/thread.c
@@ -307,6 +307,86 @@ add_thread (ptid_t ptid)
return add_thread_with_info (ptid, NULL);
}
+/* Add TP to the end of the step-over chain LIST_P. */
+
+static void
+step_over_chain_enqueue (struct thread_info **list_p, struct thread_info *tp)
+{
+ gdb_assert (tp->step_over_next == NULL);
+ gdb_assert (tp->step_over_prev == NULL);
+
+ if (*list_p == NULL)
+ {
+ *list_p = tp;
+ tp->step_over_prev = tp->step_over_next = tp;
+ }
+ else
+ {
+ struct thread_info *head = *list_p;
+ struct thread_info *tail = head->step_over_prev;
+
+ tp->step_over_prev = tail;
+ tp->step_over_next = head;
+ head->step_over_prev = tp;
+ tail->step_over_next = tp;
+ }
+}
+
+/* Remove TP from step-over chain LIST_P. */
+
+static void
+step_over_chain_remove (struct thread_info **list_p, struct thread_info *tp)
+{
+ gdb_assert (tp->step_over_next != NULL);
+ gdb_assert (tp->step_over_prev != NULL);
+
+ if (*list_p == tp)
+ {
+ if (tp == tp->step_over_next)
+ *list_p = NULL;
+ else
+ *list_p = tp->step_over_next;
+ }
+
+ tp->step_over_prev->step_over_next = tp->step_over_next;
+ tp->step_over_next->step_over_prev = tp->step_over_prev;
+ tp->step_over_prev = tp->step_over_next = NULL;
+}
+
+/* See gdbthread.h. */
+
+struct thread_info *
+thread_step_over_chain_next (struct thread_info *tp)
+{
+ struct thread_info *next = tp->step_over_next;
+
+ return (next == step_over_queue_head ? NULL : next);
+}
+
+/* See gdbthread.h. */
+
+int
+thread_is_in_step_over_chain (struct thread_info *tp)
+{
+ return (tp->step_over_next != NULL);
+}
+
+/* See gdbthread.h. */
+
+void
+thread_step_over_chain_enqueue (struct thread_info *tp)
+{
+ step_over_chain_enqueue (&step_over_queue_head, tp);
+}
+
+/* See gdbthread.h. */
+
+void
+thread_step_over_chain_remove (struct thread_info *tp)
+{
+ step_over_chain_remove (&step_over_queue_head, tp);
+}
+
/* Delete thread PTID. If SILENT, don't notify the observer of this
exit. */
static void
@@ -323,6 +403,10 @@ delete_thread_1 (ptid_t ptid, int silent)
if (!tp)
return;
+ /* Dead threads don't need to step-over. Remove from queue. */
+ if (tp->step_over_next != NULL)
+ thread_step_over_chain_remove (tp);
+
/* If this is the current thread, or there's code out there that
relies on it existing (refcount > 0) we can't delete yet. Mark
it as exited, and notify it. */