diff --git a/engines/sci/console.cpp b/engines/sci/console.cpp index bac31f6c8e7..2432d84faa0 100644 --- a/engines/sci/console.cpp +++ b/engines/sci/console.cpp @@ -176,10 +176,12 @@ Console::Console(SciEngine *engine) : GUI::Debugger(), DCmd_Register("bp_del", WRAP_METHOD(Console, cmdBreakpointDelete)); DCmd_Register("bpdel", WRAP_METHOD(Console, cmdBreakpointDelete)); // alias DCmd_Register("bc", WRAP_METHOD(Console, cmdBreakpointDelete)); // alias - DCmd_Register("bp_exec_method", WRAP_METHOD(Console, cmdBreakpointExecMethod)); - DCmd_Register("bpx", WRAP_METHOD(Console, cmdBreakpointExecMethod)); // alias - DCmd_Register("bp_exec_function", WRAP_METHOD(Console, cmdBreakpointExecFunction)); - DCmd_Register("bpe", WRAP_METHOD(Console, cmdBreakpointExecFunction)); // alias + DCmd_Register("bp_method", WRAP_METHOD(Console, cmdBreakpointMethod)); + DCmd_Register("bpx", WRAP_METHOD(Console, cmdBreakpointMethod)); // alias + DCmd_Register("bp_kernel", WRAP_METHOD(Console, cmdBreakpointKernel)); + DCmd_Register("bpk", WRAP_METHOD(Console, cmdBreakpointKernel)); // alias + DCmd_Register("bp_function", WRAP_METHOD(Console, cmdBreakpointFunction)); + DCmd_Register("bpe", WRAP_METHOD(Console, cmdBreakpointFunction)); // alias // VM DCmd_Register("script_steps", WRAP_METHOD(Console, cmdScriptSteps)); DCmd_Register("vm_varlist", WRAP_METHOD(Console, cmdVMVarlist)); @@ -384,8 +386,9 @@ bool Console::cmdHelp(int argc, const char **argv) { DebugPrintf("Breakpoints:\n"); DebugPrintf(" bp_list / bplist / bl - Lists the current breakpoints\n"); DebugPrintf(" bp_del / bpdel / bc - Deletes a breakpoint with the specified index\n"); - DebugPrintf(" bp_exec_method / bpx - Sets a breakpoint on the execution of the specified method\n"); - DebugPrintf(" bp_exec_function / bpe - Sets a breakpoint on the execution of the specified exported function\n"); + DebugPrintf(" bp_method / bpx - Sets a breakpoint on the execution or access of a specified method/selector\n"); + DebugPrintf(" bp_kernel / bpk - Sets a breakpoint on execution of a kernel function\n"); + DebugPrintf(" bp_function / bpe - Sets a breakpoint on the execution of the specified exported function\n"); DebugPrintf("\n"); DebugPrintf("VM:\n"); DebugPrintf(" script_steps - Shows the number of executed SCI operations\n"); @@ -2716,7 +2719,7 @@ bool Console::cmdLogKernel(int argc, const char **argv) { return true; } - if (g_sci->getKernel()->debugSetFunctionLogging(argv[1], logging)) + if (g_sci->getKernel()->debugSetFunction(argv[1], logging, -1)) DebugPrintf("Logging %s for k%s\n", logging ? "enabled" : "disabled", argv[1]); else DebugPrintf("Unknown kernel function %s\n", argv[1]); @@ -2794,10 +2797,10 @@ bool Console::cmdBreakpointDelete(int argc, const char **argv) { return true; } -bool Console::cmdBreakpointExecMethod(int argc, const char **argv) { +bool Console::cmdBreakpointMethod(int argc, const char **argv) { if (argc != 2) { - DebugPrintf("Sets a breakpoint on the execution of the specified method.\n"); - DebugPrintf("Usage: %s \n", argv[0]); + DebugPrintf("Sets a breakpoint on execution/access of a specified method/selector.\n"); + DebugPrintf("Usage: %s \n", argv[0]); DebugPrintf("Example: %s ego::doit\n", argv[0]); DebugPrintf("May also be used to set a breakpoint that applies whenever an object\n"); DebugPrintf("of a specific type is touched: %s foo::\n", argv[0]); @@ -2817,7 +2820,23 @@ bool Console::cmdBreakpointExecMethod(int argc, const char **argv) { return true; } -bool Console::cmdBreakpointExecFunction(int argc, const char **argv) { +bool Console::cmdBreakpointKernel(int argc, const char **argv) { + if (argc != 2) { + DebugPrintf("Sets a breakpoint on execution of a kernel function.\n"); + DebugPrintf("Usage: %s \n", argv[0]); + DebugPrintf("Example: %s DrawPic\n", argv[0]); + return true; + } + + if (g_sci->getKernel()->debugSetFunction(argv[1], -1, true)) + DebugPrintf("Breakpoint enabled for k%s\n", argv[1]); + else + DebugPrintf("Unknown kernel function %s\n", argv[1]); + + return true; +} + +bool Console::cmdBreakpointFunction(int argc, const char **argv) { // TODO/FIXME: Why does this accept 2 parameters (the high and the low part of the address)?" if (argc != 3) { DebugPrintf("Sets a breakpoint on the execution of the specified exported function.\n"); diff --git a/engines/sci/console.h b/engines/sci/console.h index 091a5d15f84..60599ea7836 100644 --- a/engines/sci/console.h +++ b/engines/sci/console.h @@ -134,8 +134,9 @@ private: // Breakpoints bool cmdBreakpointList(int argc, const char **argv); bool cmdBreakpointDelete(int argc, const char **argv); - bool cmdBreakpointExecMethod(int argc, const char **argv); - bool cmdBreakpointExecFunction(int argc, const char **argv); + bool cmdBreakpointMethod(int argc, const char **argv); + bool cmdBreakpointKernel(int argc, const char **argv); + bool cmdBreakpointFunction(int argc, const char **argv); // VM bool cmdScriptSteps(int argc, const char **argv); bool cmdVMVarlist(int argc, const char **argv); diff --git a/engines/sci/engine/kernel.cpp b/engines/sci/engine/kernel.cpp index e7020021997..25502100aec 100644 --- a/engines/sci/engine/kernel.cpp +++ b/engines/sci/engine/kernel.cpp @@ -656,7 +656,7 @@ void Kernel::mapFunctions() { return; } -bool Kernel::debugSetFunctionLogging(const char *kernelName, bool logging) { +bool Kernel::debugSetFunction(const char *kernelName, int logging, int breakpoint) { if (strcmp(kernelName, "*")) { for (uint id = 0; id < _kernelFuncs.size(); id++) { if (_kernelFuncs[id].name) { @@ -666,14 +666,21 @@ bool Kernel::debugSetFunctionLogging(const char *kernelName, bool logging) { KernelSubFunction *kernelSubCall = _kernelFuncs[id].subFunctions; uint kernelSubCallCount = _kernelFuncs[id].subFunctionCount; for (uint subId = 0; subId < kernelSubCallCount; subId++) { - if (kernelSubCall->function) - kernelSubCall->debugLogging = logging; + if (kernelSubCall->function) { + if (logging != -1) + kernelSubCall->debugLogging = logging == 1 ? true : false; + if (breakpoint != -1) + kernelSubCall->debugBreakpoint = breakpoint == 1 ? true : false; + } kernelSubCall++; } return true; } // function name matched, set for this one and exit - _kernelFuncs[id].debugLogging = logging; + if (logging != -1) + _kernelFuncs[id].debugLogging = logging == 1 ? true : false; + if (breakpoint != -1) + _kernelFuncs[id].debugBreakpoint = breakpoint == 1 ? true : false; return true; } else { // main name was not matched @@ -685,7 +692,10 @@ bool Kernel::debugSetFunctionLogging(const char *kernelName, bool logging) { if (kernelSubCall->function) { if (strcmp(kernelName, kernelSubCall->name) == 0) { // sub-function name matched, set for this one and exit - kernelSubCall->debugLogging = logging; + if (logging != -1) + kernelSubCall->debugLogging = logging == 1 ? true : false; + if (breakpoint != -1) + kernelSubCall->debugBreakpoint = breakpoint == 1 ? true : false; return true; } } @@ -702,14 +712,21 @@ bool Kernel::debugSetFunctionLogging(const char *kernelName, bool logging) { if (_kernelFuncs[id].name) { if (!_kernelFuncs[id].subFunctions) { // No sub-functions, enable actual kernel function - _kernelFuncs[id].debugLogging = logging; + if (logging != -1) + _kernelFuncs[id].debugLogging = logging == 1 ? true : false; + if (breakpoint != -1) + _kernelFuncs[id].debugBreakpoint = breakpoint == 1 ? true : false; } else { // Sub-Functions available, enable those too KernelSubFunction *kernelSubCall = _kernelFuncs[id].subFunctions; uint kernelSubCallCount = _kernelFuncs[id].subFunctionCount; for (uint subId = 0; subId < kernelSubCallCount; subId++) { - if (kernelSubCall->function) - kernelSubCall->debugLogging = logging; + if (kernelSubCall->function) { + if (logging != -1) + kernelSubCall->debugLogging = logging == 1 ? true : false; + if (breakpoint != -1) + kernelSubCall->debugBreakpoint = breakpoint == 1 ? true : false; + } kernelSubCall++; } } diff --git a/engines/sci/engine/kernel.h b/engines/sci/engine/kernel.h index 02ce102f30c..b6247b46f1b 100644 --- a/engines/sci/engine/kernel.h +++ b/engines/sci/engine/kernel.h @@ -127,6 +127,7 @@ struct KernelSubFunction { uint16 *signature; const SciWorkaroundEntry *workarounds; bool debugLogging; + bool debugBreakpoint; }; struct KernelFunction { @@ -137,6 +138,7 @@ struct KernelFunction { KernelSubFunction *subFunctions; uint16 subFunctionCount; bool debugLogging; + bool debugBreakpoint; }; class Kernel { @@ -218,9 +220,9 @@ public: void loadKernelNames(GameFeatures *features); /** - * Sets debugCalls flag for a kernel function + * Sets debug flags for a kernel function */ - bool debugSetFunctionLogging(const char *kernelName, bool debugCalls); + bool debugSetFunction(const char *kernelName, int logging, int breakpoint); private: /** diff --git a/engines/sci/engine/vm.cpp b/engines/sci/engine/vm.cpp index c25e26dc2c0..c6e8b3e2ddf 100644 --- a/engines/sci/engine/vm.cpp +++ b/engines/sci/engine/vm.cpp @@ -743,6 +743,11 @@ static void callKernelFunc(EngineState *s, int kernelCallNr, int argc) { if (kernelCall.debugLogging) logKernelCall(&kernelCall, NULL, s, argc, argv, s->r_acc); + if (kernelCall.debugBreakpoint) { + printf("Break on k%s\n", kernelCall.name); + g_sci->_debugState.debugging = true; + g_sci->_debugState.breakpointWasHit = true; + } } else { // Sub-functions available, check signature and call that one directly if (argc < 1) @@ -793,6 +798,11 @@ static void callKernelFunc(EngineState *s, int kernelCallNr, int argc) { if (kernelSubCall.debugLogging) logKernelCall(&kernelCall, &kernelSubCall, s, argc, argv, s->r_acc); + if (kernelSubCall.debugBreakpoint) { + printf("Break on k%s\n", kernelSubCall.name); + g_sci->_debugState.debugging = true; + g_sci->_debugState.breakpointWasHit = true; + } } // Remove callk stack frame again, if there's still an execution stack