qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH] Add single stepping option for all targets


From: Aurelien Jarno
Subject: Re: [Qemu-devel] [PATCH] Add single stepping option for all targets
Date: Tue, 3 Mar 2009 07:38:41 +0100
User-agent: Mutt/1.5.18 (2008-05-17)

On Sun, Feb 01, 2009 at 08:51:13PM +0100, Stefan Weil wrote:
> 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
> 
> 

> 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.

Please find my comments below.

> 
> Signed-off-by: Stefan Weil <address@hidden>
> 
> 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 },

It might be a good idea to provide that as a subset of the -d option, as
it is clearly something only useful for debugging.

> 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}).
>  
> address@hidden -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}.
>  
> address@hidden 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);

Why only on system emulation mode? During my debugging session, I mostly
used single stepping by hardcoding it in the code on user mode.

-- 
Aurelien Jarno                          GPG: 1024D/F1BCDB73
address@hidden                 http://www.aurel32.net




reply via email to

[Prev in Thread] Current Thread [Next in Thread]