diff --git a/stella/src/debugger/Debugger.cxx b/stella/src/debugger/Debugger.cxx index c30a5b2ec..f02131ebd 100644 --- a/stella/src/debugger/Debugger.cxx +++ b/stella/src/debugger/Debugger.cxx @@ -13,11 +13,13 @@ // 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.70 2005-07-19 17:59:57 stephena Exp $ +// $Id: Debugger.cxx,v 1.71 2005-07-20 04:28:13 urchlay Exp $ //============================================================================ #include "bspf.hxx" +#include +#include #include #include "Version.hxx" @@ -134,6 +136,7 @@ void Debugger::setConsole(Console* console) myTiaDebug = new TIADebug(this, myConsole); autoLoadSymbols(myOSystem->romFile()); + loadListFile(); saveOldState(); } @@ -164,6 +167,81 @@ void Debugger::autoLoadSymbols(string fileName) { // cerr << "loading syms from file " << file << ": " << ret << endl; } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +string Debugger::loadListFile(string f) { + char buffer[255]; + + if(f == "") { + f = myOSystem->romFile(); + + string::size_type pos; + if( (pos = f.find_last_of('.')) != string::npos ) { + f.replace(pos, f.size(), ".lst"); + } else { + f += ".lst"; + } + } + + ifstream in(f.c_str()); + if(!in.is_open()) + return "Unable to read listing from " + f; + + sourceLines.clear(); + int count = 0; + while( !in.eof() ) { + if(!in.getline(buffer, 255)) + break; + + if( strlen(buffer) >= 14 && + buffer[0] == ' ' && + buffer[7] == ' ' && + buffer[8] == ' ' && + isxdigit(buffer[9]) && + isxdigit(buffer[12]) && + isblank(buffer[13])) + { + count++; + char addr[5]; + for(int i=0; i<4; i++) + addr[i] = buffer[9+i]; + + for(char *c = buffer; *c != '\0'; c++) + if(*c == '\t') *c = ' '; + + addr[4] = '\0'; + string a = addr; + string b = buffer; + sourceLines.insert(make_pair(a, b)); + } + } + + in.close(); + + return valueToString(count) + " lines loaded from " + f; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +const string Debugger::getSourceLines(int addr) { + if(sourceLines.size() == 0) + return "no list file loaded (try \"loadlst file.lst\")"; + + string ret; + string want = to_hex_16(addr); + + bool found = false; + pair lines = sourceLines.equal_range(want); + for(ListIter i = lines.first; i != lines.second; i++) { + found = true; + ret += i->second; + ret += "\n"; + } + + if(found) + return ret; + else + return ""; +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Debugger::autoExec() { string file = myOSystem->romFile(); diff --git a/stella/src/debugger/Debugger.hxx b/stella/src/debugger/Debugger.hxx index 726dc6f02..19edcf940 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.57 2005-07-19 17:59:58 stephena Exp $ +// $Id: Debugger.hxx,v 1.58 2005-07-20 04:28:13 urchlay Exp $ //============================================================================ #ifndef DEBUGGER_HXX @@ -27,6 +27,8 @@ class RamDebug; class TIADebug; class TiaOutputWidget; +#include + #include "Array.hxx" #include "DialogContainer.hxx" #include "M6502.hxx" @@ -37,6 +39,9 @@ class TiaOutputWidget; #include "Rect.hxx" #include "bspf.hxx" +typedef multimap ListFile; +typedef ListFile::const_iterator ListIter; + enum { kDebuggerWidth = 639, kDebuggerLineHeight = 12, // based on the height of the console font @@ -65,7 +70,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.57 2005-07-19 17:59:58 stephena Exp $ + @version $Id: Debugger.hxx,v 1.58 2005-07-20 04:28:13 urchlay Exp $ */ class Debugger : public DialogContainer { @@ -237,6 +242,9 @@ class Debugger : public DialogContainer int getBank(); int bankCount(); + string loadListFile(string f = ""); + const string getSourceLines(int addr); + private: /** Save state of each debugger subsystem @@ -326,6 +334,8 @@ class Debugger : public DialogContainer PackedBitArray *writeTraps; PromptWidget *myPrompt; + ListFile sourceLines; + static Debugger* myStaticDebugger; }; diff --git a/stella/src/debugger/DebuggerParser.cxx b/stella/src/debugger/DebuggerParser.cxx index e1b1daf75..c076aab58 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.66 2005-07-19 01:31:36 urchlay Exp $ +// $Id: DebuggerParser.cxx,v 1.67 2005-07-20 04:28:13 urchlay Exp $ //============================================================================ #include "bspf.hxx" @@ -189,6 +189,14 @@ Command DebuggerParser::commands[] = { &DebuggerParser::executeHelp }, + { + "list", + "List source (if loaded with loadlst)", + false, + { kARG_WORD, kARG_END_ARGS }, + &DebuggerParser::executeList + }, + { "listbreaks", "List breakpoints", @@ -221,6 +229,14 @@ Command DebuggerParser::commands[] = { &DebuggerParser::executeLoadstate }, + { + "loadlst", + "Load DASM listing file", + true, + { kARG_FILE, kARG_END_ARGS }, + &DebuggerParser::executeLoadlist + }, + { "loadsym", "Load symbol file", @@ -1295,6 +1311,12 @@ void DebuggerParser::executeFrame() { if(count != 1) commandResult += "s"; } +// "list" +void DebuggerParser::executeList() { + for(int i=args[0] - 2; igetSourceLines(i); +} + // "listbreaks" void DebuggerParser::executeListbreaks() { commandResult = listBreaks(); @@ -1321,6 +1343,11 @@ void DebuggerParser::executeLoadstate() { } } +// "loadlist" +void DebuggerParser::executeLoadlist() { + commandResult = debugger->loadListFile(argStrings[0]); +} + // "loadsym" void DebuggerParser::executeLoadsym() { commandResult = debugger->equateList->loadFile(argStrings[0]); diff --git a/stella/src/debugger/DebuggerParser.hxx b/stella/src/debugger/DebuggerParser.hxx index ef206d5b4..6f63d3a0e 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.35 2005-07-18 02:03:40 urchlay Exp $ +// $Id: DebuggerParser.hxx,v 1.36 2005-07-20 04:28:13 urchlay Exp $ //============================================================================ #ifndef DEBUGGER_PARSER_HXX @@ -112,9 +112,11 @@ class DebuggerParser void executeFrame(); void executeHeight(); void executeHelp(); + void executeList(); void executeListbreaks(); void executeListtraps(); void executeListwatches(); + void executeLoadlist(); void executeLoadsym(); void executeLoadstate(); void executeN();