Support identifiers
Jeffrey Pfau jeffrey@endrift.com
Sat, 12 Jul 2014 17:25:51 -0700
2 files changed,
32 insertions(+),
4 deletions(-)
M
src/debugger/cli-debugger.c
→
src/debugger/cli-debugger.c
@@ -300,13 +300,41 @@ }
return current; } -static uint32_t _evaluateParseTree(struct ParseTree* tree, struct DebugVector* dv) { +static uint32_t _lookupIdentifier(struct ARMDebugger* debugger, const char* name, struct DebugVector* dv) { + if (strcmp(name, "sp") == 0) { + return debugger->cpu->gprs[ARM_SP]; + } + if (strcmp(name, "lr") == 0) { + return debugger->cpu->gprs[ARM_LR]; + } + if (strcmp(name, "pc") == 0) { + return debugger->cpu->gprs[ARM_PC]; + } + if (strcmp(name, "cpsr") == 0) { + return debugger->cpu->cpsr.packed; + } + // TODO: test if mode has SPSR + if (strcmp(name, "spsr") == 0) { + return debugger->cpu->spsr.packed; + } + if (name[0] == 'r' && name[1] >= '0' && name[1] <= '9') { + int reg = atoi(&name[1]); + if (reg < 16) { + return debugger->cpu->gprs[reg]; + } + } + dv->type = DV_ERROR_TYPE; + return 0; +} + +static uint32_t _evaluateParseTree(struct ARMDebugger* debugger, struct ParseTree* tree, struct DebugVector* dv) { switch (tree->token.type) { case TOKEN_UINT_TYPE: return tree->token.uintValue; case TOKEN_OPERATOR_TYPE: - return _performOperation(tree->token.operatorValue, _evaluateParseTree(tree->lhs, dv), _evaluateParseTree(tree->rhs, dv), dv); + return _performOperation(tree->token.operatorValue, _evaluateParseTree(debugger, tree->lhs, dv), _evaluateParseTree(debugger, tree->rhs, dv), dv); case TOKEN_IDENTIFIER_TYPE: + return _lookupIdentifier(debugger, tree->token.identifierValue, dv); case TOKEN_ERROR_TYPE: dv->type = DV_ERROR_TYPE; }@@ -332,7 +360,7 @@ parseLexedExpression(&tree, &lv);
if (tree.token.type == TOKEN_ERROR_TYPE) { dvTemp.type = DV_ERROR_TYPE; } else { - dvTemp.intValue = _evaluateParseTree(&tree, &dvTemp); + dvTemp.intValue = _evaluateParseTree(&debugger->d, &tree, &dvTemp); } parseFree(tree.lhs);
M
src/debugger/parser.c
→
src/debugger/parser.c
@@ -84,7 +84,7 @@ case '-':
case '*': case '/': lv->token.type = TOKEN_IDENTIFIER_TYPE; - lv->token.identifierValue = strndup(tokenStart, string - tokenStart); + lv->token.identifierValue = strndup(tokenStart, string - tokenStart - 1); lv = _lexOperator(lv, token); state = LEX_ROOT; break;