aboutsummaryrefslogtreecommitdiff
path: root/gdb/infrun.c
diff options
context:
space:
mode:
authorPedro Alves <pedro@palves.net>2021-11-23 20:35:12 +0000
committerPedro Alves <pedro@palves.net>2023-11-13 14:16:09 +0000
commit65c459abebf70bd5a64dcee11d4d7d4a8498465f (patch)
tree7079c882404567cd9a235a4c52280548837cfb81 /gdb/infrun.c
parent26f047ce788b42b7b5f96515d119138a8ae43979 (diff)
downloadgdb-65c459abebf70bd5a64dcee11d4d7d4a8498465f.zip
gdb-65c459abebf70bd5a64dcee11d4d7d4a8498465f.tar.gz
gdb-65c459abebf70bd5a64dcee11d4d7d4a8498465f.tar.bz2
Thread options & clone events (core + remote)
A previous patch taught GDB about a new TARGET_WAITKIND_THREAD_CLONED event kind, and made the Linux target report clone events. A following patch will teach Linux GDBserver to do the same thing. However, for remote debugging, it wouldn't be ideal for GDBserver to report every clone event to GDB, when GDB only cares about such events in some specific situations. Reporting clone events all the time would be potentially chatty. We don't enable thread create/exit events all the time for the same reason. Instead we have the QThreadEvents packet. QThreadEvents is target-wide, though. This patch makes GDB instead explicitly request that the target reports clone events or not, on a per-thread basis. In order to be able to do that with GDBserver, we need a new remote protocol feature. Since a following patch will want to enable thread exit events on per-thread basis too, the packet introduced here is more generic than just for clone events. It lets you enable/disable a set of options at once, modelled on Linux ptrace's PTRACE_SETOPTIONS. IOW, this commit introduces a new QThreadOptions packet, that lets you specify a set of per-thread event options you want to enable. The packet accepts a list of options/thread-id pairs, similarly to vCont, processed left to right, with the options field being a number interpreted as a bit mask of options. The only option defined in this commit is GDB_THREAD_OPTION_CLONE (0x1), which ask the remote target to report clone events. Another patch later in the series will introduce another option. For example, this packet sets option "1" (clone events) on thread p1000.2345: QThreadOptions;1:p1000.2345 and this clears options for all threads of process 1000, and then sets option "1" (clone events) on thread p1000.2345: QThreadOptions;0:p1000.-1;1:p1000.2345 This clears options of all threads of all processes: QThreadOptions;0 The target reports the set of supported options by including "QThreadOptions=<supported options>" in its qSupported response. infrun is then tweaked to enable GDB_THREAD_OPTION_CLONE when stepping over a breakpoint. Unlike PTRACE_SETOPTIONS, fork/vfork/clone children do NOT inherit their parent's thread options. This is so that GDB can send e.g., "QThreadOptions;0;1:TID" without worrying about threads it doesn't know about yet. Documentation for this new remote protocol feature is included in a documentation patch later in the series. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=19675 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=27830 Reviewed-By: Andrew Burgess <aburgess@redhat.com> Change-Id: Ie41e5093b2573f14cf6ac41b0b5804eba75be37e
Diffstat (limited to 'gdb/infrun.c')
-rw-r--r--gdb/infrun.c63
1 files changed, 62 insertions, 1 deletions
diff --git a/gdb/infrun.c b/gdb/infrun.c
index e3157f8..03eb32a 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -1606,7 +1606,6 @@ step_over_info_valid_p (void)
/* Return true if THREAD is doing a displaced step. */
static bool
-ATTRIBUTE_UNUSED
displaced_step_in_progress_thread (thread_info *thread)
{
gdb_assert (thread != nullptr);
@@ -1955,6 +1954,28 @@ displaced_step_prepare (thread_info *thread)
return status;
}
+/* Maybe disable thread-{cloned,created,exited} event reporting after
+ a step-over (either in-line or displaced) finishes. */
+
+static void
+update_thread_events_after_step_over (thread_info *event_thread)
+{
+ if (target_supports_set_thread_options (0))
+ {
+ /* We can control per-thread options. Disable events for the
+ event thread. */
+ event_thread->set_thread_options (0);
+ }
+ else
+ {
+ /* We can only control the target-wide target_thread_events
+ setting. Disable it, but only if other threads don't need it
+ enabled. */
+ if (!displaced_step_in_progress_any_thread ())
+ target_thread_events (false);
+ }
+}
+
/* If we displaced stepped an instruction successfully, adjust registers and
memory to yield the same effect the instruction would have had if we had
executed it at its original address, and return
@@ -1999,6 +2020,8 @@ displaced_step_finish (thread_info *event_thread,
if (!displaced->in_progress ())
return DISPLACED_STEP_FINISH_STATUS_OK;
+ update_thread_events_after_step_over (event_thread);
+
gdb_assert (event_thread->inf->displaced_step_state.in_progress_count > 0);
event_thread->inf->displaced_step_state.in_progress_count--;
@@ -2493,6 +2516,42 @@ do_target_resume (ptid_t resume_ptid, bool step, enum gdb_signal sig)
else
target_pass_signals (signal_pass);
+ /* Request that the target report thread-{created,cloned} events in
+ the following situations:
+
+ - If we are performing an in-line step-over-breakpoint, then we
+ will remove a breakpoint from the target and only run the
+ current thread. We don't want any new thread (spawned by the
+ step) to start running, as it might miss the breakpoint.
+
+ - If we are stepping over a breakpoint out of line (displaced
+ stepping) then we won't remove a breakpoint from the target,
+ but, if the step spawns a new clone thread, then we will need
+ to fixup the $pc address in the clone child too, so we need it
+ to start stopped.
+ */
+ if (step_over_info_valid_p ()
+ || displaced_step_in_progress_thread (tp))
+ {
+ gdb_thread_options options = GDB_THREAD_OPTION_CLONE;
+ if (target_supports_set_thread_options (options))
+ tp->set_thread_options (options);
+ else
+ target_thread_events (true);
+ }
+
+ /* If we're resuming more than one thread simultaneously, then any
+ thread other than the leader is being set to run free. Clear any
+ previous thread option for those threads. */
+ if (resume_ptid != inferior_ptid && target_supports_set_thread_options (0))
+ {
+ process_stratum_target *resume_target = tp->inf->process_target ();
+ for (thread_info *thr_iter : all_non_exited_threads (resume_target,
+ resume_ptid))
+ if (thr_iter != tp)
+ thr_iter->set_thread_options (0);
+ }
+
infrun_debug_printf ("resume_ptid=%s, step=%d, sig=%s",
resume_ptid.to_string ().c_str (),
step, gdb_signal_to_symbol_string (sig));
@@ -6281,6 +6340,8 @@ finish_step_over (struct execution_control_state *ecs)
back an event. */
gdb_assert (ecs->event_thread->control.trap_expected);
+ update_thread_events_after_step_over (ecs->event_thread);
+
clear_step_over_info ();
}