Commit 6e140f28c683578b9f94a19ba345d21b00bd41a8

Authored by aliguori
1 parent 880a7578

Introduce BP_WATCHPOINT_HIT flag (Jan Kiszka)

When one watchpoint is hit, others might have triggered as well. To
support users of the watchpoint API which need to detect such cases,
the BP_WATCHPOINT_HIT flag is introduced and maintained.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>



git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5744 c046a42c-6fe2-441c-8c8c-71466251a162
cpu-all.h
@@ -766,6 +766,7 @@ void cpu_reset_interrupt(CPUState *env, int mask); @@ -766,6 +766,7 @@ void cpu_reset_interrupt(CPUState *env, int mask);
766 #define BP_MEM_WRITE 0x02 766 #define BP_MEM_WRITE 0x02
767 #define BP_MEM_ACCESS (BP_MEM_READ | BP_MEM_WRITE) 767 #define BP_MEM_ACCESS (BP_MEM_READ | BP_MEM_WRITE)
768 #define BP_STOP_BEFORE_ACCESS 0x04 768 #define BP_STOP_BEFORE_ACCESS 0x04
  769 +#define BP_WATCHPOINT_HIT 0x08
769 #define BP_GDB 0x10 770 #define BP_GDB 0x10
770 771
771 int cpu_breakpoint_insert(CPUState *env, target_ulong pc, int flags, 772 int cpu_breakpoint_insert(CPUState *env, target_ulong pc, int flags,
cpu-exec.c
@@ -183,6 +183,15 @@ static inline TranslationBlock *tb_find_fast(void) @@ -183,6 +183,15 @@ static inline TranslationBlock *tb_find_fast(void)
183 return tb; 183 return tb;
184 } 184 }
185 185
  186 +static void cpu_handle_debug_exception(CPUState *env)
  187 +{
  188 + CPUWatchpoint *wp;
  189 +
  190 + if (!env->watchpoint_hit)
  191 + for (wp = env->watchpoints; wp != NULL; wp = wp->next)
  192 + wp->flags &= ~BP_WATCHPOINT_HIT;
  193 +}
  194 +
186 /* main execution loop */ 195 /* main execution loop */
187 196
188 int cpu_exec(CPUState *env1) 197 int cpu_exec(CPUState *env1)
@@ -237,6 +246,8 @@ int cpu_exec(CPUState *env1) @@ -237,6 +246,8 @@ int cpu_exec(CPUState *env1)
237 if (env->exception_index >= EXCP_INTERRUPT) { 246 if (env->exception_index >= EXCP_INTERRUPT) {
238 /* exit request from the cpu execution loop */ 247 /* exit request from the cpu execution loop */
239 ret = env->exception_index; 248 ret = env->exception_index;
  249 + if (ret == EXCP_DEBUG)
  250 + cpu_handle_debug_exception(env);
240 break; 251 break;
241 } else if (env->user_mode_only) { 252 } else if (env->user_mode_only) {
242 /* if user mode only, we simulate a fake exception 253 /* if user mode only, we simulate a fake exception
@@ -1340,7 +1340,7 @@ int cpu_watchpoint_remove(CPUState *env, target_ulong addr, target_ulong len, @@ -1340,7 +1340,7 @@ int cpu_watchpoint_remove(CPUState *env, target_ulong addr, target_ulong len,
1340 1340
1341 for (wp = env->watchpoints; wp != NULL; wp = wp->next) { 1341 for (wp = env->watchpoints; wp != NULL; wp = wp->next) {
1342 if (addr == wp->vaddr && len_mask == wp->len_mask 1342 if (addr == wp->vaddr && len_mask == wp->len_mask
1343 - && flags == wp->flags) { 1343 + && flags == (wp->flags & ~BP_WATCHPOINT_HIT)) {
1344 cpu_watchpoint_remove_by_ref(env, wp); 1344 cpu_watchpoint_remove_by_ref(env, wp);
1345 return 0; 1345 return 0;
1346 } 1346 }
@@ -2519,21 +2519,26 @@ static void check_watchpoint(int offset, int len_mask, int flags) @@ -2519,21 +2519,26 @@ static void check_watchpoint(int offset, int len_mask, int flags)
2519 for (wp = env->watchpoints; wp != NULL; wp = wp->next) { 2519 for (wp = env->watchpoints; wp != NULL; wp = wp->next) {
2520 if ((vaddr == (wp->vaddr & len_mask) || 2520 if ((vaddr == (wp->vaddr & len_mask) ||
2521 (vaddr & wp->len_mask) == wp->vaddr) && (wp->flags & flags)) { 2521 (vaddr & wp->len_mask) == wp->vaddr) && (wp->flags & flags)) {
2522 - env->watchpoint_hit = wp;  
2523 - tb = tb_find_pc(env->mem_io_pc);  
2524 - if (!tb) {  
2525 - cpu_abort(env, "check_watchpoint: could not find TB for pc=%p",  
2526 - (void *)env->mem_io_pc);  
2527 - }  
2528 - cpu_restore_state(tb, env, env->mem_io_pc, NULL);  
2529 - tb_phys_invalidate(tb, -1);  
2530 - if (wp->flags & BP_STOP_BEFORE_ACCESS) {  
2531 - env->exception_index = EXCP_DEBUG;  
2532 - } else {  
2533 - cpu_get_tb_cpu_state(env, &pc, &cs_base, &cpu_flags);  
2534 - tb_gen_code(env, pc, cs_base, cpu_flags, 1); 2522 + wp->flags |= BP_WATCHPOINT_HIT;
  2523 + if (!env->watchpoint_hit) {
  2524 + env->watchpoint_hit = wp;
  2525 + tb = tb_find_pc(env->mem_io_pc);
  2526 + if (!tb) {
  2527 + cpu_abort(env, "check_watchpoint: could not find TB for "
  2528 + "pc=%p", (void *)env->mem_io_pc);
  2529 + }
  2530 + cpu_restore_state(tb, env, env->mem_io_pc, NULL);
  2531 + tb_phys_invalidate(tb, -1);
  2532 + if (wp->flags & BP_STOP_BEFORE_ACCESS) {
  2533 + env->exception_index = EXCP_DEBUG;
  2534 + } else {
  2535 + cpu_get_tb_cpu_state(env, &pc, &cs_base, &cpu_flags);
  2536 + tb_gen_code(env, pc, cs_base, cpu_flags, 1);
  2537 + }
  2538 + cpu_resume_from_signal(env, NULL);
2535 } 2539 }
2536 - cpu_resume_from_signal(env, NULL); 2540 + } else {
  2541 + wp->flags &= ~BP_WATCHPOINT_HIT;
2537 } 2542 }
2538 } 2543 }
2539 } 2544 }