Permalink
Browse files

Debugger: Migrate identifier lookups

  • Loading branch information...
endrift committed Dec 29, 2017
1 parent 5d8403f commit e192973bc5a0f32dce3bf52ef8c91320d08eec37
View
@@ -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*);
@@ -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
@@ -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;
@@ -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;
View
@@ -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 @@ 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;
+}
View
@@ -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;
View
@@ -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;
View
@@ -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;
View
@@ -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;

0 comments on commit e192973

Please sign in to comment.