Fixed bug where doing a 'define label address' without the required

address resulted in a crash.  This was caused by non-existent
error checking in DebuggerParser for this case.  I've reworked the
method in question quite a bit, so I'm not sure if it's completely
bug free ...


git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@806 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
stephena 2005-10-02 01:15:53 +00:00
parent da85d8198a
commit ef55ef20e1
1 changed files with 98 additions and 65 deletions

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: DebuggerParser.cxx,v 1.82 2005-09-25 20:18:46 urchlay Exp $ // $Id: DebuggerParser.cxx,v 1.83 2005-10-02 01:15:53 stephena Exp $
//============================================================================ //============================================================================
#include "bspf.hxx" #include "bspf.hxx"
@ -997,47 +997,66 @@ string DebuggerParser::trapStatus(int addr) {
return result; return result;
} }
bool DebuggerParser::validateArgs(int cmd) { bool DebuggerParser::validateArgs(int cmd)
{
// cerr << "entering validateArgs(" << cmd << ")" << endl; // cerr << "entering validateArgs(" << cmd << ")" << endl;
bool required = commands[cmd].parmsRequired; bool required = commands[cmd].parmsRequired;
parameters *p = commands[cmd].parms; parameters *p = commands[cmd].parms;
if(argCount == 0) { if(argCount == 0)
if(required) { {
if(required)
{
commandResult = red("missing required argument(s)"); commandResult = red("missing required argument(s)");
return false; // needed args. didn't get 'em. return false; // needed args. didn't get 'em.
} else { }
else
return true; // no args needed, no args got return true; // no args needed, no args got
} }
// Figure out how many arguments are required by the command
int count = 0, argRequiredCount = 0;
while(*p != kARG_END_ARGS && *p != kARG_MULTI_BYTE)
{
count++;
*p++;
} }
// Evil hack: some commands intentionally take multiple arguments
// In this case, the required number of arguments is unbounded
argRequiredCount = (*p == kARG_END_ARGS) ? count : argCount;
p = commands[cmd].parms;
int curCount = 0; int curCount = 0;
do { do {
if(argCount == curCount) { if(curCount >= argCount)
return true; break;
}
int curArgInt = args[curCount]; int curArgInt = args[curCount];
string curArgStr = argStrings[curCount]; string& curArgStr = argStrings[curCount];
switch(*p) { switch(*p)
{
case kARG_WORD: case kARG_WORD:
if(curArgInt < 0 || curArgInt > 0xffff) { if(curArgInt < 0 || curArgInt > 0xffff)
{
commandResult = red("invalid word argument (must be 0-$ffff)"); commandResult = red("invalid word argument (must be 0-$ffff)");
return false; return false;
} }
break; break;
case kARG_BYTE: case kARG_BYTE:
if(curArgInt < 0 || curArgInt > 0xff) { if(curArgInt < 0 || curArgInt > 0xff)
{
commandResult = red("invalid byte argument (must be 0-$ff)"); commandResult = red("invalid byte argument (must be 0-$ff)");
return false; return false;
} }
break; break;
case kARG_BOOL: case kARG_BOOL:
if(curArgInt != 0 && curArgInt != 1) { if(curArgInt != 0 && curArgInt != 1)
{
commandResult = red("invalid boolean argument (must be 0 or 1)"); commandResult = red("invalid boolean argument (must be 0 or 1)");
return false; return false;
} }
@ -1060,17 +1079,27 @@ bool DebuggerParser::validateArgs(int cmd) {
case kARG_MULTI_WORD: case kARG_MULTI_WORD:
break; // FIXME: validate these (for now, any number's allowed) break; // FIXME: validate these (for now, any number's allowed)
default: case kARG_END_ARGS:
commandResult = red("too many arguments");
return false;
break; break;
} }
curCount++; curCount++;
*p++;
} while(*p++ != kARG_END_ARGS); } while(*p != kARG_END_ARGS && curCount < argRequiredCount);
if(curCount < argCount) { /*
cerr << "curCount = " << curCount << endl
<< "argRequiredCount = " << argRequiredCount << endl
<< "*p = " << *p << endl << endl;
*/
if(curCount < argRequiredCount)
{
commandResult = red("missing required argument(s)");
return false;
}
else if(argCount > curCount)
{
commandResult = red("too many arguments"); commandResult = red("too many arguments");
return false; return false;
} }
@ -1417,6 +1446,7 @@ void DebuggerParser::executeD() {
void DebuggerParser::executeDefine() { void DebuggerParser::executeDefine() {
// TODO: check if label already defined? // TODO: check if label already defined?
debugger->addLabel(argStrings[0], args[1]); debugger->addLabel(argStrings[0], args[1]);
debugger->myRom->invalidate();
commandResult = "label " + argStrings[0] + " defined as " + debugger->valueToString(args[1]); commandResult = "label " + argStrings[0] + " defined as " + debugger->valueToString(args[1]);
} }
@ -1728,7 +1758,10 @@ void DebuggerParser::executeTrapwrite() {
// "undef" // "undef"
void DebuggerParser::executeUndef() { void DebuggerParser::executeUndef() {
if(debugger->equateList->undefine(argStrings[0])) if(debugger->equateList->undefine(argStrings[0]))
{
debugger->myRom->invalidate();
commandResult = argStrings[0] + " now undefined"; commandResult = argStrings[0] + " now undefined";
}
else else
commandResult = red("no such label"); commandResult = red("no such label");
} }