Debugger: Begin refactoring ARMDebugger into Debugger
jump to
@@ -499,7 +499,7 @@ printf("%s\n", ERROR_MISSING_ARGS);
return; } uint32_t address = dv->intValue; - ARMDebuggerSetBreakpoint(&debugger->d, address); + DebuggerSetBreakpoint(&debugger->d, address); } static void _setBreakpointARM(struct CLIDebugger* debugger, struct CLIDebugVector* dv) {@@ -508,7 +508,7 @@ printf("%s\n", ERROR_MISSING_ARGS);
return; } uint32_t address = dv->intValue; - ARMDebuggerSetSoftwareBreakpoint(&debugger->d, address, MODE_ARM); + DebuggerSetSoftwareBreakpoint(&debugger->d, address, MODE_ARM); } static void _setBreakpointThumb(struct CLIDebugger* debugger, struct CLIDebugVector* dv) {@@ -517,7 +517,7 @@ printf("%s\n", ERROR_MISSING_ARGS);
return; } uint32_t address = dv->intValue; - ARMDebuggerSetSoftwareBreakpoint(&debugger->d, address, MODE_THUMB); + DebuggerSetSoftwareBreakpoint(&debugger->d, address, MODE_THUMB); } static void _clearBreakpoint(struct CLIDebugger* debugger, struct CLIDebugVector* dv) {@@ -526,8 +526,8 @@ printf("%s\n", ERROR_MISSING_ARGS);
return; } uint32_t address = dv->intValue; - ARMDebuggerClearBreakpoint(&debugger->d, address); - ARMDebuggerClearWatchpoint(&debugger->d, address); + DebuggerClearBreakpoint(&debugger->d, address); + DebuggerClearWatchpoint(&debugger->d, address); } static void _setWatchpoint(struct CLIDebugger* debugger, struct CLIDebugVector* dv) {@@ -536,12 +536,12 @@ printf("%s\n", ERROR_MISSING_ARGS);
return; } uint32_t address = dv->intValue; - ARMDebuggerSetWatchpoint(&debugger->d, address, WATCHPOINT_RW); // TODO: ro/wo + DebuggerSetWatchpoint(&debugger->d, address, WATCHPOINT_RW); // TODO: ro/wo } static void _breakIntoDefault(int signal) { UNUSED(signal); - ARMDebuggerEnter(&_activeDebugger->d, DEBUGGER_ENTER_MANUAL, 0); + DebuggerEnter(&_activeDebugger->d, DEBUGGER_ENTER_MANUAL, 0); } static uint32_t _performOperation(enum Operation operation, uint32_t current, uint32_t next, struct CLIDebugVector* dv) {@@ -570,7 +570,7 @@ }
return current; } -static uint32_t _lookupIdentifier(struct ARMDebugger* debugger, const char* name, struct CLIDebugVector* dv) { +static uint32_t _lookupIdentifier(struct Debugger* debugger, const char* name, struct CLIDebugVector* dv) { struct CLIDebugger* cliDebugger = (struct CLIDebugger*) debugger; if (strcmp(name, "sp") == 0) { return debugger->cpu->gprs[ARM_SP];@@ -605,7 +605,7 @@ }
return 0; } -static uint32_t _evaluateParseTree(struct ARMDebugger* debugger, struct ParseTree* tree, struct CLIDebugVector* dv) { +static uint32_t _evaluateParseTree(struct Debugger* debugger, struct ParseTree* tree, struct CLIDebugVector* dv) { switch (tree->token.type) { case TOKEN_UINT_TYPE: return tree->token.uintValue;@@ -765,7 +765,7 @@ UNUSED(el);
return "> "; } -static void _commandLine(struct ARMDebugger* debugger) { +static void _commandLine(struct Debugger* debugger) { struct CLIDebugger* cliDebugger = (struct CLIDebugger*) debugger; const char* line; _printStatus(cliDebugger, 0);@@ -787,7 +787,7 @@ }
} } -static void _reportEntry(struct ARMDebugger* debugger, enum DebuggerEntryReason reason, struct DebuggerEntryInfo* info) { +static void _reportEntry(struct Debugger* debugger, enum DebuggerEntryReason reason, struct DebuggerEntryInfo* info) { UNUSED(debugger); switch (reason) { case DEBUGGER_ENTER_MANUAL:@@ -874,7 +874,7 @@ el_insertstr(elstate, " ");
return CC_REDISPLAY; } -static void _cliDebuggerInit(struct ARMDebugger* debugger) { +static void _cliDebuggerInit(struct Debugger* debugger) { struct CLIDebugger* cliDebugger = (struct CLIDebugger*) debugger; // TODO: get argv[0] cliDebugger->elstate = el_init(binaryName, stdin, stdout, stderr);@@ -892,7 +892,7 @@ _activeDebugger = cliDebugger;
signal(SIGINT, _breakIntoDefault); } -static void _cliDebuggerDeinit(struct ARMDebugger* debugger) { +static void _cliDebuggerDeinit(struct Debugger* debugger) { struct CLIDebugger* cliDebugger = (struct CLIDebugger*) debugger; history_end(cliDebugger->histate); el_end(cliDebugger->elstate);@@ -904,7 +904,7 @@ cliDebugger->system = 0;
} } -static void _cliDebuggerCustom(struct ARMDebugger* debugger) { +static void _cliDebuggerCustom(struct Debugger* debugger) { struct CLIDebugger* cliDebugger = (struct CLIDebugger*) debugger; bool retain = false; if (cliDebugger->system) {@@ -916,7 +916,7 @@ }
} void CLIDebuggerCreate(struct CLIDebugger* debugger) { - ARMDebuggerCreate(&debugger->d); + DebuggerCreate(&debugger->d); debugger->d.init = _cliDebuggerInit; debugger->d.deinit = _cliDebuggerDeinit; debugger->d.custom = _cliDebuggerCustom;
@@ -52,7 +52,7 @@ const char* name;
}; struct CLIDebugger { - struct ARMDebugger d; + struct Debugger d; struct CLIDebuggerSystem* system;
@@ -10,7 +10,7 @@ #include "isa-inlines.h"
#include "memory-debugger.h" -const uint32_t ARM_DEBUGGER_ID = 0xDEADBEEF; +const uint32_t DEBUGGER_ID = 0xDEADBEEF; DEFINE_VECTOR(DebugBreakpointList, struct DebugBreakpoint); DEFINE_VECTOR(DebugWatchpointList, struct DebugWatchpoint);@@ -25,7 +25,7 @@ }
return 0; } -static void _checkBreakpoints(struct ARMDebugger* debugger) { +static void _checkBreakpoints(struct Debugger* debugger) { int instructionLength; enum ExecutionMode mode = debugger->cpu->cpsr.t; if (mode == MODE_ARM) {@@ -40,20 +40,20 @@ }
struct DebuggerEntryInfo info = { .address = breakpoint->address }; - ARMDebuggerEnter(debugger, DEBUGGER_ENTER_BREAKPOINT, &info); + DebuggerEnter(debugger, DEBUGGER_ENTER_BREAKPOINT, &info); } -static void ARMDebuggerInit(void* cpu, struct mCPUComponent*); -static void ARMDebuggerDeinit(struct mCPUComponent*); +static void DebuggerInit(void* cpu, struct mCPUComponent*); +static void DebuggerDeinit(struct mCPUComponent*); -void ARMDebuggerCreate(struct ARMDebugger* debugger) { - debugger->d.id = ARM_DEBUGGER_ID; - debugger->d.init = ARMDebuggerInit; - debugger->d.deinit = ARMDebuggerDeinit; +void DebuggerCreate(struct Debugger* debugger) { + debugger->d.id = DEBUGGER_ID; + debugger->d.init = DebuggerInit; + debugger->d.deinit = DebuggerDeinit; } -void ARMDebuggerInit(void* cpu, struct mCPUComponent* component) { - struct ARMDebugger* debugger = (struct ARMDebugger*) component; +void DebuggerInit(void* cpu, struct mCPUComponent* component) { + struct Debugger* debugger = (struct Debugger*) component; debugger->cpu = cpu; debugger->state = DEBUGGER_RUNNING; debugger->originalMemory = debugger->cpu->memory;@@ -66,15 +66,15 @@ debugger->init(debugger);
} } -void ARMDebuggerDeinit(struct mCPUComponent* component) { - struct ARMDebugger* debugger = (struct ARMDebugger*) component; +void DebuggerDeinit(struct mCPUComponent* component) { + struct Debugger* debugger = (struct Debugger*) component; debugger->deinit(debugger); DebugBreakpointListDeinit(&debugger->breakpoints); DebugBreakpointListDeinit(&debugger->swBreakpoints); DebugWatchpointListDeinit(&debugger->watchpoints); } -void ARMDebuggerRun(struct ARMDebugger* debugger) { +void DebuggerRun(struct Debugger* debugger) { switch (debugger->state) { case DEBUGGER_RUNNING: if (!DebugBreakpointListSize(&debugger->breakpoints) && !DebugWatchpointListSize(&debugger->watchpoints)) {@@ -107,7 +107,7 @@ return;
} } -void ARMDebuggerEnter(struct ARMDebugger* debugger, enum DebuggerEntryReason reason, struct DebuggerEntryInfo* info) { +void DebuggerEnter(struct Debugger* debugger, enum DebuggerEntryReason reason, struct DebuggerEntryInfo* info) { debugger->state = DEBUGGER_PAUSED; struct ARMCore* cpu = debugger->cpu; cpu->nextEvent = cpu->cycles;@@ -128,13 +128,13 @@ debugger->entered(debugger, reason, info);
} } -void ARMDebuggerSetBreakpoint(struct ARMDebugger* debugger, uint32_t address) { +void DebuggerSetBreakpoint(struct Debugger* debugger, uint32_t address) { struct DebugBreakpoint* breakpoint = DebugBreakpointListAppend(&debugger->breakpoints); breakpoint->address = address; breakpoint->isSw = false; } -bool ARMDebuggerSetSoftwareBreakpoint(struct ARMDebugger* debugger, uint32_t address, enum ExecutionMode mode) { +bool DebuggerSetSoftwareBreakpoint(struct Debugger* debugger, uint32_t address, enum ExecutionMode mode) { uint32_t opcode; if (!debugger->setSoftwareBreakpoint || !debugger->setSoftwareBreakpoint(debugger, address, mode, &opcode)) { return false;@@ -149,7 +149,7 @@
return true; } -void ARMDebuggerClearBreakpoint(struct ARMDebugger* debugger, uint32_t address) { +void DebuggerClearBreakpoint(struct Debugger* debugger, uint32_t address) { struct DebugBreakpointList* breakpoints = &debugger->breakpoints; size_t i; for (i = 0; i < DebugBreakpointListSize(breakpoints); ++i) {@@ -160,16 +160,16 @@ }
} -void ARMDebuggerSetWatchpoint(struct ARMDebugger* debugger, uint32_t address, enum WatchpointType type) { +void DebuggerSetWatchpoint(struct Debugger* debugger, uint32_t address, enum WatchpointType type) { if (!DebugWatchpointListSize(&debugger->watchpoints)) { - ARMDebuggerInstallMemoryShim(debugger); + DebuggerInstallMemoryShim(debugger); } struct DebugWatchpoint* watchpoint = DebugWatchpointListAppend(&debugger->watchpoints); watchpoint->address = address; watchpoint->type = type; } -void ARMDebuggerClearWatchpoint(struct ARMDebugger* debugger, uint32_t address) { +void DebuggerClearWatchpoint(struct Debugger* debugger, uint32_t address) { struct DebugWatchpointList* watchpoints = &debugger->watchpoints; size_t i; for (i = 0; i < DebugWatchpointListSize(watchpoints); ++i) {@@ -178,6 +178,6 @@ DebugWatchpointListShift(watchpoints, i, 1);
} } if (!DebugWatchpointListSize(&debugger->watchpoints)) { - ARMDebuggerRemoveMemoryShim(debugger); + DebuggerRemoveMemoryShim(debugger); } }
@@ -11,7 +11,18 @@
#include "arm/arm.h" #include "util/vector.h" -extern const uint32_t ARM_DEBUGGER_ID; +extern const uint32_t DEBUGGER_ID; + +enum DebuggerType { + DEBUGGER_NONE = 0, +#ifdef USE_CLI_DEBUGGER + DEBUGGER_CLI, +#endif +#ifdef USE_GDB_STUB + DEBUGGER_GDB, +#endif + DEBUGGER_MAX +}; enum DebuggerState { DEBUGGER_PAUSED,@@ -74,7 +85,7 @@ DEBUGGER_LOG_WARN = 0x04,
DEBUGGER_LOG_ERROR = 0x08 }; -struct ARMDebugger { +struct Debugger { struct mCPUComponent d; enum DebuggerState state; struct ARMCore* cpu;@@ -86,26 +97,26 @@ struct ARMMemory originalMemory;
struct DebugBreakpoint* currentBreakpoint; - void (*init)(struct ARMDebugger*); - void (*deinit)(struct ARMDebugger*); - void (*paused)(struct ARMDebugger*); - void (*entered)(struct ARMDebugger*, enum DebuggerEntryReason, struct DebuggerEntryInfo*); - void (*custom)(struct ARMDebugger*); + void (*init)(struct Debugger*); + void (*deinit)(struct Debugger*); + void (*paused)(struct Debugger*); + void (*entered)(struct Debugger*, enum DebuggerEntryReason, struct DebuggerEntryInfo*); + void (*custom)(struct Debugger*); - bool (*setSoftwareBreakpoint)(struct ARMDebugger*, uint32_t address, enum ExecutionMode mode, uint32_t* opcode); - bool (*clearSoftwareBreakpoint)(struct ARMDebugger*, uint32_t address, enum ExecutionMode mode, uint32_t opcode); + bool (*setSoftwareBreakpoint)(struct Debugger*, uint32_t address, enum ExecutionMode mode, uint32_t* opcode); + bool (*clearSoftwareBreakpoint)(struct Debugger*, uint32_t address, enum ExecutionMode mode, uint32_t opcode); ATTRIBUTE_FORMAT(printf, 3, 4) - void (*log)(struct ARMDebugger*, enum DebuggerLogLevel, const char* format, ...); + void (*log)(struct Debugger*, enum DebuggerLogLevel, const char* format, ...); }; -void ARMDebuggerCreate(struct ARMDebugger*); -void ARMDebuggerRun(struct ARMDebugger*); -void ARMDebuggerEnter(struct ARMDebugger*, enum DebuggerEntryReason, struct DebuggerEntryInfo*); -void ARMDebuggerSetBreakpoint(struct ARMDebugger* debugger, uint32_t address); -bool ARMDebuggerSetSoftwareBreakpoint(struct ARMDebugger* debugger, uint32_t address, enum ExecutionMode mode); -void ARMDebuggerClearBreakpoint(struct ARMDebugger* debugger, uint32_t address); -void ARMDebuggerSetWatchpoint(struct ARMDebugger* debugger, uint32_t address, enum WatchpointType type); -void ARMDebuggerClearWatchpoint(struct ARMDebugger* debugger, uint32_t address); +void DebuggerCreate(struct Debugger*); +void DebuggerRun(struct Debugger*); +void DebuggerEnter(struct Debugger*, enum DebuggerEntryReason, struct DebuggerEntryInfo*); +void DebuggerSetBreakpoint(struct Debugger* debugger, uint32_t address); +bool DebuggerSetSoftwareBreakpoint(struct Debugger* debugger, uint32_t address, enum ExecutionMode mode); +void DebuggerClearBreakpoint(struct Debugger* debugger, uint32_t address); +void DebuggerSetWatchpoint(struct Debugger* debugger, uint32_t address, enum WatchpointType type); +void DebuggerClearWatchpoint(struct Debugger* debugger, uint32_t address); #endif
@@ -26,14 +26,14 @@ };
static void _sendMessage(struct GDBStub* stub); -static void _gdbStubDeinit(struct ARMDebugger* debugger) { +static void _gdbStubDeinit(struct Debugger* debugger) { struct GDBStub* stub = (struct GDBStub*) debugger; if (!SOCKET_FAILED(stub->socket)) { GDBStubShutdown(stub); } } -static void _gdbStubEntered(struct ARMDebugger* debugger, enum DebuggerEntryReason reason, struct DebuggerEntryInfo* info) { +static void _gdbStubEntered(struct Debugger* debugger, enum DebuggerEntryReason reason, struct DebuggerEntryInfo* info) { struct GDBStub* stub = (struct GDBStub*) debugger; switch (reason) { case DEBUGGER_ENTER_MANUAL:@@ -76,7 +76,7 @@ }
_sendMessage(stub); } -static void _gdbStubPoll(struct ARMDebugger* debugger) { +static void _gdbStubPoll(struct Debugger* debugger) { struct GDBStub* stub = (struct GDBStub*) debugger; --stub->untilPoll; if (stub->untilPoll > 0) {@@ -87,7 +87,7 @@ stub->shouldBlock = false;
GDBStubUpdate(stub); } -static void _gdbStubWait(struct ARMDebugger* debugger) { +static void _gdbStubWait(struct Debugger* debugger) { struct GDBStub* stub = (struct GDBStub*) debugger; stub->shouldBlock = true; GDBStubUpdate(stub);@@ -302,7 +302,7 @@ static void _processVReadCommand(struct GDBStub* stub, const char* message) {
stub->outgoing[0] = '\0'; if (!strncmp("Attach", message, 6)) { strncpy(stub->outgoing, "1", GDB_STUB_MAX_LINE - 4); - ARMDebuggerEnter(&stub->d, DEBUGGER_ENTER_MANUAL, 0); + DebuggerEnter(&stub->d, DEBUGGER_ENTER_MANUAL, 0); } _sendMessage(stub); }@@ -318,22 +318,22 @@
switch (message[0]) { case '0': // Memory breakpoints are not currently supported case '1': - ARMDebuggerSetBreakpoint(&stub->d, address); + DebuggerSetBreakpoint(&stub->d, address); strncpy(stub->outgoing, "OK", GDB_STUB_MAX_LINE - 4); _sendMessage(stub); break; case '2': - ARMDebuggerSetWatchpoint(&stub->d, address, WATCHPOINT_WRITE); + DebuggerSetWatchpoint(&stub->d, address, WATCHPOINT_WRITE); strncpy(stub->outgoing, "OK", GDB_STUB_MAX_LINE - 4); _sendMessage(stub); break; case '3': - ARMDebuggerSetWatchpoint(&stub->d, address, WATCHPOINT_READ); + DebuggerSetWatchpoint(&stub->d, address, WATCHPOINT_READ); strncpy(stub->outgoing, "OK", GDB_STUB_MAX_LINE - 4); _sendMessage(stub); break; case '4': - ARMDebuggerSetWatchpoint(&stub->d, address, WATCHPOINT_RW); + DebuggerSetWatchpoint(&stub->d, address, WATCHPOINT_RW); strncpy(stub->outgoing, "OK", GDB_STUB_MAX_LINE - 4); _sendMessage(stub); break;@@ -351,12 +351,12 @@ uint32_t address = _readHex(readAddress, &i);
switch (message[0]) { case '0': // Memory breakpoints are not currently supported case '1': - ARMDebuggerClearBreakpoint(&stub->d, address); + DebuggerClearBreakpoint(&stub->d, address); break; case '2': case '3': case '4': - ARMDebuggerClearWatchpoint(&stub->d, address); + DebuggerClearWatchpoint(&stub->d, address); break; default: break;@@ -379,7 +379,7 @@ case '$':
++message; break; case '\x03': - ARMDebuggerEnter(&stub->d, DEBUGGER_ENTER_MANUAL, 0); + DebuggerEnter(&stub->d, DEBUGGER_ENTER_MANUAL, 0); return parsed; default: _nak(stub);@@ -468,7 +468,7 @@ return parsed;
} void GDBStubCreate(struct GDBStub* stub) { - ARMDebuggerCreate(&stub->d); + DebuggerCreate(&stub->d); stub->socket = INVALID_SOCKET; stub->connection = INVALID_SOCKET; stub->d.init = 0;@@ -547,7 +547,7 @@ if (!SOCKET_FAILED(stub->connection)) {
if (!SocketSetBlocking(stub->connection, false)) { goto connectionLost; } - ARMDebuggerEnter(&stub->d, DEBUGGER_ENTER_ATTACHED, 0); + DebuggerEnter(&stub->d, DEBUGGER_ENTER_ATTACHED, 0); } else if (SocketWouldBlock()) { return; } else {
@@ -23,7 +23,7 @@ GDB_ACK_OFF
}; struct GDBStub { - struct ARMDebugger d; + struct Debugger d; char line[GDB_STUB_MAX_LINE]; char outgoing[GDB_STUB_MAX_LINE];
@@ -11,52 +11,52 @@ #include "util/math.h"
#include <string.h> -static bool _checkWatchpoints(struct ARMDebugger* debugger, uint32_t address, struct DebuggerEntryInfo* info, enum WatchpointType type, uint32_t newValue, int width); +static bool _checkWatchpoints(struct Debugger* debugger, uint32_t address, struct DebuggerEntryInfo* info, enum WatchpointType type, uint32_t newValue, int width); #define FIND_DEBUGGER(DEBUGGER, CPU) \ { \ DEBUGGER = 0; \ size_t i; \ for (i = 0; i < CPU->numComponents; ++i) { \ - if (CPU->components[i]->id == ARM_DEBUGGER_ID) { \ - DEBUGGER = (struct ARMDebugger*) cpu->components[i]; \ + if (CPU->components[i]->id == DEBUGGER_ID) { \ + DEBUGGER = (struct Debugger*) cpu->components[i]; \ break; \ } \ } \ } #define CREATE_SHIM(NAME, RETURN, TYPES, ...) \ - static RETURN ARMDebuggerShim_ ## NAME TYPES { \ - struct ARMDebugger* debugger; \ + static RETURN DebuggerShim_ ## NAME TYPES { \ + struct Debugger* debugger; \ FIND_DEBUGGER(debugger, cpu); \ return debugger->originalMemory.NAME(cpu, __VA_ARGS__); \ } #define CREATE_WATCHPOINT_READ_SHIM(NAME, WIDTH, RETURN, TYPES, ...) \ - static RETURN ARMDebuggerShim_ ## NAME TYPES { \ - struct ARMDebugger* debugger; \ + static RETURN DebuggerShim_ ## NAME TYPES { \ + struct Debugger* debugger; \ FIND_DEBUGGER(debugger, cpu); \ struct DebuggerEntryInfo info; \ if (_checkWatchpoints(debugger, address, &info, WATCHPOINT_READ, 0, WIDTH)) { \ - ARMDebuggerEnter(debugger, DEBUGGER_ENTER_WATCHPOINT, &info); \ + DebuggerEnter(debugger, DEBUGGER_ENTER_WATCHPOINT, &info); \ } \ return debugger->originalMemory.NAME(cpu, __VA_ARGS__); \ } #define CREATE_WATCHPOINT_WRITE_SHIM(NAME, WIDTH, RETURN, TYPES, ...) \ - static RETURN ARMDebuggerShim_ ## NAME TYPES { \ - struct ARMDebugger* debugger; \ + static RETURN DebuggerShim_ ## NAME TYPES { \ + struct Debugger* debugger; \ FIND_DEBUGGER(debugger, cpu); \ struct DebuggerEntryInfo info; \ if (_checkWatchpoints(debugger, address, &info, WATCHPOINT_WRITE, value, WIDTH)) { \ - ARMDebuggerEnter(debugger, DEBUGGER_ENTER_WATCHPOINT, &info); \ + DebuggerEnter(debugger, DEBUGGER_ENTER_WATCHPOINT, &info); \ } \ return debugger->originalMemory.NAME(cpu, __VA_ARGS__); \ } #define CREATE_MULTIPLE_WATCHPOINT_SHIM(NAME, ACCESS_TYPE) \ - static uint32_t ARMDebuggerShim_ ## NAME (struct ARMCore* cpu, uint32_t address, int mask, enum LSMDirection direction, int* cycleCounter) { \ - struct ARMDebugger* debugger; \ + static uint32_t DebuggerShim_ ## NAME (struct ARMCore* cpu, uint32_t address, int mask, enum LSMDirection direction, int* cycleCounter) { \ + struct Debugger* debugger; \ FIND_DEBUGGER(debugger, cpu); \ uint32_t popcount = popcount32(mask); \ int offset = 4; \@@ -72,7 +72,7 @@ unsigned i; \
for (i = 0; i < popcount; ++i) { \ struct DebuggerEntryInfo info; \ if (_checkWatchpoints(debugger, base + 4 * i, &info, ACCESS_TYPE, 0, 4)) { \ - ARMDebuggerEnter(debugger, DEBUGGER_ENTER_WATCHPOINT, &info); \ + DebuggerEnter(debugger, DEBUGGER_ENTER_WATCHPOINT, &info); \ } \ } \ return debugger->originalMemory.NAME(cpu, address, mask, direction, cycleCounter); \@@ -88,7 +88,7 @@ CREATE_MULTIPLE_WATCHPOINT_SHIM(loadMultiple, WATCHPOINT_READ)
CREATE_MULTIPLE_WATCHPOINT_SHIM(storeMultiple, WATCHPOINT_WRITE) CREATE_SHIM(setActiveRegion, void, (struct ARMCore* cpu, uint32_t address), address) -static bool _checkWatchpoints(struct ARMDebugger* debugger, uint32_t address, struct DebuggerEntryInfo* info, enum WatchpointType type, uint32_t newValue, int width) { +static bool _checkWatchpoints(struct Debugger* debugger, uint32_t address, struct DebuggerEntryInfo* info, enum WatchpointType type, uint32_t newValue, int width) { --width; struct DebugWatchpoint* watchpoint; size_t i;@@ -116,20 +116,20 @@ }
return false; } -void ARMDebuggerInstallMemoryShim(struct ARMDebugger* debugger) { +void DebuggerInstallMemoryShim(struct Debugger* debugger) { debugger->originalMemory = debugger->cpu->memory; - debugger->cpu->memory.store32 = ARMDebuggerShim_store32; - debugger->cpu->memory.store16 = ARMDebuggerShim_store16; - debugger->cpu->memory.store8 = ARMDebuggerShim_store8; - debugger->cpu->memory.load32 = ARMDebuggerShim_load32; - debugger->cpu->memory.load16 = ARMDebuggerShim_load16; - debugger->cpu->memory.load8 = ARMDebuggerShim_load8; - debugger->cpu->memory.storeMultiple = ARMDebuggerShim_storeMultiple; - debugger->cpu->memory.loadMultiple = ARMDebuggerShim_loadMultiple; - debugger->cpu->memory.setActiveRegion = ARMDebuggerShim_setActiveRegion; + debugger->cpu->memory.store32 = DebuggerShim_store32; + debugger->cpu->memory.store16 = DebuggerShim_store16; + debugger->cpu->memory.store8 = DebuggerShim_store8; + debugger->cpu->memory.load32 = DebuggerShim_load32; + debugger->cpu->memory.load16 = DebuggerShim_load16; + debugger->cpu->memory.load8 = DebuggerShim_load8; + debugger->cpu->memory.storeMultiple = DebuggerShim_storeMultiple; + debugger->cpu->memory.loadMultiple = DebuggerShim_loadMultiple; + debugger->cpu->memory.setActiveRegion = DebuggerShim_setActiveRegion; } -void ARMDebuggerRemoveMemoryShim(struct ARMDebugger* debugger) { +void DebuggerRemoveMemoryShim(struct Debugger* debugger) { debugger->cpu->memory.store32 = debugger->originalMemory.store32; debugger->cpu->memory.store16 = debugger->originalMemory.store16; debugger->cpu->memory.store8 = debugger->originalMemory.store8;
@@ -10,9 +10,9 @@ #include "util/common.h"
#include "arm.h" -struct ARMDebugger; +struct Debugger; -void ARMDebuggerInstallMemoryShim(struct ARMDebugger* debugger); -void ARMDebuggerRemoveMemoryShim(struct ARMDebugger* debugger); +void DebuggerInstallMemoryShim(struct Debugger* debugger); +void DebuggerRemoveMemoryShim(struct Debugger* debugger); #endif
@@ -40,8 +40,8 @@ static void GBAHitStub(struct ARMCore* cpu, uint32_t opcode);
static void GBAIllegal(struct ARMCore* cpu, uint32_t opcode); static void GBABreakpoint(struct ARMCore* cpu, int immediate); -static bool _setSoftwareBreakpoint(struct ARMDebugger*, uint32_t address, enum ExecutionMode mode, uint32_t* opcode); -static bool _clearSoftwareBreakpoint(struct ARMDebugger*, uint32_t address, enum ExecutionMode mode, uint32_t opcode); +static bool _setSoftwareBreakpoint(struct Debugger*, uint32_t address, enum ExecutionMode mode, uint32_t* opcode); +static bool _clearSoftwareBreakpoint(struct Debugger*, uint32_t address, enum ExecutionMode mode, uint32_t opcode); #ifdef _3DS@@ -402,7 +402,7 @@ }
return nextEvent; } -void GBAAttachDebugger(struct GBA* gba, struct ARMDebugger* debugger) { +void GBAAttachDebugger(struct GBA* gba, struct Debugger* debugger) { debugger->setSoftwareBreakpoint = _setSoftwareBreakpoint; debugger->clearSoftwareBreakpoint = _clearSoftwareBreakpoint; gba->debugger = debugger;@@ -698,7 +698,7 @@ _GBAVLog(gba, level, format, args);
va_end(args); } -void GBADebuggerLogShim(struct ARMDebugger* debugger, enum DebuggerLogLevel level, const char* format, ...) { +void GBADebuggerLogShim(struct Debugger* debugger, enum DebuggerLogLevel level, const char* format, ...) { struct GBA* gba = 0; if (debugger->cpu) { gba = (struct GBA*) debugger->cpu->master;@@ -819,7 +819,7 @@ struct DebuggerEntryInfo info = {
.address = _ARMPCAddress(cpu), .opcode = opcode }; - ARMDebuggerEnter(gba->debugger, DEBUGGER_ENTER_ILLEGAL_OP, &info); + DebuggerEnter(gba->debugger, DEBUGGER_ENTER_ILLEGAL_OP, &info); } GBALog(gba, level, "Stub opcode: %08x", opcode); }@@ -834,7 +834,7 @@ struct DebuggerEntryInfo info = {
.address = _ARMPCAddress(cpu), .opcode = opcode }; - ARMDebuggerEnter(gba->debugger, DEBUGGER_ENTER_ILLEGAL_OP, &info); + DebuggerEnter(gba->debugger, DEBUGGER_ENTER_ILLEGAL_OP, &info); } else { ARMRaiseUndefined(cpu); }@@ -851,7 +851,7 @@ if (gba->debugger) {
struct DebuggerEntryInfo info = { .address = _ARMPCAddress(cpu) }; - ARMDebuggerEnter(gba->debugger, DEBUGGER_ENTER_BREAKPOINT, &info); + DebuggerEnter(gba->debugger, DEBUGGER_ENTER_BREAKPOINT, &info); } break; case GBA_COMPONENT_CHEAT_DEVICE:@@ -978,12 +978,12 @@ return 0;
} #endif -static bool _setSoftwareBreakpoint(struct ARMDebugger* debugger, uint32_t address, enum ExecutionMode mode, uint32_t* opcode) { +static bool _setSoftwareBreakpoint(struct Debugger* debugger, uint32_t address, enum ExecutionMode mode, uint32_t* opcode) { GBASetBreakpoint((struct GBA*) debugger->cpu->master, &debugger->d, address, mode, opcode); return true; } -static bool _clearSoftwareBreakpoint(struct ARMDebugger* debugger, uint32_t address, enum ExecutionMode mode, uint32_t opcode) { +static bool _clearSoftwareBreakpoint(struct Debugger* debugger, uint32_t address, enum ExecutionMode mode, uint32_t opcode) { GBAClearBreakpoint((struct GBA*) debugger->cpu->master, address, mode, opcode); return true; }
@@ -88,7 +88,7 @@ struct GBASIO sio;
struct mCoreSync* sync; - struct ARMDebugger* debugger; + struct Debugger* debugger; uint32_t bus; int performingDMA;@@ -166,7 +166,7 @@ void GBATestIRQ(struct ARMCore* cpu);
void GBAHalt(struct GBA* gba); void GBAStop(struct GBA* gba); -void GBAAttachDebugger(struct GBA* gba, struct ARMDebugger* debugger); +void GBAAttachDebugger(struct GBA* gba, struct Debugger* debugger); void GBADetachDebugger(struct GBA* gba); void GBASetBreakpoint(struct GBA* gba, struct mCPUComponent* component, uint32_t address, enum ExecutionMode mode,@@ -196,6 +196,6 @@ ATTRIBUTE_FORMAT(printf, 3, 4)
void GBALog(struct GBA* gba, enum GBALogLevel level, const char* format, ...); ATTRIBUTE_FORMAT(printf, 3, 4) -void GBADebuggerLogShim(struct ARMDebugger* debugger, enum DebuggerLogLevel level, const char* format, ...); +void GBADebuggerLogShim(struct Debugger* debugger, enum DebuggerLogLevel level, const char* format, ...); #endif
@@ -61,7 +61,7 @@ struct GBACLIDebugger* gbaDebugger = (struct GBACLIDebugger*) debugger;
if (gbaDebugger->frameAdvance) { if (!gbaDebugger->inVblank && GBARegisterDISPSTATIsInVblank(((struct GBA*) gbaDebugger->core->board)->memory.io[REG_DISPSTAT >> 1])) { - ARMDebuggerEnter(&gbaDebugger->d.p->d, DEBUGGER_ENTER_MANUAL, 0); + DebuggerEnter(&gbaDebugger->d.p->d, DEBUGGER_ENTER_MANUAL, 0); gbaDebugger->frameAdvance = false; return false; }
@@ -275,7 +275,7 @@
if (threadContext->debugger) { threadContext->debugger->log = GBADebuggerLogShim; GBAAttachDebugger(&gba, threadContext->debugger); - ARMDebuggerEnter(threadContext->debugger, DEBUGGER_ENTER_ATTACHED, 0); + DebuggerEnter(threadContext->debugger, DEBUGGER_ENTER_ATTACHED, 0); } GBASIOSetDriverSet(&gba.sio, &threadContext->sioDrivers);@@ -299,8 +299,8 @@ _changeState(threadContext, THREAD_RUNNING, true);
while (threadContext->state < THREAD_EXITING) { if (threadContext->debugger) { - struct ARMDebugger* debugger = threadContext->debugger; - ARMDebuggerRun(debugger); + struct Debugger* debugger = threadContext->debugger; + DebuggerRun(debugger); if (debugger->state == DEBUGGER_SHUTDOWN) { _changeState(threadContext, THREAD_EXITING, false); }
@@ -34,7 +34,7 @@
// Input struct GBAVideoRenderer* renderer; struct GBASIODriverSet sioDrivers; - struct ARMDebugger* debugger; + struct Debugger* debugger; #if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2 struct mDirectorySet dirs; #endif
@@ -199,12 +199,12 @@ struct mGraphicsOpts* graphicsOpts = parser->opts;
mCoreConfigSetOverrideIntValue(config, "fullscreen", graphicsOpts->fullscreen); } -struct ARMDebugger* createDebugger(struct mArguments* opts, struct mCore* core) { +struct Debugger* createDebugger(struct mArguments* opts, struct mCore* core) { #ifndef USE_CLI_DEBUGGER UNUSED(context); #endif union DebugUnion { - struct ARMDebugger d; + struct Debugger d; #ifdef USE_CLI_DEBUGGER struct CLIDebugger cli; #endif
@@ -8,16 +8,7 @@ #define COMMAND_LINE_H
#include "util/common.h" -enum DebuggerType { - DEBUGGER_NONE = 0, -#ifdef USE_CLI_DEBUGGER - DEBUGGER_CLI, -#endif -#ifdef USE_GDB_STUB - DEBUGGER_GDB, -#endif - DEBUGGER_MAX -}; +#include "debugger/debugger.h" struct mArguments { char* fname;@@ -48,8 +39,6 @@ int multiplier;
bool fullscreen; }; -struct GBAThread; - bool parseArguments(struct mArguments* args, int argc, char* const* argv, struct mSubParser* subparser); void applyArguments(struct mArguments* args, struct mSubParser* subparser, struct mCoreConfig* config);@@ -60,6 +49,6 @@ void version(const char* arg0);
void initParserForGraphics(struct mSubParser* parser, struct mGraphicsOpts* opts); struct mCore; -struct ARMDebugger* createDebugger(struct mArguments* opts, struct mCore* core); +struct Debugger* createDebugger(struct mArguments* opts, struct mCore* core); #endif
@@ -41,12 +41,12 @@ return;
} m_gameController->setDebugger(&m_gdbStub.d); if (m_gameController->isLoaded()) { - ARMDebuggerEnter(&m_gdbStub.d, DEBUGGER_ENTER_ATTACHED, 0); + DebuggerEnter(&m_gdbStub.d, DEBUGGER_ENTER_ATTACHED, 0); } else { QObject::disconnect(m_autoattach); m_autoattach = connect(m_gameController, &GameController::gameStarted, [this]() { QObject::disconnect(m_autoattach); - ARMDebuggerEnter(&m_gdbStub.d, DEBUGGER_ENTER_ATTACHED, 0); + DebuggerEnter(&m_gdbStub.d, DEBUGGER_ENTER_ATTACHED, 0); }); } }@@ -81,6 +81,6 @@ if (!isAttached()) {
return; } m_gameController->threadInterrupt(); - ARMDebuggerEnter(&m_gdbStub.d, DEBUGGER_ENTER_MANUAL, 0); + DebuggerEnter(&m_gdbStub.d, DEBUGGER_ENTER_MANUAL, 0); m_gameController->threadContinue(); }
@@ -262,11 +262,11 @@ threadContinue();
} #ifdef USE_GDB_STUB -ARMDebugger* GameController::debugger() { +Debugger* GameController::debugger() { return m_threadContext.debugger; } -void GameController::setDebugger(ARMDebugger* debugger) { +void GameController::setDebugger(Debugger* debugger) { threadInterrupt(); if (m_threadContext.debugger && GBAThreadIsActive(&m_threadContext)) { GBADetachDebugger(m_threadContext.gba);
@@ -75,8 +75,8 @@
int stateSlot() const { return m_stateSlot; } #ifdef USE_GDB_STUB - ARMDebugger* debugger(); - void setDebugger(ARMDebugger*); + Debugger* debugger(); + void setDebugger(Debugger*); #endif signals:
@@ -405,7 +405,7 @@ if (event->type == SDL_KEYDOWN) {
switch (event->keysym.sym) { case SDLK_F11: if (context->debugger) { - ARMDebuggerEnter(context->debugger, DEBUGGER_ENTER_MANUAL, 0); + DebuggerEnter(context->debugger, DEBUGGER_ENTER_MANUAL, 0); } return; #ifdef USE_PNG