From e572811aedc5141189d4c1db9069a9ad564f21dd Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Sat, 6 Jun 2009 16:43:13 +0000 Subject: Moved some more debug commands to ScummVM's coneole svn-id: r41227 --- engines/sci/console.cpp | 159 +++++++++++++++++++++++++++++++++-- engines/sci/console.h | 6 +- engines/sci/debug.h | 5 +- engines/sci/engine/game.cpp | 2 +- engines/sci/engine/grammar.cpp | 16 ++-- engines/sci/engine/kevent.cpp | 21 +++++ engines/sci/engine/kgraphics.cpp | 26 +++--- engines/sci/engine/said.cpp | 8 +- engines/sci/engine/scriptdebug.cpp | 164 +++++-------------------------------- engines/sci/vocabulary.cpp | 8 +- engines/sci/vocabulary.h | 7 +- 11 files changed, 236 insertions(+), 186 deletions(-) (limited to 'engines/sci') diff --git a/engines/sci/console.cpp b/engines/sci/console.cpp index f9e13304c5..006537c0c4 100644 --- a/engines/sci/console.cpp +++ b/engines/sci/console.cpp @@ -52,7 +52,19 @@ int g_debug_sleeptime_factor = 1; int g_debug_simulated_key = 0; bool g_debug_track_mouse_clicks = false; bool g_debug_weak_validations = true; - +// Script related variables +int g_debug_seeking = 0; // Stepping forward until some special condition is met +int g_debug_seek_special = 0; // Used for special seeks +int g_debug_seek_level = 0; // Used for seekers that want to check their exec stack depth + +enum DebugSeeking { + kDebugSeekNothing = 0, + kDebugSeekCallk = 1, // Step forward until callk is found + kDebugSeekLevelRet = 2, // Step forward until returned from this level + kDebugSeekSpecialCallk = 3, // Step forward until a /special/ callk is found + kDebugSeekSO = 4, // Step forward until specified PC (after the send command) and stack depth + kDebugSeekGlobal = 5 // Step forward until one specified global variable is modified +}; Console::Console(SciEngine *vm) : GUI::Debugger() { _vm = vm; @@ -80,6 +92,7 @@ Console::Console(SciEngine *vm) : GUI::Debugger() { DCmd_Register("parser_words", WRAP_METHOD(Console, cmdParserWords)); DCmd_Register("sentence_fragments", WRAP_METHOD(Console, cmdSentenceFragments)); DCmd_Register("parse", WRAP_METHOD(Console, cmdParse)); + DCmd_Register("set_parse_nodes", WRAP_METHOD(Console, cmdSetParseNodes)); // Resources DCmd_Register("hexdump", WRAP_METHOD(Console, cmdHexDump)); DCmd_Register("resource_id", WRAP_METHOD(Console, cmdResourceId)); @@ -141,6 +154,9 @@ 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_event", WRAP_METHOD(Console, cmdStepEvent)); + DCmd_Register("step_ret", WRAP_METHOD(Console, cmdStepRet)); + DCmd_Register("step_global", WRAP_METHOD(Console, cmdStepGlobal)); // Breakpoints DCmd_Register("bp_list", WRAP_METHOD(Console, cmdBreakpointList)); DCmd_Register("bp_del", WRAP_METHOD(Console, cmdBreakpointDelete)); @@ -220,6 +236,7 @@ bool Console::cmdHelp(int argc, const char **argv) { DebugPrintf(" parser_words - Shows the words from the parse node tree\n"); DebugPrintf(" sentence_fragments - Shows the sentence fragments (used to build Parse trees)\n"); DebugPrintf(" parse - Parses a sequence of words and prints the resulting parse tree\n"); + DebugPrintf(" set_parse_nodes - Sets the contents of all parse nodes\n"); DebugPrintf("\n"); DebugPrintf("Resources:\n"); DebugPrintf(" hexdump - Dumps the specified resource to standard output\n"); @@ -290,6 +307,9 @@ 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_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("\n"); DebugPrintf("Breakpoints:\n"); DebugPrintf(" bp_list - Lists the current breakpoints\n"); @@ -391,6 +411,98 @@ bool Console::cmdParserWords(int argc, const char **argv) { return true; } +enum { + kParseEndOfInput = 0, + kParseOpeningParenthesis = 1, + kParseClosingParenthesis = 2, + kParseNil = 3, + kParseNumber = 4 +}; + +int parseNodes(EngineState *s, int *i, int *pos, int type, int nr, int argc, const char **argv) { + int nextToken = 0, nextValue = 0, newPos = 0, oldPos = 0; + + if (type == kParseNil) + return 0; + + if (type == kParseNumber) { + s->parser_nodes[*pos += 1].type = kParseTreeLeafNode; + s->parser_nodes[*pos].content.value = nr; + return *pos; + } + if (type == kParseEndOfInput) { + sciprintf("Unbalanced parentheses\n"); + return -1; + } + if (type == kParseClosingParenthesis) { + sciprintf("Syntax error at token %d\n", *i); + return -1; + } + + s->parser_nodes[oldPos = ++(*pos)].type = kParseTreeBranchNode; + + for (int j = 0; j <= 1; j++) { + if (*i == argc) { + nextToken = kParseEndOfInput; + } else { + const char *token = argv[(*i)++]; + + if (!strcmp(token, "(")) { + nextToken = kParseOpeningParenthesis; + } else if (!strcmp(token, ")")) { + nextToken = kParseClosingParenthesis; + } else if (!strcmp(token, "nil")) { + nextToken = kParseNil; + } else { + nextValue = strtol(token, NULL, 0); + nextToken = kParseNumber; + } + } + + if ((newPos = s->parser_nodes[oldPos].content.branches[j] = parseNodes(s, i, pos, nextToken, nextValue, argc, argv)) == -1) + return -1; + } + + const char *token = argv[(*i)++]; + if (strcmp(token, ")")) + sciprintf("Expected ')' at token %d\n", *i); + + return oldPos; +} + +bool Console::cmdSetParseNodes(int argc, const char **argv) { + if (argc < 2) { + DebugPrintf("Sets the contents of all parse nodes.\n"); + DebugPrintf("Usage: %s ... \n", argv[0]); + DebugPrintf("Tokens should be separated by blanks and enclosed in parentheses\n"); + return true; + } + + int i = 0; + int pos = -1; + int nextToken = 0, nextValue = 0; + + const char *token = argv[i++]; + + if (!strcmp(token, "(")) { + nextToken = kParseOpeningParenthesis; + } else if (!strcmp(token, ")")) { + nextToken = kParseClosingParenthesis; + } else if (!strcmp(token, "nil")) { + nextToken = kParseNil; + } else { + nextValue = strtol(token, NULL, 0); + nextToken = kParseNumber; + } + + if (parseNodes(g_EngineState, &i, &pos, nextToken, nextValue, argc, argv) == -1) + return 1; + + vocab_dump_parse_tree("debug-parse-tree", g_EngineState->parser_nodes); + + return true; +} + bool Console::cmdRegisters(int argc, const char **argv) { DebugPrintf("Current register values:\n"); #if 0 @@ -832,7 +944,7 @@ bool Console::cmdParserNodes(int argc, const char **argv) { for (int i = 0; i < end; i++) { DebugPrintf(" Node %03x: ", i); - if (g_EngineState->parser_nodes[i].type == PARSE_TREE_NODE_LEAF) + if (g_EngineState->parser_nodes[i].type == kParseTreeLeafNode) DebugPrintf("Leaf: %04x\n", g_EngineState->parser_nodes[i].content.value); else DebugPrintf("Branch: ->%04x, ->%04x\n", g_EngineState->parser_nodes[i].content.branches[0], @@ -1954,6 +2066,35 @@ bool Console::cmdBacktrace(int argc, const char **argv) { return true; } +bool Console::cmdStepEvent(int argc, const char **argv) { + g_stop_on_event = 1; + g_debugstate_valid = 0; + + return true; +} + +bool Console::cmdStepRet(int argc, const char **argv) { + g_debug_seeking = kDebugSeekLevelRet; + g_debug_seek_level = g_EngineState->_executionStack.size() - 1; + g_debugstate_valid = 0; + + return true; +} + +bool Console::cmdStepGlobal(int argc, const char **argv) { + if (argc != 2) { + DebugPrintf("Steps until the global variable with the specified index is modified.\n"); + DebugPrintf("Usage: %s \n", argv[0]); + return true; + } + + g_debug_seeking = kDebugSeekGlobal; + g_debug_seek_special = atoi(argv[1]); + g_debugstate_valid = 0; + + return true; +} + bool Console::cmdBreakpointList(int argc, const char **argv) { Breakpoint *bp = g_EngineState->bp_list; int i = 0; @@ -2858,29 +2999,29 @@ int c_stepover(EngineState *s, const Common::Array &cmdParams) { opnumber = opcode >> 1; if (opnumber == 0x22 /* callb */ || opnumber == 0x23 /* calle */ || opnumber == 0x25 /* send */ || opnumber == 0x2a /* self */ || opnumber == 0x2b /* super */) { - g_debug_seeking = _DEBUG_SEEK_SO; - s_debug_seek_level = s->_executionStack.size()-1; - // Store in s_debug_seek_special the offset of the next command after send + g_debug_seeking = kDebugSeekSO; + g_debug_seek_level = s->_executionStack.size()-1; + // Store in g_debug_seek_special the offset of the next command after send switch (opcode) { case 0x46: // calle W - s_debug_seek_special = *p_pc + 5; + g_debug_seek_special = *p_pc + 5; break; case 0x44: // callb W case 0x47: // calle B case 0x56: // super W - s_debug_seek_special = *p_pc + 4; + g_debug_seek_special = *p_pc + 4; break; case 0x45: // callb B case 0x57: // super B case 0x4A: // send W case 0x54: // self W - s_debug_seek_special = *p_pc + 3; + g_debug_seek_special = *p_pc + 3; break; default: - s_debug_seek_special = *p_pc + 2; + g_debug_seek_special = *p_pc + 2; } } diff --git a/engines/sci/console.h b/engines/sci/console.h index b2e66daa0f..fdd930e451 100644 --- a/engines/sci/console.h +++ b/engines/sci/console.h @@ -59,9 +59,10 @@ private: bool cmdSuffixes(int argc, const char **argv); bool cmdParseGrammar(int argc, const char **argv); bool cmdParserNodes(int argc, const char **argv); - bool cmdParserWords(int argc, const char **argv); + bool cmdParserWords(int argc, const char **argv); bool cmdSentenceFragments(int argc, const char **argv); bool cmdParse(int argc, const char **argv); + bool cmdSetParseNodes(int argc, const char **argv); // Resources bool cmdHexDump(int argc, const char **argv); bool cmdResourceId(int argc, const char **argv); @@ -121,6 +122,9 @@ private: bool cmdDissectScript(int argc, const char **argv); bool cmdSetAccumulator(int argc, const char **argv); bool cmdBacktrace(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); // Breakpoints bool cmdBreakpointList(int argc, const char **argv); bool cmdBreakpointDelete(int argc, const char **argv); diff --git a/engines/sci/debug.h b/engines/sci/debug.h index ec44838826..e12d7fbe2d 100644 --- a/engines/sci/debug.h +++ b/engines/sci/debug.h @@ -40,7 +40,10 @@ extern int g_debug_sleeptime_factor; extern int g_debug_simulated_key; extern bool g_debug_track_mouse_clicks; extern bool g_debug_weak_validations; - +// Script related variables +extern int g_debug_seeking; +extern int g_debug_seek_special; +extern int g_debug_seek_level; } // End of namespace Sci diff --git a/engines/sci/engine/game.cpp b/engines/sci/engine/game.cpp index bfd38f2c1b..5a250529cd 100644 --- a/engines/sci/engine/game.cpp +++ b/engines/sci/engine/game.cpp @@ -499,7 +499,7 @@ int game_init(EngineState *s) { s->game_obj = game_obj; // Mark parse tree as unused - s->parser_nodes[0].type = PARSE_TREE_NODE_LEAF; + s->parser_nodes[0].type = kParseTreeLeafNode; s->parser_nodes[0].content.value = 0; s->_menubar = new Menubar(); // Create menu bar diff --git a/engines/sci/engine/grammar.cpp b/engines/sci/engine/grammar.cpp index 2c035fcb53..275a31a0d4 100644 --- a/engines/sci/engine/grammar.cpp +++ b/engines/sci/engine/grammar.cpp @@ -414,7 +414,7 @@ parse_rule_list_t *Vocabulary::buildGNF(bool verbose) { static int _vbpt_pareno(parse_tree_node_t *nodes, int *pos, int base) { // Opens parentheses nodes[base].content.branches[0] = (*pos) + 1; - nodes[++(*pos)].type = PARSE_TREE_NODE_BRANCH; + nodes[++(*pos)].type = kParseTreeBranchNode; nodes[*pos].content.branches[0] = 0; nodes[*pos].content.branches[1] = 0; return *pos; @@ -423,7 +423,7 @@ static int _vbpt_pareno(parse_tree_node_t *nodes, int *pos, int base) { static int _vbpt_parenc(parse_tree_node_t *nodes, int *pos, int paren) { // Closes parentheses for appending nodes[paren].content.branches[1] = ++(*pos); - nodes[*pos].type = PARSE_TREE_NODE_BRANCH; + nodes[*pos].type = kParseTreeBranchNode; nodes[*pos].content.branches[0] = 0; nodes[*pos].content.branches[1] = 0; return *pos; @@ -432,10 +432,10 @@ static int _vbpt_parenc(parse_tree_node_t *nodes, int *pos, int paren) { static int _vbpt_append(parse_tree_node_t *nodes, int *pos, int base, int value) { // writes one value to an existing base node and creates a successor node for writing nodes[base].content.branches[0] = ++(*pos); - nodes[*pos].type = PARSE_TREE_NODE_LEAF; + nodes[*pos].type = kParseTreeLeafNode; nodes[*pos].content.value = value; nodes[base].content.branches[1] = ++(*pos); - nodes[*pos].type = PARSE_TREE_NODE_BRANCH; + nodes[*pos].type = kParseTreeBranchNode; nodes[*pos].content.branches[0] = 0; nodes[*pos].content.branches[1] = 0; return *pos; @@ -443,7 +443,7 @@ static int _vbpt_append(parse_tree_node_t *nodes, int *pos, int base, int value) static int _vbpt_terminate(parse_tree_node_t *nodes, int *pos, int base, int value) { // Terminates, overwriting a nextwrite forknode - nodes[base].type = PARSE_TREE_NODE_LEAF; + nodes[base].type = kParseTreeLeafNode; nodes[base].content.value = value; return *pos; } @@ -554,14 +554,14 @@ int Vocabulary::parseGNF(parse_tree_node_t *nodes, const ResultWordList &words, { int temp, pos; - nodes[0].type = PARSE_TREE_NODE_BRANCH; + nodes[0].type = kParseTreeBranchNode; nodes[0].content.branches[0] = 1; nodes[0].content.branches[1] = 2; - nodes[1].type = PARSE_TREE_NODE_LEAF; + nodes[1].type = kParseTreeLeafNode; nodes[1].content.value = 0x141; - nodes[2].type = PARSE_TREE_NODE_BRANCH; + nodes[2].type = kParseTreeBranchNode; nodes[2].content.branches[0] = 0; nodes[2].content.branches[1] = 0; diff --git a/engines/sci/engine/kevent.cpp b/engines/sci/engine/kevent.cpp index 66395035c8..d6db12b2f8 100644 --- a/engines/sci/engine/kevent.cpp +++ b/engines/sci/engine/kevent.cpp @@ -139,6 +139,27 @@ reg_t kGetEvent(EngineState *s, int funct_nr, int argc, reg_t *argv) { if ((s->r_acc.offset) && (g_stop_on_event)) { g_stop_on_event = 0; + + // A SCI event occured, and we have been asked to stop, so open the debug console + GUI::Debugger *con = ((Sci::SciEngine*)g_engine)->getDebugger(); + con->DebugPrintf("SCI event occured: "); + switch (e.type) { + case SCI_EVT_QUIT: + con->DebugPrintf("quit event\n"); + break; + case SCI_EVT_KEYBOARD: + con->DebugPrintf("keyboard event\n"); + break; + case SCI_EVT_MOUSE_RELEASE: + case SCI_EVT_MOUSE_PRESS: + con->DebugPrintf("mouse click event\n"); + break; + default: + con->DebugPrintf("unknown or no event (event type %d)\n", e.type); + } + + con->attach(); + con->onFrame(); } return s->r_acc; diff --git a/engines/sci/engine/kgraphics.cpp b/engines/sci/engine/kgraphics.cpp index 1f35f6ed04..994a4f7902 100644 --- a/engines/sci/engine/kgraphics.cpp +++ b/engines/sci/engine/kgraphics.cpp @@ -348,8 +348,8 @@ reg_t kSetCursor(EngineState *s, int funct_nr, int argc, reg_t *argv) { // Set pointer position, if requested if (argc > 2) { - Common::Point newpos = Common::Point(SKPV(2) + s->port->_bounds.x, SKPV(3) + s->port->_bounds.y); - GFX_ASSERT(gfxop_set_pointer_position(s->gfx_state, newpos)); + Common::Point newPos = Common::Point(SKPV(2) + s->port->_bounds.x, SKPV(3) + s->port->_bounds.y); + GFX_ASSERT(gfxop_set_pointer_position(s->gfx_state, newPos)); } break; case 3 : @@ -370,26 +370,26 @@ reg_t kSetCursor(EngineState *s, int funct_nr, int argc, reg_t *argv) { } reg_t kMoveCursor(EngineState *s, int funct_nr, int argc, reg_t *argv) { - Common::Point newpos; + Common::Point newPos; - newpos = s->gfx_state->pointer_pos; + newPos = s->gfx_state->pointer_pos; if (argc == 1) { // Case ignored on IBM PC } else { - newpos.x = SKPV(0) + s->port->zone.x; - newpos.y = SKPV(1) + s->port->zone.y; + newPos.x = SKPV(0) + s->port->zone.x; + newPos.y = SKPV(1) + s->port->zone.y; - if (newpos.x > s->port->zone.x + s->port->zone.width) - newpos.x = s->port->zone.x + s->port->zone.width; - if (newpos.y > s->port->zone.y + s->port->zone.height) - newpos.y = s->port->zone.y + s->port->zone.height; + if (newPos.x > s->port->zone.x + s->port->zone.width) + newPos.x = s->port->zone.x + s->port->zone.width; + if (newPos.y > s->port->zone.y + s->port->zone.height) + newPos.y = s->port->zone.y + s->port->zone.height; - if (newpos.x < 0) newpos.x = 0; - if (newpos.y < 0) newpos.y = 0; + if (newPos.x < 0) newPos.x = 0; + if (newPos.y < 0) newPos.y = 0; } - GFX_ASSERT(gfxop_set_pointer_position(s->gfx_state, newpos)); + GFX_ASSERT(gfxop_set_pointer_position(s->gfx_state, newPos)); return s->r_acc; } diff --git a/engines/sci/engine/said.cpp b/engines/sci/engine/said.cpp index 7d0467efa6..327231857e 100644 --- a/engines/sci/engine/said.cpp +++ b/engines/sci/engine/said.cpp @@ -1918,7 +1918,7 @@ static int said_next_node() { #define SAID_NEXT_NODE said_next_node() static int said_leaf_node(tree_t pos, int value) { - said_tree[pos].type = PARSE_TREE_NODE_LEAF; + said_tree[pos].type = kParseTreeLeafNode; if (value != VALUE_IGNORE) said_tree[pos].content.value = value; @@ -1927,7 +1927,7 @@ static int said_leaf_node(tree_t pos, int value) { } static int said_branch_node(tree_t pos, int left, int right) { - said_tree[pos].type = PARSE_TREE_NODE_BRANCH; + said_tree[pos].type = kParseTreeBranchNode; if (left != VALUE_IGNORE) said_tree[pos].content.branches[0] = left; @@ -2057,12 +2057,12 @@ static int said_parse_spec(EngineState *s, byte *spec) { // primitive functions #define AUG_READ_BRANCH(a, br, p) \ - if (tree[p].type != PARSE_TREE_NODE_BRANCH) \ + if (tree[p].type != kParseTreeBranchNode) \ return 0; \ a = tree[p].content.branches[br]; #define AUG_READ_VALUE(a, p) \ - if (tree[p].type != PARSE_TREE_NODE_LEAF) \ + if (tree[p].type != kParseTreeLeafNode) \ return 0; \ a = tree[p].content.value; diff --git a/engines/sci/engine/scriptdebug.cpp b/engines/sci/engine/scriptdebug.cpp index 64ab86a3e1..1e243fafc1 100644 --- a/engines/sci/engine/scriptdebug.cpp +++ b/engines/sci/engine/scriptdebug.cpp @@ -49,17 +49,7 @@ namespace Sci { int g_debugstate_valid = 0; // Set to 1 while script_debug is running int g_debug_step_running = 0; // Set to >0 to allow multiple stepping -static bool s_debug_commands_hooked = false; // Commands hooked to the console yet? -int g_debug_seeking = 0; // Stepping forward until some special condition is met -static int s_debug_seek_level = 0; // Used for seekers that want to check their exec stack depth -static int s_debug_seek_special = 0; // Used for special seeks(1) - -#define _DEBUG_SEEK_NOTHING 0 -#define _DEBUG_SEEK_CALLK 1 // Step forward until callk is found -#define _DEBUG_SEEK_LEVEL_RET 2 // Step forward until returned from this level -#define _DEBUG_SEEK_SPECIAL_CALLK 3 // Step forward until a /special/ callk is found -#define _DEBUG_SEEK_SO 5 // Step forward until specified PC (after the send command) and stack depth -#define _DEBUG_SEEK_GLOBAL 6 // Step forward until one specified global variable is modified +extern int g_debug_seek_special; static reg_t *p_pc; static StackPtr *p_sp; @@ -105,89 +95,6 @@ int c_step(EngineState *s, const Common::Array &cmdParams) { return 0; } -enum { - _parse_eoi, - _parse_token_pareno, - _parse_token_parenc, - _parse_token_nil, - _parse_token_number -}; - -int _parse_getinp(int *i, int *nr, const Common::Array &cmdParams) { - const char *token; - - if ((unsigned)*i == cmdParams.size()) - return _parse_eoi; - - token = cmdParams[(*i)++].str; - - if (!strcmp(token, "(")) - return _parse_token_pareno; - - if (!strcmp(token, ")")) - return _parse_token_parenc; - - if (!strcmp(token, "nil")) - return _parse_token_nil; - - *nr = strtol(token, NULL, 0); - - return _parse_token_number; -} - -int _parse_nodes(EngineState *s, int *i, int *pos, int type, int nr, const Common::Array &cmdParams) { - int nexttk, nextval, newpos, oldpos; - - if (type == _parse_token_nil) - return 0; - - if (type == _parse_token_number) { - s->parser_nodes[*pos += 1].type = PARSE_TREE_NODE_LEAF; - s->parser_nodes[*pos].content.value = nr; - return *pos; - } - if (type == _parse_eoi) { - sciprintf("Unbalanced parentheses\n"); - return -1; - } - if (type == _parse_token_parenc) { - sciprintf("Syntax error at token %d\n", *i); - return -1; - } - s->parser_nodes[oldpos = ++(*pos)].type = PARSE_TREE_NODE_BRANCH; - - nexttk = _parse_getinp(i, &nextval, cmdParams); - if ((newpos = s->parser_nodes[oldpos].content.branches[0] = _parse_nodes(s, i, pos, nexttk, nextval, cmdParams)) == -1) - return -1; - - nexttk = _parse_getinp(i, &nextval, cmdParams); - if ((newpos = s->parser_nodes[oldpos].content.branches[1] = _parse_nodes(s, i, pos, nexttk, nextval, cmdParams)) == -1) - return -1; - - if (_parse_getinp(i, &nextval, cmdParams) != _parse_token_parenc) - sciprintf("Expected ')' at token %d\n", *i); - - return oldpos; -} - -int c_set_parse_nodes(EngineState *s, const Common::Array &cmdParams) { - int i = 0; - int foo, bar; - int pos = -1; - - if (!s) { - sciprintf("Not in debug state\n"); - return 1; - } - - bar = _parse_getinp(&i, &foo, cmdParams); - if (_parse_nodes(s, &i, &pos, bar, foo, cmdParams) == -1) - return 1; - - vocab_dump_parse_tree("debug-parse-tree", s->parser_nodes); - return 0; -} - extern const char *selector_name(EngineState *s, int selector); int prop_ofs_to_id(EngineState *s, int prop_ofs, reg_t objp) { @@ -528,15 +435,10 @@ static int c_disasm(EngineState *s, const Common::Array &cmdParams) return 0; } -static int c_sg(EngineState *s, const Common::Array &cmdParams) { - g_debug_seeking = _DEBUG_SEEK_GLOBAL; - s_debug_seek_special = cmdParams[0].val; - g_debugstate_valid = 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; @@ -564,24 +466,18 @@ static int c_snk(EngineState *s, const Common::Array &cmdParams) { } } - g_debug_seeking = _DEBUG_SEEK_SPECIAL_CALLK; - s_debug_seek_special = callk_index; + g_debug_seeking = kDebugSeekSpecialCallk; + g_debug_seek_special = callk_index; g_debugstate_valid = 0; } else { - g_debug_seeking = _DEBUG_SEEK_CALLK; + g_debug_seeking = kDebugSeekCallk; g_debugstate_valid = 0; } +#endif return 0; } -static int c_sret(EngineState *s, const Common::Array &cmdParams) { - g_debug_seeking = _DEBUG_SEEK_LEVEL_RET; - s_debug_seek_level = s->_executionStack.size()-1; - g_debugstate_valid = 0; - return 0; -} - static int c_go(EngineState *s, const Common::Array &cmdParams) { g_debug_seeking = 0; g_debugstate_valid = 0; @@ -645,15 +541,10 @@ static int c_send(EngineState *s, const Common::Array &cmdParams) { // Breakpoint commands -int c_se(EngineState *s, const Common::Array &cmdParams) { - g_stop_on_event = 1; - g_debugstate_valid = 0; - - return 0; -} - void script_debug(EngineState *s, reg_t *pc, StackPtr *sp, StackPtr *pp, reg_t *objp, int *restadjust, SegmentId *segids, reg_t **variables, reg_t **variables_base, int *variables_nr, int bp) { +// TODO: disabled till this is moved in console.cpp +#if 0 // Do we support a separate console? int old_debugstate = g_debugstate_valid; @@ -670,9 +561,9 @@ void script_debug(EngineState *s, reg_t *pc, StackPtr *sp, StackPtr *pp, reg_t * sciprintf("%d: acc=%04x:%04x ", script_step_counter, PRINT_REG(s->r_acc)); g_debugstate_valid = 1; disassemble(s, *pc, 0, 1); - if (g_debug_seeking == _DEBUG_SEEK_GLOBAL) - sciprintf("Global %d (0x%x) = %04x:%04x\n", s_debug_seek_special, - s_debug_seek_special, PRINT_REG(s->script_000->locals_block->_locals[s_debug_seek_special])); + if (g_debug_seeking == kDebugSeekGlobal) + sciprintf("Global %d (0x%x) = %04x:%04x\n", g_debug_seek_special, + g_debug_seek_special, PRINT_REG(s->script_000->locals_block->_locals[g_debug_seek_special])); g_debugstate_valid = old_debugstate; @@ -689,39 +580,40 @@ void script_debug(EngineState *s, reg_t *pc, StackPtr *sp, StackPtr *pp, reg_t * int paramf1 = (opcode & 1) ? paramb1 : (pc->offset + 2 >= code_buf_size ? 0 : (int16)READ_LE_UINT16(code_buf + pc->offset + 1)); switch (g_debug_seeking) { - case _DEBUG_SEEK_SPECIAL_CALLK: - if (paramb1 != s_debug_seek_special) + case kDebugSeekSpecialCallk: + if (paramb1 != g_debug_seek_special) return; - case _DEBUG_SEEK_CALLK: { + case kDebugSeekCallk: { if (op != op_callk) return; break; } - case _DEBUG_SEEK_LEVEL_RET: { - if ((op != op_ret) || (s_debug_seek_level < (int)s->_executionStack.size()-1)) + case kDebugSeekLevelRet: { + if ((op != op_ret) || (g_debug_seek_level < (int)s->_executionStack.size()-1)) return; break; } - case _DEBUG_SEEK_GLOBAL: + case kDebugSeekGlobal: if (op < op_sag) return; if ((op & 0x3) > 1) return; // param or temp if ((op & 0x3) && s->_executionStack.back().local_segment > 0) return; // locals and not running in script.000 - if (paramf1 != s_debug_seek_special) + if (paramf1 != g_debug_seek_special) return; // CORRECT global? break; } - g_debug_seeking = _DEBUG_SEEK_NOTHING; + g_debug_seeking = kDebugSeekNothing; // OK, found whatever we were looking for } } +#endif g_debugstate_valid = (g_debug_step_running == 0); @@ -739,9 +631,6 @@ 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); - if (!s_debug_commands_hooked) { - s_debug_commands_hooked = true; - 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" @@ -753,17 +642,8 @@ void script_debug(EngineState *s, reg_t *pc, StackPtr *sp, StackPtr *pp, reg_t * 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_se, "se", "", "Steps forward until an SCI event is received.\n"); con_hook_command(c_send, "send", "!asa*", "Sends a message to an object\nExample: send ?fooScript cue"); - con_hook_command(c_sret, "sret", "", "Steps forward until ret is called\n on the current execution stack\n level."); con_hook_command(c_go, "go", "", "Executes the script.\n"); - con_hook_command(c_set_parse_nodes, "set_parse_nodes", "s*", "Sets the contents of all parse nodes.\n" - " Input token must be separated by\n blanks."); - con_hook_command(c_sg, "sg", "!i", - "Steps until the global variable with the\n" - "specified index is modified.\n\nSEE ALSO\n\n" - " s.1, snk.1, so.1, bpx.1"); - } // If commands were not hooked up } if (g_debug_step_running) diff --git a/engines/sci/vocabulary.cpp b/engines/sci/vocabulary.cpp index b12114d845..c25f045561 100644 --- a/engines/sci/vocabulary.cpp +++ b/engines/sci/vocabulary.cpp @@ -488,7 +488,7 @@ void _vocab_recursive_ptree_dump_treelike(parse_tree_node_t *nodes, int nr, int return; } - if (nodes[nr].type == PARSE_TREE_NODE_LEAF) + if (nodes[nr].type == kParseTreeLeafNode) //sciprintf("[%03x]%04x", nr, nodes[nr].content.value); sciprintf("%x", nodes[nr].content.value); else { @@ -518,7 +518,7 @@ void _vocab_recursive_ptree_dump(parse_tree_node_t *nodes, int nr, int prevnr, i int rbranch = nodes[nr].content.branches[1]; int i; - if (nodes[nr].type == PARSE_TREE_NODE_LEAF) { + if (nodes[nr].type == kParseTreeLeafNode) { sciprintf("vocab_dump_parse_tree: Error: consp is nil for element %03x\n", nr); return; } @@ -529,7 +529,7 @@ void _vocab_recursive_ptree_dump(parse_tree_node_t *nodes, int nr, int prevnr, i } if (lbranch) { - if (nodes[lbranch].type == PARSE_TREE_NODE_BRANCH) { + if (nodes[lbranch].type == kParseTreeBranchNode) { sciprintf("\n"); for (i = 0; i < blanks; i++) sciprintf(" "); @@ -544,7 +544,7 @@ void _vocab_recursive_ptree_dump(parse_tree_node_t *nodes, int nr, int prevnr, i }/* else sciprintf ("nil");*/ if (rbranch) { - if (nodes[rbranch].type == PARSE_TREE_NODE_BRANCH) + if (nodes[rbranch].type == kParseTreeBranchNode) _vocab_recursive_ptree_dump(nodes, rbranch, nr, blanks); else sciprintf("%x", nodes[rbranch].content.value); diff --git a/engines/sci/vocabulary.h b/engines/sci/vocabulary.h index 9f0d277ef2..ce6d48c570 100644 --- a/engines/sci/vocabulary.h +++ b/engines/sci/vocabulary.h @@ -160,9 +160,10 @@ struct parse_tree_branch_t { int data[10]; }; -#define PARSE_TREE_NODE_LEAF 0 -#define PARSE_TREE_NODE_BRANCH 1 - +enum ParseTypes { + kParseTreeLeafNode = 0, + kParseTreeBranchNode = 1 +}; struct parse_tree_node_t { short type; /* leaf or branch */ -- cgit v1.2.3