Debugger: Migrate identifier lookups
@@ -141,6 +141,7 @@ void (*attachDebugger)(struct mCore*, struct mDebugger*);
void (*detachDebugger)(struct mCore*); void (*loadSymbols)(struct mCore*, struct VFile*); + bool (*lookupIdentifier)(struct mCore*, const char* name, int32_t* value, int* segment); #endif struct mCheatDevice* (*cheatDevice)(struct mCore*);
@@ -87,9 +87,9 @@ void (*trace)(struct mDebuggerPlatform*, char* out, size_t* length);
bool (*getRegister)(struct mDebuggerPlatform*, const char* name, int32_t* value); bool (*setRegister)(struct mDebuggerPlatform*, const char* name, int32_t value); + bool (*lookupIdentifier)(struct mDebuggerPlatform*, const char* name, int32_t* value, int* segment); }; -struct mDebuggerSymbols; struct mDebugger { struct mCPUComponent d; struct mDebuggerPlatform* platform;@@ -111,6 +111,8 @@ void mDebuggerAttach(struct mDebugger*, struct mCore*);
void mDebuggerRun(struct mDebugger*); void mDebuggerRunFrame(struct mDebugger*); void mDebuggerEnter(struct mDebugger*, enum mDebuggerEntryReason, struct mDebuggerEntryInfo*); + +bool mDebuggerLookupIdentifier(struct mDebugger* debugger, const char* name, int32_t* value, int* segment); CXX_GUARD_END
@@ -47,7 +47,6 @@ void (*deinit)(struct CLIDebuggerSystem*);
bool (*custom)(struct CLIDebuggerSystem*); void (*disassemble)(struct CLIDebuggerSystem*, struct CLIDebugVector* dv); - uint32_t (*lookupIdentifier)(struct CLIDebuggerSystem*, const char* name, struct CLIDebugVector* dv); void (*printStatus)(struct CLIDebuggerSystem*); struct CLIDebuggerCommandSummary* commands;
@@ -588,31 +588,6 @@ }
return current; } -static void _lookupIdentifier(struct mDebugger* debugger, const char* name, struct CLIDebugVector* dv) { - struct CLIDebugger* cliDebugger = (struct CLIDebugger*) debugger; - if (cliDebugger->system) { - uint32_t value; -#ifdef ENABLE_SCRIPTING - if (debugger->bridge && mScriptBridgeLookupSymbol(debugger->bridge, name, &dv->intValue)) { - return; - } -#endif - if (debugger->core->symbolTable && mDebuggerSymbolLookup(debugger->core->symbolTable, name, &dv->intValue, &dv->segmentValue)) { - return; - } - dv->type = CLIDV_INT_TYPE; - if (debugger->platform->getRegister(debugger->platform, name, &dv->intValue)) { - return; - } - value = cliDebugger->system->lookupIdentifier(cliDebugger->system, name, dv); - if (dv->type != CLIDV_ERROR_TYPE) { - dv->intValue = value; - return; - } - } - dv->type = CLIDV_ERROR_TYPE; -} - static void _evaluateParseTree(struct mDebugger* debugger, struct ParseTree* tree, struct CLIDebugVector* dv) { int32_t lhs, rhs; switch (tree->token.type) {@@ -632,8 +607,10 @@ rhs = dv->intValue;
dv->intValue = _performOperation(tree->token.operatorValue, lhs, rhs, dv); break; case TOKEN_IDENTIFIER_TYPE: - _lookupIdentifier(debugger, tree->token.identifierValue, dv); - break; + if (mDebuggerLookupIdentifier(debugger, tree->token.identifierValue, &dv->intValue, &dv->segmentValue)) { + break; + } + // Fall through case TOKEN_ERROR_TYPE: default: dv->type = CLIDV_ERROR_TYPE;
@@ -8,6 +8,7 @@
#include <mgba/core/core.h> #include <mgba/internal/debugger/cli-debugger.h> +#include <mgba/internal/debugger/symbols.h> #ifdef USE_GDB_STUB #include <mgba/internal/debugger/gdb-stub.h>@@ -137,3 +138,22 @@ debugger->deinit(debugger);
} debugger->platform->deinit(debugger->platform); } + +bool mDebuggerLookupIdentifier(struct mDebugger* debugger, const char* name, int32_t* value, int* segment) { + *segment = -1; +#ifdef ENABLE_SCRIPTING + if (debugger->bridge && mScriptBridgeLookupSymbol(debugger->bridge, name, value)) { + return true; + } +#endif + if (debugger->core->symbolTable && mDebuggerSymbolLookup(debugger->core->symbolTable, name, value, segment)) { + return true; + } + if (debugger->core->lookupIdentifier(debugger->core, name, value, segment)) { + return true; + } + if (debugger->platform && debugger->platform->getRegister(debugger->platform, name, value)) { + return true; + } + return false; +}
@@ -723,6 +723,20 @@ return;
} GBLoadSymbols(core->symbolTable, vf); } + +static bool _GBCoreLookupIdentifier(struct mCore* core, const char* name, int32_t* value, int* segment) { + UNUSED(core); + *segment = -1; + int i; + for (i = 0; i < REG_MAX; ++i) { + const char* reg = GBIORegisterNames[i]; + if (reg && strcasecmp(reg, name) == 0) { + *value = GB_BASE_IO | i; + return true; + } + } + return false; +} #endif static struct mCheatDevice* _GBCoreCheatDevice(struct mCore* core) {@@ -905,6 +919,7 @@ core->cliDebuggerSystem = _GBCoreCliDebuggerSystem;
core->attachDebugger = _GBCoreAttachDebugger; core->detachDebugger = _GBCoreDetachDebugger; core->loadSymbols = _GBCoreLoadSymbols; + core->lookupIdentifier = _GBCoreLookupIdentifier; #endif core->cheatDevice = _GBCoreCheatDevice; core->savedataClone = _GBCoreSavedataClone;
@@ -14,7 +14,6 @@ #include <mgba/internal/lr35902/debugger/cli-debugger.h>
static void _GBCLIDebuggerInit(struct CLIDebuggerSystem*); static bool _GBCLIDebuggerCustom(struct CLIDebuggerSystem*); -static uint32_t _GBCLIDebuggerLookupIdentifier(struct CLIDebuggerSystem*, const char* name, struct CLIDebugVector* dv); static void _frame(struct CLIDebugger*, struct CLIDebugVector*); static void _load(struct CLIDebugger*, struct CLIDebugVector*);@@ -34,7 +33,6 @@ LR35902CLIDebuggerCreate(&debugger->d);
debugger->d.init = _GBCLIDebuggerInit; debugger->d.deinit = NULL; debugger->d.custom = _GBCLIDebuggerCustom; - debugger->d.lookupIdentifier = _GBCLIDebuggerLookupIdentifier; debugger->d.name = "Game Boy"; debugger->d.commands = _GBCLIDebuggerCommands;@@ -63,19 +61,6 @@ gbDebugger->inVblank = GBRegisterSTATGetMode(((struct GB*) gbDebugger->core->board)->memory.io[REG_STAT]) == 1;
return true; } return false; -} - -static uint32_t _GBCLIDebuggerLookupIdentifier(struct CLIDebuggerSystem* debugger, const char* name, struct CLIDebugVector* dv) { - UNUSED(debugger); - int i; - for (i = 0; i < REG_MAX; ++i) { - const char* reg = GBIORegisterNames[i]; - if (reg && strcasecmp(reg, name) == 0) { - return GB_BASE_IO | i; - } - } - dv->type = CLIDV_ERROR_TYPE; - return 0; } static void _frame(struct CLIDebugger* debugger, struct CLIDebugVector* dv) {
@@ -724,6 +724,20 @@ vf->close(vf);
} #endif } + +static bool _GBACoreLookupIdentifier(struct mCore* core, const char* name, int32_t* value, int* segment) { + UNUSED(core); + *segment = -1; + int i; + for (i = 0; i < REG_MAX; i += 2) { + const char* reg = GBAIORegisterNames[i >> 1]; + if (reg && strcasecmp(reg, name) == 0) { + *value = BASE_IO | i; + return true; + } + } + return false; +} #endif static struct mCheatDevice* _GBACoreCheatDevice(struct mCore* core) {@@ -921,6 +935,7 @@ core->cliDebuggerSystem = _GBACoreCliDebuggerSystem;
core->attachDebugger = _GBACoreAttachDebugger; core->detachDebugger = _GBACoreDetachDebugger; core->loadSymbols = _GBACoreLoadSymbols; + core->lookupIdentifier = _GBACoreLookupIdentifier; #endif core->cheatDevice = _GBACoreCheatDevice; core->savedataClone = _GBACoreSavedataClone;
@@ -14,7 +14,6 @@ #include <mgba/internal/arm/debugger/cli-debugger.h>
static void _GBACLIDebuggerInit(struct CLIDebuggerSystem*); static bool _GBACLIDebuggerCustom(struct CLIDebuggerSystem*); -static uint32_t _GBACLIDebuggerLookupIdentifier(struct CLIDebuggerSystem*, const char* name, struct CLIDebugVector* dv); static void _frame(struct CLIDebugger*, struct CLIDebugVector*); static void _load(struct CLIDebugger*, struct CLIDebugVector*);@@ -33,7 +32,6 @@ ARMCLIDebuggerCreate(&debugger->d);
debugger->d.init = _GBACLIDebuggerInit; debugger->d.deinit = NULL; debugger->d.custom = _GBACLIDebuggerCustom; - debugger->d.lookupIdentifier = _GBACLIDebuggerLookupIdentifier; debugger->d.name = "Game Boy Advance"; debugger->d.commands = _GBACLIDebuggerCommands;@@ -62,19 +60,6 @@ gbaDebugger->inVblank = GBARegisterDISPSTATGetInVblank(((struct GBA*) gbaDebugger->core->board)->memory.io[REG_DISPSTAT >> 1]);
return true; } return false; -} - -static uint32_t _GBACLIDebuggerLookupIdentifier(struct CLIDebuggerSystem* debugger, const char* name, struct CLIDebugVector* dv) { - UNUSED(debugger); - int i; - for (i = 0; i < REG_MAX; i += 2) { - const char* reg = GBAIORegisterNames[i >> 1]; - if (reg && strcasecmp(reg, name) == 0) { - return BASE_IO | i; - } - } - dv->type = CLIDV_ERROR_TYPE; - return 0; } static void _frame(struct CLIDebugger* debugger, struct CLIDebugVector* dv) {