qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
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] [PATCH v5 16/24] gdbstub: add reverse step support in replay mode
Date: Wed, 25 Jul 2018 15:16:21 +0300	[thread overview]
Message-ID: <20180725121621.12867.99063.stgit@pasha-VirtualBox> (raw)
In-Reply-To: <20180725121311.12867.21729.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 afd0a49..33a543e 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 9b98b1f..e53a364 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 4f5df07..c4b5125 100644
--- a/exec.c
+++ b/exec.c
@@ -2761,6 +2761,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 d6ab950..fa108f4 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;
@@ -1082,9 +1096,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;
@@ -1347,6 +1380,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;
+}

  parent reply	other threads:[~2018-07-25 12:16 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-25 12:13 [Qemu-devel] [PATCH v5 00/24] Fixing record/replay and adding reverse debugging Pavel Dovgalyuk
2018-07-25 12:13 ` [Qemu-devel] [PATCH v5 01/24] block: implement bdrv_snapshot_goto for blkreplay Pavel Dovgalyuk
2018-07-25 12:13 ` [Qemu-devel] [PATCH v5 02/24] replay: disable default snapshot for record/replay Pavel Dovgalyuk
2018-07-25 12:13 ` [Qemu-devel] [PATCH v5 03/24] replay: update docs for record/replay with block devices Pavel Dovgalyuk
2018-07-25 12:13 ` [Qemu-devel] [PATCH v5 04/24] replay: don't drain/flush bdrv queue while RR is working Pavel Dovgalyuk
2018-07-25 12:13 ` [Qemu-devel] [PATCH v5 05/24] replay: finish record/replay before closing the disks Pavel Dovgalyuk
2018-07-25 12:13 ` [Qemu-devel] [PATCH v5 06/24] qcow2: introduce icount field for snapshots Pavel Dovgalyuk
2018-07-25 12:13 ` [Qemu-devel] [PATCH v5 07/24] migration: " Pavel Dovgalyuk
2018-07-25 12:14 ` [Qemu-devel] [PATCH v5 08/24] replay: introduce info hmp/qmp command Pavel Dovgalyuk
2018-07-25 14:56   ` Dr. David Alan Gilbert
2018-07-31  6:54     ` Pavel Dovgalyuk
2018-07-25 12:14 ` [Qemu-devel] [PATCH v5 09/24] replay: introduce breakpoint at the specified step Pavel Dovgalyuk
2018-07-25 12:14 ` [Qemu-devel] [PATCH v5 10/24] replay: implement replay-seek command to proceed to the desired step Pavel Dovgalyuk
2018-07-25 12:14 ` [Qemu-devel] [PATCH v5 11/24] replay: flush events when exiting Pavel Dovgalyuk
2018-07-25 12:15 ` [Qemu-devel] [PATCH v5 12/24] timer: remove replay clock probe in deadline calculation Pavel Dovgalyuk
2018-07-25 12:15 ` [Qemu-devel] [PATCH v5 13/24] replay: refine replay-time module Pavel Dovgalyuk
2018-07-25 12:15 ` [Qemu-devel] [PATCH v5 14/24] translator: fix breakpoint processing Pavel Dovgalyuk
2018-07-25 12:16 ` [Qemu-devel] [PATCH v5 15/24] replay: flush rr queue before loading the vmstate Pavel Dovgalyuk
2018-07-25 12:16 ` Pavel Dovgalyuk [this message]
2018-07-25 12:16 ` [Qemu-devel] [PATCH v5 17/24] gdbstub: add reverse continue support in replay mode Pavel Dovgalyuk
2018-07-25 12:16 ` [Qemu-devel] [PATCH v5 18/24] replay: describe reverse debugging in docs/replay.txt Pavel Dovgalyuk
2018-07-25 12:16 ` [Qemu-devel] [PATCH v5 19/24] replay: allow loading any snapshots before recording Pavel Dovgalyuk
2018-07-25 12:16 ` [Qemu-devel] [PATCH v5 20/24] ps2: prevent changing irq state on save and load Pavel Dovgalyuk
2018-07-25 12:16 ` [Qemu-devel] [PATCH v5 21/24] replay: wake up vCPU when replaying Pavel Dovgalyuk
2018-07-25 12:16 ` [Qemu-devel] [PATCH v5 22/24] replay: replay BH for IDE trim operation Pavel Dovgalyuk
2018-07-25 12:29   ` Paolo Bonzini
2018-07-25 12:17 ` [Qemu-devel] [PATCH v5 23/24] replay: add BH oneshot event for block layer Pavel Dovgalyuk
2018-07-26 15:36   ` Alex Bennée
2018-07-26 17:20     ` Alex Bennée
2018-07-27  4:52     ` Pavel Dovgalyuk
2018-07-27 16:44       ` Alex Bennée
2018-08-02  5:50         ` Pavel Dovgalyuk
2018-07-26 17:17   ` Alex Bennée
2018-07-31  7:00     ` Pavel Dovgalyuk
2018-08-01 16:54     ` Paolo Bonzini
2018-07-25 12:17 ` [Qemu-devel] [PATCH v5 24/24] slirp: fix ipv6 timers Pavel Dovgalyuk
2018-07-25 13:44   ` Samuel Thibault
2018-07-26  7:08     ` Pavel Dovgalyuk
2018-07-26  7:35       ` Samuel Thibault
2018-07-26  7:37         ` Pavel Dovgalyuk
2018-07-26  7:40           ` Samuel Thibault
2018-07-26  8:07       ` Samuel Thibault
2018-07-26  8:37         ` Pavel Dovgalyuk
2018-07-26  9:15           ` Samuel Thibault
2018-07-31  6:58             ` Pavel Dovgalyuk
2018-08-01 19:22               ` Samuel Thibault
2018-07-25 14:15 ` [Qemu-devel] [PATCH v5 00/24] Fixing record/replay and adding reverse debugging no-reply
2018-08-07 23:13 ` Ciro Santilli
2018-09-12  8:14   ` dovgaluk

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=20180725121621.12867.99063.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).