Added "save" command, to save the current debugger watches, breaks, etc.

In the process, I've discovered a bug in the argument processing: any of
the commands that use kARG_FILE as their first argument will work *only*
if they're the first command issued after starting Stella, otherwise
they segfault. Am investigating this now


git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@691 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
urchlay 2005-07-23 19:07:15 +00:00
parent f088765c01
commit d1a7f5f75d
4 changed files with 81 additions and 9 deletions

View File

@ -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.75 2005-07-21 19:30:14 stephena Exp $
// $Id: Debugger.cxx,v 1.76 2005-07-23 19:07:15 urchlay Exp $
//============================================================================
#include "bspf.hxx"
@ -940,3 +940,8 @@ Expression *Debugger::getFunction(string name) {
else
return iter->second;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
const FunctionMap Debugger::getFunctionMap() {
return functions;
}

View File

@ -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.hxx,v 1.60 2005-07-21 19:30:15 stephena Exp $
// $Id: Debugger.hxx,v 1.61 2005-07-23 19:07:15 urchlay Exp $
//============================================================================
#ifndef DEBUGGER_HXX
@ -74,7 +74,7 @@ typedef uInt16 (Debugger::*DEBUGGER_WORD_METHOD)();
for all debugging operations in Stella (parser, 6502 debugger, etc).
@author Stephen Anthony
@version $Id: Debugger.hxx,v 1.60 2005-07-21 19:30:15 stephena Exp $
@version $Id: Debugger.hxx,v 1.61 2005-07-23 19:07:15 urchlay Exp $
*/
class Debugger : public DialogContainer
{
@ -124,6 +124,7 @@ class Debugger : public DialogContainer
void addFunction(string name, Expression *exp);
void delFunction(string name);
Expression *getFunction(string name);
const FunctionMap getFunctionMap();
/**
The debugger subsystem responsible for all CPU state

View File

@ -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: DebuggerParser.cxx,v 1.68 2005-07-21 03:26:58 urchlay Exp $
// $Id: DebuggerParser.cxx,v 1.69 2005-07-23 19:07:15 urchlay Exp $
//============================================================================
#include "bspf.hxx"
@ -238,7 +238,7 @@ Command DebuggerParser::commands[] = {
},
{
"loadlst",
"loadlist",
"Load DASM listing file",
true,
{ kARG_FILE, kARG_END_ARGS },
@ -269,6 +269,14 @@ Command DebuggerParser::commands[] = {
&DebuggerParser::executePc
},
{
"poke",
"Set address to value. Can give multiple values (for address+1, etc)",
true,
{ kARG_WORD, kARG_MULTI_BYTE },
&DebuggerParser::executeRam
},
{
"print",
"Evaluate and print expression in hex/dec/binary",
@ -279,7 +287,7 @@ Command DebuggerParser::commands[] = {
{
"ram",
"Show RAM contents (no args), or set RAM address xx to value yy",
"Show RAM contents (no args), or set address xx to value yy",
false,
{ kARG_WORD, kARG_MULTI_BYTE },
&DebuggerParser::executeRam
@ -341,6 +349,14 @@ Command DebuggerParser::commands[] = {
&DebuggerParser::executeS
},
{
"save",
"Save breaks, watches, traps as a .stella script file",
true,
{ kARG_FILE, kARG_END_ARGS },
&DebuggerParser::executeSave
},
{
"saveses",
"Save console session to file",
@ -1090,8 +1106,7 @@ string DebuggerParser::exec(const string& cmd, bool verbose) {
int count = 0;
char buffer[256]; // FIXME: static buffers suck
string::size_type pos;
if( (pos = file.find_last_of('.')) == string::npos ) {
if( file.find_last_of('.') == string::npos ) {
file += ".stella";
}
@ -1120,6 +1135,45 @@ string DebuggerParser::exec(const string& cmd, bool verbose) {
return ret;
}
bool DebuggerParser::saveScriptFile(string file) {
if( file.find_last_of('.') == string::npos ) {
file += ".stella";
}
ofstream out(file.c_str());
FunctionMap funcs = debugger->getFunctionMap();
for(FunctionMap::const_iterator i = funcs.begin(); i != funcs.end(); ++i)
out << "function " << i->first << " " << i->second << endl;
for(unsigned int i=0; i<watches.size(); i++)
out << "watch " << watches[i] << endl;
for(unsigned int i=0; i<0x10000; i++)
if(debugger->breakPoint(i))
out << "break #" << i << endl;
for(unsigned int i=0; i<0x10000; i++) {
bool r = debugger->readTrap(i);
bool w = debugger->writeTrap(i);
if(r && w)
out << "trap #" << i << endl;
else if(r)
out << "trapread #" << i << endl;
else if(w)
out << "trapwrite #" << i << endl;
}
StringList conds = debugger->cpuDebug().m6502().getCondBreakNames();
for(unsigned int i=0; i<conds.size(); i++)
out << "breakif " << conds[i] << endl;
bool ok = out.good();
out.close();
return ok;
}
////// executor methods for commands[] array. All are void, no args.
// "a"
@ -1466,6 +1520,15 @@ void DebuggerParser::executeS() {
debugger->cpuDebug().setSP(args[0]);
}
// "save"
void DebuggerParser::executeSave() {
cerr << "got here" << endl;
if(saveScriptFile(argStrings[0]))
commandResult = "saved script to file " + argStrings[0];
else
commandResult = red("I/O error");
}
// "saveses"
void DebuggerParser::executeSaveses() {
if(debugger->prompt()->saveBuffer(argStrings[0]))

View File

@ -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: DebuggerParser.hxx,v 1.37 2005-07-21 03:26:58 urchlay Exp $
// $Id: DebuggerParser.hxx,v 1.38 2005-07-23 19:07:15 urchlay Exp $
//============================================================================
#ifndef DEBUGGER_PARSER_HXX
@ -92,6 +92,8 @@ class DebuggerParser
string completions;
string compPrefix;
bool saveScriptFile(string file);
void executeA();
void executeBank();
void executeBase();
@ -131,6 +133,7 @@ class DebuggerParser
void executeRun();
void executeRunTo();
void executeS();
void executeSave();
void executeSaveses();
void executeSavestate();
void executeSavesym();