From cdb61cddb0d89a377ed7007853245369bdf29a93 Mon Sep 17 00:00:00 2001 From: urchlay Date: Tue, 14 Jun 2005 03:11:03 +0000 Subject: [PATCH] DebuggerParser now supports labels in input. Labels are treated case-insensitively! We look for labels *first*, so if there were a label "aa", it'd be impossible to input the hex value "aa" (the label would take precedence). This doesn't matter for now, since the labels are hard-coded and none of them conflict with anything, but in the future we'll be loading symbol files... even then, I don't think anyone's dumb enough to create a label that looks like a hex value, but it could happen... git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@495 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba --- stella/src/debugger/Debugger.cxx | 11 +++-- stella/src/debugger/DebuggerParser.cxx | 61 +++++++++++++++++++++----- stella/src/debugger/DebuggerParser.hxx | 7 ++- stella/src/debugger/EquateList.cxx | 4 +- stella/src/debugger/EquateList.hxx | 2 +- 5 files changed, 67 insertions(+), 18 deletions(-) diff --git a/stella/src/debugger/Debugger.cxx b/stella/src/debugger/Debugger.cxx index 5f93ea9df..e63a8d65f 100644 --- a/stella/src/debugger/Debugger.cxx +++ b/stella/src/debugger/Debugger.cxx @@ -13,7 +13,7 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: Debugger.cxx,v 1.4 2005-06-14 00:58:39 urchlay Exp $ +// $Id: Debugger.cxx,v 1.5 2005-06-14 03:11:03 urchlay Exp $ //============================================================================ #include "bspf.hxx" @@ -192,13 +192,18 @@ void Debugger::writeRAM(uInt16 addr, uInt8 value) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - const string Debugger::setRAM(int argCount, int *args) { + char buf[10]; + int address = args[0]; for(int i=1; ipoke(address++, args[i]); string ret = "changed "; - ret += args[0]; - ret += " locations"; + sprintf(buf, "%d", argCount-1); + ret += buf; + ret += " location"; + if(argCount > 2) + ret += "s"; return ret; } diff --git a/stella/src/debugger/DebuggerParser.cxx b/stella/src/debugger/DebuggerParser.cxx index ff5b25190..7836eed8c 100644 --- a/stella/src/debugger/DebuggerParser.cxx +++ b/stella/src/debugger/DebuggerParser.cxx @@ -13,12 +13,13 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: DebuggerParser.cxx,v 1.2 2005-06-13 02:47:44 urchlay Exp $ +// $Id: DebuggerParser.cxx,v 1.3 2005-06-14 03:11:03 urchlay Exp $ //============================================================================ #include "bspf.hxx" #include "Debugger.hxx" #include "DebuggerParser.hxx" +#include "EquateList.hxx" // Constants for argument processing enum { @@ -32,10 +33,12 @@ enum { DebuggerParser::DebuggerParser(Debugger* d) : debugger(d) { + equateList = new EquateList(); done = false; } DebuggerParser::~DebuggerParser() { + delete equateList; } string DebuggerParser::currentAddress() { @@ -53,13 +56,35 @@ int DebuggerParser::conv_hex_digit(char d) { return d - 'a' + 10; else if(d >= 'A' && d <= 'F') return d - 'A' + 10; - else return 0; + else return -1; } -void DebuggerParser::getArgs(const string& command) { +// Given a string argument that's either a label or a +// hex value, either dereference the label or convert +// the hex to an int. Returns -1 on error. +int DebuggerParser::decipher_arg(string &arg) { + const char *a = arg.c_str(); + int address = equateList->getAddress(a); + // cerr << "decipher_arg: equateList->getAddress(" << a << ") == " << address << endl; + if(address >= 0) + return address; + + address = 0; + while(*a != '\0') { + int hex = conv_hex_digit(*a++); + if(hex < 0) + return -1; + + address = (address << 4) + hex; + } + + return address; +} + +bool DebuggerParser::getArgs(const string& command) { int state = kIN_COMMAND; int deref = 0; - int curArg = 0; + string curArg = ""; argCount = 0; verb = ""; const char *c = command.c_str(); @@ -85,8 +110,9 @@ void DebuggerParser::getArgs(const string& command) { break; case kIN_ARG_START: - curArg = 0; + curArg = ""; state = kIN_ARG_CONT; + // FIXME: actually use this. if(*c == '*') { deref = 1; c++; @@ -95,7 +121,7 @@ void DebuggerParser::getArgs(const string& command) { } // FALL THROUGH! case kIN_ARG_CONT: - if(isxdigit(*c)) { + /*if(isxdigit(*c)) { int dig = conv_hex_digit(*c); curArg = (curArg << 4) + dig; *c++; @@ -103,23 +129,37 @@ void DebuggerParser::getArgs(const string& command) { args[argCount++] = curArg; state = kIN_SPACE; } - break; + break;*/ + if(isalpha(*c) || isdigit(*c) || *c == '_') { + curArg += *c++; + // cerr << "curArg: " << curArg << endl; + } else { + args[argCount] = decipher_arg(curArg); + if(args[argCount] < 0) + return false; + argCount++; + curArg = ""; + state = kIN_SPACE; + } + } if(argCount == 10) { cerr << "reached max 10 args" << endl; - return; + return true; } } // pick up last arg, if any: if(state == kIN_ARG_CONT || state == kIN_ARG_START) - args[argCount++] = curArg; + if( (args[argCount++] = decipher_arg(curArg)) < 0) + return false; // for(int i=0; i