gdbstub: add reverse continue support in replay mode

This patch adds support of the reverse continue operation for gdbstub.
Reverse continue finds the last breakpoint that would happen in normal
execution from the beginning to the current moment.
Implementation of the reverse continue replays the execution twice:
to find the breakpoints that were hit and to seek to the last breakpoint.
Reverse continue loads the previous snapshot and tries to find the breakpoint
since that moment. If there are no such breakpoints, it proceeds to
the earlier snapshot, and so on. When no breakpoints or watchpoints were
hit at all, execution stops at the beginning of the replay log.

Signed-off-by: Pavel Dovgalyuk <Pavel.Dovgalyuk@ispras.ru>
Message-Id: <160174522930.12451.6994758004725016836.stgit@pasha-ThinkPad-X280>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
Pavel Dovgalyuk
2020-10-03 20:13:49 +03:00
committed by Paolo Bonzini
parent fda8458bd3
commit cda382594b
6 changed files with 100 additions and 1 deletions

View File

@@ -23,6 +23,8 @@
#include "migration/snapshot.h"
static bool replay_is_debugging;
static int64_t replay_last_breakpoint;
static int64_t replay_last_snapshot;
bool replay_running_debug(void)
{
@@ -246,3 +248,73 @@ bool replay_reverse_step(void)
return false;
}
static void replay_continue_end(void)
{
replay_is_debugging = false;
vm_stop(RUN_STATE_DEBUG);
replay_delete_break();
}
static void replay_continue_stop(void *opaque)
{
Error *err = NULL;
if (replay_last_breakpoint != -1LL) {
replay_seek(replay_last_breakpoint, replay_stop_vm_debug, &err);
if (err) {
error_free(err);
replay_continue_end();
}
return;
}
/*
* No breakpoints since the last snapshot.
* Find previous snapshot and try again.
*/
if (replay_last_snapshot != 0) {
replay_seek(replay_last_snapshot - 1, replay_continue_stop, &err);
if (err) {
error_free(err);
replay_continue_end();
}
replay_last_snapshot = replay_get_current_icount();
return;
} else {
/* Seek to the very first step */
replay_seek(0, replay_stop_vm_debug, &err);
if (err) {
error_free(err);
replay_continue_end();
}
return;
}
replay_continue_end();
}
bool replay_reverse_continue(void)
{
Error *err = NULL;
assert(replay_mode == REPLAY_MODE_PLAY);
if (replay_get_current_icount() != 0) {
replay_seek(replay_get_current_icount() - 1,
replay_continue_stop, &err);
if (err) {
error_free(err);
return false;
}
replay_last_breakpoint = -1LL;
replay_is_debugging = true;
replay_last_snapshot = replay_get_current_icount();
return true;
}
return false;
}
void replay_breakpoint(void)
{
assert(replay_mode == REPLAY_MODE_PLAY);
replay_last_breakpoint = replay_get_current_icount();
}