GDB remote protocol supports two reverse debugging commands:
reverse step and reverse continue.
This patch adds support of the first one to the gdbstub.
Reverse step is intended to step one instruction in the backwards
direction. This is not possible in regular execution.
But replayed execution is deterministic, therefore we can load one of
the prior snapshots and proceed to the desired step. It is equivalent
to stepping one instruction back.
There should be at least one snapshot preceding the debugged part of
the replay log.
Signed-off-by: Pavel Dovgalyuk <[email protected]>
Reviewed-by: Alex Bennée <[email protected]>
--
v4 changes:
- inverted condition in cpu_handle_guest_debug (suggested by Alex Bennée)
Message-Id: <
160174522341.12451.
1498758422543765253.stgit@pasha-ThinkPad-X280>
Signed-off-by: Paolo Bonzini <[email protected]>
#include "exec/log.h"
#include "exec/translator.h"
#include "exec/plugin-gen.h"
+#include "sysemu/replay.h"
/* Pairs with tcg_clear_temp_count.
To be called by #TranslatorOps.{translate_insn,tb_stop} if
QTAILQ_FOREACH(wp, &cpu->watchpoints, entry) {
if (watchpoint_address_matches(wp, addr, len)
&& (wp->flags & flags)) {
+ if (replay_running_debug()) {
+ /*
+ * Don't process the watchpoints when we are
+ * in a reverse debugging operation.
+ */
+ return;
+ }
if (flags == BP_MEM_READ) {
wp->flags |= BP_WATCHPOINT_HIT_READ;
} else {
#include "sysemu/runstate.h"
#include "hw/semihosting/semihost.h"
#include "exec/exec-all.h"
+#include "sysemu/replay.h"
#ifdef CONFIG_USER_ONLY
#define GDB_ATTACHED "0"
*/
static int sstep_flags = SSTEP_ENABLE|SSTEP_NOIRQ|SSTEP_NOTIMER;
+/* Retrieves flags for single step mode. */
+static int get_sstep_flags(void)
+{
+ /*
+ * In replay mode all events written into the log should be replayed.
+ * That is why NOIRQ flag is removed in this mode.
+ */
+ if (replay_mode != REPLAY_MODE_NONE) {
+ return SSTEP_ENABLE;
+ } else {
+ return sstep_flags;
+ }
+}
+
static GDBState gdbserver_state;
static void init_gdbserver_state(void)
break; /* nothing to do here */
case 's':
trace_gdbstub_op_stepping(cpu->cpu_index);
- cpu_single_step(cpu, sstep_flags);
+ cpu_single_step(cpu, get_sstep_flags());
cpu_resume(cpu);
flag = 1;
break;
gdb_set_cpu_pc((target_ulong)gdb_ctx->params[0].val_ull);
}
- cpu_single_step(gdbserver_state.c_cpu, sstep_flags);
+ cpu_single_step(gdbserver_state.c_cpu, get_sstep_flags());
gdb_continue();
}
+static void handle_backward(GdbCmdContext *gdb_ctx, void *user_ctx)
+{
+ if (replay_mode != REPLAY_MODE_PLAY) {
+ put_packet("E22");
+ }
+ if (gdb_ctx->num_params == 1) {
+ switch (gdb_ctx->params[0].opcode) {
+ case 's':
+ if (replay_reverse_step()) {
+ gdb_continue();
+ } else {
+ put_packet("E14");
+ }
+ return;
+ }
+ }
+
+ /* Default invalid command */
+ put_packet("");
+}
+
static void handle_v_cont_query(GdbCmdContext *gdb_ctx, void *user_ctx)
{
put_packet("vCont;c;C;s;S");
g_string_append(gdbserver_state.str_buf, ";qXfer:features:read+");
}
+ if (replay_mode == REPLAY_MODE_PLAY) {
+ g_string_append(gdbserver_state.str_buf, ";ReverseStep+");
+ }
+
if (gdb_ctx->num_params &&
strstr(gdb_ctx->params[0].data, "multiprocess+")) {
gdbserver_state.multiprocess = true;
cmd_parser = &step_cmd_desc;
}
break;
+ case 'b':
+ {
+ static const GdbCmdParseEntry backward_cmd_desc = {
+ .handler = handle_backward,
+ .cmd = "b",
+ .cmd_startswith = 1,
+ .schema = "o0"
+ };
+ cmd_parser = &backward_cmd_desc;
+ }
+ break;
case 'F':
{
static const GdbCmdParseEntry file_io_cmd_desc = {
void replay_add_blocker(Error *reason);
/* Returns name of the replay log file */
const char *replay_get_filename(void);
+/*
+ * Start making one step in backward direction.
+ * Used by gdbstub for backwards debugging.
+ * Returns true on success.
+ */
+bool replay_reverse_step(void);
+/*
+ * Returns true if replay module is processing
+ * reverse_continue or reverse_step request
+ */
+bool replay_running_debug(void);
/* Processing the instructions */
#include "block/snapshot.h"
#include "migration/snapshot.h"
+static bool replay_is_debugging;
+
+bool replay_running_debug(void)
+{
+ return replay_is_debugging;
+}
+
void hmp_info_replay(Monitor *mon, const QDict *qdict)
{
if (replay_mode == REPLAY_MODE_NONE) {
return;
}
}
+
+static void replay_stop_vm_debug(void *opaque)
+{
+ replay_is_debugging = false;
+ vm_stop(RUN_STATE_DEBUG);
+ replay_delete_break();
+}
+
+bool replay_reverse_step(void)
+{
+ Error *err = NULL;
+
+ assert(replay_mode == REPLAY_MODE_PLAY);
+
+ if (replay_get_current_icount() != 0) {
+ replay_seek(replay_get_current_icount() - 1,
+ replay_stop_vm_debug, &err);
+ if (err) {
+ error_free(err);
+ return false;
+ }
+ replay_is_debugging = true;
+ return true;
+ }
+
+ return false;
+}
void cpu_handle_guest_debug(CPUState *cpu)
{
- gdb_set_stop_cpu(cpu);
- qemu_system_debug_request();
- cpu->stopped = true;
+ if (replay_running_debug()) {
+ if (!cpu->singlestep_enabled) {
+ cpu_single_step(cpu, SSTEP_ENABLE);
+ } else {
+ cpu_single_step(cpu, 0);
+ }
+ } else {
+ gdb_set_stop_cpu(cpu);
+ qemu_system_debug_request();
+ cpu->stopped = true;
+ }
}
#ifdef CONFIG_LINUX
{
return 0;
}
+
+bool replay_reverse_step(void)
+{
+ return false;
+}