diff --git a/nemu/src/cpu/cpu-exec.c b/nemu/src/cpu/cpu-exec.c index e91b4c8..6ad158a 100644 --- a/nemu/src/cpu/cpu-exec.c +++ b/nemu/src/cpu/cpu-exec.c @@ -31,7 +31,7 @@ static uint64_t g_timer = 0; // unit: us static bool g_print_step = false; void device_update(); -void wp_eval_all(); +bool wp_eval_all(); static void trace_and_difftest(Decode *_this, vaddr_t dnpc) { #ifdef CONFIG_ITRACE_COND @@ -78,6 +78,8 @@ static void execute(uint64_t n) { exec_once(&s, cpu.pc); g_nr_guest_inst ++; trace_and_difftest(&s, cpu.pc); + if (wp_eval_all()) break; + if (nemu_state.state != NEMU_RUNNING) break; IFDEF(CONFIG_DEVICE, device_update()); } @@ -114,8 +116,6 @@ void cpu_exec(uint64_t n) { uint64_t timer_end = get_time(); g_timer += timer_end - timer_start; - wp_eval_all(); - switch (nemu_state.state) { case NEMU_RUNNING: nemu_state.state = NEMU_STOP; break; diff --git a/nemu/src/monitor/sdb/watchpoint.c b/nemu/src/monitor/sdb/watchpoint.c index 5362ecd..aa48d78 100644 --- a/nemu/src/monitor/sdb/watchpoint.c +++ b/nemu/src/monitor/sdb/watchpoint.c @@ -136,12 +136,15 @@ static bool wp_check_change(WP* wp) { /* Check if watchpoint value changed after execution */ -void wp_eval_all() { +bool wp_eval_all() { WP *wp; + bool value_change = false; for (wp = head; wp != NULL; wp = wp->next) { int prev_val = wp->val; if (wp_check_change(wp)) { printf("Watchpoint %d: %s\n %u -> %u\n", wp->NO, wp->expr, prev_val, wp->val); + value_change = true; } } + return value_change; }