From d1a7f5f75d8c52f1b3db7246823df782c90e5d61 Mon Sep 17 00:00:00 2001 From: urchlay Date: Sat, 23 Jul 2005 19:07:15 +0000 Subject: [PATCH] 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 --- stella/src/debugger/Debugger.cxx | 7 ++- stella/src/debugger/Debugger.hxx | 5 +- stella/src/debugger/DebuggerParser.cxx | 73 ++++++++++++++++++++++++-- stella/src/debugger/DebuggerParser.hxx | 5 +- 4 files changed, 81 insertions(+), 9 deletions(-) diff --git a/stella/src/debugger/Debugger.cxx b/stella/src/debugger/Debugger.cxx index 2402360f1..a997649db 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.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; +} diff --git a/stella/src/debugger/Debugger.hxx b/stella/src/debugger/Debugger.hxx index 3c5664375..89acc5fab 100644 --- a/stella/src/debugger/Debugger.hxx +++ b/stella/src/debugger/Debugger.hxx @@ -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 diff --git a/stella/src/debugger/DebuggerParser.cxx b/stella/src/debugger/DebuggerParser.cxx index db5d66d03..6eca3114a 100644 --- a/stella/src/debugger/DebuggerParser.cxx +++ b/stella/src/debugger/DebuggerParser.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: 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; ibreakPoint(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; icpuDebug().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])) diff --git a/stella/src/debugger/DebuggerParser.hxx b/stella/src/debugger/DebuggerParser.hxx index 0af1ed142..493253c82 100644 --- a/stella/src/debugger/DebuggerParser.hxx +++ b/stella/src/debugger/DebuggerParser.hxx @@ -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();