From 7375039158207373b0ec599d5bd4c0ce29c7dec2 Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Sat, 6 Jun 2009 20:29:37 +0000 Subject: Moved some more debug commands to ScummVM's coneole svn-id: r41302 --- engines/sci/console.cpp | 145 +++++++++++++++++++++++++++++++++++++ engines/sci/console.h | 4 + engines/sci/engine/scriptdebug.cpp | 130 +-------------------------------- 3 files changed, 151 insertions(+), 128 deletions(-) (limited to 'engines/sci') diff --git a/engines/sci/console.cpp b/engines/sci/console.cpp index 006537c0c4..91c126754a 100644 --- a/engines/sci/console.cpp +++ b/engines/sci/console.cpp @@ -154,9 +154,13 @@ Console::Console(SciEngine *vm) : GUI::Debugger() { DCmd_Register("dissect_script", WRAP_METHOD(Console, cmdDissectScript)); DCmd_Register("set_acc", WRAP_METHOD(Console, cmdSetAccumulator)); DCmd_Register("backtrace", WRAP_METHOD(Console, cmdBacktrace)); + DCmd_Register("step", WRAP_METHOD(Console, cmdStep)); DCmd_Register("step_event", WRAP_METHOD(Console, cmdStepEvent)); DCmd_Register("step_ret", WRAP_METHOD(Console, cmdStepRet)); DCmd_Register("step_global", WRAP_METHOD(Console, cmdStepGlobal)); + DCmd_Register("step_callk", WRAP_METHOD(Console, cmdStepCallk)); + DCmd_Register("disasm", WRAP_METHOD(Console, cmdDissassemble)); + DCmd_Register("disasm_addr", WRAP_METHOD(Console, cmdDissassembleAddress)); // Breakpoints DCmd_Register("bp_list", WRAP_METHOD(Console, cmdBreakpointList)); DCmd_Register("bp_del", WRAP_METHOD(Console, cmdBreakpointDelete)); @@ -307,9 +311,13 @@ bool Console::cmdHelp(int argc, const char **argv) { DebugPrintf(" dissect_script - Examines a script\n"); DebugPrintf(" set_acc - Sets the accumulator\n"); DebugPrintf(" backtrace - Dumps the send/self/super/call/calle/callb stack\n"); + DebugPrintf(" step - Executes one operation (no parameters) or several operations (specified as a parameter) \n"); DebugPrintf(" step_event - Steps forward until a SCI event is received.\n"); DebugPrintf(" step_ret - Steps forward until ret is called on the current execution stack level.\n"); DebugPrintf(" step_global - Steps until the global variable with the specified index is modified.\n"); + DebugPrintf(" step_callk - Steps forward until it hits the next callk operation, or a specific callk (specified as a parameter)\n"); + DebugPrintf(" disasm - Disassembles a method by name\n"); + DebugPrintf(" disasm_addr - Disassembles one or more commands\n"); DebugPrintf("\n"); DebugPrintf("Breakpoints:\n"); DebugPrintf(" bp_list - Lists the current breakpoints\n"); @@ -2066,6 +2074,14 @@ bool Console::cmdBacktrace(int argc, const char **argv) { return true; } +bool Console::cmdStep(int argc, const char **argv) { + g_debugstate_valid = 0; + if (argc == 2 && atoi(argv[1]) > 0) + g_debug_step_running = atoi(argv[1]) - 1; + + return true; +} + bool Console::cmdStepEvent(int argc, const char **argv) { g_stop_on_event = 1; g_debugstate_valid = 0; @@ -2095,6 +2111,135 @@ bool Console::cmdStepGlobal(int argc, const char **argv) { return true; } +bool Console::cmdStepCallk(int argc, const char **argv) { + int callk_index; + char *endptr; + + if (argc == 2) { + /* Try to convert the parameter to a number. If the conversion stops + before end of string, assume that the parameter is a function name + and scan the function table to find out the index. */ + callk_index = strtoul(argv[1], &endptr, 0); + if (*endptr != '\0') { + callk_index = -1; + for (uint i = 0; i < g_EngineState->_kernel->getKernelNamesSize(); i++) + if (argv[1] == g_EngineState->_kernel->getKernelName(i)) { + callk_index = i; + break; + } + + if (callk_index == -1) { + DebugPrintf("Unknown kernel function '%s'\n", argv[1]); + return true; + } + } + + g_debug_seeking = kDebugSeekSpecialCallk; + g_debug_seek_special = callk_index; + g_debugstate_valid = 0; + } else { + g_debug_seeking = kDebugSeekCallk; + g_debugstate_valid = 0; + } + + return true; +} + +bool Console::cmdDissassemble(int argc, const char **argv) { + if (argc != 3) { + DebugPrintf("Disassembles a method by name.\n"); + DebugPrintf("Usage: %s \n", argv[0]); + return true; + } + + reg_t objAddr = NULL_REG; + + if (parse_reg_t(g_EngineState, argv[1], &objAddr)) { + DebugPrintf("Invalid address passed.\n"); + DebugPrintf("Check the \"addresses\" command on how to use addresses\n"); + return true; + } + + Object *obj = obj_get(g_EngineState, objAddr); + int selector_id = g_EngineState->_kernel->findSelector(argv[2]); + reg_t addr; + + if (!obj) { + DebugPrintf("Not an object."); + return true; + } + + if (selector_id < 0) { + DebugPrintf("Not a valid selector name."); + return true; + } + + if (lookup_selector(g_EngineState, objAddr, selector_id, NULL, &addr) != kSelectorMethod) { + DebugPrintf("Not a method."); + return true; + } + + do { + // TODO + //addr = disassemble(g_EngineState, addr, 0, 0); + } while (addr.offset > 0); + + return true; +} + +bool Console::cmdDissassembleAddress(int argc, const char **argv) { + if (argc < 2) { + DebugPrintf("Disassembles one or more commands.\n"); + DebugPrintf("Usage: %s [startaddr] \n", argv[0]); + DebugPrintf("Valid options are:\n"); + DebugPrintf(" bwt : Print byte/word tag\n"); + DebugPrintf(" c : Disassemble bytes\n"); + DebugPrintf(" bc : Print bytecode\n"); + return true; + } + + reg_t vpc = NULL_REG; + int op_count = 1; + int do_bwc = 0; + int do_bytes = 0; + int size; + + if (parse_reg_t(g_EngineState, argv[1], &vpc)) { + DebugPrintf("Invalid address passed.\n"); + DebugPrintf("Check the \"addresses\" command on how to use addresses\n"); + return true; + } + + g_EngineState->seg_manager->dereference(vpc, &size); + size += vpc.offset; // total segment size + + for (int i = 1; i < argc; i++) { + if (!scumm_stricmp(argv[i], "bwt")) + do_bwc = 1; + else if (!scumm_stricmp(argv[i], "bc")) + do_bytes = 1; + else if (toupper(argv[i][0]) == 'C') + op_count = atoi(argv[i] + 1); + else { + DebugPrintf("Invalid option '%s'\n", argv[i]); + return true; + } + } + + if (op_count < 0) { + DebugPrintf("Invalid op_count\n"); + return true; + } + + do { + // TODO + //vpc = disassemble(g_EngineState, vpc, do_bwc, do_bytes); + + } while ((vpc.offset > 0) && (vpc.offset + 6 < size) && (--op_count)); + + return true; +} + bool Console::cmdBreakpointList(int argc, const char **argv) { Breakpoint *bp = g_EngineState->bp_list; int i = 0; diff --git a/engines/sci/console.h b/engines/sci/console.h index fdd930e451..bc4d84abf2 100644 --- a/engines/sci/console.h +++ b/engines/sci/console.h @@ -122,9 +122,13 @@ private: bool cmdDissectScript(int argc, const char **argv); bool cmdSetAccumulator(int argc, const char **argv); bool cmdBacktrace(int argc, const char **argv); + bool cmdStep(int argc, const char **argv); bool cmdStepEvent(int argc, const char **argv); bool cmdStepRet(int argc, const char **argv); bool cmdStepGlobal(int argc, const char **argv); + bool cmdStepCallk(int argc, const char **argv); + bool cmdDissassemble(int argc, const char **argv); + bool cmdDissassembleAddress(int argc, const char **argv); // Breakpoints bool cmdBreakpointList(int argc, const char **argv); bool cmdBreakpointDelete(int argc, const char **argv); diff --git a/engines/sci/engine/scriptdebug.cpp b/engines/sci/engine/scriptdebug.cpp index 1e243fafc1..29e1bcf8db 100644 --- a/engines/sci/engine/scriptdebug.cpp +++ b/engines/sci/engine/scriptdebug.cpp @@ -87,14 +87,6 @@ int con_hook_command(ConCommand command, const char *name, const char *param, co return 0; } -int c_step(EngineState *s, const Common::Array &cmdParams) { - g_debugstate_valid = 0; - if (cmdParams.size() && (cmdParams[0].val > 0)) - g_debug_step_running = cmdParams[0].val - 1; - - return 0; -} - extern const char *selector_name(EngineState *s, int selector); int prop_ofs_to_id(EngineState *s, int prop_ofs, reg_t objp) { @@ -373,111 +365,6 @@ reg_t disassemble(EngineState *s, reg_t pos, int print_bw_tag, int print_bytecod return retval; } -static int c_disasm_addr(EngineState *s, const Common::Array &cmdParams) { - reg_t vpc = cmdParams[0].reg; - int op_count = 1; - int do_bwc = 0; - int do_bytes = 0; - unsigned int i; - int invalid = 0; - int size; - - s->seg_manager->dereference(vpc, &size); - size += vpc.offset; // total segment size - - for (i = 1; i < cmdParams.size(); i++) { - if (!scumm_stricmp(cmdParams[i].str, "bwt")) - do_bwc = 1; - else if (!scumm_stricmp(cmdParams[i].str, "bc")) - do_bytes = 1; - else if (toupper(cmdParams[i].str[0]) == 'C') - op_count = atoi(cmdParams[i].str + 1); - else { - invalid = 1; - sciprintf("Invalid option '%s'\n", cmdParams[i].str); - } - } - - if (invalid || op_count < 0) - return invalid; - - do { - vpc = disassemble(s, vpc, do_bwc, do_bytes); - - } while ((vpc.offset > 0) && (vpc.offset + 6 < size) && (--op_count)); - return 0; -} - -static int c_disasm(EngineState *s, const Common::Array &cmdParams) { - Object *obj = obj_get(s, cmdParams[0].reg); - int selector_id = s->_kernel->findSelector(cmdParams[1].str); - reg_t addr; - - if (!obj) { - sciprintf("Not an object."); - return 1; - } - - if (selector_id < 0) { - sciprintf("Not a valid selector name."); - return 1; - } - - if (lookup_selector(s, cmdParams[0].reg, selector_id, NULL, &addr) != kSelectorMethod) { - sciprintf("Not a method."); - return 1; - } - - do { - addr = disassemble(s, addr, 0, 0); - } while (addr.offset > 0); - - return 0; -} - -static int c_snk(EngineState *s, const Common::Array &cmdParams) { -// TODO: disabled till this is moved in console.cpp -#if 0 - - int callk_index; - char *endptr; - - if (!g_debugstate_valid) { - sciprintf("Not in debug state\n"); - return 1; - } - - if (cmdParams.size() > 0) { - /* Try to convert the parameter to a number. If the conversion stops - before end of string, assume that the parameter is a function name - and scan the function table to find out the index. */ - callk_index = strtoul(cmdParams [0].str, &endptr, 0); - if (*endptr != '\0') { - callk_index = -1; - for (uint i = 0; i < s->_kernel->getKernelNamesSize(); i++) - if (cmdParams [0].str == s->_kernel->getKernelName(i)) { - callk_index = i; - break; - } - - if (callk_index == -1) { - sciprintf("Unknown kernel function '%s'\n", cmdParams[0].str); - return 1; - } - } - - g_debug_seeking = kDebugSeekSpecialCallk; - g_debug_seek_special = callk_index; - g_debugstate_valid = 0; - } else { - g_debug_seeking = kDebugSeekCallk; - g_debugstate_valid = 0; - } -#endif - - return 0; -} - static int c_go(EngineState *s, const Common::Array &cmdParams) { g_debug_seeking = 0; g_debugstate_valid = 0; @@ -631,23 +518,10 @@ void script_debug(EngineState *s, reg_t *pc, StackPtr *sp, StackPtr *pp, reg_t * sciprintf("Step #%d\n", script_step_counter); disassemble(s, *pc, 0, 1); - con_hook_command(c_step, "s", "i*", "Executes one or several operations\n\nEXAMPLES\n\n" - " s 4\n\n Execute 4 commands\n\n s\n\n Execute next command"); - con_hook_command(c_disasm_addr, "disasm-addr", "!as*", "Disassembles one or more commands\n\n" - "USAGE\n\n disasm-addr [startaddr] \n\n" - " Valid options are:\n" - " bwt : Print byte/word tag\n" - " c : Disassemble bytes\n" - " bc : Print bytecode\n\n"); - con_hook_command(c_disasm, "disasm", "!as", "Disassembles a method by name\n\nUSAGE\n\n disasm \n\n"); - con_hook_command(c_snk, "snk", "s*", "Steps forward until it hits the next\n callk operation.\n" - " If invoked with a parameter, it will\n look for that specific callk.\n"); - con_hook_command(c_send, "send", "!asa*", "Sends a message to an object\nExample: send ?fooScript cue"); - con_hook_command(c_go, "go", "", "Executes the script.\n"); + con_hook_command(c_send, "send", "!asa*", "Sends a message to an object\nExample: send ?fooScript cue"); + con_hook_command(c_go, "go", "", "Executes the script.\n"); } - if (g_debug_step_running) - g_debug_step_running--; } } // End of namespace Sci -- cgit v1.2.3