From: Pavel Dovgalyuk <Pavel.Dovgaluk@ispras.ru>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, peter.maydell@linaro.org, war2jordan@live.com,
crosthwaite.peter@gmail.com, boost.lists@gmail.com,
quintela@redhat.com, ciro.santilli@gmail.com,
jasowang@redhat.com, mst@redhat.com, zuban32s@gmail.com,
armbru@redhat.com, maria.klimushenkova@ispras.ru,
dovgaluk@ispras.ru, kraxel@redhat.com, pavel.dovgaluk@ispras.ru,
thomas.dullien@googlemail.com, pbonzini@redhat.com,
mreitz@redhat.com, alex.bennee@linaro.org, dgilbert@redhat.com,
rth@twiddle.net
Subject: [Qemu-devel] [RFC PATCH v2 16/19] gdbstub: add reverse step support in replay mode
Date: Sat, 28 Apr 2018 15:38:00 +0300 [thread overview]
Message-ID: <20180428123800.12445.15147.stgit@pasha-VirtualBox> (raw)
In-Reply-To: <20180428123627.12445.9923.stgit@pasha-VirtualBox>
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 <Pavel.Dovgaluk@ispras.ru>
---
accel/tcg/translator.c | 1 +
cpus.c | 14 +++++++++++---
exec.c | 5 +++++
gdbstub.c | 42 +++++++++++++++++++++++++++++++++++++++---
include/sysemu/replay.h | 7 +++++++
replay/replay-debugging.c | 33 +++++++++++++++++++++++++++++++++
stubs/replay.c | 5 +++++
7 files changed, 101 insertions(+), 6 deletions(-)
diff --git a/accel/tcg/translator.c b/accel/tcg/translator.c
index 3c7a035..4adb37c 100644
--- a/accel/tcg/translator.c
+++ b/accel/tcg/translator.c
@@ -17,6 +17,7 @@
#include "exec/gen-icount.h"
#include "exec/log.h"
#include "exec/translator.h"
+#include "sysemu/replay.h"
/* Pairs with tcg_clear_temp_count.
To be called by #TranslatorOps.{translate_insn,tb_stop} if
diff --git a/cpus.c b/cpus.c
index 140cc4f..3fb9321 100644
--- a/cpus.c
+++ b/cpus.c
@@ -1042,9 +1042,17 @@ static bool cpu_can_run(CPUState *cpu)
static void cpu_handle_guest_debug(CPUState *cpu)
{
- gdb_set_stop_cpu(cpu);
- qemu_system_debug_request();
- cpu->stopped = true;
+ if (!replay_running_debug()) {
+ gdb_set_stop_cpu(cpu);
+ qemu_system_debug_request();
+ cpu->stopped = true;
+ } else {
+ if (!cpu->singlestep_enabled) {
+ cpu_single_step(cpu, SSTEP_ENABLE);
+ } else {
+ cpu_single_step(cpu, 0);
+ }
+ }
}
#ifdef CONFIG_LINUX
diff --git a/exec.c b/exec.c
index c7fcefa..0802aa4 100644
--- a/exec.c
+++ b/exec.c
@@ -2546,6 +2546,11 @@ static void check_watchpoint(int offset, int len, MemTxAttrs attrs, int flags)
QTAILQ_FOREACH(wp, &cpu->watchpoints, entry) {
if (cpu_watchpoint_address_matches(wp, vaddr, 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 {
diff --git a/gdbstub.c b/gdbstub.c
index 3c38073..86dec56 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -39,6 +39,7 @@
#include "sysemu/kvm.h"
#include "exec/semihost.h"
#include "exec/exec-all.h"
+#include "sysemu/replay.h"
#ifdef CONFIG_USER_ONLY
#define GDB_ATTACHED "0"
@@ -334,6 +335,19 @@ typedef struct GDBState {
*/
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;
bool gdb_has_xml;
@@ -424,7 +438,7 @@ static int gdb_continue_partial(GDBState *s, char *newstates)
CPU_FOREACH(cpu) {
if (newstates[cpu->cpu_index] == 's') {
trace_gdbstub_op_stepping(cpu->cpu_index);
- cpu_single_step(cpu, sstep_flags);
+ cpu_single_step(cpu, get_sstep_flags());
}
}
s->running_state = 1;
@@ -443,7 +457,7 @@ static int gdb_continue_partial(GDBState *s, char *newstates)
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;
@@ -1072,9 +1086,28 @@ static int gdb_handle_packet(GDBState *s, const char *line_buf)
addr = strtoull(p, (char **)&p, 16);
gdb_set_cpu_pc(s, addr);
}
- cpu_single_step(s->c_cpu, sstep_flags);
+ cpu_single_step(s->c_cpu, get_sstep_flags());
gdb_continue(s);
return RS_IDLE;
+ case 'b':
+ /* Backward debugging commands */
+ if (replay_mode == REPLAY_MODE_PLAY) {
+ switch (*p) {
+ case 's':
+ if (replay_reverse_step()) {
+ gdb_continue(s);
+ return RS_IDLE;
+ } else {
+ put_packet(s, "E14");
+ break;
+ }
+ default:
+ goto unknown_command;
+ }
+ } else {
+ put_packet(s, "E22");
+ }
+ goto unknown_command;
case 'F':
{
target_ulong ret;
@@ -1337,6 +1370,9 @@ static int gdb_handle_packet(GDBState *s, const char *line_buf)
if (cc->gdb_core_xml_file != NULL) {
pstrcat(buf, sizeof(buf), ";qXfer:features:read+");
}
+ if (replay_mode == REPLAY_MODE_PLAY) {
+ pstrcat(buf, sizeof(buf), ";ReverseStep+");
+ }
put_packet(s, buf);
break;
}
diff --git a/include/sysemu/replay.h b/include/sysemu/replay.h
index 84a1ec5..611eabb 100644
--- a/include/sysemu/replay.h
+++ b/include/sysemu/replay.h
@@ -74,6 +74,13 @@ void replay_add_blocker(Error *reason);
/*! Sets breakpoint at the specified step.
If step = -1LL the existing breakpoint is removed. */
void replay_break(int64_t step, QEMUTimerCB callback, void *opaque);
+/*! 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 */
diff --git a/replay/replay-debugging.c b/replay/replay-debugging.c
index 8d6c03d..388cf12 100644
--- a/replay/replay-debugging.c
+++ b/replay/replay-debugging.c
@@ -21,6 +21,13 @@
#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) {
@@ -183,3 +190,29 @@ void hmp_replay_seek(Monitor *mon, const QDict *qdict)
return;
}
}
+
+static void replay_stop_vm_debug(void *opaque)
+{
+ replay_is_debugging = false;
+ vm_stop(RUN_STATE_DEBUG);
+ replay_break(-1LL, NULL, NULL);
+}
+
+bool replay_reverse_step(void)
+{
+ Error *err = NULL;
+
+ assert(replay_mode == REPLAY_MODE_PLAY);
+
+ if (replay_get_current_step() != 0) {
+ replay_seek(replay_get_current_step() - 1, &err, replay_stop_vm_debug);
+ if (err) {
+ error_free(err);
+ return false;
+ }
+ replay_is_debugging = true;
+ return true;
+ }
+
+ return false;
+}
diff --git a/stubs/replay.c b/stubs/replay.c
index 04279ab..b0fba0e 100644
--- a/stubs/replay.c
+++ b/stubs/replay.c
@@ -80,3 +80,8 @@ void replay_mutex_lock(void)
void replay_mutex_unlock(void)
{
}
+
+bool replay_reverse_step(void)
+{
+ return false;
+}
next prev parent reply other threads:[~2018-04-28 12:38 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-28 12:36 [Qemu-devel] [RFC PATCH v2 00/19] reverse debugging Pavel Dovgalyuk
2018-04-28 12:36 ` [Qemu-devel] [RFC PATCH v2 01/19] block: implement bdrv_snapshot_goto for blkreplay Pavel Dovgalyuk
2018-04-28 12:36 ` [Qemu-devel] [RFC PATCH v2 02/19] replay: disable default snapshot for record/replay Pavel Dovgalyuk
2018-04-28 12:36 ` [Qemu-devel] [RFC PATCH v2 03/19] replay: update docs for record/replay with block devices Pavel Dovgalyuk
2018-04-28 12:36 ` [Qemu-devel] [RFC PATCH v2 04/19] replay: don't drain/flush bdrv queue while RR is working Pavel Dovgalyuk
2018-04-28 12:36 ` [Qemu-devel] [RFC PATCH v2 05/19] replay: finish record/replay before closing the disks Pavel Dovgalyuk
2018-04-28 12:37 ` [Qemu-devel] [RFC PATCH v2 06/19] qcow2: introduce icount field for snapshots Pavel Dovgalyuk
2018-04-28 12:37 ` [Qemu-devel] [RFC PATCH v2 07/19] migration: " Pavel Dovgalyuk
2018-04-28 12:37 ` [Qemu-devel] [RFC PATCH v2 08/19] replay: introduce info hmp/qmp command Pavel Dovgalyuk
2018-04-28 12:37 ` [Qemu-devel] [RFC PATCH v2 09/19] replay: introduce breakpoint at the specified step Pavel Dovgalyuk
2018-04-28 12:37 ` [Qemu-devel] [RFC PATCH v2 10/19] replay: implement replay-seek command to proceed to the desired step Pavel Dovgalyuk
2018-04-28 12:37 ` [Qemu-devel] [RFC PATCH v2 11/19] replay: flush events when exitting Pavel Dovgalyuk
2018-04-30 16:18 ` Eric Blake
2018-04-28 12:37 ` [Qemu-devel] [RFC PATCH v2 12/19] timer: remove replay clock probe in deadline calculation Pavel Dovgalyuk
2018-04-28 12:37 ` [Qemu-devel] [RFC PATCH v2 13/19] replay: refine replay-time module Pavel Dovgalyuk
2018-04-28 12:37 ` [Qemu-devel] [RFC PATCH v2 14/19] translator: fix breakpoint processing Pavel Dovgalyuk
2018-04-28 12:37 ` [Qemu-devel] [RFC PATCH v2 15/19] replay: flush rr queue before loading the vmstate Pavel Dovgalyuk
2018-04-28 12:38 ` Pavel Dovgalyuk [this message]
2018-04-28 12:38 ` [Qemu-devel] [RFC PATCH v2 17/19] gdbstub: add reverse continue support in replay mode Pavel Dovgalyuk
2018-04-28 12:38 ` [Qemu-devel] [RFC PATCH v2 18/19] replay: describe reverse debugging in docs/replay.txt Pavel Dovgalyuk
2018-04-28 12:38 ` [Qemu-devel] [RFC PATCH v2 19/19] replay: allow loading any snapshots before recording Pavel Dovgalyuk
2018-04-30 14:19 ` [Qemu-devel] [RFC PATCH v2 00/19] reverse debugging Ciro Santilli
2018-04-30 14:24 ` Pavel Dovgalyuk
2018-05-11 8:32 ` Pavel Dovgalyuk
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180428123800.12445.15147.stgit@pasha-VirtualBox \
--to=pavel.dovgaluk@ispras.ru \
--cc=alex.bennee@linaro.org \
--cc=armbru@redhat.com \
--cc=boost.lists@gmail.com \
--cc=ciro.santilli@gmail.com \
--cc=crosthwaite.peter@gmail.com \
--cc=dgilbert@redhat.com \
--cc=dovgaluk@ispras.ru \
--cc=jasowang@redhat.com \
--cc=kraxel@redhat.com \
--cc=kwolf@redhat.com \
--cc=maria.klimushenkova@ispras.ru \
--cc=mreitz@redhat.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=quintela@redhat.com \
--cc=rth@twiddle.net \
--cc=thomas.dullien@googlemail.com \
--cc=war2jordan@live.com \
--cc=zuban32s@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).