Start separating out debugger logic

This commit is contained in:
Jeffrey Pfau 2014-02-01 00:27:53 -08:00
parent 6ad2b673b1
commit 6822a0d770
5 changed files with 47 additions and 12 deletions

View File

@ -242,8 +242,7 @@ static void _checkBreakpoints(struct ARMDebugger* debugger) {
} }
for (breakpoint = debugger->breakpoints; breakpoint; breakpoint = breakpoint->next) { for (breakpoint = debugger->breakpoints; breakpoint; breakpoint = breakpoint->next) {
if (breakpoint->address + instructionLength == debugger->cpu->gprs[ARM_PC]) { if (breakpoint->address + instructionLength == debugger->cpu->gprs[ARM_PC]) {
debugger->state = DEBUGGER_PAUSED; ARMDebuggerEnter(debugger, DEBUGGER_ENTER_BREAKPOINT);
printf("Hit breakpoint\n");
break; break;
} }
} }
@ -251,7 +250,7 @@ static void _checkBreakpoints(struct ARMDebugger* debugger) {
static void _breakIntoDefault(int signal) { static void _breakIntoDefault(int signal) {
(void)(signal); (void)(signal);
_activeDebugger->state = DEBUGGER_PAUSED; ARMDebuggerEnter(_activeDebugger, DEBUGGER_ENTER_MANUAL);
} }
enum _DVParseState { enum _DVParseState {
@ -558,6 +557,23 @@ static void _commandLine(struct ARMDebugger* debugger) {
} }
} }
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) { static unsigned char _tabComplete(EditLine* elstate, int ch) {
(void)(ch); (void)(ch);
const LineInfo* li = el_line(elstate); const LineInfo* li = el_line(elstate);
@ -603,6 +619,10 @@ void ARMDebuggerInit(struct ARMDebugger* debugger, struct ARMCore* cpu) {
debugger->memoryShim.p = debugger; debugger->memoryShim.p = debugger;
debugger->memoryShim.watchpoints = 0; debugger->memoryShim.watchpoints = 0;
_activeDebugger = debugger; _activeDebugger = debugger;
debugger->init = 0;
debugger->deinit = 0;
debugger->paused = _commandLine;
debugger->entered = _reportEntry;
signal(SIGINT, _breakIntoDefault); signal(SIGINT, _breakIntoDefault);
} }
@ -631,7 +651,7 @@ void ARMDebuggerRun(struct ARMDebugger* debugger) {
case DEBUGGER_RUNNING: case DEBUGGER_RUNNING:
break; break;
case DEBUGGER_PAUSED: case DEBUGGER_PAUSED:
_commandLine(debugger); debugger->paused(debugger);
break; break;
case DEBUGGER_EXITING: case DEBUGGER_EXITING:
case DEBUGGER_SHUTDOWN: case DEBUGGER_SHUTDOWN:
@ -640,6 +660,9 @@ void ARMDebuggerRun(struct ARMDebugger* debugger) {
} }
} }
void ARMDebuggerEnter(struct ARMDebugger* debugger) { void ARMDebuggerEnter(struct ARMDebugger* debugger, enum DebuggerEntryReason reason) {
debugger->state = DEBUGGER_PAUSED; debugger->state = DEBUGGER_PAUSED;
if (debugger->entered) {
debugger->entered(debugger, reason);
}
} }

View File

@ -29,6 +29,13 @@ struct DebugMemoryShim {
struct DebugBreakpoint* watchpoints; struct DebugBreakpoint* watchpoints;
}; };
enum DebuggerEntryReason {
DEBUGGER_ENTER_MANUAL,
DEBUGGER_ENTER_BREAKPOINT,
DEBUGGER_ENTER_WATCHPOINT,
DEBUGGER_ENTER_ILLEGAL_OP
};
struct ARMDebugger { struct ARMDebugger {
enum DebuggerState state; enum DebuggerState state;
struct ARMCore* cpu; struct ARMCore* cpu;
@ -38,12 +45,17 @@ struct ARMDebugger {
struct DebugBreakpoint* breakpoints; struct DebugBreakpoint* breakpoints;
struct DebugMemoryShim memoryShim; 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 ARMDebuggerInit(struct ARMDebugger*, struct ARMCore*);
void ARMDebuggerDeinit(struct ARMDebugger*); void ARMDebuggerDeinit(struct ARMDebugger*);
void ARMDebuggerRun(struct ARMDebugger*); void ARMDebuggerRun(struct ARMDebugger*);
void ARMDebuggerEnter(struct ARMDebugger*); void ARMDebuggerEnter(struct ARMDebugger*, enum DebuggerEntryReason);
#else #else

View File

@ -76,7 +76,7 @@ uint8_t ARMDebuggerLoadU8(struct ARMMemory* memory, uint32_t address, int* cycle
void ARMDebuggerShim_store32(struct ARMMemory* memory, uint32_t address, int32_t value, int* cycleCounter) { void ARMDebuggerShim_store32(struct ARMMemory* memory, uint32_t address, int32_t value, int* cycleCounter) {
struct DebugMemoryShim* debugMemory = (struct DebugMemoryShim*) memory; struct DebugMemoryShim* debugMemory = (struct DebugMemoryShim*) memory;
if (_checkWatchpoints(debugMemory->watchpoints, address, 4)) { if (_checkWatchpoints(debugMemory->watchpoints, address, 4)) {
ARMDebuggerEnter(debugMemory->p); ARMDebuggerEnter(debugMemory->p, DEBUGGER_ENTER_WATCHPOINT);
} }
debugMemory->original->store32(debugMemory->original, address, value, cycleCounter); debugMemory->original->store32(debugMemory->original, address, value, cycleCounter);
} }
@ -84,7 +84,7 @@ void ARMDebuggerShim_store32(struct ARMMemory* memory, uint32_t address, int32_t
void ARMDebuggerShim_store16(struct ARMMemory* memory, uint32_t address, int16_t value, int* cycleCounter) { void ARMDebuggerShim_store16(struct ARMMemory* memory, uint32_t address, int16_t value, int* cycleCounter) {
struct DebugMemoryShim* debugMemory = (struct DebugMemoryShim*) memory; struct DebugMemoryShim* debugMemory = (struct DebugMemoryShim*) memory;
if (_checkWatchpoints(debugMemory->watchpoints, address, 2)) { if (_checkWatchpoints(debugMemory->watchpoints, address, 2)) {
ARMDebuggerEnter(debugMemory->p); ARMDebuggerEnter(debugMemory->p, DEBUGGER_ENTER_WATCHPOINT);
} }
debugMemory->original->store16(debugMemory->original, address, value, cycleCounter); debugMemory->original->store16(debugMemory->original, address, value, cycleCounter);
} }
@ -92,7 +92,7 @@ void ARMDebuggerShim_store16(struct ARMMemory* memory, uint32_t address, int16_t
void ARMDebuggerShim_store8(struct ARMMemory* memory, uint32_t address, int8_t value, int* cycleCounter) { void ARMDebuggerShim_store8(struct ARMMemory* memory, uint32_t address, int8_t value, int* cycleCounter) {
struct DebugMemoryShim* debugMemory = (struct DebugMemoryShim*) memory; struct DebugMemoryShim* debugMemory = (struct DebugMemoryShim*) memory;
if (_checkWatchpoints(debugMemory->watchpoints, address, 1)) { if (_checkWatchpoints(debugMemory->watchpoints, address, 1)) {
ARMDebuggerEnter(debugMemory->p); ARMDebuggerEnter(debugMemory->p, DEBUGGER_ENTER_WATCHPOINT);
} }
debugMemory->original->store8(debugMemory->original, address, value, cycleCounter); debugMemory->original->store8(debugMemory->original, address, value, cycleCounter);
} }

View File

@ -542,7 +542,7 @@ void GBAHitStub(struct ARMBoard* board, uint32_t opcode) {
#ifdef USE_DEBUGGER #ifdef USE_DEBUGGER
if (gbaBoard->p->debugger) { if (gbaBoard->p->debugger) {
level = GBA_LOG_STUB; level = GBA_LOG_STUB;
ARMDebuggerEnter(gbaBoard->p->debugger); ARMDebuggerEnter(gbaBoard->p->debugger, DEBUGGER_ENTER_ILLEGAL_OP);
} }
#endif #endif
GBALog(gbaBoard->p, level, "Stub opcode: %08x", opcode); GBALog(gbaBoard->p, level, "Stub opcode: %08x", opcode);
@ -553,7 +553,7 @@ void GBAIllegal(struct ARMBoard* board, uint32_t opcode) {
GBALog(gbaBoard->p, GBA_LOG_WARN, "Illegal opcode: %08x", opcode); GBALog(gbaBoard->p, GBA_LOG_WARN, "Illegal opcode: %08x", opcode);
#ifdef USE_DEBUGGER #ifdef USE_DEBUGGER
if (gbaBoard->p->debugger) { if (gbaBoard->p->debugger) {
ARMDebuggerEnter(gbaBoard->p->debugger); ARMDebuggerEnter(gbaBoard->p->debugger, DEBUGGER_ENTER_ILLEGAL_OP);
} }
#endif #endif
} }

View File

@ -62,7 +62,7 @@ static void _GBASDLHandleKeypress(struct GBAThread* context, const struct SDL_Ke
#ifdef USE_DEBUGGER #ifdef USE_DEBUGGER
case SDLK_F11: case SDLK_F11:
if (event->type == SDL_KEYDOWN && context->debugger) { if (event->type == SDL_KEYDOWN && context->debugger) {
ARMDebuggerEnter(context->debugger); ARMDebuggerEnter(context->debugger, DEBUGGER_ENTER_MANUAL);
} }
break; break;
#endif #endif