btrace: do not stop replaying or recording while a thread is running

With asynchronous stepping commands, one may start replaying a thread in
the background and then stop recording its inferior in the foreground.

This causes the execution history to be cleared and the record target to
be unpushed while the thread is using said execution history.

I fail to see a use-case for this, so rather than trying to make this
work, I prevent such a scenario by not allowing replaying or recording to
be stopped while a thread is running.

We could do this only when a thread is running in replay mode and preserve
the existing behavior of being able to stop recording while threads are
running in recording mode.  It seems more consistent to not allow this for
both replaying and recording threads, though.
This commit is contained in:
Markus Metzger
2025-08-13 14:25:27 +00:00
parent 0b6e72d4c1
commit 92dc62fe6e
2 changed files with 22 additions and 4 deletions

View File

@@ -413,6 +413,11 @@ record_btrace_target::stop_recording ()
{
DEBUG ("stop recording");
/* Check that before so stop recording is atomic. */
for (thread_info &tp : current_inferior ()->non_exited_threads ())
if (tp.state == THREAD_RUNNING)
error (_("You cannot stop recording while threads are running."));
bool is_replaying = record_is_replaying (inferior_ptid);
record_stop_replaying ();
record_btrace_auto_disable ();
@@ -2140,12 +2145,25 @@ record_btrace_start_replaying (struct thread_info *tp)
static void
record_btrace_stop_replaying (struct thread_info *tp)
{
struct btrace_thread_info *btinfo;
struct btrace_thread_info *btinfo = &tp->btrace;
btinfo = &tp->btrace;
if (btinfo->replay == nullptr)
return;
switch (tp->state)
{
case THREAD_STOPPED:
break;
case THREAD_RUNNING:
error (_("Cannot stop replaying a running thread."));
case THREAD_EXITED:
gdb_assert_not_reached ("unexpected thread state");
}
xfree (btinfo->replay);
btinfo->replay = NULL;
btinfo->replay = nullptr;
/* Make sure we're not leaving any stale registers. */
registers_changed_thread (tp);

View File

@@ -93,4 +93,4 @@ foreach thread {1 2 3 4} {
}
# Stop recording while all threads are running.
gdb_test "record stop" "Process record is stopped \[^\\\r\\\n\]*"
gdb_test "record stop" "You cannot stop recording while threads are running\."