From e0a3a387b986ced784b9635244d29b924f830863 Mon Sep 17 00:00:00 2001 From: sluicebox Date: Thu, 9 Jan 2020 18:03:32 -0800 Subject: SCI: Log bp_function (bpe) parameters in debugger Trac #9833 --- engines/sci/engine/scriptdebug.cpp | 56 +++++++++++++++++++++++++------------- engines/sci/engine/scriptdebug.h | 2 ++ engines/sci/engine/vm.cpp | 4 ++- 3 files changed, 42 insertions(+), 20 deletions(-) (limited to 'engines') diff --git a/engines/sci/engine/scriptdebug.cpp b/engines/sci/engine/scriptdebug.cpp index 05d9ade3ba..2f0dd008fc 100644 --- a/engines/sci/engine/scriptdebug.cpp +++ b/engines/sci/engine/scriptdebug.cpp @@ -988,27 +988,11 @@ void debugPropertyAccess(Object *obj, reg_t objp, unsigned int index, Selector s } } -void logKernelCall(const KernelFunction *kernelCall, const KernelSubFunction *kernelSubCall, EngineState *s, int argc, reg_t *argv, reg_t result) { - if (s->abortScriptProcessing != kAbortNone) { - return; - } - - Kernel *kernel = g_sci->getKernel(); - if (!kernelSubCall) { - debugN("k%s: ", kernelCall->name); - } else { - int callNameLen = strlen(kernelCall->name); - if (strncmp(kernelCall->name, kernelSubCall->name, callNameLen) == 0) { - const char *subCallName = kernelSubCall->name + callNameLen; - debugN("k%s(%s): ", kernelCall->name, subCallName); - } else { - debugN("k%s(%s): ", kernelCall->name, kernelSubCall->name); - } - } +static void logParameters(const KernelFunction *kernelCall, EngineState *s, int argc, reg_t *argv) { for (int parmNr = 0; parmNr < argc; parmNr++) { if (parmNr) debugN(", "); - uint16 regType = kernel->findRegType(argv[parmNr]); + uint16 regType = g_sci->getKernel()->findRegType(argv[parmNr]); if (regType & SIG_TYPE_NULL) debugN("0"); else if (regType & SIG_TYPE_UNINITIALIZED) @@ -1045,7 +1029,7 @@ void logKernelCall(const KernelFunction *kernelCall, const KernelSubFunction *ke // TODO: Any other segment types which could // use special handling? - if (kernelCall->function == &kSaid) { + if (kernelCall != nullptr && kernelCall->function == &kSaid) { SegmentRef saidSpec = s->_segMan->dereference(argv[parmNr]); if (saidSpec.isRaw) { debugN(" ('"); @@ -1066,12 +1050,46 @@ void logKernelCall(const KernelFunction *kernelCall, const KernelSubFunction *ke } } } +} + +void logKernelCall(const KernelFunction *kernelCall, const KernelSubFunction *kernelSubCall, EngineState *s, int argc, reg_t *argv, reg_t result) { + if (s->abortScriptProcessing != kAbortNone) { + return; + } + + if (!kernelSubCall) { + debugN("k%s: ", kernelCall->name); + } else { + int callNameLen = strlen(kernelCall->name); + if (strncmp(kernelCall->name, kernelSubCall->name, callNameLen) == 0) { + const char *subCallName = kernelSubCall->name + callNameLen; + debugN("k%s(%s): ", kernelCall->name, subCallName); + } else { + debugN("k%s(%s): ", kernelCall->name, kernelSubCall->name); + } + } + + logParameters(kernelCall, s, argc, argv); + if (result.isPointer()) debugN(" = %04x:%04x\n", PRINT_REG(result)); else debugN(" = %d\n", result.getOffset()); } +void logExportCall(uint16 script, uint16 pubfunct, EngineState *s, int argc, reg_t *argv) { + if (s->abortScriptProcessing != kAbortNone) { + return; + } + + debugN("script %d, export %d: ", script, pubfunct); + + if (argc > 1) { + argv++; + logParameters(nullptr, s, argc, argv); + } + debugN("\n"); +} void logBacktrace() { Console *con = g_sci->getSciDebugger(); diff --git a/engines/sci/engine/scriptdebug.h b/engines/sci/engine/scriptdebug.h index 7b176aed4e..3d54b327d3 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, Selector s void logKernelCall(const KernelFunction *kernelCall, const KernelSubFunction *kernelSubCall, EngineState *s, int argc, reg_t *argv, reg_t result); +void logExportCall(uint16 script, uint16 pubfunct, EngineState *s, int argc, reg_t *argv); + void logBacktrace(); bool printObject(reg_t obj); diff --git a/engines/sci/engine/vm.cpp b/engines/sci/engine/vm.cpp index b4221eb28c..e8808a715c 100644 --- a/engines/sci/engine/vm.cpp +++ b/engines/sci/engine/vm.cpp @@ -222,7 +222,9 @@ ExecStack *execute_method(EngineState *s, uint16 script, uint16 pubfunct, StackP } // Check if a breakpoint is set on this method - g_sci->checkExportBreakpoint(script, pubfunct); + if (g_sci->checkExportBreakpoint(script, pubfunct)) { + logExportCall(script, pubfunct, s, argc, argp); + } uint32 exportAddr = scr->validateExportFunc(pubfunct, false); if (!exportAddr) -- cgit v1.2.3