Fixed bug where debugger 'loadlist' command caused a segfault, and

improved its error handling message.

Made TiaZoomWidget take extra debugger dialog real-estate into account.

Beginning work on fixing debugger 'run' and 'reload' commands, which
currently cause a segfault.


git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@1345 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
stephena 2007-08-14 19:49:21 +00:00
parent 7ebe5185c0
commit d73b834a61
8 changed files with 123 additions and 84 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: Debugger.cxx,v 1.112 2007-08-12 23:05:12 stephena Exp $ // $Id: Debugger.cxx,v 1.113 2007-08-14 19:49:20 stephena Exp $
//============================================================================ //============================================================================
#include "bspf.hxx" #include "bspf.hxx"
@ -233,78 +233,81 @@ void Debugger::autoLoadSymbols(string fileName) {
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
string Debugger::loadListFile(string f) { string Debugger::loadListFile(string f)
char buffer[255]; {
char buffer[255];
if(f == "") { if(f == "")
f = myOSystem->romFile(); {
f = myOSystem->romFile();
string::size_type pos; string::size_type pos;
if( (pos = f.find_last_of('.')) != string::npos ) { if( (pos = f.find_last_of('.')) != string::npos )
f.replace(pos, f.size(), ".lst"); f.replace(pos, f.size(), ".lst");
} else { else
f += ".lst"; f += ".lst";
} }
}
ifstream in(f.c_str()); ifstream in(f.c_str());
if(!in.is_open()) if(!in.is_open())
return "Unable to read listing from " + f; return "Unable to read listing from " + f;
sourceLines.clear(); sourceLines.clear();
int count = 0; int count = 0;
while( !in.eof() ) { while( !in.eof() )
if(!in.getline(buffer, 255)) {
break; if(!in.getline(buffer, 255))
break;
if( strlen(buffer) >= 14 && if(strlen(buffer) >= 14 &&
buffer[0] == ' ' && buffer[0] == ' ' &&
buffer[7] == ' ' && buffer[7] == ' ' &&
buffer[8] == ' ' && buffer[8] == ' ' &&
isxdigit(buffer[9]) && isxdigit(buffer[9]) &&
isxdigit(buffer[12]) && isxdigit(buffer[12]) &&
BSPF_isblank(buffer[13])) BSPF_isblank(buffer[13]))
{ {
count++; count++;
char addr[5]; char addr[5];
for(int i=0; i<4; i++) for(int i=0; i<4; i++)
addr[i] = buffer[9+i]; addr[i] = buffer[9+i];
for(char *c = buffer; *c != '\0'; c++) for(char *c = buffer; *c != '\0'; c++)
if(*c == '\t') *c = ' '; if(*c == '\t') *c = ' ';
addr[4] = '\0'; addr[4] = '\0';
string a = addr; string a = addr;
string b = buffer; string b = buffer;
sourceLines.insert(make_pair(a, b)); sourceLines.insert(make_pair(a, b));
} }
} }
in.close();
in.close(); return valueToString(count) + " lines loaded from " + f;
return valueToString(count) + " lines loaded from " + f;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
const string Debugger::getSourceLines(int addr) { const string Debugger::getSourceLines(int addr)
if(sourceLines.size() == 0) {
return "no list file loaded (try \"loadlst file.lst\")"; if(sourceLines.size() == 0)
return "";
string ret; string ret;
string want = to_hex_16(addr); string want = to_hex_16(addr);
bool found = false; bool found = false;
pair<ListIter, ListIter> lines = sourceLines.equal_range(want); pair<ListIter, ListIter> lines = sourceLines.equal_range(want);
for(ListIter i = lines.first; i != lines.second; i++) { for(ListIter i = lines.first; i != lines.second; i++)
found = true; {
ret += i->second; found = true;
ret += "\n"; ret += i->second;
} ret += "\n";
}
if(found) if(found)
return ret; return ret;
else else
return ""; return "";
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -901,8 +904,9 @@ void Debugger::addLabel(string label, int address) {
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Debugger::reloadROM() { void Debugger::reloadROM()
myOSystem->createConsole( myOSystem->romFile() ); {
myOSystem->createConsole();
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -1003,13 +1007,14 @@ GUI::Rect Debugger::getStatusBounds() const
{ {
// The status area is the full area to the right of the TIA image // The status area is the full area to the right of the TIA image
// extending as far as necessary // extending as far as necessary
// 30% of any space above 1030 pixels will be allocated to this area
GUI::Rect dlg = getDialogBounds(); GUI::Rect dlg = getDialogBounds();
GUI::Rect tia = getTiaBounds(); GUI::Rect tia = getTiaBounds();
int x1 = tia.right + 1; int x1 = tia.right + 1;
int y1 = 0; int y1 = 0;
int x2 = tia.right + 225 + (dlg.width() > 1030 ? int x2 = tia.right + 225 + (dlg.width() > 1030 ?
(int) (0.2 * (dlg.width() - 1030)) : 0); (int) (0.3 * (dlg.width() - 1030)) : 0);
int y2 = tia.bottom; int y2 = tia.bottom;
GUI::Rect r(x1, y1, x2, y2); GUI::Rect r(x1, y1, x2, y2);

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.88 2007-08-10 18:27:10 stephena Exp $ // $Id: Debugger.hxx,v 1.89 2007-08-14 19:49:20 stephena Exp $
//============================================================================ //============================================================================
#ifndef DEBUGGER_HXX #ifndef DEBUGGER_HXX
@ -69,7 +69,7 @@ typedef uInt16 (Debugger::*DEBUGGER_WORD_METHOD)();
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.88 2007-08-10 18:27:10 stephena Exp $ @version $Id: Debugger.hxx,v 1.89 2007-08-14 19:49:20 stephena Exp $
*/ */
class Debugger : public DialogContainer class Debugger : public DialogContainer
{ {
@ -275,6 +275,7 @@ class Debugger : public DialogContainer
string loadListFile(string f = ""); string loadListFile(string f = "");
const string getSourceLines(int addr); const string getSourceLines(int addr);
bool haveListFile() { return sourceLines.size() > 0; }
bool saveROM(string filename); bool saveROM(string filename);

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.97 2007-08-10 18:27:10 stephena Exp $ // $Id: DebuggerParser.cxx,v 1.98 2007-08-14 19:49:20 stephena Exp $
//============================================================================ //============================================================================
#include <fstream> #include <fstream>
@ -111,6 +111,7 @@ string DebuggerParser::run(const string& command)
if(commands[i].refreshRequired) if(commands[i].refreshRequired)
debugger->myBaseDialog->loadConfig(); debugger->myBaseDialog->loadConfig();
cerr << " ==> commandResult = " << commandResult << endl;
return commandResult; return commandResult;
} }
} }
@ -412,7 +413,7 @@ bool DebuggerParser::getArgs(const string& command, string& verb)
argStrings.push_back(curArg); argStrings.push_back(curArg);
argCount = argStrings.size(); argCount = argStrings.size();
cerr << "count = " << argCount << endl;
/* /*
cerr << "verb = " << verb << endl; cerr << "verb = " << verb << endl;
cerr << "arguments (" << argCount << "):\n"; cerr << "arguments (" << argCount << "):\n";
@ -964,6 +965,9 @@ void DebuggerParser::executeFunction()
// "list" // "list"
void DebuggerParser::executeList() void DebuggerParser::executeList()
{ {
if(!debugger->haveListFile())
commandResult = "no list file loaded (try \"loadlist file.lst\")";
for(int i=args[0] - 2; i<args[0] + 3; i++) for(int i=args[0] - 2; i<args[0] + 3; i++)
commandResult += debugger->getSourceLines(i); commandResult += debugger->getSourceLines(i);
} }
@ -1097,9 +1101,10 @@ void DebuggerParser::executeRam()
// "reload" // "reload"
void DebuggerParser::executeReload() void DebuggerParser::executeReload()
{ {
debugger->reloadROM(); debugger->quit();
debugger->getOSystem()->createConsole();
debugger->start(); debugger->start();
commandResult = "reloaded"; commandResult = "_EXIT_DEBUGGER"; // Set PromptWidget for more info
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -1147,7 +1152,7 @@ void DebuggerParser::executeRun()
{ {
debugger->saveOldState(); debugger->saveOldState();
debugger->quit(); debugger->quit();
commandResult = "exiting debugger"; commandResult = "_EXIT_DEBUGGER"; // See PromptWidget for more info
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -1571,7 +1576,7 @@ DebuggerParser::Command DebuggerParser::commands[kNumCommands] = {
{ {
"list", "list",
"List source (if loaded with loadlst)", "List source (if loaded with loadlst)",
false, true,
false, false,
{ kARG_WORD, kARG_END_ARGS }, { kARG_WORD, kARG_END_ARGS },
&DebuggerParser::executeList &DebuggerParser::executeList

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: DebuggerDialog.cxx,v 1.20 2007-08-06 20:16:51 stephena Exp $ // $Id: DebuggerDialog.cxx,v 1.21 2007-08-14 19:49:20 stephena Exp $
// //
// Based on code from ScummVM - Scumm Interpreter // Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project // Copyright (C) 2002-2004 The ScummVM project
@ -199,6 +199,7 @@ void DebuggerDialog::addTabArea()
void DebuggerDialog::addStatusArea() void DebuggerDialog::addStatusArea()
{ {
const GUI::Font& font = instance()->consoleFont(); const GUI::Font& font = instance()->consoleFont();
const int lineHeight = font.getLineHeight();
GUI::Rect r = instance()->debugger().getStatusBounds(); GUI::Rect r = instance()->debugger().getStatusBounds();
int xpos, ypos; int xpos, ypos;
@ -206,10 +207,11 @@ void DebuggerDialog::addStatusArea()
myTiaInfo = new TiaInfoWidget(this, instance()->consoleFont(), xpos, ypos); myTiaInfo = new TiaInfoWidget(this, instance()->consoleFont(), xpos, ypos);
ypos += myTiaInfo->getHeight() + 10; ypos += myTiaInfo->getHeight() + 10;
myTiaZoom = new TiaZoomWidget(this, instance()->consoleFont(), xpos+10, ypos); myTiaZoom = new TiaZoomWidget(this, instance()->consoleFont(), xpos+10, ypos,
r.width()-10, r.height()-lineHeight-ypos-10);
addToFocusList(myTiaZoom->getFocusList()); addToFocusList(myTiaZoom->getFocusList());
xpos += 10; ypos += myTiaZoom->getHeight() + 20; xpos += 10; ypos += myTiaZoom->getHeight() + 10;
myMessageBox = new EditTextWidget(this, instance()->consoleFont(), myMessageBox = new EditTextWidget(this, instance()->consoleFont(),
xpos, ypos, myTiaZoom->getWidth(), xpos, ypos, myTiaZoom->getWidth(),
font.getLineHeight(), ""); font.getLineHeight(), "");

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: PromptWidget.cxx,v 1.18 2007-08-12 23:05:12 stephena Exp $ // $Id: PromptWidget.cxx,v 1.19 2007-08-14 19:49:20 stephena Exp $
// //
// Based on code from ScummVM - Scumm Interpreter // Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project // Copyright (C) 2002-2004 The ScummVM project
@ -189,8 +189,17 @@ bool PromptWidget::handleKeyDown(int ascii, int keycode, int modifiers)
addToHistory(command.c_str()); addToHistory(command.c_str());
// Pass the command to the debugger, and print the result // Pass the command to the debugger, and print the result
string result = instance()->debugger().run(command) + "\n"; string result = instance()->debugger().run(command);
print( result );
// This is a bit of a hack
// Certain commands remove the debugger dialog from underneath us,
// so we shouldn't print any messages
// Those commands will return 'EXIT_DEBUGGER' as their result
//cerr << " ==> result = \'" << result << "\'\n";
if(result == "_EXIT_DEBUGGER")
return true;
print(result + "\n");
} }
printPrompt(); printPrompt();
@ -500,6 +509,18 @@ GUI::Rect PromptWidget::getRect() const
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void PromptWidget::loadConfig() void PromptWidget::loadConfig()
{ {
cerr << "loadConfig()" << endl
<< "_promptStartPos = " << _promptStartPos << endl
<< "_promptEndPos = " << _promptEndPos << endl
<< "_currentPos = " << _currentPos << endl
<< endl;
if(_promptStartPos != _currentPos)
{
print(PROMPT);
_promptStartPos = _promptEndPos = _currentPos;
}
// See logic at the end of handleKeyDown for an explanation of this // See logic at the end of handleKeyDown for an explanation of this
_makeDirty = true; _makeDirty = true;

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: PromptWidget.hxx,v 1.9 2007-01-01 18:04:44 stephena Exp $ // $Id: PromptWidget.hxx,v 1.10 2007-08-14 19:49:20 stephena Exp $
// //
// Based on code from ScummVM - Scumm Interpreter // Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project // Copyright (C) 2002-2004 The ScummVM project
@ -85,7 +85,7 @@ class PromptWidget : public Widget, public CommandSender
void loadConfig(); void loadConfig();
protected: private:
int _buffer[kBufferSize]; int _buffer[kBufferSize];
int _linesInBuffer; int _linesInBuffer;

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: TiaZoomWidget.cxx,v 1.11 2007-01-01 18:04:44 stephena Exp $ // $Id: TiaZoomWidget.cxx,v 1.12 2007-08-14 19:49:20 stephena Exp $
// //
// Based on code from ScummVM - Scumm Interpreter // Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project // Copyright (C) 2002-2004 The ScummVM project
@ -29,7 +29,7 @@
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
TiaZoomWidget::TiaZoomWidget(GuiObject* boss, const GUI::Font& font, TiaZoomWidget::TiaZoomWidget(GuiObject* boss, const GUI::Font& font,
int x, int y) int x, int y, int w, int h)
: Widget(boss, font, x, y, 16, 16), : Widget(boss, font, x, y, 16, 16),
CommandSender(boss), CommandSender(boss),
myMenu(NULL) myMenu(NULL)
@ -37,8 +37,12 @@ TiaZoomWidget::TiaZoomWidget(GuiObject* boss, const GUI::Font& font,
_flags = WIDGET_ENABLED | WIDGET_CLEARBG | WIDGET_RETAIN_FOCUS | _flags = WIDGET_ENABLED | WIDGET_CLEARBG | WIDGET_RETAIN_FOCUS |
WIDGET_WANTS_RAWDATA; WIDGET_WANTS_RAWDATA;
_type = kTiaZoomWidget; _type = kTiaZoomWidget;
_w = 210; _bgcolor = _bgcolorhi = kDlgColor;
_h = 120;
// Use all available space, up to the maximum bounds of the TIA image
// Width myst
_w = BSPF_min(w, 320);
_h = BSPF_min(h, 260);
addFocusWidget(this); addFocusWidget(this);

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: TiaZoomWidget.hxx,v 1.6 2007-01-01 18:04:44 stephena Exp $ // $Id: TiaZoomWidget.hxx,v 1.7 2007-08-14 19:49:21 stephena Exp $
// //
// Based on code from ScummVM - Scumm Interpreter // Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project // Copyright (C) 2002-2004 The ScummVM project
@ -32,7 +32,8 @@ class ContextMenu;
class TiaZoomWidget : public Widget, public CommandSender class TiaZoomWidget : public Widget, public CommandSender
{ {
public: public:
TiaZoomWidget(GuiObject *boss, const GUI::Font& font, int x, int y); TiaZoomWidget(GuiObject *boss, const GUI::Font& font,
int x, int y, int w, int h);
virtual ~TiaZoomWidget(); virtual ~TiaZoomWidget();
void loadConfig(); void loadConfig();