aboutsummaryrefslogtreecommitdiff
path: root/engines/sci
diff options
context:
space:
mode:
authorFilippos Karapetis2009-07-02 23:16:40 +0000
committerFilippos Karapetis2009-07-02 23:16:40 +0000
commit80cb18e87fb2a0a6ecc3c7f96c5b8366550648ea (patch)
treec47b51026b4876adc2ce358421933312d54b3aa3 /engines/sci
parent650248dbd1871444e88a01b696d5d671e636650c (diff)
downloadscummvm-rg350-80cb18e87fb2a0a6ecc3c7f96c5b8366550648ea.tar.gz
scummvm-rg350-80cb18e87fb2a0a6ecc3c7f96c5b8366550648ea.tar.bz2
scummvm-rg350-80cb18e87fb2a0a6ecc3c7f96c5b8366550648ea.zip
Moved all the debug state variables in a separate struct and re-enabled several places where they're used
svn-id: r42043
Diffstat (limited to 'engines/sci')
-rw-r--r--engines/sci/console.cpp52
-rw-r--r--engines/sci/debug.h12
-rw-r--r--engines/sci/engine/scriptdebug.cpp70
3 files changed, 59 insertions, 75 deletions
diff --git a/engines/sci/console.cpp b/engines/sci/console.cpp
index 2f2fbc5243..9433b5a625 100644
--- a/engines/sci/console.cpp
+++ b/engines/sci/console.cpp
@@ -54,6 +54,7 @@ bool g_debug_weak_validations = true;
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
+extern DebugState debugState;
Console::Console(SciEngine *vm) : GUI::Debugger() {
_vm = vm;
@@ -522,16 +523,13 @@ bool Console::cmdSetParseNodes(int argc, const char **argv) {
bool Console::cmdRegisters(int argc, const char **argv) {
DebugPrintf("Current register values:\n");
-#if 0
- // TODO: p_restadjust
- DebugPrintf("acc=%04x:%04x prev=%04x:%04x &rest=%x\n", PRINT_REG(_vm->_gamestate->r_acc), PRINT_REG(_vm->_gamestate->r_prev), *p_restadjust);
-#endif
+ DebugPrintf("acc=%04x:%04x prev=%04x:%04x &rest=%x\n", PRINT_REG(_vm->_gamestate->r_acc), PRINT_REG(_vm->_gamestate->r_prev), *debugState.p_restadjust);
if (!_vm->_gamestate->_executionStack.empty()) {
-#if 0
- // TODO: p_pc, p_objp, p_pp, p_sp
- DebugPrintf("pc=%04x:%04x obj=%04x:%04x fp=ST:%04x sp=ST:%04x\n", PRINT_REG(*p_pc), PRINT_REG(*p_objp), PRINT_STK(*p_pp), PRINT_STK(*p_sp));
-#endif
+ EngineState *s = _vm->_gamestate; // for PRINT_STK
+ DebugPrintf("pc=%04x:%04x obj=%04x:%04x fp=ST:%04x sp=ST:%04x\n",
+ PRINT_REG(*debugState.p_pc), PRINT_REG(*debugState.p_objp),
+ PRINT_STK(*debugState.p_pp), PRINT_STK(*debugState.p_sp));
} else
DebugPrintf("<no execution stack: pc,obj,fp omitted>\n");
@@ -1689,20 +1687,16 @@ bool Console::cmdGCNormalize(int argc, const char **argv) {
}
bool Console::cmdVMVarlist(int argc, const char **argv) {
- //const char *varnames[] = {"global", "local", "temp", "param"};
+ const char *varnames[] = {"global", "local", "temp", "param"};
DebugPrintf("Addresses of variables in the VM:\n");
-#if 0
- // TODO: p_var_segs, p_vars, p_var_base, p_var_max
-
for (int i = 0; i < 4; i++) {
- DebugPrintf("%s vars at %04x:%04x ", varnames[i], PRINT_REG(make_reg(p_var_segs[i], p_vars[i] - p_var_base[i])));
- if (p_var_max)
- DebugPrintf(" total %d", p_var_max[i]);
+ DebugPrintf("%s vars at %04x:%04x ", varnames[i], PRINT_REG(make_reg(debugState.p_var_segs[i], debugState.p_vars[i] - debugState.p_var_base[i])));
+ if (debugState.p_var_max)
+ DebugPrintf(" total %d", debugState.p_var_max[i]);
DebugPrintf("\n");
}
-#endif
return true;
}
@@ -1718,7 +1712,7 @@ bool Console::cmdVMVars(int argc, const char **argv) {
return true;
}
- //const char *varnames[] = {"global", "local", "temp", "param"};
+ const char *varnames[] = {"global", "local", "temp", "param"};
const char *varabbrev = "gltp";
const char *vartype_pre = strchr(varabbrev, *argv[1]);
int vartype;
@@ -1736,31 +1730,21 @@ bool Console::cmdVMVars(int argc, const char **argv) {
return true;
}
-#if 0
- // TODO: p_var_max
- if ((p_var_max) && (p_var_max[vartype] <= idx)) {
- DebugPrintf("Max. index is %d (0x%x)\n", p_var_max[vartype], p_var_max[vartype]);
+ if ((debugState.p_var_max) && (debugState.p_var_max[vartype] <= idx)) {
+ DebugPrintf("Max. index is %d (0x%x)\n", debugState.p_var_max[vartype], debugState.p_var_max[vartype]);
return true;
}
-#endif
switch (argc) {
case 2:
-#if 0
- // TODO: p_vars
- DebugPrintf("%s var %d == %04x:%04x\n", varnames[vartype], idx, PRINT_REG(p_vars[vartype][idx]));
-#endif
+ DebugPrintf("%s var %d == %04x:%04x\n", varnames[vartype], idx, PRINT_REG(debugState.p_vars[vartype][idx]));
break;
case 3:
-#if 0
- // TODO: p_vars
-
- if (parse_reg_t(_vm->_gamestate, argv[3], &p_vars[vartype][idx])) {
+ if (parse_reg_t(_vm->_gamestate, argv[3], &debugState.p_vars[vartype][idx])) {
DebugPrintf("Invalid address passed.\n");
DebugPrintf("Check the \"addresses\" command on how to use addresses\n");
return true;
}
-#endif
break;
default:
DebugPrintf("Too many arguments\n");
@@ -1995,11 +1979,7 @@ bool Console::cmdViewObject(int argc, const char **argv) {
bool Console::cmdViewActiveObject(int argc, const char **argv) {
DebugPrintf("Information on the currently active object or class:\n");
-
-#if 0
- // TODO: p_objp
- printObject(_vm->_gamestate, *p_objp);
-#endif
+ printObject(_vm->_gamestate, *debugState.p_objp);
return true;
}
diff --git a/engines/sci/debug.h b/engines/sci/debug.h
index e12d7fbe2d..2be28ac905 100644
--- a/engines/sci/debug.h
+++ b/engines/sci/debug.h
@@ -45,6 +45,18 @@ extern int g_debug_seeking;
extern int g_debug_seek_special;
extern int g_debug_seek_level;
+struct DebugState {
+ reg_t *p_pc;
+ StackPtr *p_sp;
+ StackPtr *p_pp;
+ reg_t *p_objp;
+ int *p_restadjust;
+ SegmentId *p_var_segs;
+ reg_t **p_vars;
+ reg_t **p_var_base;
+ int *p_var_max; // May be NULL even in valid state!
+};
+
} // End of namespace Sci
#endif
diff --git a/engines/sci/engine/scriptdebug.cpp b/engines/sci/engine/scriptdebug.cpp
index 11c38052db..0bd1442cf4 100644
--- a/engines/sci/engine/scriptdebug.cpp
+++ b/engines/sci/engine/scriptdebug.cpp
@@ -36,18 +36,10 @@ 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
extern int g_debug_seek_special;
-static reg_t *p_pc;
-static StackPtr *p_sp;
-static StackPtr *p_pp;
-static reg_t *p_objp;
-static int *p_restadjust;
-static SegmentId *p_var_segs;
-static reg_t **p_vars;
-static reg_t **p_var_base;
-static int *p_var_max; // May be NULL even in valid state!
-
extern const char *selector_name(EngineState *s, int selector);
+DebugState debugState;
+
int propertyOffsetToId(EngineState *s, int prop_ofs, reg_t objp) {
Object *obj = obj_get(s, objp);
byte *selectoroffset;
@@ -238,11 +230,11 @@ reg_t disassemble(EngineState *s, reg_t pos, int print_bw_tag, int print_bytecod
}
}
- if (pos == *p_pc) { // Extra information if debugging the current opcode
+ if (pos == *debugState.p_pc) { // Extra information if debugging the current opcode
if ((opcode == op_pTos) || (opcode == op_sTop) || (opcode == op_pToa) || (opcode == op_aTop) ||
(opcode == op_dpToa) || (opcode == op_ipToa) || (opcode == op_dpTos) || (opcode == op_ipTos)) {
int prop_ofs = scr[pos.offset + 1];
- int prop_id = propertyOffsetToId(s, prop_ofs, *p_objp);
+ int prop_id = propertyOffsetToId(s, prop_ofs, *debugState.p_objp);
sciprintf(" (%s)", selector_name(s, prop_id));
}
@@ -250,38 +242,38 @@ reg_t disassemble(EngineState *s, reg_t pos, int print_bw_tag, int print_bytecod
sciprintf("\n");
- if (pos == *p_pc) { // Extra information if debugging the current opcode
+ if (pos == *debugState.p_pc) { // Extra information if debugging the current opcode
if (opcode == op_callk) {
- int stackframe = (scr[pos.offset + 2] >> 1) + (*p_restadjust);
- int argc = ((*p_sp)[- stackframe - 1]).offset;
+ int stackframe = (scr[pos.offset + 2] >> 1) + (*debugState.p_restadjust);
+ int argc = ((*debugState.p_sp)[- stackframe - 1]).offset;
if (!(s->_flags & GF_SCI0_OLD))
- argc += (*p_restadjust);
+ argc += (*debugState.p_restadjust);
sciprintf(" Kernel params: (");
for (int j = 0; j < argc; j++) {
- sciprintf("%04x:%04x", PRINT_REG((*p_sp)[j - stackframe]));
+ sciprintf("%04x:%04x", PRINT_REG((*debugState.p_sp)[j - stackframe]));
if (j + 1 < argc)
sciprintf(", ");
}
sciprintf(")\n");
} else if ((opcode == op_send) || (opcode == op_self)) {
- int restmod = *p_restadjust;
+ int restmod = *debugState.p_restadjust;
int stackframe = (scr[pos.offset + 1] >> 1) + restmod;
- reg_t *sb = *p_sp;
+ reg_t *sb = *debugState.p_sp;
uint16 selector;
reg_t fun_ref;
while (stackframe > 0) {
int argc = sb[- stackframe + 1].offset;
const char *name = NULL;
- reg_t called_obj_addr = *p_objp;
+ reg_t called_obj_addr = *debugState.p_objp;
if (opcode == op_send)
called_obj_addr = s->r_acc;
else if (opcode == op_self)
- called_obj_addr = *p_objp;
+ called_obj_addr = *debugState.p_objp;
selector = sb[- stackframe].offset;
@@ -331,15 +323,15 @@ void script_debug(EngineState *s, reg_t *pc, StackPtr *sp, StackPtr *pp, reg_t *
int old_debugstate = g_debugstate_valid;
- p_var_segs = segids;
- p_vars = variables;
- p_var_max = variables_nr;
- p_var_base = variables_base;
- p_pc = pc;
- p_sp = sp;
- p_pp = pp;
- p_objp = objp;
- p_restadjust = restadjust;
+ debugState.p_var_segs = segids;
+ debugState.p_vars = variables;
+ debugState.p_var_max = variables_nr;
+ debugState.p_var_base = variables_base;
+ debugState.p_pc = pc;
+ debugState.p_sp = sp;
+ debugState.p_pp = pp;
+ debugState.p_objp = objp;
+ debugState.p_restadjust = restadjust;
sciprintf("%d: acc=%04x:%04x ", script_step_counter, PRINT_REG(s->r_acc));
g_debugstate_valid = 1;
disassemble(s, *pc, 0, 1);
@@ -399,15 +391,15 @@ void script_debug(EngineState *s, reg_t *pc, StackPtr *sp, StackPtr *pp, reg_t *
g_debugstate_valid = (g_debug_step_running == 0);
if (g_debugstate_valid) {
- p_pc = pc;
- p_sp = sp;
- p_pp = pp;
- p_objp = objp;
- p_restadjust = restadjust;
- p_var_segs = segids;
- p_vars = variables;
- p_var_max = variables_nr;
- p_var_base = variables_base;
+ debugState.p_pc = pc;
+ debugState.p_sp = sp;
+ debugState.p_pp = pp;
+ debugState.p_objp = objp;
+ debugState.p_restadjust = restadjust;
+ debugState.p_var_segs = segids;
+ debugState.p_vars = variables;
+ debugState.p_var_max = variables_nr;
+ debugState.p_var_base = variables_base;
sciprintf("Step #%d\n", script_step_counter);
disassemble(s, *pc, 0, 1);