From eaa8fa898b0df5087348aaff3737de6815ae6e09 Mon Sep 17 00:00:00 2001 From: urchlay Date: Fri, 17 Jun 2005 21:59:54 +0000 Subject: [PATCH] Implemented "disassemble" command in prompt, in case you want to see more code than the current line. On ROM load, we replace the file extension with .sym and attempt to load that as a symbol file for the debugger. No harm is done if the file is missing. git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@521 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba --- stella/src/debugger/Debugger.cxx | 68 ++++++++++++++++++++------ stella/src/debugger/Debugger.hxx | 7 ++- stella/src/debugger/DebuggerParser.cxx | 24 ++++++++- stella/src/debugger/DebuggerParser.hxx | 5 +- stella/src/emucore/OSystem.hxx | 6 ++- stella/src/gui/PromptWidget.cxx | 4 +- 6 files changed, 89 insertions(+), 25 deletions(-) diff --git a/stella/src/debugger/Debugger.cxx b/stella/src/debugger/Debugger.cxx index 13ffc2e4d..798b133a8 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.13 2005-06-17 03:49:08 urchlay Exp $ +// $Id: Debugger.cxx,v 1.14 2005-06-17 21:59:53 urchlay Exp $ //============================================================================ #include "bspf.hxx" @@ -89,6 +89,22 @@ void Debugger::setConsole(Console* console) // Create a new 6502 debugger for this console delete myDebugger; myDebugger = new D6502(mySystem); + + autoLoadSymbols(myOSystem->romFile()); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void Debugger::autoLoadSymbols(string fileName) { + string file = fileName; + + string::size_type pos; + if( (pos = file.find_last_of('.')) != string::npos ) { + file.replace(pos, file.size(), ".sym"); + } else { + file += ".sym"; + } + string ret = equateList->loadFile(file); + // cerr << "loading syms from file " << file << ": " << ret << endl; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -101,7 +117,7 @@ const string Debugger::run(const string& command) const string Debugger::state() { string result; - char buf[255], bbuf[255]; + char buf[255]; //cerr << "state(): pc is " << myDebugger->pc() << endl; result += "\nPC="; @@ -123,21 +139,8 @@ const string Debugger::state() sprintf(buf, "%d", mySystem->cycles()); result += buf; result += "\n "; - char *label = equateList->getLabel(myDebugger->pc()); - if(label != NULL) { - result += label; - result += ": "; - } - int count = myDebugger->disassemble(myDebugger->pc(), buf, equateList); - for(int i=0; ipc() + i)); - result += bbuf; - } - if(count < 3) result += " "; - if(count < 2) result += " "; - result += " "; - result += buf; + result += disassemble(myDebugger->pc(), 1); return result; } @@ -389,3 +392,36 @@ bool Debugger::breakPoint(int bp) { return breakPoints->isSet(bp) != 0; } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +int Debugger::getPC() { + return myDebugger->pc(); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +string Debugger::disassemble(int start, int lines) { + char buf[255], bbuf[255]; + string result; + + do { + char *label = equateList->getFormatted(start, 4); + + result += label; + result += ": "; + + int count = myDebugger->disassemble(start, buf, equateList); + + for(int i=0; i 0); + + return result; +} diff --git a/stella/src/debugger/Debugger.hxx b/stella/src/debugger/Debugger.hxx index f331dbbbf..cea19f663 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.11 2005-06-17 17:34:01 stephena Exp $ +// $Id: Debugger.hxx,v 1.12 2005-06-17 21:59:53 urchlay Exp $ //============================================================================ #ifndef DEBUGGER_HXX @@ -49,7 +49,7 @@ enum { for all debugging operations in Stella (parser, 6502 debugger, etc). @author Stephen Anthony - @version $Id: Debugger.hxx,v 1.11 2005-06-17 17:34:01 stephena Exp $ + @version $Id: Debugger.hxx,v 1.12 2005-06-17 21:59:53 urchlay Exp $ */ class Debugger : public DialogContainer { @@ -108,6 +108,7 @@ class Debugger : public DialogContainer void toggleBreakPoint(int bp); bool breakPoint(int bp); + string disassemble(int start, int lines); public: /** @@ -144,12 +145,14 @@ class Debugger : public DialogContainer void setY(int y); void setS(int sp); void setPC(int pc); + int getPC(); void toggleC(); void toggleZ(); void toggleN(); void toggleV(); void toggleD(); void reset(); + void autoLoadSymbols(string file); void formatFlags(int f, char *out); EquateList *equates(); diff --git a/stella/src/debugger/DebuggerParser.cxx b/stella/src/debugger/DebuggerParser.cxx index bcee53722..05efe33b5 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.9 2005-06-17 03:49:08 urchlay Exp $ +// $Id: DebuggerParser.cxx,v 1.10 2005-06-17 21:59:53 urchlay Exp $ //============================================================================ #include "bspf.hxx" @@ -188,6 +188,23 @@ string DebuggerParser::listBreaks() { return "no breakpoints set"; } +string DebuggerParser::disasm() { + int start, lines = 20; + + if(argCount == 0) { + start = debugger->getPC(); + } else if(argCount == 1) { + start = args[0]; + } else if(argCount == 2) { + start = args[0]; + lines = args[1]; + } else { + return "wrong number of arguments"; + } + + return debugger->disassemble(start, lines); +} + string DebuggerParser::run(const string& command) { string result; @@ -302,6 +319,8 @@ string DebuggerParser::run(const string& command) { return "Cleared breakpoint"; } else if(subStringMatch(verb, "listbreaks")) { return listBreaks(); + } else if(subStringMatch(verb, "disasm")) { + return disasm(); } else if(subStringMatch(verb, "clearbreaks")) { //debugger->clearAllBreakPoints(); return "cleared all breakpoints"; @@ -309,12 +328,15 @@ string DebuggerParser::run(const string& command) { // please leave each option on its own line so they're // easy to sort - bkw return + "Commands are case-insensitive and may be abbreviated.\n" "a xx - Set Accumulator to xx\n" "break - Set/clear breakpoint at current PC\n" "break xx - Set/clear breakpoint at address xx\n" "c - Toggle Carry Flag\n" "clearbreaks - Clear all breakpoints\n" "d - Toggle Decimal Flag\n" + "disasm - Disassemble (from current PC)\n" + "disasm xx - Disassemble (from address xx)\n" "listbreaks - List all breakpoints\n" "loadsym f - Load DASM symbols from file f\n" "n - Toggle Negative Flag\n" diff --git a/stella/src/debugger/DebuggerParser.hxx b/stella/src/debugger/DebuggerParser.hxx index 8558053c1..11d836674 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.5 2005-06-17 03:49:08 urchlay Exp $ +// $Id: DebuggerParser.hxx,v 1.6 2005-06-17 21:59:53 urchlay Exp $ //============================================================================ #ifndef DEBUGGER_PARSER_HXX @@ -34,12 +34,13 @@ class DebuggerParser void setDone(); string run(const string& command); bool getArgs(const string& command); - string listBreaks(); private: int DebuggerParser::conv_hex_digit(char d); bool DebuggerParser::subStringMatch(const string& needle, const string& haystack); int decipher_arg(string &arg); + string disasm(); + string listBreaks(); Debugger* debugger; EquateList *equateList; diff --git a/stella/src/emucore/OSystem.hxx b/stella/src/emucore/OSystem.hxx index bb158160d..be22182f3 100644 --- a/stella/src/emucore/OSystem.hxx +++ b/stella/src/emucore/OSystem.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: OSystem.hxx,v 1.21 2005-06-16 01:11:28 stephena Exp $ +// $Id: OSystem.hxx,v 1.22 2005-06-17 21:59:53 urchlay Exp $ //============================================================================ #ifndef OSYSTEM_HXX @@ -44,7 +44,7 @@ class Debugger; other objects belong. @author Stephen Anthony - @version $Id: OSystem.hxx,v 1.21 2005-06-16 01:11:28 stephena Exp $ + @version $Id: OSystem.hxx,v 1.22 2005-06-17 21:59:53 urchlay Exp $ */ class OSystem { @@ -282,6 +282,8 @@ class OSystem */ bool openROM(const string& rom, uInt8** image, int* size); + const string& romFile() { return myRomFile; } + public: ////////////////////////////////////////////////////////////////////// // The following methods are system-specific and must be implemented diff --git a/stella/src/gui/PromptWidget.cxx b/stella/src/gui/PromptWidget.cxx index ff0442a78..64b7d9e51 100644 --- a/stella/src/gui/PromptWidget.cxx +++ b/stella/src/gui/PromptWidget.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: PromptWidget.cxx,v 1.8 2005-06-17 03:49:10 urchlay Exp $ +// $Id: PromptWidget.cxx,v 1.9 2005-06-17 21:59:54 urchlay Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -138,7 +138,7 @@ void PromptWidget::handleMouseWheel(int x, int y, int direction) } void PromptWidget::printPrompt() { - print( instance()->debugger().state() + "\n"); + print( instance()->debugger().state() ); print(PROMPT); _promptStartPos = _promptEndPos = _currentPos; }