From e192973bc5a0f32dce3bf52ef8c91320d08eec37 Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Thu, 28 Dec 2017 20:34:37 -0500 Subject: [PATCH] Debugger: Migrate identifier lookups --- include/mgba/core/core.h | 1 + include/mgba/debugger/debugger.h | 4 ++- include/mgba/internal/debugger/cli-debugger.h | 1 - src/debugger/cli-debugger.c | 31 +++---------------- src/debugger/debugger.c | 20 ++++++++++++ src/gb/core.c | 15 +++++++++ src/gb/debugger/cli.c | 15 --------- src/gba/core.c | 15 +++++++++ src/gba/debugger/cli.c | 15 --------- 9 files changed, 58 insertions(+), 59 deletions(-) diff --git a/include/mgba/core/core.h b/include/mgba/core/core.h index 12304f561..59d9e429a 100644 --- a/include/mgba/core/core.h +++ b/include/mgba/core/core.h @@ -141,6 +141,7 @@ struct mCore { 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*); diff --git a/include/mgba/debugger/debugger.h b/include/mgba/debugger/debugger.h index 3dc813334..f2a030827 100644 --- a/include/mgba/debugger/debugger.h +++ b/include/mgba/debugger/debugger.h @@ -87,9 +87,9 @@ struct mDebuggerPlatform { 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; @@ -112,6 +112,8 @@ 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 #endif diff --git a/include/mgba/internal/debugger/cli-debugger.h b/include/mgba/internal/debugger/cli-debugger.h index eabb3bcf1..7a03d1df0 100644 --- a/include/mgba/internal/debugger/cli-debugger.h +++ b/include/mgba/internal/debugger/cli-debugger.h @@ -47,7 +47,6 @@ 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; diff --git a/src/debugger/cli-debugger.c b/src/debugger/cli-debugger.c index 786afcb60..b85308692 100644 --- a/src/debugger/cli-debugger.c +++ b/src/debugger/cli-debugger.c @@ -588,31 +588,6 @@ static uint32_t _performOperation(enum Operation operation, uint32_t current, ui 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 @@ static void _evaluateParseTree(struct mDebugger* debugger, struct ParseTree* tre 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; diff --git a/src/debugger/debugger.c b/src/debugger/debugger.c index 79b06076a..14e4d101c 100644 --- a/src/debugger/debugger.c +++ b/src/debugger/debugger.c @@ -8,6 +8,7 @@ #include #include +#include #ifdef USE_GDB_STUB #include @@ -137,3 +138,22 @@ static void mDebuggerDeinit(struct mCPUComponent* component) { } 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; +} diff --git a/src/gb/core.c b/src/gb/core.c index 753a93bde..299a6f5b6 100644 --- a/src/gb/core.c +++ b/src/gb/core.c @@ -723,6 +723,20 @@ static void _GBCoreLoadSymbols(struct mCore* core, struct VFile* vf) { } 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 @@ struct mCore* GBCoreCreate(void) { core->attachDebugger = _GBCoreAttachDebugger; core->detachDebugger = _GBCoreDetachDebugger; core->loadSymbols = _GBCoreLoadSymbols; + core->lookupIdentifier = _GBCoreLookupIdentifier; #endif core->cheatDevice = _GBCoreCheatDevice; core->savedataClone = _GBCoreSavedataClone; diff --git a/src/gb/debugger/cli.c b/src/gb/debugger/cli.c index 75cc53e54..a051ea577 100644 --- a/src/gb/debugger/cli.c +++ b/src/gb/debugger/cli.c @@ -14,7 +14,6 @@ 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 @@ struct CLIDebuggerSystem* GBCLIDebuggerCreate(struct mCore* core) { 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; @@ -65,19 +63,6 @@ static bool _GBCLIDebuggerCustom(struct CLIDebuggerSystem* debugger) { 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) { UNUSED(dv); debugger->d.state = DEBUGGER_CUSTOM; diff --git a/src/gba/core.c b/src/gba/core.c index 16c1d1040..8c307ceff 100644 --- a/src/gba/core.c +++ b/src/gba/core.c @@ -724,6 +724,20 @@ static void _GBACoreLoadSymbols(struct mCore* core, struct VFile* 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 @@ struct mCore* GBACoreCreate(void) { core->attachDebugger = _GBACoreAttachDebugger; core->detachDebugger = _GBACoreDetachDebugger; core->loadSymbols = _GBACoreLoadSymbols; + core->lookupIdentifier = _GBACoreLookupIdentifier; #endif core->cheatDevice = _GBACoreCheatDevice; core->savedataClone = _GBACoreSavedataClone; diff --git a/src/gba/debugger/cli.c b/src/gba/debugger/cli.c index 07287eebc..4eb13b0f3 100644 --- a/src/gba/debugger/cli.c +++ b/src/gba/debugger/cli.c @@ -14,7 +14,6 @@ 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 @@ struct GBACLIDebugger* GBACLIDebuggerCreate(struct mCore* core) { 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; @@ -64,19 +62,6 @@ static bool _GBACLIDebuggerCustom(struct CLIDebuggerSystem* debugger) { 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) { UNUSED(dv); debugger->d.state = DEBUGGER_CUSTOM;