Start separating out debugger logic
Jeffrey Pfau jeffrey@endrift.com
Sat, 01 Feb 2014 00:27:53 -0800
5 files changed,
47 insertions(+),
12 deletions(-)
M
src/debugger/debugger.c
→
src/debugger/debugger.c
@@ -242,8 +242,7 @@ instructionLength = WORD_SIZE_THUMB;
} for (breakpoint = debugger->breakpoints; breakpoint; breakpoint = breakpoint->next) { if (breakpoint->address + instructionLength == debugger->cpu->gprs[ARM_PC]) { - debugger->state = DEBUGGER_PAUSED; - printf("Hit breakpoint\n"); + ARMDebuggerEnter(debugger, DEBUGGER_ENTER_BREAKPOINT); break; } }@@ -251,7 +250,7 @@ }
static void _breakIntoDefault(int signal) { (void)(signal); - _activeDebugger->state = DEBUGGER_PAUSED; + ARMDebuggerEnter(_activeDebugger, DEBUGGER_ENTER_MANUAL); } enum _DVParseState {@@ -558,6 +557,23 @@ }
} } +static void _reportEntry(struct ARMDebugger* debugger, enum DebuggerEntryReason reason) { + (void) (debugger); + switch (reason) { + case DEBUGGER_ENTER_MANUAL: + break; + case DEBUGGER_ENTER_BREAKPOINT: + printf("Hit breakpoint\n"); + break; + case DEBUGGER_ENTER_WATCHPOINT: + printf("Hit watchpoint\n"); + break; + case DEBUGGER_ENTER_ILLEGAL_OP: + printf("Hit illegal opcode\n"); + break; + } +} + static unsigned char _tabComplete(EditLine* elstate, int ch) { (void)(ch); const LineInfo* li = el_line(elstate);@@ -603,6 +619,10 @@ el_set(debugger->elstate, EL_HIST, history, debugger->histate);
debugger->memoryShim.p = debugger; debugger->memoryShim.watchpoints = 0; _activeDebugger = debugger; + debugger->init = 0; + debugger->deinit = 0; + debugger->paused = _commandLine; + debugger->entered = _reportEntry; signal(SIGINT, _breakIntoDefault); }@@ -631,7 +651,7 @@ switch (debugger->state) {
case DEBUGGER_RUNNING: break; case DEBUGGER_PAUSED: - _commandLine(debugger); + debugger->paused(debugger); break; case DEBUGGER_EXITING: case DEBUGGER_SHUTDOWN:@@ -640,6 +660,9 @@ }
} } -void ARMDebuggerEnter(struct ARMDebugger* debugger) { +void ARMDebuggerEnter(struct ARMDebugger* debugger, enum DebuggerEntryReason reason) { debugger->state = DEBUGGER_PAUSED; + if (debugger->entered) { + debugger->entered(debugger, reason); + } }
M
src/debugger/debugger.h
→
src/debugger/debugger.h
@@ -29,6 +29,13 @@ struct ARMDebugger* p;
struct DebugBreakpoint* watchpoints; }; +enum DebuggerEntryReason { + DEBUGGER_ENTER_MANUAL, + DEBUGGER_ENTER_BREAKPOINT, + DEBUGGER_ENTER_WATCHPOINT, + DEBUGGER_ENTER_ILLEGAL_OP +}; + struct ARMDebugger { enum DebuggerState state; struct ARMCore* cpu;@@ -38,12 +45,17 @@ History* histate;
struct DebugBreakpoint* breakpoints; struct DebugMemoryShim memoryShim; + + void (*init)(struct ARMDebugger*, struct ARMCore*); + void (*deinit)(struct ARMDebugger*); + void (*paused)(struct ARMDebugger*); + void (*entered)(struct ARMDebugger*, enum DebuggerEntryReason); }; void ARMDebuggerInit(struct ARMDebugger*, struct ARMCore*); void ARMDebuggerDeinit(struct ARMDebugger*); void ARMDebuggerRun(struct ARMDebugger*); -void ARMDebuggerEnter(struct ARMDebugger*); +void ARMDebuggerEnter(struct ARMDebugger*, enum DebuggerEntryReason); #else
M
src/debugger/memory-debugger.c
→
src/debugger/memory-debugger.c
@@ -76,7 +76,7 @@
void ARMDebuggerShim_store32(struct ARMMemory* memory, uint32_t address, int32_t value, int* cycleCounter) { struct DebugMemoryShim* debugMemory = (struct DebugMemoryShim*) memory; if (_checkWatchpoints(debugMemory->watchpoints, address, 4)) { - ARMDebuggerEnter(debugMemory->p); + ARMDebuggerEnter(debugMemory->p, DEBUGGER_ENTER_WATCHPOINT); } debugMemory->original->store32(debugMemory->original, address, value, cycleCounter); }@@ -84,7 +84,7 @@
void ARMDebuggerShim_store16(struct ARMMemory* memory, uint32_t address, int16_t value, int* cycleCounter) { struct DebugMemoryShim* debugMemory = (struct DebugMemoryShim*) memory; if (_checkWatchpoints(debugMemory->watchpoints, address, 2)) { - ARMDebuggerEnter(debugMemory->p); + ARMDebuggerEnter(debugMemory->p, DEBUGGER_ENTER_WATCHPOINT); } debugMemory->original->store16(debugMemory->original, address, value, cycleCounter); }@@ -92,7 +92,7 @@
void ARMDebuggerShim_store8(struct ARMMemory* memory, uint32_t address, int8_t value, int* cycleCounter) { struct DebugMemoryShim* debugMemory = (struct DebugMemoryShim*) memory; if (_checkWatchpoints(debugMemory->watchpoints, address, 1)) { - ARMDebuggerEnter(debugMemory->p); + ARMDebuggerEnter(debugMemory->p, DEBUGGER_ENTER_WATCHPOINT); } debugMemory->original->store8(debugMemory->original, address, value, cycleCounter); }
M
src/gba/gba.c
→
src/gba/gba.c
@@ -542,7 +542,7 @@ enum GBALogLevel level = GBA_LOG_FATAL;
#ifdef USE_DEBUGGER if (gbaBoard->p->debugger) { level = GBA_LOG_STUB; - ARMDebuggerEnter(gbaBoard->p->debugger); + ARMDebuggerEnter(gbaBoard->p->debugger, DEBUGGER_ENTER_ILLEGAL_OP); } #endif GBALog(gbaBoard->p, level, "Stub opcode: %08x", opcode);@@ -553,7 +553,7 @@ struct GBABoard* gbaBoard = (struct GBABoard*) board;
GBALog(gbaBoard->p, GBA_LOG_WARN, "Illegal opcode: %08x", opcode); #ifdef USE_DEBUGGER if (gbaBoard->p->debugger) { - ARMDebuggerEnter(gbaBoard->p->debugger); + ARMDebuggerEnter(gbaBoard->p->debugger, DEBUGGER_ENTER_ILLEGAL_OP); } #endif }
M
src/platform/sdl/sdl-events.c
→
src/platform/sdl/sdl-events.c
@@ -62,7 +62,7 @@ break;
#ifdef USE_DEBUGGER case SDLK_F11: if (event->type == SDL_KEYDOWN && context->debugger) { - ARMDebuggerEnter(context->debugger); + ARMDebuggerEnter(context->debugger, DEBUGGER_ENTER_MANUAL); } break; #endif