Debugger 'listtraps' now shows all traps (fixes #190).

This commit is contained in:
Stephen Anthony 2017-08-18 18:47:35 -02:30
parent 48a99c6b6b
commit a9dd2b32cb
2 changed files with 31 additions and 26 deletions

View File

@ -284,16 +284,16 @@ int DebuggerParser::decipher_arg(const string& str)
string DebuggerParser::showWatches() string DebuggerParser::showWatches()
{ {
ostringstream buf; ostringstream buf;
for(uInt32 i = 0; i < watches.size(); i++) for(uInt32 i = 0; i < myWatches.size(); ++i)
{ {
if(watches[i] != "") if(myWatches[i] != "")
{ {
// Clear the args, since we're going to pass them to eval() // Clear the args, since we're going to pass them to eval()
argStrings.clear(); argStrings.clear();
args.clear(); args.clear();
argCount = 1; argCount = 1;
argStrings.push_back(watches[i]); argStrings.push_back(myWatches[i]);
args.push_back(decipher_arg(argStrings[0])); args.push_back(decipher_arg(argStrings[0]));
if(args[0] < 0) if(args[0] < 0)
buf << "BAD WATCH " << (i+1) << ": " << argStrings[0] << endl; buf << "BAD WATCH " << (i+1) << ": " << argStrings[0] << endl;
@ -534,13 +534,14 @@ string DebuggerParser::eval()
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
string DebuggerParser::trapStatus(int addr) string DebuggerParser::trapStatus(uInt32 addr, bool& enabled)
{ {
string result; string result;
result += Base::toString(addr); result += Base::toString(addr);
result += ": "; result += ": ";
bool r = debugger.readTrap(addr); bool r = debugger.readTrap(addr);
bool w = debugger.writeTrap(addr); bool w = debugger.writeTrap(addr);
enabled = r || w;
if(r && w) if(r && w)
result += "read|write"; result += "read|write";
else if(r) else if(r)
@ -570,11 +571,11 @@ bool DebuggerParser::saveScriptFile(string file)
ofstream out(file); ofstream out(file);
FunctionDefMap funcs = debugger.getFunctionDefMap(); FunctionDefMap funcs = debugger.getFunctionDefMap();
for(const auto& i: funcs) for(const auto& f: funcs)
out << "function " << i.first << " { " << i.second << " }" << endl; out << "function " << f.first << " { " << f.second << " }" << endl;
for(const auto& i: watches) for(const auto& w: myWatches)
out << "watch " << i << endl; out << "watch " << w << endl;
for(uInt32 i = 0; i < 0x10000; ++i) for(uInt32 i = 0; i < 0x10000; ++i)
if(debugger.breakPoint(i)) if(debugger.breakPoint(i))
@ -735,6 +736,7 @@ void DebuggerParser::executeClearconfig()
// "cleartraps" // "cleartraps"
void DebuggerParser::executeCleartraps() void DebuggerParser::executeCleartraps()
{ {
myTraps.clear();
debugger.clearAllTraps(); debugger.clearAllTraps();
commandResult << "all traps cleared"; commandResult << "all traps cleared";
} }
@ -743,7 +745,7 @@ void DebuggerParser::executeCleartraps()
// "clearwatches" // "clearwatches"
void DebuggerParser::executeClearwatches() void DebuggerParser::executeClearwatches()
{ {
watches.clear(); myWatches.clear();
commandResult << "all watches cleared"; commandResult << "all watches cleared";
} }
@ -856,9 +858,9 @@ void DebuggerParser::executeDelfunction()
void DebuggerParser::executeDelwatch() void DebuggerParser::executeDelwatch()
{ {
int which = args[0] - 1; int which = args[0] - 1;
if(which >= 0 && which < int(watches.size())) if(which >= 0 && which < int(myWatches.size()))
{ {
Vec::removeAt(watches, which); Vec::removeAt(myWatches, which);
commandResult << "removed watch"; commandResult << "removed watch";
} }
else else
@ -1096,19 +1098,13 @@ void DebuggerParser::executeListfunctions()
// "listtraps" // "listtraps"
void DebuggerParser::executeListtraps() void DebuggerParser::executeListtraps()
{ {
int count = 0; if(myTraps.size() > 0)
for(uInt32 i = 0; i <= 0xffff; ++i)
{ {
if(debugger.readTrap(i) || debugger.writeTrap(i)) bool enabled = true;
{ for(const auto& trap: myTraps)
commandResult << trapStatus(i) << " + mirrors" << endl; commandResult << trapStatus(trap, enabled) << " + mirrors" << endl;
count++;
break;
} }
} else
if(!count)
commandResult << "no traps set"; commandResult << "no traps set";
} }
@ -1570,7 +1566,12 @@ void DebuggerParser::executeTrapRW(uInt32 addr, bool read, bool write)
} }
} }
commandResult << trapStatus(addr) << " + mirrors" << endl; bool trapEnabled = false;
const string& result = trapStatus(addr, trapEnabled);
if(trapEnabled) myTraps.insert(addr);
else myTraps.erase(addr);
commandResult << result << " + mirrors" << endl;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -1629,7 +1630,7 @@ void DebuggerParser::executeV()
// "watch" // "watch"
void DebuggerParser::executeWatch() void DebuggerParser::executeWatch()
{ {
watches.push_back(argStrings[0]); myWatches.push_back(argStrings[0]);
commandResult << "added watch \"" << argStrings[0] << "\""; commandResult << "added watch \"" << argStrings[0] << "\"";
} }

View File

@ -20,6 +20,7 @@
#include <functional> #include <functional>
#include <sstream> #include <sstream>
#include <set>
class Debugger; class Debugger;
class FilesystemNode; class FilesystemNode;
@ -64,7 +65,6 @@ class DebuggerParser
bool getArgs(const string& command, string& verb); bool getArgs(const string& command, string& verb);
bool validateArgs(int cmd); bool validateArgs(int cmd);
string eval(); string eval();
string trapStatus(int addr);
bool saveScriptFile(string file); bool saveScriptFile(string file);
private: private:
@ -114,7 +114,11 @@ class DebuggerParser
StringList argStrings; StringList argStrings;
uInt32 argCount; uInt32 argCount;
StringList watches; StringList myWatches;
// Keep track of traps (read and/or write)
std::set<uInt32> myTraps;
string trapStatus(uInt32 addr, bool& enabled);
// List of available command methods // List of available command methods
void executeA(); void executeA();