[5738] Refactor and enhance break/watchpoint API (Jan Kiszka)
Revision: 5738
http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=5738 Author: aliguori Date: 2008-11-18 20:07:32 +0000 (Tue, 18 Nov 2008)
Log Message:
-----------
Refactor and enhance break/watchpoint API (Jan Kiszka)
This patch prepares the QEMU cpu_watchpoint/breakpoint API to allow the succeeding enhancements this series comes with.
First of all, it overcomes MAX_BREAKPOINTS/MAX_WATCHPOINTS by switching to dynamically allocated data structures that are kept in linked lists. This also allows to return a stable reference to the related objects, required for later introduced x86 debug register support.
Breakpoints and watchpoints are stored with their full information set and an additional flag field that makes them easily extensible for use beyond pure guest debugging.
Modified Paths:
--------------
trunk/cpu-all.h
trunk/cpu-defs.h
trunk/exec.c
trunk/gdbstub.c
trunk/target-alpha/translate.c
trunk/target-arm/translate.c
trunk/target-cris/translate.c
trunk/target-i386/translate.c
trunk/target-m68k/translate.c
trunk/target-mips/translate.c
trunk/target-ppc/translate.c
trunk/target-sh4/translate.c
trunk/target-sparc/translate.c
Modified: trunk/cpu-all.h
===================================================================
cpu-all.h +17 -6
@@ -761,13 +761,24 @@void cpu_interrupt (CPUState *s,int mask);void cpu_reset_interrupt (CPUState *env,int mask); -int cpu_watchpoint_insert (CPUState *env,target_ulong addr,int type); -int cpu_watchpoint_remove (CPUState *env,target_ulong addr); -void cpu_watchpoint_remove_all (CPUState *env); -int cpu_breakpoint_insert (CPUState *env,target_ulong pc); -int cpu_breakpoint_remove (CPUState *env,target_ulong pc); -void cpu_breakpoint_remove_all (CPUState *env); +/* Breakpoint/watchpoint flags */ +#define BP_MEM_READ 0x01 +#define BP_MEM_WRITE 0x02 +#define BP_MEM_ACCESS (BP_MEM_READ | BP_MEM_WRITE) +#define BP_GDB 0x10 +int cpu_breakpoint_insert (CPUState *env,target_ulong pc,int flags, +CPUBreakpoint **breakpoint); +int cpu_breakpoint_remove (CPUState *env,target_ulong pc,int flags); +void cpu_breakpoint_remove_by_ref (CPUState *env,CPUBreakpoint *breakpoint); +void cpu_breakpoint_remove_all (CPUState *env,int mask); +int cpu_watchpoint_insert (CPUState *env,target_ulong addr,target_ulong len, +int flags,CPUWatchpoint **watchpoint); +int cpu_watchpoint_remove (CPUState *env,target_ulong addr, +target_ulong len,int flags); +void cpu_watchpoint_remove_by_ref (CPUState *env,CPUWatchpoint *watchpoint); +void cpu_watchpoint_remove_all (CPUState *env,int mask); +#define SSTEP_ENABLE 0x1/* Enable simulated HW single stepping */ #define SSTEP_NOIRQ 0x2/* Do not use IRQ while single stepping */ #define SSTEP_NOTIMER 0x4/* Do not Timers while single stepping */
Modified: trunk/cpu-defs.h
===================================================================
cpu-defs.h +16 -10
@@ -82,8 +82,6 @@#define EXCP_HLT 0x10001/* hlt instruction reached */ #define EXCP_DEBUG 0x10002/* cpu stopped after a breakpoint or singlestep */ #define EXCP_HALTED 0x10003/* cpu is halted (waiting for external event) */ -#define MAX_BREAKPOINTS 32 -#define MAX_WATCHPOINTS 32#define TB_JMP_CACHE_BITS 12#define TB_JMP_CACHE_SIZE (1 << TB_JMP_CACHE_BITS)
@@ -145,6 +143,19 @@struct kvm_run ;struct KVMState ; +typedef struct CPUBreakpoint { +target_ulong pc; +int flags;/* BP_* */ +struct CPUBreakpoint *prev, *next; +}CPUBreakpoint ; + +typedef struct CPUWatchpoint { +target_ulong vaddr; +target_ulong len_mask; +int flags;/* BP_* */ +struct CPUWatchpoint *prev, *next; +}CPUWatchpoint ; +#define CPU_TEMP_BUF_NLONGS 128#define CPU_COMMON \ struct TranslationBlock *current_tb;/* currently executing TB */ \
@@ -177,16 +188,11 @@ \/* from this point: preserved by CPU reset */ \/* ice debug support */ \ -target_ulong breakpoints[MAX_BREAKPOINTS ]; \ -int nb_breakpoints; \ +CPUBreakpoint *breakpoints; \int singlestep_enabled; \ \ -struct { \ -target_ulong vaddr; \ -int type;/* PAGE_READ/PAGE_WRITE */ \ - } watchpoint[MAX_WATCHPOINTS ]; \ -int nb_watchpoints; \ -int watchpoint_hit; \ +CPUWatchpoint *watchpoints; \ +CPUWatchpoint *watchpoint_hit; \ \struct GDBRegisterState *gdb_regs; \ \
Modified: trunk/exec.c
===================================================================
exec.c +118 -77
303 lines not on this page · raw message
Modified: trunk/gdbstub.c
===================================================================
gdbstub.c +77 -60
186 lines not on this page · raw message
Modified: trunk/target-alpha/translate.c
===================================================================
target-alpha/translate.c +4 -3
@@ -2340,6 +2340,7 @@target_ulong pc_start;uint32_t insn;uint16_t *gen_opc_end; +CPUBreakpoint *bp;int j, lj =-1 ;int ret;int num_insns;
@@ -2362,9 +2363,9 @@gen_icount_start ();for (ret =0 ; ret ==0 ;) { -if (env->nb_breakpoints >0 ) { -for (j =0 ; j < env->nb_breakpoints; j++) { -if (env->breakpoints[j] == ctx.pc) { +if (unlikely (env->breakpoints)) { +for (bp = env->breakpoints; bp !=NULL ; bp = bp->next) { +if (bp->pc == ctx.pc) {gen_excp (&ctx,EXCP_DEBUG ,0 );break ; }
Modified: trunk/target-arm/translate.c
===================================================================
target-arm/translate.c +5 -4
@@ -8600,6 +8600,7 @@ int search_pc) {DisasContext dc1, *dc = &dc1; +CPUBreakpoint *bp;uint16_t *gen_opc_end;int j, lj;target_ulong pc_start;
@@ -8676,9 +8677,9 @@ }#endif -if (env->nb_breakpoints >0 ) { -for (j =0 ; j < env->nb_breakpoints; j++) { -if (env->breakpoints[j] == dc->pc) { +if (unlikely (env->breakpoints)) { +for (bp = env->breakpoints; bp !=NULL ; bp = bp->next) { +if (bp->pc == dc->pc) {gen_set_condexec (dc);gen_set_pc_im (dc->pc);gen_exception (EXCP_DEBUG );
@@ -8731,7 +8732,7 @@/* Terminate the TB on memory ops if watchpoints are present. */ /* FIXME: This should be replacd by the deterministic execution * IRQ raising bits. */ -if (dc->is_mem && env->nb_watchpoints) +if (dc->is_mem && env->watchpoints)break ;/* Translation stops when a conditional branch is enoutered.
Modified: trunk/target-cris/translate.c
===================================================================
target-cris/translate.c +5 -4
@@ -3187,10 +3187,11 @@static void check_breakpoint (CPUState *env,DisasContext *dc) { -int j; -if (env->nb_breakpoints >0 ) { -for (j =0 ; j < env->nb_breakpoints; j++) { -if (env->breakpoints[j] == dc->pc) { +CPUBreakpoint *bp; + +if (unlikely (env->breakpoints)) { +for (bp = env->breakpoints; bp !=NULL ; bp = bp->next) { +if (bp->pc == dc->pc) {cris_evaluate_flags (dc);tcg_gen_movi_tl (env_pc, dc->pc);t_gen_raise_exception (EXCP_DEBUG );
Modified: trunk/target-i386/translate.c
===================================================================
target-i386/translate.c +4 -3
@@ -7522,6 +7522,7 @@DisasContext dc1, *dc = &dc1;target_ulong pc_ptr;uint16_t *gen_opc_end; +CPUBreakpoint *bp;int j, lj, cflags;uint64_t flags;target_ulong pc_start;
@@ -7605,9 +7606,9 @@gen_icount_start ();for (;;) { -if (env->nb_breakpoints >0 ) { -for (j =0 ; j < env->nb_breakpoints; j++) { -if (env->breakpoints[j] == pc_ptr) { +if (unlikely (env->breakpoints)) { +for (bp = env->breakpoints; bp !=NULL ; bp = bp->next) { +if (bp->pc == pc_ptr) {gen_debug (dc, pc_ptr - dc->cs_base);break ; }
Modified: trunk/target-m68k/translate.c
===================================================================
target-m68k/translate.c +5 -4
@@ -2965,6 +2965,7 @@ {DisasContext dc1, *dc = &dc1;uint16_t *gen_opc_end; +CPUBreakpoint *bp;int j, lj;target_ulong pc_start;int pc_offset;
@@ -2998,9 +2999,9 @@ do { pc_offset = dc->pc - pc_start; gen_throws_exception = NULL; - if (env->nb_breakpoints > 0) { - for(j = 0; j < env->nb_breakpoints; j++) { - if (env->breakpoints[j] == dc->pc) { + if (unlikely(env->breakpoints)) { + for (bp = env->breakpoints; bp != NULL; bp = bp->next) { + if (bp->pc == dc->pc) { gen_exception(dc, dc->pc, EXCP_DEBUG); dc->is_jmp = DISAS_JUMP; break;
@@ -3030,7 +3031,7 @@/* Terminate the TB on memory ops if watchpoints are present. */ /* FIXME: This should be replaced by the deterministic execution * IRQ raising bits. */ -if (dc->is_mem && env->nb_watchpoints) +if (dc->is_mem && env->watchpoints)break ; } while (!dc->is_jmp && gen_opc_ptr < gen_opc_end && !env->singlestep_enabled &&
Modified: trunk/target-mips/translate.c
===================================================================
target-mips/translate.c +4 -3
@@ -8246,6 +8246,7 @@DisasContext ctx;target_ulong pc_start;uint16_t *gen_opc_end; +CPUBreakpoint *bp;int j, lj =-1 ;int num_insns;int max_insns;
@@ -8285,9 +8286,9 @@#endif gen_icount_start ();while (ctx.bstate ==BS_NONE ) { -if (env->nb_breakpoints >0 ) { -for (j =0 ; j < env->nb_breakpoints; j++) { -if (env->breakpoints[j] == ctx.pc) { +if (unlikely (env->breakpoints)) { +for (bp = env->breakpoints; bp !=NULL ; bp = bp->next) { +if (bp->pc == ctx.pc) {save_cpu_state (&ctx,1 ); ctx.bstate =BS_BRANCH ;gen_helper_0i (raise_exception,EXCP_DEBUG );
Modified: trunk/target-ppc/translate.c
===================================================================
target-ppc/translate.c +4 -3
@@ -7170,6 +7170,7 @@target_ulong pc_start;uint16_t *gen_opc_end;int supervisor, little_endian; +CPUBreakpoint *bp;int j, lj =-1 ;int num_insns;int max_insns;
@@ -7224,9 +7225,9 @@gen_icount_start ();/* Set env in case of segfault during code fetch */ while (ctx.exception ==POWERPC_EXCP_NONE && gen_opc_ptr < gen_opc_end) { -if (unlikely (env->nb_breakpoints >0 )) { -for (j =0 ; j < env->nb_breakpoints; j++) { -if (env->breakpoints[j] == ctx.nip) { +if (unlikely (env->breakpoints)) { +for (bp = env->breakpoints; bp !=NULL ; bp = bp->next) { +if (bp->pc == ctx.nip) {gen_update_nip (&ctx, ctx.nip);gen_op_debug ();break ;
Modified: trunk/target-sh4/translate.c
===================================================================
target-sh4/translate.c +4 -3
@@ -1803,6 +1803,7 @@DisasContext ctx;target_ulong pc_start;static uint16_t *gen_opc_end; +CPUBreakpoint *bp;int i, ii;int num_insns;int max_insns;
@@ -1836,9 +1837,9 @@ max_insns =CF_COUNT_MASK ;gen_icount_start ();while (ctx.bstate ==BS_NONE && gen_opc_ptr < gen_opc_end) { -if (env->nb_breakpoints >0 ) { -for (i =0 ; i < env->nb_breakpoints; i++) { -if (ctx.pc == env->breakpoints[i]) { +if (unlikely (env->breakpoints)) { +for (bp = env->breakpoints; bp !=NULL ; bp = bp->next) { +if (ctx.pc == bp->pc) {/* We have hit a breakpoint - make sure PC is up-to-date */ tcg_gen_movi_i32 (cpu_pc, ctx.pc);gen_helper_debug ();
Modified: trunk/target-sparc/translate.c
===================================================================
target-sparc/translate.c +4 -3
@@ -4778,6 +4778,7 @@target_ulong pc_start, last_pc;uint16_t *gen_opc_end;DisasContext dc1, *dc = &dc1; +CPUBreakpoint *bp;int j, lj =-1 ;int num_insns;int max_insns;
@@ -4815,9 +4816,9 @@ max_insns =CF_COUNT_MASK ;gen_icount_start (); do { - if (env->nb_breakpoints > 0) { - for(j = 0; j < env->nb_breakpoints; j++) { - if (env->breakpoints[j] == dc->pc) { + if (unlikely(env->breakpoints)) { + for (bp = env->breakpoints; bp != NULL; bp = bp->next) { + if (bp->pc == dc->pc) { if (dc->pc != pc_start) save_state(dc, cpu_cond); gen_helper_debug();