all repos — mgba @ a6c8089601ba6669b6664d8117e8b6d6bf8830fa

mGBA Game Boy Advance Emulator

Add read watchpoints (fixes #69)
Jeffrey Pfau jeffrey@endrift.com
Sat, 05 Jul 2014 22:30:20 -0700
commit

a6c8089601ba6669b6664d8117e8b6d6bf8830fa

parent

28ba251cfbb4396f9501b5404c0a4a5afcf43211

1 files changed, 20 insertions(+), 42 deletions(-)

jump to
M src/debugger/memory-debugger.csrc/debugger/memory-debugger.c

@@ -4,10 +4,7 @@ #include "debugger.h"

#include <string.h> -static void ARMDebuggerShim_store32(struct ARMCore*, uint32_t address, int32_t value, int* cycleCounter); -static void ARMDebuggerShim_store16(struct ARMCore*, uint32_t address, int16_t value, int* cycleCounter); -static void ARMDebuggerShim_store8(struct ARMCore*, uint32_t address, int8_t value, int* cycleCounter); -static void ARMDebuggerShim_setActiveRegion(struct ARMCore* cpu, uint32_t address); +static int _checkWatchpoints(struct DebugBreakpoint* watchpoints, uint32_t address, int width); #define FIND_DEBUGGER(DEBUGGER, CPU) \ { \

@@ -28,12 +25,26 @@ FIND_DEBUGGER(debugger, cpu); \

return debugger->originalMemory.NAME(cpu, ARGS); \ } -CREATE_SHIM(load32, int32_t, (struct ARMCore* cpu, uint32_t address, int* cycleCounter), address, cycleCounter) -CREATE_SHIM(load16, int16_t, (struct ARMCore* cpu, uint32_t address, int* cycleCounter), address, cycleCounter) -CREATE_SHIM(loadU16, uint16_t, (struct ARMCore* cpu, uint32_t address, int* cycleCounter), address, cycleCounter) -CREATE_SHIM(load8, int8_t, (struct ARMCore* cpu, uint32_t address, int* cycleCounter), address, cycleCounter) -CREATE_SHIM(loadU8, uint8_t, (struct ARMCore* cpu, uint32_t address, int* cycleCounter), address, cycleCounter) +#define CREATE_WATCHPOINT_SHIM(NAME, WIDTH, RETURN, TYPES, ARGS...) \ + static RETURN ARMDebuggerShim_ ## NAME TYPES { \ + struct ARMDebugger* debugger; \ + FIND_DEBUGGER(debugger, cpu); \ + if (_checkWatchpoints(debugger->watchpoints, address, WIDTH)) { \ + ARMDebuggerEnter(debugger, DEBUGGER_ENTER_WATCHPOINT); \ + } \ + return debugger->originalMemory.NAME(cpu, ARGS); \ + } + +CREATE_WATCHPOINT_SHIM(load32, 4, int32_t, (struct ARMCore* cpu, uint32_t address, int* cycleCounter), address, cycleCounter) +CREATE_WATCHPOINT_SHIM(load16, 2, int16_t, (struct ARMCore* cpu, uint32_t address, int* cycleCounter), address, cycleCounter) +CREATE_WATCHPOINT_SHIM(loadU16, 2, uint16_t, (struct ARMCore* cpu, uint32_t address, int* cycleCounter), address, cycleCounter) +CREATE_WATCHPOINT_SHIM(load8, 1, int8_t, (struct ARMCore* cpu, uint32_t address, int* cycleCounter), address, cycleCounter) +CREATE_WATCHPOINT_SHIM(loadU8, 1, uint8_t, (struct ARMCore* cpu, uint32_t address, int* cycleCounter), address, cycleCounter) +CREATE_WATCHPOINT_SHIM(store32, 4, void, (struct ARMCore* cpu, uint32_t address, int32_t value, int* cycleCounter), address, value, cycleCounter) +CREATE_WATCHPOINT_SHIM(store16, 2, void, (struct ARMCore* cpu, uint32_t address, int16_t value, int* cycleCounter), address, value, cycleCounter) +CREATE_WATCHPOINT_SHIM(store8, 1, void, (struct ARMCore* cpu, uint32_t address, int8_t value, int* cycleCounter), address, value, cycleCounter) CREATE_SHIM(waitMultiple, int, (struct ARMCore* cpu, uint32_t startAddress, int count), startAddress, count) +CREATE_SHIM(setActiveRegion, void, (struct ARMCore* cpu, uint32_t address), address) static int _checkWatchpoints(struct DebugBreakpoint* watchpoints, uint32_t address, int width) { width -= 1;

@@ -58,36 +69,3 @@ debugger->cpu->memory.loadU8 = ARMDebuggerShim_loadU8;

debugger->cpu->memory.setActiveRegion = ARMDebuggerShim_setActiveRegion; debugger->cpu->memory.waitMultiple = ARMDebuggerShim_waitMultiple; } - -void ARMDebuggerShim_store32(struct ARMCore* cpu, uint32_t address, int32_t value, int* cycleCounter) { - struct ARMDebugger* debugger; - FIND_DEBUGGER(debugger, cpu); - if (_checkWatchpoints(debugger->watchpoints, address, 4)) { - ARMDebuggerEnter(debugger, DEBUGGER_ENTER_WATCHPOINT); - } - debugger->originalMemory.store32(debugger->cpu, address, value, cycleCounter); -} - -void ARMDebuggerShim_store16(struct ARMCore* cpu, uint32_t address, int16_t value, int* cycleCounter) { - struct ARMDebugger* debugger; - FIND_DEBUGGER(debugger, cpu); - if (_checkWatchpoints(debugger->watchpoints, address, 2)) { - ARMDebuggerEnter(debugger, DEBUGGER_ENTER_WATCHPOINT); - } - debugger->originalMemory.store16(debugger->cpu, address, value, cycleCounter); -} - -void ARMDebuggerShim_store8(struct ARMCore* cpu, uint32_t address, int8_t value, int* cycleCounter) { - struct ARMDebugger* debugger; - FIND_DEBUGGER(debugger, cpu); - if (_checkWatchpoints(debugger->watchpoints, address, 1)) { - ARMDebuggerEnter(debugger, DEBUGGER_ENTER_WATCHPOINT); - } - debugger->originalMemory.store8(debugger->cpu, address, value, cycleCounter); -} - -void ARMDebuggerShim_setActiveRegion(struct ARMCore* cpu, uint32_t address) { - struct ARMDebugger* debugger; - FIND_DEBUGGER(debugger, cpu); - debugger->originalMemory.setActiveRegion(cpu, address); -}