From 7df571d42f78b57b651ff8d0f873fbab8e84ff4c Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Sun, 13 May 2018 23:17:23 +0300 Subject: [PATCH] Less strict matching for `delete` and `unwatch`. Fixes #71 --- Core/debugger.c | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/Core/debugger.c b/Core/debugger.c index 02cf6d6..a843f9b 100644 --- a/Core/debugger.c +++ b/Core/debugger.c @@ -929,16 +929,32 @@ static bool delete(GB_gameboy_t *gb, char *arguments, char *modifiers, const deb if (error) return true; - uint16_t index = find_breakpoint(gb, result); - if (index >= gb->n_breakpoints || gb->breakpoints[index].key != key) { + uint16_t index = 0; + for (unsigned i = 0; i < gb->n_breakpoints; i++) { + if (gb->breakpoints[i].key == key) { + /* Full match */ + index = i; + break; + } + if (gb->breakpoints[i].addr == result.value && result.has_bank != (gb->breakpoints[i].bank != (uint16_t) -1)) { + /* Partial match */ + index = i; + } + } + + if (index >= gb->n_breakpoints) { GB_log(gb, "No breakpoint set at %s\n", debugger_value_to_string(gb, result, true)); return true; } + result.bank = gb->breakpoints[index].bank; + result.has_bank = gb->breakpoints[index].bank != (uint16_t) -1; + if (gb->breakpoints[index].condition) { free(gb->breakpoints[index].condition); } + memmove(&gb->breakpoints[index], &gb->breakpoints[index + 1], (gb->n_breakpoints - index - 1) * sizeof(gb->breakpoints[0])); gb->n_breakpoints--; gb->breakpoints = realloc(gb->breakpoints, gb->n_breakpoints * sizeof(gb->breakpoints[0])); @@ -1086,11 +1102,26 @@ static bool unwatch(GB_gameboy_t *gb, char *arguments, char *modifiers, const de if (error) return true; - uint16_t index = find_watchpoint(gb, result); - if (index >= gb->n_watchpoints || gb->watchpoints[index].key != key) { + uint16_t index = 0; + for (unsigned i = 0; i < gb->n_watchpoints; i++) { + if (gb->watchpoints[i].key == key) { + /* Full match */ + index = i; + break; + } + if (gb->watchpoints[i].addr == result.value && result.has_bank != (gb->watchpoints[i].bank != (uint16_t) -1)) { + /* Partial match */ + index = i; + } + } + + if (index >= gb->n_watchpoints) { GB_log(gb, "No watchpoint set at %s\n", debugger_value_to_string(gb, result, true)); return true; } + + result.bank = gb->watchpoints[index].bank; + result.has_bank = gb->watchpoints[index].bank != (uint16_t) -1; if (gb->watchpoints[index].condition) { free(gb->watchpoints[index].condition);