DIRECTOR: Add step, finish and next commands for debugger

This commit is contained in:
Scott Percival 2022-09-11 16:27:31 +08:00 committed by Eugene Sandulenko
parent 05c8119220
commit 6876849f97
4 changed files with 96 additions and 3 deletions

View File

@ -47,6 +47,19 @@ Debugger::Debugger(): GUI::Debugger() {
registerCmd("backtrace", WRAP_METHOD(Debugger, cmdBacktrace));
registerCmd("bt", WRAP_METHOD(Debugger, cmdBacktrace));
registerCmd("vars", WRAP_METHOD(Debugger, cmdVars));
registerCmd("step", WRAP_METHOD(Debugger, cmdStep));
registerCmd("s", WRAP_METHOD(Debugger, cmdStep));
registerCmd("next", WRAP_METHOD(Debugger, cmdNext));
registerCmd("n", WRAP_METHOD(Debugger, cmdNext));
registerCmd("finish", WRAP_METHOD(Debugger, cmdFinish));
registerCmd("fin", WRAP_METHOD(Debugger, cmdFinish));
_step = false;
_stepCounter = 0;
_finish = false;
_finishCounter = 0;
_next = false;
_nextCounter = 0;
}
Debugger::~Debugger() {
@ -81,9 +94,9 @@ bool Debugger::cmdHelp(int argc, const char **argv) {
debugPrintf(" stack / st - Lists the elements on the stack\n");
//debugPrintf(" frame / f - Prints the current script frame\n");
debugPrintf(" vars - Lists all of the variables available in the current script frame\n");
//debugPrintf(" step / s [n] - Steps forward one or more operations\n");
//debugPrintf(" next / n [n] - Steps forward one or more operations, skips over calls\n");
//debugPrintf(" finish / fin - Steps until the current stack frame returns/n");
debugPrintf(" step / s [n] - Steps forward one or more operations\n");
debugPrintf(" next / n [n] - Steps forward one or more operations, skips over calls\n");
debugPrintf(" finish / fin - Steps until the current stack frame returns/n");
debugPrintf("\n");
debugPrintf("Breakpoints:\n");
debugPrintf("\n");
@ -130,6 +143,33 @@ bool Debugger::cmdVars(int argc, const char **argv) {
return true;
}
bool Debugger::cmdStep(int argc, const char **argv) {
_step = true;
if (argc == 2 && atoi(argv[1]) > 0) {
_stepCounter = atoi(argv[1]);
} else {
_stepCounter = 1;
}
return cmdExit(0, nullptr);
}
bool Debugger::cmdNext(int argc, const char **argv) {
_step = true;
_next = true;
if (argc == 2 && atoi(argv[1]) > 0) {
_stepCounter = atoi(argv[1]);
} else {
_stepCounter = 1;
}
return cmdExit(0, nullptr);
}
bool Debugger::cmdFinish(int argc, const char **argv) {
_finish = true;
_finishCounter = 1;
return cmdExit(0, nullptr);
}
bool Debugger::lingoCommandProcessor(const char *inputOrig) {
if (!strcmp(inputOrig, "exit")) {
registerDefaultCmd(nullptr);
@ -146,6 +186,38 @@ bool Debugger::lingoCommandProcessor(const char *inputOrig) {
return true;
}
void Debugger::stepHook() {
if (_step && _nextCounter == 0) {
_stepCounter--;
if (_stepCounter == 0) {
_step = false;
_next = false;
attach();
g_system->updateScreen();
}
}
if (_finish && _finishCounter == 0) {
_finish = false;
attach();
g_system->updateScreen();
}
}
void Debugger::pushContextHook() {
if (_next)
_nextCounter++;
if (_finish)
_finishCounter++;
}
void Debugger::popContextHook() {
if (_next && _nextCounter > 0)
_nextCounter--;
if (_finish)
_finishCounter--;
}
void Debugger::debugLogFile(Common::String logs, bool prompt) {
if (prompt)
debugPrintf("-- %s", logs.c_str());

View File

@ -32,6 +32,9 @@ public:
Debugger();
~Debugger();
void debugLogFile(Common::String logs, bool prompt);
void stepHook();
void pushContextHook();
void popContextHook();
private:
bool cmdHelp(int argc, const char **argv);
@ -41,11 +44,22 @@ private:
bool cmdBacktrace(int argc, const char **argv);
bool cmdStack(int argc, const char **argv);
bool cmdVars(int argc, const char **argv);
bool cmdStep(int argc, const char **argv);
bool cmdNext(int argc, const char **argv);
bool cmdFinish(int argc, const char **argv);
bool lingoCommandProcessor(const char *inputOrig);
Common::DumpFile _out;
Common::String _outName;
bool _step;
int _stepCounter;
bool _finish;
int _finishCounter;
bool _next;
int _nextCounter;
};

View File

@ -240,6 +240,7 @@ void Lingo::saveStateToWindow() {
}
void Lingo::pushContext(const Symbol funcSym, bool allowRetVal, Datum defaultRetVal) {
g_debugger->pushContextHook();
Common::Array<CFrame *> &callstack = _vm->getCurrentWindow()->_callstack;
debugC(5, kDebugLingoExec, "Pushing frame %d", callstack.size() + 1);
@ -373,6 +374,8 @@ void Lingo::popContext(bool aborting) {
}
delete fp;
g_debugger->popContextHook();
}
bool Lingo::hasFrozenContext() {

View File

@ -459,6 +459,7 @@ void Lingo::execute() {
Common::String instr = decodeInstruction(_currentScript, _pc);
uint current = _pc;
if (debugChannelSet(5, kDebugLingoExec))
printStack("Stack before: ", current);
@ -471,6 +472,8 @@ void Lingo::execute() {
debugC(3, kDebugLingoExec, "[%3d]: %s", current, instr.c_str());
g_debugger->stepHook();
_pc++;
(*((*_currentScript)[_pc - 1]))();
@ -502,6 +505,7 @@ void Lingo::execute() {
if (_freezeContext) {
debugC(1, kDebugLingoExec, "Lingo::execute(): Context is frozen, pausing execution");
}
g_debugger->stepHook();
}
void Lingo::executeScript(ScriptType type, CastMemberID id) {