Use the ID of the watchpoint instead of a loop over all. This fixes a bug in which addr was compared against wp->vaddr, so that we never recognized watchpoints that didn't trigger at the start of the region.
Signed-off-by: Richard Henderson <[email protected]> --- target/riscv/debug.c | 55 +++----------------------------------------- 1 file changed, 3 insertions(+), 52 deletions(-) diff --git a/target/riscv/debug.c b/target/riscv/debug.c index 511a69c28d..56ae1e6107 100644 --- a/target/riscv/debug.c +++ b/target/riscv/debug.c @@ -960,59 +960,10 @@ bool riscv_cpu_debug_check_watchpoint(CPUState *cs, CPUWatchpoint *wp) { RISCVCPU *cpu = RISCV_CPU(cs); CPURISCVState *env = &cpu->env; - target_ulong ctrl; - target_ulong addr; - int trigger_type; - BreakpointFlags flags; - int i; + int i = wp->id; + trigger_type_t trigger_type = get_trigger_type(env, i); - for (i = 0; i < env->num_triggers; i++) { - trigger_type = get_trigger_type(env, i); - - if (!trigger_common_match(env, trigger_type, i)) { - continue; - } - - switch (trigger_type) { - case TRIGGER_TYPE_AD_MATCH: - ctrl = env->tdata1[i]; - addr = env->tdata2[i]; - flags = 0; - - if (ctrl & TYPE2_LOAD) { - flags |= BP_MEM_READ; - } - if (ctrl & TYPE2_STORE) { - flags |= BP_MEM_WRITE; - } - - if ((wp->flags & flags) && (wp->vaddr == addr)) { - return true; - } - break; - case TRIGGER_TYPE_AD_MATCH6: - ctrl = env->tdata1[i]; - addr = env->tdata2[i]; - flags = 0; - - if (ctrl & TYPE6_LOAD) { - flags |= BP_MEM_READ; - } - if (ctrl & TYPE6_STORE) { - flags |= BP_MEM_WRITE; - } - - if ((wp->flags & flags) && (wp->vaddr == addr)) { - return true; - } - break; - default: - /* other trigger types are not supported */ - break; - } - } - - return false; + return trigger_common_match(env, trigger_type, i); } void riscv_trigger_realize(CPURISCVState *env) -- 2.43.0
