qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Weil <weil@mail.berlios.de>
To: QEMU Developers <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] [PATCH] Add single stepping option for all targets
Date: Sun, 01 Feb 2009 20:51:13 +0100	[thread overview]
Message-ID: <4985FD31.4010000@mail.berlios.de> (raw)
In-Reply-To: <494D18B1.8080900@mail.berlios.de>

[-- Attachment #1: Type: text/plain, Size: 990 bytes --]

Stefan Weil schrieb:
> This patch replaces the compile time options SH4_SINGLE_STEP,
> DO_SINGLE_STEP and MIPS_SINGLE_STEP
> by a command line option -singlestep.
>
> It also adds single step mode for targets which did not have a compile
> time option,
> so all system emulations can be used with -singlestep. Please note that
> I did only run a short test for i386 and mips targets.
>
> A new monitor command is provided to enable or disable single step mode.
> The monitor command "info status" was modified to display single step
> mode when activated.
>
> Single stepping in Qemu's system emulation mode is useful to see the cpu
> state
> for each cpu instruction when used with -d in_asm,cpu. It is also a
> simple way to slow down the emulation.
>
> The patch does not add single step mode for Qemu's user mode emulation.
> Would this be useful, too?
>
> Kind regards
> Stefan Weil
>
>   

Hello,

here is an update of the patch. Please apply it to Qemu trunk.

Regards
Stefan Weil



[-- Attachment #2: singlestep.patch --]
[-- Type: text/x-diff, Size: 9734 bytes --]

Add new command line option for tcg single stepping.
This replaces a compile time option for some targets and adds
this feature to targets which did not have a compile time option.

Add monitor command to enable or disable single step mode.

Modify monitor command "info status" to display single step mode.


Signed-off-by: Stefan Weil <weil@mail.berlios.de>

Index: trunk/target-sh4/translate.c
===================================================================
--- trunk.orig/target-sh4/translate.c	2009-02-01 19:12:41.000000000 +0100
+++ trunk/target-sh4/translate.c	2009-02-01 19:18:33.000000000 +0100
@@ -1896,9 +1896,8 @@
 	    break;
         if (num_insns >= max_insns)
             break;
-#ifdef SH4_SINGLE_STEP
-	break;
-#endif
+        if (vm_singlestep)
+            break;
     }
     if (tb->cflags & CF_LAST_IO)
         gen_io_end();
Index: trunk/target-cris/translate.c
===================================================================
--- trunk.orig/target-cris/translate.c	2009-02-01 19:12:41.000000000 +0100
+++ trunk/target-cris/translate.c	2009-02-01 19:18:33.000000000 +0100
@@ -3271,6 +3271,7 @@
 			break;
 	} while (!dc->is_jmp && !dc->cpustate_changed
 		 && gen_opc_ptr < gen_opc_end
+		 && !vm_singlestep
 		 && (dc->pc < next_page_start)
                  && num_insns < max_insns);
 
Index: trunk/target-alpha/translate.c
===================================================================
--- trunk.orig/target-alpha/translate.c	2009-02-01 19:12:41.000000000 +0100
+++ trunk/target-alpha/translate.c	2009-02-01 19:18:33.000000000 +0100
@@ -2413,11 +2413,10 @@
         if (env->singlestep_enabled) {
             gen_excp(&ctx, EXCP_DEBUG, 0);
             break;
-	}
+        }
 
-#if defined (DO_SINGLE_STEP)
-        break;
-#endif
+        if (vm_singlestep)
+            break;
     }
     if (ret != 1 && ret != 3) {
         tcg_gen_movi_i64(cpu_pc, ctx.pc);
Index: trunk/vl.c
===================================================================
--- trunk.orig/vl.c	2009-02-01 19:12:41.000000000 +0100
+++ trunk/vl.c	2009-02-01 19:18:33.000000000 +0100
@@ -193,6 +193,7 @@
 int nb_nics;
 NICInfo nd_table[MAX_NICS];
 int vm_running;
+int vm_singlestep;
 static int rtc_utc = 1;
 static int rtc_date_offset = -1; /* -1 means no change */
 int cirrus_vga_enabled = 1;
@@ -3984,6 +3985,7 @@
            "-parallel dev   redirect the parallel port to char device 'dev'\n"
            "-monitor dev    redirect the monitor to char device 'dev'\n"
            "-pidfile file   write PID to 'file'\n"
+           "-singlestep     always run in singlestep mode\n"
            "-S              freeze CPU at startup (use 'c' to start execution)\n"
            "-s              wait gdb connection to port\n"
            "-p port         set gdb connection port [default=%s]\n"
@@ -4119,6 +4121,7 @@
     QEMU_OPTION_parallel,
     QEMU_OPTION_monitor,
     QEMU_OPTION_pidfile,
+    QEMU_OPTION_singlestep,
     QEMU_OPTION_S,
     QEMU_OPTION_s,
     QEMU_OPTION_p,
@@ -4238,6 +4241,7 @@
     { "parallel", HAS_ARG, QEMU_OPTION_parallel },
     { "monitor", HAS_ARG, QEMU_OPTION_monitor },
     { "pidfile", HAS_ARG, QEMU_OPTION_pidfile },
+    { "singlestep", 0, QEMU_OPTION_singlestep },
     { "S", 0, QEMU_OPTION_S },
     { "s", 0, QEMU_OPTION_s },
     { "p", HAS_ARG, QEMU_OPTION_p },
Index: trunk/target-ppc/translate.c
===================================================================
--- trunk.orig/target-ppc/translate.c	2009-02-01 19:12:41.000000000 +0100
+++ trunk/target-ppc/translate.c	2009-02-01 19:18:33.000000000 +0100
@@ -38,7 +38,6 @@
 #define GDBSTUB_SINGLE_STEP 0x4
 
 /* Include definitions for instructions classes and implementations flags */
-//#define DO_SINGLE_STEP
 //#define PPC_DEBUG_DISAS
 //#define DO_PPC_STATISTICS
 
@@ -8305,9 +8304,9 @@
              */
             break;
         }
-#if defined (DO_SINGLE_STEP)
-        break;
-#endif
+
+        if (vm_singlestep)
+            break;
     }
     if (tb->cflags & CF_LAST_IO)
         gen_io_end();
Index: trunk/target-mips/translate.c
===================================================================
--- trunk.orig/target-mips/translate.c	2009-02-01 19:12:41.000000000 +0100
+++ trunk/target-mips/translate.c	2009-02-01 19:18:33.000000000 +0100
@@ -38,7 +38,6 @@
 
 //#define MIPS_DEBUG_DISAS
 //#define MIPS_DEBUG_SIGN_EXTENSIONS
-//#define MIPS_SINGLE_STEP
 
 /* MIPS major opcodes */
 #define MASK_OP_MAJOR(op)  (op & (0x3F << 26))
@@ -8247,9 +8246,9 @@
 
         if (num_insns >= max_insns)
             break;
-#if defined (MIPS_SINGLE_STEP)
-        break;
-#endif
+
+        if (vm_singlestep)
+            break;
     }
     if (tb->cflags & CF_LAST_IO)
         gen_io_end();
Index: trunk/monitor.c
===================================================================
--- trunk.orig/monitor.c	2009-02-01 19:12:41.000000000 +0100
+++ trunk/monitor.c	2009-02-01 19:18:33.000000000 +0100
@@ -489,6 +489,18 @@
     cpu_set_log(mask);
 }
 
+static void do_singlestep(const char *option)
+{
+    qemu_printf("setting vm_singlestep to %s\n", option);
+    if (!option) {
+        vm_singlestep = 1;
+    } else if (!strcmp(option, "off")) {
+        vm_singlestep = 0;
+    } else {
+        term_printf("unexpected option %s\n", option);
+    }
+}
+
 static void do_stop(void)
 {
     vm_stop(EXCP_INTERRUPT);
@@ -1403,9 +1415,13 @@
 
 static void do_info_status(void)
 {
-    if (vm_running)
-       term_printf("VM status: running\n");
-    else
+    if (vm_running) {
+        if (vm_singlestep) {
+            term_printf("VM status: running (single step mode)\n");
+        } else {
+            term_printf("VM status: running\n");
+        }
+    } else
        term_printf("VM status: paused\n");
 }
 
@@ -1455,6 +1471,8 @@
       "tag|id", "restore a VM snapshot from its tag or id" },
     { "delvm", "s", do_delvm,
       "tag|id", "delete a VM snapshot from its tag or id" },
+    { "singlestep", "s?", do_singlestep,
+      "[off]", "run emulation in singlestep mode or switch to normal mode", },
     { "stop", "", do_stop,
       "", "stop emulation", },
     { "c|cont", "", do_cont,
Index: trunk/target-i386/translate.c
===================================================================
--- trunk.orig/target-i386/translate.c	2009-02-01 19:12:41.000000000 +0100
+++ trunk/target-i386/translate.c	2009-02-01 19:18:33.000000000 +0100
@@ -7661,6 +7661,11 @@
             gen_eob(dc);
             break;
         }
+        if (vm_singlestep) {
+            gen_jmp_im(pc_ptr - dc->cs_base);
+            gen_eob(dc);
+            break;
+        }
     }
     if (tb->cflags & CF_LAST_IO)
         gen_io_end();
Index: trunk/target-arm/translate.c
===================================================================
--- trunk.orig/target-arm/translate.c	2009-02-01 19:12:41.000000000 +0100
+++ trunk/target-arm/translate.c	2009-02-01 19:18:33.000000000 +0100
@@ -8788,7 +8788,7 @@
          * ensures prefetch aborts occur at the right place.  */
         num_insns ++;
     } while (!dc->is_jmp && gen_opc_ptr < gen_opc_end &&
-             !env->singlestep_enabled &&
+             !env->singlestep_enabled && !vm_singlestep &&
              dc->pc < next_page_start &&
              num_insns < max_insns);
 
Index: trunk/target-m68k/translate.c
===================================================================
--- trunk.orig/target-m68k/translate.c	2009-02-01 19:12:41.000000000 +0100
+++ trunk/target-m68k/translate.c	2009-02-01 19:18:33.000000000 +0100
@@ -3028,7 +3028,7 @@
 	disas_m68k_insn(env, dc);
         num_insns++;
     } while (!dc->is_jmp && gen_opc_ptr < gen_opc_end &&
-             !env->singlestep_enabled &&
+             !env->singlestep_enabled && !vm_singlestep &&
              (pc_offset) < (TARGET_PAGE_SIZE - 32) &&
              num_insns < max_insns);
 
Index: trunk/target-sparc/translate.c
===================================================================
--- trunk.orig/target-sparc/translate.c	2009-02-01 19:12:41.000000000 +0100
+++ trunk/target-sparc/translate.c	2009-02-01 19:18:33.000000000 +0100
@@ -4858,7 +4858,7 @@
             break;
         /* if single step mode, we generate only one instruction and
            generate an exception */
-        if (env->singlestep_enabled) {
+        if (env->singlestep_enabled || vm_singlestep) {
             tcg_gen_movi_tl(cpu_pc, dc->pc);
             tcg_gen_exit_tb(0);
             break;
Index: trunk/qemu-doc.texi
===================================================================
--- trunk.orig/qemu-doc.texi	2009-02-01 19:12:41.000000000 +0100
+++ trunk/qemu-doc.texi	2009-02-01 19:18:33.000000000 +0100
@@ -1064,6 +1064,9 @@
 @item -s
 Wait gdb connection to port 1234 (@pxref{gdb_usage}).
 
+@item -singlestep
+Run the emulation in single step mode.
+
 @item -p @var{port}
 Change gdb connection port.  @var{port} can be either a decimal number
 to specify a TCP port, or a host device (same devices as the serial port).
@@ -1383,6 +1386,10 @@
 @item delvm @var{tag}|@var{id}
 Delete the snapshot identified by @var{tag} or @var{id}.
 
+@item singlestep [off]
+Run the emulation in single step mode.
+If called with option off, the emulation returns to normal mode.
+
 @item stop
 Stop emulation.
 
Index: trunk/exec-all.h
===================================================================
--- trunk.orig/exec-all.h	2009-02-01 19:18:18.000000000 +0100
+++ trunk/exec-all.h	2009-02-01 19:18:33.000000000 +0100
@@ -386,6 +386,12 @@
 
 #endif
 
+#if defined(CONFIG_USER_ONLY)
+# define vm_singlestep 0
+#else
+extern int vm_singlestep;
+#endif
+
 typedef void (CPUDebugExcpHandler)(CPUState *env);
 
 CPUDebugExcpHandler *cpu_set_debug_excp_handler(CPUDebugExcpHandler *handler);

  parent reply	other threads:[~2009-02-01 19:51 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-12-20 16:09 [Qemu-devel] [PATCH] Add single stepping option for all targets Stefan Weil
2008-12-29 12:34 ` Stefan Weil
2008-12-29 14:40 ` Stuart Brady
2009-02-01 19:51 ` Stefan Weil [this message]
2009-02-01 22:24   ` Laurent Desnogues
2009-02-04 12:50     ` Stefan Weil
2009-02-28 16:27   ` Stefan Weil
2009-03-01 20:52     ` Aurelien Jarno
2009-03-03  6:38   ` Aurelien Jarno
2009-03-13 16:35     ` Stefan Weil
2009-03-13 16:54       ` Laurent Desnogues
2009-03-13 17:21         ` [Qemu-devel] " Jan Kiszka
2009-03-20 15:42       ` [Qemu-devel] " Stefan Weil
2009-03-28 22:12       ` Aurelien Jarno
2009-03-30 10:18         ` Stefan Weil
2009-04-05 20:09           ` Aurelien Jarno

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=4985FD31.4010000@mail.berlios.de \
    --to=weil@mail.berlios.de \
    --cc=qemu-devel@nongnu.org \
    /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).