Eliminated final Valgrind complaints about uninitialized data. The rest

occur in libraries, so there's not much I can do about those.

Eliminated memory leaks in DebuggerParser by using the GUI::Array class.
This is basically a dynamically sized array implementation.  As a result,
there's no longer a hardcoded limit on the # of arguments or watches.

Brian, this new array class is a bit different than raw arrays in the
following ways:

1)  You add to it with push_back().  You *can* add to it with index
notation, but it will assert and exit if you attempt to walk past the
end of it.

2)  Because it's dynamically sized, you can't assume it has 100
elements (or even 1 element).  That's why push_back() should be used
for assignment, unless you check the bound of the index first.

2)  It has a size() method, so you always know how far to walk it.

3)  You can erase all items with clear().

4)  It makes use of templates, so is quite fast.

5)  The syntax is close to STL containers. so when we eventually
move to a faster container (hashmap, etc), minimal syntax changes
will be required.

6)  And finally, it frees you from having to deal with memory issues
(new/delete or malloc/free).

Have a look at gui/Array.hxx (which probably should be moved to
common/Array.hxx at some point).


git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@541 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
stephena 2005-06-21 23:01:25 +00:00
parent 1ff07b3be2
commit 4c790bcbd5
6 changed files with 53 additions and 67 deletions

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: FrameBufferGL.cxx,v 1.30 2005-06-16 00:55:56 stephena Exp $ // $Id: FrameBufferGL.cxx,v 1.31 2005-06-21 23:01:23 stephena Exp $
//============================================================================ //============================================================================
#include <SDL.h> #include <SDL.h>
@ -32,9 +32,10 @@
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
FrameBufferGL::FrameBufferGL(OSystem* osystem) FrameBufferGL::FrameBufferGL(OSystem* osystem)
: FrameBuffer(osystem), : FrameBuffer(osystem),
myTexture(0), myTexture(NULL),
myScreenmode(0), myScreenmode(0),
myScreenmodeCount(0), myScreenmodeCount(0),
myTextureID(0),
myFilterParam(GL_NEAREST), myFilterParam(GL_NEAREST),
myFilterParamName("GL_NEAREST"), myFilterParamName("GL_NEAREST"),
myFSScaleFactor(1.0) myFSScaleFactor(1.0)

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: Debugger.cxx,v 1.25 2005-06-21 18:46:33 stephena Exp $ // $Id: Debugger.cxx,v 1.26 2005-06-21 23:01:24 stephena Exp $
//============================================================================ //============================================================================
#include "bspf.hxx" #include "bspf.hxx"
@ -274,18 +274,19 @@ void Debugger::writeRAM(uInt16 addr, uInt8 value)
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
const string Debugger::setRAM(int argCount, int *args) { const string Debugger::setRAM(IntArray args) {
char buf[10]; char buf[10];
int count = args.size();
int address = args[0]; int address = args[0];
for(int i=1; i<argCount; i++) for(int i=1; i<count; i++)
mySystem->poke(address++, args[i]); mySystem->poke(address++, args[i]);
string ret = "changed "; string ret = "changed ";
sprintf(buf, "%d", argCount-1); sprintf(buf, "%d", count-1);
ret += buf; ret += buf;
ret += " location"; ret += " location";
if(argCount > 2) if(count > 2)
ret += "s"; ret += "s";
return ret; return ret;
} }

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: Debugger.hxx,v 1.21 2005-06-21 04:30:49 urchlay Exp $ // $Id: Debugger.hxx,v 1.22 2005-06-21 23:01:24 stephena Exp $
//============================================================================ //============================================================================
#ifndef DEBUGGER_HXX #ifndef DEBUGGER_HXX
@ -51,7 +51,7 @@ enum {
for all debugging operations in Stella (parser, 6502 debugger, etc). for all debugging operations in Stella (parser, 6502 debugger, etc).
@author Stephen Anthony @author Stephen Anthony
@version $Id: Debugger.hxx,v 1.21 2005-06-21 04:30:49 urchlay Exp $ @version $Id: Debugger.hxx,v 1.22 2005-06-21 23:01:24 stephena Exp $
*/ */
class Debugger : public DialogContainer class Debugger : public DialogContainer
{ {
@ -168,7 +168,7 @@ class Debugger : public DialogContainer
void writeRAM(uInt16 addr, uInt8 value); void writeRAM(uInt16 addr, uInt8 value);
// set a bunch of RAM locations at once // set a bunch of RAM locations at once
const string setRAM(int argCount, int *args); const string setRAM(IntArray args);
bool start(); bool start();
void quit(); void quit();

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: DebuggerParser.cxx,v 1.23 2005-06-21 04:30:49 urchlay Exp $ // $Id: DebuggerParser.cxx,v 1.24 2005-06-21 23:01:24 stephena Exp $
//============================================================================ //============================================================================
#include "bspf.hxx" #include "bspf.hxx"
@ -35,11 +35,12 @@ DebuggerParser::DebuggerParser(Debugger* d)
{ {
done = false; done = false;
defaultBase = kBASE_16; defaultBase = kBASE_16;
for(int i=0; i<kMAX_WATCHES; i++)
watches[i] = new string;
} }
DebuggerParser::~DebuggerParser() { DebuggerParser::~DebuggerParser() {
args.clear();
argStrings.clear();
watches.clear();
} }
int DebuggerParser::conv_hex_digit(char d) { int DebuggerParser::conv_hex_digit(char d) {
@ -162,10 +163,12 @@ int DebuggerParser::decipher_arg(const string &str) {
bool DebuggerParser::getArgs(const string& command) { bool DebuggerParser::getArgs(const string& command) {
int state = kIN_COMMAND; int state = kIN_COMMAND;
string curArg = ""; string curArg = "";
argCount = 0;
verb = ""; verb = "";
const char *c = command.c_str(); const char *c = command.c_str();
argStrings.clear();
args.clear();
// cerr << "Parsing \"" << command << "\"" << endl; // cerr << "Parsing \"" << command << "\"" << endl;
// First, pick apart string into space-separated tokens. // First, pick apart string into space-separated tokens.
@ -189,29 +192,27 @@ bool DebuggerParser::getArgs(const string& command) {
case kIN_ARG: case kIN_ARG:
if(*c == ' ' || *c == '\0') { if(*c == ' ' || *c == '\0') {
state = kIN_SPACE; state = kIN_SPACE;
argStrings[argCount++] = curArg; argStrings.push_back(curArg);
curArg = ""; curArg = "";
} else { } else {
curArg += *c; curArg += *c;
} }
break; break;
} // switch(state) } // switch(state)
if(argCount == kMAX_ARGS) {
cerr << "reached max " << kMAX_ARGS << " args" << endl;
return true;
}
} while(*c++ != '\0'); } while(*c++ != '\0');
argCount = argStrings.size();
//for(int i=0; i<argCount; i++) //for(int i=0; i<argCount; i++)
//cerr << "argStrings[" << i << "] == \"" << argStrings[i] << "\"" << endl; //cerr << "argStrings[" << i << "] == \"" << argStrings[i] << "\"" << endl;
// Now decipher each argument, in turn. // Now decipher each argument, in turn.
for(int i=0; i<argCount; i++) { for(int i=0; i<argCount; i++) {
curArg = argStrings[i]; int temp = decipher_arg(argStrings[i]);
if( (args[i] = decipher_arg(curArg)) < 0) { if(temp < 0) {
return false; return false;
} }
args.push_back(temp);
//cerr << "args[" << i << "] == " << args[i] << endl; //cerr << "args[" << i << "] == " << args[i] << endl;
} }
@ -309,13 +310,16 @@ string DebuggerParser::showWatches() {
string ret = "\n"; string ret = "\n";
char buf[10]; char buf[10];
for(int i=0; i<kMAX_WATCHES; i++) { // Clear the args, since we're going to pass them to eval()
if(*(watches[i]->c_str()) != '\0') { argStrings.clear();
args.clear();
for(unsigned int i=0; i<watches.size(); i++) {
if(watches[i] != "") {
//cerr << "here1 " << i << endl; //cerr << "here1 " << i << endl;
sprintf(buf, "%d", i+1); sprintf(buf, "%d", i+1);
argCount = 1; argCount = 1;
argStrings[0] = *watches[i]; argStrings.push_back(watches[i]);
args[0] = decipher_arg(argStrings[0]); args.push_back(decipher_arg(argStrings[0]));
if(args[0] < 0) { if(args[0] < 0) {
ret += "BAD WATCH "; ret += "BAD WATCH ";
ret += buf; ret += buf;
@ -333,27 +337,20 @@ string DebuggerParser::showWatches() {
} }
string DebuggerParser::addWatch(string watch) { string DebuggerParser::addWatch(string watch) {
for(int i=0; i<kMAX_WATCHES; i++) { watches.push_back(watch);
if(*(watches[i]->c_str()) == '\0') { return "Added watch";
string *w = new string(watch);
watches[i] = w;
return "Added watch";
}
}
return "Can't add watch: Too many watches";
} }
void DebuggerParser::delAllWatches() { void DebuggerParser::delAllWatches() {
for(int i=0; i<kMAX_WATCHES; i++) watches.clear();
watches[i] = new string;
} }
string DebuggerParser::delWatch(int which) { string DebuggerParser::delWatch(int which) {
which--; which--;
if(which < 0 || which >= kMAX_WATCHES) if(which < 0 || which >= (int)watches.size())
return "no such watch"; return "no such watch";
else else
watches[which] = new string; watches.remove_at(which);
return "removed watch"; return "removed watch";
} }
@ -386,7 +383,7 @@ string DebuggerParser::run(const string& command) {
// "verb" is the command, stripped of any arguments. // "verb" is the command, stripped of any arguments.
// In the if/else below, put shorter command names first. // In the if/else below, put shorter command names first.
// In case of conflicts (e.g. user enters "t", possible // In case of conflicts (e.g. user enters "t", possible
// commands are "tia" and "trace"), try to guess which // commands are "tia" and "trace"), try to guess which
// will be used more often, and put it first. The user // will be used more often, and put it first. The user
// can always disambiguate: "ti" is short for "tia", or // can always disambiguate: "ti" is short for "tia", or
// "tr" for "trace". // "tr" for "trace".
@ -462,7 +459,7 @@ string DebuggerParser::run(const string& command) {
else if(argCount == 1) else if(argCount == 1)
return "missing data (need 2 or more args)"; return "missing data (need 2 or more args)";
else else
result = debugger->setRAM(argCount, args); result = debugger->setRAM(args);
} else if(subStringMatch(verb, "tia")) { } else if(subStringMatch(verb, "tia")) {
result = debugger->dumpTIA(); result = debugger->dumpTIA();
} else if(subStringMatch(verb, "reset")) { } else if(subStringMatch(verb, "reset")) {
@ -526,6 +523,9 @@ string DebuggerParser::run(const string& command) {
delAllWatches(); delAllWatches();
return "cleared all watches"; return "cleared all watches";
} else if(subStringMatch(verb, "watch")) { } else if(subStringMatch(verb, "watch")) {
if(argCount != 1)
return "one argument required";
addWatch(argStrings[0]); addWatch(argStrings[0]);
} else if(subStringMatch(verb, "delwatch")) { } else if(subStringMatch(verb, "delwatch")) {
if(argCount == 1) if(argCount == 1)

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: DebuggerParser.hxx,v 1.14 2005-06-21 04:30:49 urchlay Exp $ // $Id: DebuggerParser.hxx,v 1.15 2005-06-21 23:01:25 stephena Exp $
//============================================================================ //============================================================================
#ifndef DEBUGGER_PARSER_HXX #ifndef DEBUGGER_PARSER_HXX
@ -23,9 +23,7 @@ class Debugger;
#include "bspf.hxx" #include "bspf.hxx"
#include "EquateList.hxx" #include "EquateList.hxx"
#include "Array.hxx"
#define kMAX_ARGS 100
#define kMAX_WATCHES 10
typedef enum { typedef enum {
kBASE_16, kBASE_16,
@ -34,6 +32,9 @@ typedef enum {
kBASE_DEFAULT kBASE_DEFAULT
} BaseFormat; } BaseFormat;
typedef GUI::Array<int> IntArray;
typedef GUI::Array<string> StringArray;
class DebuggerParser class DebuggerParser
{ {
public: public:
@ -66,11 +67,13 @@ class DebuggerParser
bool done; bool done;
string verb; string verb;
int args[kMAX_ARGS+1]; // FIXME: should be dynamic
string argStrings[kMAX_ARGS+1]; IntArray args;
StringArray argStrings;
int argCount; int argCount;
BaseFormat defaultBase; BaseFormat defaultBase;
string *watches[kMAX_WATCHES]; // FIXME: remove the limit sometime StringArray watches;
}; };
#endif #endif

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: EquateList.cxx,v 1.11 2005-06-21 18:46:33 stephena Exp $ // $Id: EquateList.cxx,v 1.12 2005-06-21 23:01:25 stephena Exp $
//============================================================================ //============================================================================
#include <string> #include <string>
@ -107,7 +107,6 @@ EquateList::EquateList() {
} }
EquateList::~EquateList() { EquateList::~EquateList() {
cerr << "EquateList::~EquateList()\n";
ourVcsEquates.clear(); ourVcsEquates.clear();
} }
@ -170,21 +169,7 @@ string EquateList::loadFile(string file) {
if(!in.is_open()) if(!in.is_open())
return "Unable to read symbols from " + file; return "Unable to read symbols from " + file;
long start = in.tellg(); // save pointer to beginning of file
// FIXME - we no longer need # of lines, so this can probably be removed
// 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 plus the
// hard-coded symbols
int hardSize = sizeof(hardCodedEquates)/sizeof(struct Equate); int hardSize = sizeof(hardCodedEquates)/sizeof(struct Equate);
lines = hardSize;
// Make sure the hard-coded equates show up first // Make sure the hard-coded equates show up first
ourVcsEquates.clear(); ourVcsEquates.clear();
@ -192,10 +177,6 @@ string EquateList::loadFile(string file) {
ourVcsEquates.push_back(hardCodedEquates[i]); ourVcsEquates.push_back(hardCodedEquates[i]);
} }
// start over, now that we've allocated enough entries.
in.clear();
in.seekg(start);
while( !in.eof() ) { while( !in.eof() ) {
curVal = 0; curVal = 0;
curLabel = ""; curLabel = "";