From ab9e047d49f629ea5628484d081f100862773bb9 Mon Sep 17 00:00:00 2001 From: urchlay Date: Wed, 15 Jun 2005 04:30:35 +0000 Subject: [PATCH] Implemented symbol file loading. There are still some rough edges, but it does work. git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@498 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba --- stella/src/debugger/Debugger.cxx | 7 +- stella/src/debugger/Debugger.hxx | 6 +- stella/src/debugger/DebuggerParser.cxx | 12 ++- stella/src/debugger/EquateList.cxx | 122 ++++++++++++++++++++++++- stella/src/debugger/EquateList.hxx | 12 +++ stella/src/emucore/m6502/src/D6502.cxx | 9 +- stella/src/emucore/m6502/src/D6502.hxx | 8 +- 7 files changed, 166 insertions(+), 10 deletions(-) diff --git a/stella/src/debugger/Debugger.cxx b/stella/src/debugger/Debugger.cxx index e63a8d65f..b631c2df9 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.5 2005-06-14 03:11:03 urchlay Exp $ +// $Id: Debugger.cxx,v 1.6 2005-06-15 04:30:33 urchlay Exp $ //============================================================================ #include "bspf.hxx" @@ -336,3 +336,8 @@ void Debugger::toggleV() { void Debugger::toggleN() { myDebugger->ps( myDebugger->ps() ^ 0x80 ); } + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void Debugger::setEquateList(EquateList *l) { + myDebugger->setEquateList(l); +} diff --git a/stella/src/debugger/Debugger.hxx b/stella/src/debugger/Debugger.hxx index 27f23eca6..6cf7d2ad0 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.2 2005-06-13 02:47:44 urchlay Exp $ +// $Id: Debugger.hxx,v 1.3 2005-06-15 04:30:35 urchlay Exp $ //============================================================================ #ifndef DEBUGGER_HXX @@ -28,6 +28,7 @@ class D6502; #include "DialogContainer.hxx" #include "M6502.hxx" +#include "EquateList.hxx" #include "bspf.hxx" enum { @@ -46,7 +47,7 @@ enum { for all debugging operations in Stella (parser, 6502 debugger, etc). @author Stephen Anthony - @version $Id: Debugger.hxx,v 1.2 2005-06-13 02:47:44 urchlay Exp $ + @version $Id: Debugger.hxx,v 1.3 2005-06-15 04:30:35 urchlay Exp $ */ class Debugger : public DialogContainer { @@ -135,6 +136,7 @@ class Debugger : public DialogContainer void reset(); void formatFlags(int f, char *out); + void setEquateList(EquateList *l); protected: Console* myConsole; diff --git a/stella/src/debugger/DebuggerParser.cxx b/stella/src/debugger/DebuggerParser.cxx index 7836eed8c..89f06a3db 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.3 2005-06-14 03:11:03 urchlay Exp $ +// $Id: DebuggerParser.cxx,v 1.4 2005-06-15 04:30:35 urchlay Exp $ //============================================================================ #include "bspf.hxx" @@ -175,6 +175,15 @@ bool DebuggerParser::subStringMatch(const string& needle, const string& haystack string DebuggerParser::run(const string& command) { string result; + // special case command, takes a filename instead of an address: + if(subStringMatch("loadsym ", command)) { + result = command; + result.erase(0, 8); + result = equateList->loadFile(result); + debugger->setEquateList(equateList); + return result; + } + if(!getArgs(command)) return "invalid label or address"; @@ -268,6 +277,7 @@ string DebuggerParser::run(const string& command) { // "break xx - Set/clear breakpoint at address xx\n" "c - Toggle Carry Flag\n" "d - Toggle Decimal Flag\n" + "loadsym f - Load DASM symbols from file f\n" "n - Toggle Negative Flag\n" "pc xx - Set Program Counter to xx\n" "ram - Show RIOT RAM contents\n" diff --git a/stella/src/debugger/EquateList.cxx b/stella/src/debugger/EquateList.cxx index 5363c0f5c..9d4107f8a 100644 --- a/stella/src/debugger/EquateList.cxx +++ b/stella/src/debugger/EquateList.cxx @@ -1,10 +1,14 @@ +#include +#include +#include + #include "bspf.hxx" #include "Equate.hxx" #include "EquateList.hxx" // built in labels -static struct Equate ourVcsEquates[] = { +static struct Equate hardCodedEquates[] = { { "VSYNC", 0x00 }, { "VBLANK", 0x01 }, { "WSYNC", 0x02 }, @@ -78,6 +82,19 @@ static struct Equate ourVcsEquates[] = { }; EquateList::EquateList() { + cerr << sizeof(hardCodedEquates)/sizeof(struct Equate) << endl; + ourVcsEquates = new Equate[ sizeof(hardCodedEquates)/sizeof(struct Equate) ]; + for(int i=0; hardCodedEquates[i].label != NULL; i++) + ourVcsEquates[i] = hardCodedEquates[i]; + calcSize(); +} + +int EquateList::calcSize() { + currentSize = 0; + for(int i=0; ourVcsEquates[i].label != NULL; i++) + currentSize++; + + return currentSize; } // FIXME: use something smarter than a linear search in the future. @@ -109,3 +126,106 @@ int EquateList::getAddress(const char *label) { return -1; } + +string EquateList::loadFile(string file) { + int lines = 0; + string curLabel; + int curVal; + // string::size_type p; + char buffer[256]; // FIXME: static buffers suck + + // cerr << "loading file " << file << endl; + + ifstream in(file.c_str()); + if(!in.is_open()) + return "Unable to read symbols from " + file; + + long start = in.tellg(); // save pointer to beginning of file + + // iterate over file, count lines + while( !in.eof() ) { + in.getline(buffer, 255); + lines++; + } + + // cerr << "total lines " << lines << endl; + + // allocate enough storage for all the lines + // FIXME: decide whether to keep the hard-coded symbols or throw them out + // (currently allocating space for them, but throwing them away anyway) + Equate *newEquates = new Equate[lines + currentSize + 1]; + lines = 0; + + // start over, now that we've allocated enough entries. + in.clear(); + in.seekg(start); + + while( !in.eof() ) { + curVal = 0; + curLabel = ""; + + if(!in.getline(buffer, 255)) + break; + + if(buffer[0] != '-') { + curLabel = getLabel(buffer); + if((curVal = parse4hex(buffer+25)) < 0) + return "invalid symbol file"; + + struct Equate *e = new struct Equate; + + // FIXME: this is cumbersome... + // I shouldn't have to use sprintf() here. + // also, is this a memory leak? I miss malloc() and free()... + newEquates[lines] = *e; + newEquates[lines].label = new char[curLabel.length() + 1]; + sprintf(newEquates[lines].label, "%s", curLabel.c_str()); + newEquates[lines].address = curVal; + + // cerr << "label: " << curLabel << ", address: " << curVal << endl; + // cerr << buffer; + lines++; + } + } + in.close(); + + struct Equate *e = new struct Equate; + newEquates[lines] = *e; + newEquates[lines].label = NULL; + newEquates[lines].address = 0; + + calcSize(); + delete ourVcsEquates; + ourVcsEquates = newEquates; + + // dumpAll(); + return "loaded " + file + " OK"; +} + +int EquateList::parse4hex(char *c) { + int ret = 0; + for(int i=0; i<4; i++) { + if(*c >= '0' && *c <= '9') + ret = (ret << 4) + (*c) - '0'; + else if(*c >= 'a' && *c <= 'f') + ret = (ret << 4) + (*c) - 'a' + 10; + else + return -1; + c++; + } + + return ret; +} + +string EquateList::getLabel(char *c) { + string l = ""; + while(*c != ' ') + l += *c++; + + return l; +} + +void EquateList::dumpAll() { + for(int i=0; ourVcsEquates[i].label != NULL; i++) + cerr << i << ": " << "label==" << ourVcsEquates[i].label << ", address==" << ourVcsEquates[i].address << endl; +} diff --git a/stella/src/debugger/EquateList.hxx b/stella/src/debugger/EquateList.hxx index 88baf1338..a286f73ba 100644 --- a/stella/src/debugger/EquateList.hxx +++ b/stella/src/debugger/EquateList.hxx @@ -2,12 +2,24 @@ #ifndef EQUATELIST_HXX #define EQUATELIST_HXX +#include + class EquateList { public: EquateList(); char *getLabel(int addr); char *EquateList::getFormatted(int addr, int places); int getAddress(const char *label); + string loadFile(string file); + + private: + int calcSize(); + int parse4hex(char *c); + string EquateList::getLabel(char *c); + void dumpAll(); + + struct Equate *ourVcsEquates; + int currentSize; }; #endif diff --git a/stella/src/emucore/m6502/src/D6502.cxx b/stella/src/emucore/m6502/src/D6502.cxx index 893e496f5..62683e5af 100644 --- a/stella/src/emucore/m6502/src/D6502.cxx +++ b/stella/src/emucore/m6502/src/D6502.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: D6502.cxx,v 1.4 2005-06-14 01:55:52 urchlay Exp $ +// $Id: D6502.cxx,v 1.5 2005-06-15 04:30:35 urchlay Exp $ //============================================================================ #include @@ -32,7 +32,7 @@ D6502::D6502(System* system) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - D6502::~D6502() { - delete equateList; + // delete equateList; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -207,3 +207,8 @@ void D6502::y(uInt8 value) mySystem->m6502().Y = value; } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void D6502::setEquateList(EquateList *el) +{ + equateList = el; +} diff --git a/stella/src/emucore/m6502/src/D6502.hxx b/stella/src/emucore/m6502/src/D6502.hxx index 475a9c95e..edd2fceca 100644 --- a/stella/src/emucore/m6502/src/D6502.hxx +++ b/stella/src/emucore/m6502/src/D6502.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: D6502.hxx,v 1.3 2005-06-14 01:55:52 urchlay Exp $ +// $Id: D6502.hxx,v 1.4 2005-06-15 04:30:35 urchlay Exp $ //============================================================================ #ifndef D6502_HXX @@ -31,7 +31,7 @@ class System; basic functionality needed for interactive debuggers. @author Bradford W. Mott - @version $Id: D6502.hxx,v 1.3 2005-06-14 01:55:52 urchlay Exp $ + @version $Id: D6502.hxx,v 1.4 2005-06-15 04:30:35 urchlay Exp $ */ class D6502 { @@ -145,7 +145,9 @@ class D6502 */ void y(uInt8 value); - uInt16 D6502::dPeek(uInt16 address); + uInt16 dPeek(uInt16 address); + + void setEquateList(EquateList *el); protected: // Pointer to the system I'm debugging