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
// 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>
@ -32,9 +32,10 @@
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
FrameBufferGL::FrameBufferGL(OSystem* osystem)
: FrameBuffer(osystem),
myTexture(0),
myTexture(NULL),
myScreenmode(0),
myScreenmodeCount(0),
myTextureID(0),
myFilterParam(GL_NEAREST),
myFilterParamName("GL_NEAREST"),
myFSScaleFactor(1.0)

View File

@ -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.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"
@ -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];
int count = args.size();
int address = args[0];
for(int i=1; i<argCount; i++)
for(int i=1; i<count; i++)
mySystem->poke(address++, args[i]);
string ret = "changed ";
sprintf(buf, "%d", argCount-1);
sprintf(buf, "%d", count-1);
ret += buf;
ret += " location";
if(argCount > 2)
if(count > 2)
ret += "s";
return ret;
}

View File

@ -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.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
@ -51,7 +51,7 @@ enum {
for all debugging operations in Stella (parser, 6502 debugger, etc).
@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
{
@ -168,7 +168,7 @@ class Debugger : public DialogContainer
void writeRAM(uInt16 addr, uInt8 value);
// set a bunch of RAM locations at once
const string setRAM(int argCount, int *args);
const string setRAM(IntArray args);
bool start();
void quit();

View File

@ -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.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"
@ -35,11 +35,12 @@ DebuggerParser::DebuggerParser(Debugger* d)
{
done = false;
defaultBase = kBASE_16;
for(int i=0; i<kMAX_WATCHES; i++)
watches[i] = new string;
}
DebuggerParser::~DebuggerParser() {
args.clear();
argStrings.clear();
watches.clear();
}
int DebuggerParser::conv_hex_digit(char d) {
@ -162,10 +163,12 @@ int DebuggerParser::decipher_arg(const string &str) {
bool DebuggerParser::getArgs(const string& command) {
int state = kIN_COMMAND;
string curArg = "";
argCount = 0;
verb = "";
const char *c = command.c_str();
argStrings.clear();
args.clear();
// cerr << "Parsing \"" << command << "\"" << endl;
// First, pick apart string into space-separated tokens.
@ -189,29 +192,27 @@ bool DebuggerParser::getArgs(const string& command) {
case kIN_ARG:
if(*c == ' ' || *c == '\0') {
state = kIN_SPACE;
argStrings[argCount++] = curArg;
argStrings.push_back(curArg);
curArg = "";
} else {
curArg += *c;
}
break;
} // switch(state)
if(argCount == kMAX_ARGS) {
cerr << "reached max " << kMAX_ARGS << " args" << endl;
return true;
}
} while(*c++ != '\0');
argCount = argStrings.size();
//for(int i=0; i<argCount; i++)
//cerr << "argStrings[" << i << "] == \"" << argStrings[i] << "\"" << endl;
// Now decipher each argument, in turn.
for(int i=0; i<argCount; i++) {
curArg = argStrings[i];
if( (args[i] = decipher_arg(curArg)) < 0) {
int temp = decipher_arg(argStrings[i]);
if(temp < 0) {
return false;
}
args.push_back(temp);
//cerr << "args[" << i << "] == " << args[i] << endl;
}
@ -309,13 +310,16 @@ string DebuggerParser::showWatches() {
string ret = "\n";
char buf[10];
for(int i=0; i<kMAX_WATCHES; i++) {
if(*(watches[i]->c_str()) != '\0') {
// Clear the args, since we're going to pass them to eval()
argStrings.clear();
args.clear();
for(unsigned int i=0; i<watches.size(); i++) {
if(watches[i] != "") {
//cerr << "here1 " << i << endl;
sprintf(buf, "%d", i+1);
argCount = 1;
argStrings[0] = *watches[i];
args[0] = decipher_arg(argStrings[0]);
argStrings.push_back(watches[i]);
args.push_back(decipher_arg(argStrings[0]));
if(args[0] < 0) {
ret += "BAD WATCH ";
ret += buf;
@ -333,27 +337,20 @@ string DebuggerParser::showWatches() {
}
string DebuggerParser::addWatch(string watch) {
for(int i=0; i<kMAX_WATCHES; i++) {
if(*(watches[i]->c_str()) == '\0') {
string *w = new string(watch);
watches[i] = w;
return "Added watch";
}
}
return "Can't add watch: Too many watches";
watches.push_back(watch);
return "Added watch";
}
void DebuggerParser::delAllWatches() {
for(int i=0; i<kMAX_WATCHES; i++)
watches[i] = new string;
watches.clear();
}
string DebuggerParser::delWatch(int which) {
which--;
if(which < 0 || which >= kMAX_WATCHES)
if(which < 0 || which >= (int)watches.size())
return "no such watch";
else
watches[which] = new string;
watches.remove_at(which);
return "removed watch";
}
@ -386,7 +383,7 @@ string DebuggerParser::run(const string& command) {
// "verb" is the command, stripped of any arguments.
// In the if/else below, put shorter command names first.
// 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
// can always disambiguate: "ti" is short for "tia", or
// "tr" for "trace".
@ -462,7 +459,7 @@ string DebuggerParser::run(const string& command) {
else if(argCount == 1)
return "missing data (need 2 or more args)";
else
result = debugger->setRAM(argCount, args);
result = debugger->setRAM(args);
} else if(subStringMatch(verb, "tia")) {
result = debugger->dumpTIA();
} else if(subStringMatch(verb, "reset")) {
@ -526,6 +523,9 @@ string DebuggerParser::run(const string& command) {
delAllWatches();
return "cleared all watches";
} else if(subStringMatch(verb, "watch")) {
if(argCount != 1)
return "one argument required";
addWatch(argStrings[0]);
} else if(subStringMatch(verb, "delwatch")) {
if(argCount == 1)

View File

@ -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.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
@ -23,9 +23,7 @@ class Debugger;
#include "bspf.hxx"
#include "EquateList.hxx"
#define kMAX_ARGS 100
#define kMAX_WATCHES 10
#include "Array.hxx"
typedef enum {
kBASE_16,
@ -34,6 +32,9 @@ typedef enum {
kBASE_DEFAULT
} BaseFormat;
typedef GUI::Array<int> IntArray;
typedef GUI::Array<string> StringArray;
class DebuggerParser
{
public:
@ -66,11 +67,13 @@ class DebuggerParser
bool done;
string verb;
int args[kMAX_ARGS+1]; // FIXME: should be dynamic
string argStrings[kMAX_ARGS+1];
IntArray args;
StringArray argStrings;
int argCount;
BaseFormat defaultBase;
string *watches[kMAX_WATCHES]; // FIXME: remove the limit sometime
StringArray watches;
};
#endif

View File

@ -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: 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>
@ -107,7 +107,6 @@ EquateList::EquateList() {
}
EquateList::~EquateList() {
cerr << "EquateList::~EquateList()\n";
ourVcsEquates.clear();
}
@ -170,21 +169,7 @@ string EquateList::loadFile(string file) {
if(!in.is_open())
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);
lines = hardSize;
// Make sure the hard-coded equates show up first
ourVcsEquates.clear();
@ -192,10 +177,6 @@ string EquateList::loadFile(string file) {
ourVcsEquates.push_back(hardCodedEquates[i]);
}
// start over, now that we've allocated enough entries.
in.clear();
in.seekg(start);
while( !in.eof() ) {
curVal = 0;
curLabel = "";