diff options
author | Willem Jan Palenstijn | 2017-05-26 13:30:42 +0200 |
---|---|---|
committer | Willem Jan Palenstijn | 2017-06-10 21:32:35 +0200 |
commit | b56a49c53e90acc334d8c86d3e3c1f97662e881b (patch) | |
tree | 0d3066cf6ffbdabdac9df4beca18b6dd55f051d5 | |
parent | e9867356f5ccedf5d9a8a087852230b416d8d458 (diff) | |
download | scummvm-rg350-b56a49c53e90acc334d8c86d3e3c1f97662e881b.tar.gz scummvm-rg350-b56a49c53e90acc334d8c86d3e3c1f97662e881b.tar.bz2 scummvm-rg350-b56a49c53e90acc334d8c86d3e3c1f97662e881b.zip |
SCI: Move backtrace output to scriptdebug.cpp
-rw-r--r-- | engines/sci/console.cpp | 71 | ||||
-rw-r--r-- | engines/sci/engine/scriptdebug.cpp | 80 | ||||
-rw-r--r-- | engines/sci/engine/scriptdebug.h | 2 |
3 files changed, 84 insertions, 69 deletions
diff --git a/engines/sci/console.cpp b/engines/sci/console.cpp index 211aab0d6e..ec54642b8a 100644 --- a/engines/sci/console.cpp +++ b/engines/sci/console.cpp @@ -34,6 +34,7 @@ #include "sci/engine/savegame.h" #include "sci/engine/gc.h" #include "sci/engine/features.h" +#include "sci/engine/scriptdebug.h" #include "sci/sound/midiparser_sci.h" #include "sci/sound/music.h" #include "sci/sound/drivers/mididriver.h" @@ -3260,75 +3261,7 @@ void Console::printOffsets(int scriptNr, uint16 showType) { } bool Console::cmdBacktrace(int argc, const char **argv) { - debugPrintf("Call stack (current base: 0x%x):\n", _engine->_gamestate->executionStackBase); - Common::List<ExecStack>::const_iterator iter; - uint i = 0; - - for (iter = _engine->_gamestate->_executionStack.begin(); - iter != _engine->_gamestate->_executionStack.end(); ++iter, ++i) { - const ExecStack &call = *iter; - const char *objname = _engine->_gamestate->_segMan->getObjectName(call.sendp); - int paramc, totalparamc; - - switch (call.type) { - case EXEC_STACK_TYPE_CALL: // Normal function - if (call.type == EXEC_STACK_TYPE_CALL) - debugPrintf(" %x: script %d - ", i, (*(Script *)_engine->_gamestate->_segMan->_heap[call.addr.pc.getSegment()]).getScriptNumber()); - if (call.debugSelector != -1) { - debugPrintf("%s::%s(", objname, _engine->getKernel()->getSelectorName(call.debugSelector).c_str()); - } else if (call.debugExportId != -1) { - debugPrintf("export %d (", call.debugExportId); - } else if (call.debugLocalCallOffset != -1) { - debugPrintf("call %x (", call.debugLocalCallOffset); - } - break; - - case EXEC_STACK_TYPE_KERNEL: // Kernel function - if (call.debugKernelSubFunction == -1) - debugPrintf(" %x:[%x] k%s(", i, call.debugOrigin, _engine->getKernel()->getKernelName(call.debugKernelFunction).c_str()); - else - debugPrintf(" %x:[%x] k%s(", i, call.debugOrigin, _engine->getKernel()->getKernelName(call.debugKernelFunction, call.debugKernelSubFunction).c_str()); - break; - - case EXEC_STACK_TYPE_VARSELECTOR: - debugPrintf(" %x:[%x] vs%s %s::%s (", i, call.debugOrigin, (call.argc) ? "write" : "read", - objname, _engine->getKernel()->getSelectorName(call.debugSelector).c_str()); - break; - } - - totalparamc = call.argc; - - if (totalparamc > 16) - totalparamc = 16; - - for (paramc = 1; paramc <= totalparamc; paramc++) { - debugPrintf("%04x:%04x", PRINT_REG(call.variables_argp[paramc])); - - if (paramc < call.argc) - debugPrintf(", "); - } - - if (call.argc > 16) - debugPrintf("..."); - - debugPrintf(")\n "); - if (call.debugOrigin != -1) - debugPrintf("by %x ", call.debugOrigin); - debugPrintf("obj@%04x:%04x", PRINT_REG(call.objp)); - if (call.type == EXEC_STACK_TYPE_CALL) { - debugPrintf(" pc=%04x:%04x", PRINT_REG(call.addr.pc)); - if (call.sp == CALL_SP_CARRY) - debugPrintf(" sp,fp:carry"); - else { - debugPrintf(" sp=ST:%04x", (unsigned)(call.sp - _engine->_gamestate->stack_base)); - debugPrintf(" fp=ST:%04x", (unsigned)(call.fp - _engine->_gamestate->stack_base)); - } - } else - debugPrintf(" pc:none"); - - debugPrintf(" argp:ST:%04x", (unsigned)(call.variables_argp - _engine->_gamestate->stack_base)); - debugPrintf("\n"); - } + logBacktrace(); return true; } diff --git a/engines/sci/engine/scriptdebug.cpp b/engines/sci/engine/scriptdebug.cpp index 28c7b950de..17fc27154c 100644 --- a/engines/sci/engine/scriptdebug.cpp +++ b/engines/sci/engine/scriptdebug.cpp @@ -915,4 +915,84 @@ void logKernelCall(const KernelFunction *kernelCall, const KernelSubFunction *ke debugN(" = %d\n", result.getOffset()); } + +void logBacktrace() { + Console *con = g_sci->getSciDebugger(); + EngineState *s = g_sci->getEngineState(); + + con->debugPrintf("Call stack (current base: 0x%x):\n", s->executionStackBase); + Common::List<ExecStack>::const_iterator iter; + uint i = 0; + + + for (iter = s->_executionStack.begin(); + iter != s->_executionStack.end(); ++iter, ++i) { + const ExecStack &call = *iter; + const char *objname = s->_segMan->getObjectName(call.sendp); + int paramc, totalparamc; + + switch (call.type) { + case EXEC_STACK_TYPE_CALL: // Normal function + if (call.type == EXEC_STACK_TYPE_CALL) + con->debugPrintf(" %x: script %d - ", i, s->_segMan->getScript(call.addr.pc.getSegment())->getScriptNumber()); + if (call.debugSelector != -1) { + con->debugPrintf("%s::%s(", objname, g_sci->getKernel()->getSelectorName(call.debugSelector).c_str()); + } else if (call.debugExportId != -1) { + con->debugPrintf("export %d (", call.debugExportId); + } else if (call.debugLocalCallOffset != -1) { + con->debugPrintf("call %x (", call.debugLocalCallOffset); + } + break; + + case EXEC_STACK_TYPE_KERNEL: // Kernel function + if (call.debugKernelSubFunction == -1) + con->debugPrintf(" %x:[%x] k%s(", i, call.debugOrigin, g_sci->getKernel()->getKernelName(call.debugKernelFunction).c_str()); + else + con->debugPrintf(" %x:[%x] k%s(", i, call.debugOrigin, g_sci->getKernel()->getKernelName(call.debugKernelFunction, call.debugKernelSubFunction).c_str()); + break; + + case EXEC_STACK_TYPE_VARSELECTOR: + con->debugPrintf(" %x:[%x] vs%s %s::%s (", i, call.debugOrigin, (call.argc) ? "write" : "read", + objname, g_sci->getKernel()->getSelectorName(call.debugSelector).c_str()); + break; + } + + totalparamc = call.argc; + + if (totalparamc > 16) + totalparamc = 16; + + for (paramc = 1; paramc <= totalparamc; paramc++) { + con->debugPrintf("%04x:%04x", PRINT_REG(call.variables_argp[paramc])); + + if (paramc < call.argc) + con->debugPrintf(", "); + } + + if (call.argc > 16) + con->debugPrintf("..."); + + con->debugPrintf(")\n "); + if (call.debugOrigin != -1) + con->debugPrintf("by %x ", call.debugOrigin); + con->debugPrintf("obj@%04x:%04x", PRINT_REG(call.objp)); + if (call.type == EXEC_STACK_TYPE_CALL) { + con->debugPrintf(" pc=%04x:%04x", PRINT_REG(call.addr.pc)); + if (call.sp == CALL_SP_CARRY) + con->debugPrintf(" sp,fp:carry"); + else { + con->debugPrintf(" sp=ST:%04x", (unsigned)(call.sp - s->stack_base)); + con->debugPrintf(" fp=ST:%04x", (unsigned)(call.fp - s->stack_base)); + } + } else + con->debugPrintf(" pc:none"); + + con->debugPrintf(" argp:ST:%04x", (unsigned)(call.variables_argp - s->stack_base)); + con->debugPrintf("\n"); + } +} + + + + } // End of namespace Sci diff --git a/engines/sci/engine/scriptdebug.h b/engines/sci/engine/scriptdebug.h index 964b8a4b54..1d8a2ef6bb 100644 --- a/engines/sci/engine/scriptdebug.h +++ b/engines/sci/engine/scriptdebug.h @@ -35,6 +35,8 @@ void debugPropertyAccess(Object *obj, reg_t objp, unsigned int index, reg_t curV void logKernelCall(const KernelFunction *kernelCall, const KernelSubFunction *kernelSubCall, EngineState *s, int argc, reg_t *argv, reg_t result); +void logBacktrace(); + } #endif |