Moved all the debug state variables in a separate struct and re-enabled several places where they're used

svn-id: r42043
This commit is contained in:
Filippos Karapetis 2009-07-02 23:16:40 +00:00
parent 650248dbd1
commit 80cb18e87f
3 changed files with 59 additions and 75 deletions

View file

@ -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_seeking = 0; // Stepping forward until some special condition is met
int g_debug_seek_special = 0; // Used for special seeks 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 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() { Console::Console(SciEngine *vm) : GUI::Debugger() {
_vm = vm; _vm = vm;
@ -522,16 +523,13 @@ bool Console::cmdSetParseNodes(int argc, const char **argv) {
bool Console::cmdRegisters(int argc, const char **argv) { bool Console::cmdRegisters(int argc, const char **argv) {
DebugPrintf("Current register values:\n"); DebugPrintf("Current register values:\n");
#if 0 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);
// 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
if (!_vm->_gamestate->_executionStack.empty()) { if (!_vm->_gamestate->_executionStack.empty()) {
#if 0 EngineState *s = _vm->_gamestate; // for PRINT_STK
// TODO: p_pc, p_objp, p_pp, p_sp DebugPrintf("pc=%04x:%04x obj=%04x:%04x fp=ST:%04x sp=ST:%04x\n",
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)); PRINT_REG(*debugState.p_pc), PRINT_REG(*debugState.p_objp),
#endif PRINT_STK(*debugState.p_pp), PRINT_STK(*debugState.p_sp));
} else } else
DebugPrintf("<no execution stack: pc,obj,fp omitted>\n"); 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) { 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"); 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++) { 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]))); 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 (p_var_max) if (debugState.p_var_max)
DebugPrintf(" total %d", p_var_max[i]); DebugPrintf(" total %d", debugState.p_var_max[i]);
DebugPrintf("\n"); DebugPrintf("\n");
} }
#endif
return true; return true;
} }
@ -1718,7 +1712,7 @@ bool Console::cmdVMVars(int argc, const char **argv) {
return true; return true;
} }
//const char *varnames[] = {"global", "local", "temp", "param"}; const char *varnames[] = {"global", "local", "temp", "param"};
const char *varabbrev = "gltp"; const char *varabbrev = "gltp";
const char *vartype_pre = strchr(varabbrev, *argv[1]); const char *vartype_pre = strchr(varabbrev, *argv[1]);
int vartype; int vartype;
@ -1736,31 +1730,21 @@ bool Console::cmdVMVars(int argc, const char **argv) {
return true; return true;
} }
#if 0 if ((debugState.p_var_max) && (debugState.p_var_max[vartype] <= idx)) {
// TODO: p_var_max DebugPrintf("Max. index is %d (0x%x)\n", debugState.p_var_max[vartype], debugState.p_var_max[vartype]);
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]);
return true; return true;
} }
#endif
switch (argc) { switch (argc) {
case 2: case 2:
#if 0 DebugPrintf("%s var %d == %04x:%04x\n", varnames[vartype], idx, PRINT_REG(debugState.p_vars[vartype][idx]));
// TODO: p_vars
DebugPrintf("%s var %d == %04x:%04x\n", varnames[vartype], idx, PRINT_REG(p_vars[vartype][idx]));
#endif
break; break;
case 3: case 3:
#if 0 if (parse_reg_t(_vm->_gamestate, argv[3], &debugState.p_vars[vartype][idx])) {
// TODO: p_vars
if (parse_reg_t(_vm->_gamestate, argv[3], &p_vars[vartype][idx])) {
DebugPrintf("Invalid address passed.\n"); DebugPrintf("Invalid address passed.\n");
DebugPrintf("Check the \"addresses\" command on how to use addresses\n"); DebugPrintf("Check the \"addresses\" command on how to use addresses\n");
return true; return true;
} }
#endif
break; break;
default: default:
DebugPrintf("Too many arguments\n"); 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) { bool Console::cmdViewActiveObject(int argc, const char **argv) {
DebugPrintf("Information on the currently active object or class:\n"); DebugPrintf("Information on the currently active object or class:\n");
printObject(_vm->_gamestate, *debugState.p_objp);
#if 0
// TODO: p_objp
printObject(_vm->_gamestate, *p_objp);
#endif
return true; return true;
} }

View file

@ -45,6 +45,18 @@ extern int g_debug_seeking;
extern int g_debug_seek_special; extern int g_debug_seek_special;
extern int g_debug_seek_level; 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 } // End of namespace Sci
#endif #endif

View file

@ -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 int g_debug_step_running = 0; // Set to >0 to allow multiple stepping
extern int g_debug_seek_special; 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); extern const char *selector_name(EngineState *s, int selector);
DebugState debugState;
int propertyOffsetToId(EngineState *s, int prop_ofs, reg_t objp) { int propertyOffsetToId(EngineState *s, int prop_ofs, reg_t objp) {
Object *obj = obj_get(s, objp); Object *obj = obj_get(s, objp);
byte *selectoroffset; 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) || 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)) { (opcode == op_dpToa) || (opcode == op_ipToa) || (opcode == op_dpTos) || (opcode == op_ipTos)) {
int prop_ofs = scr[pos.offset + 1]; 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)); 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"); 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) { if (opcode == op_callk) {
int stackframe = (scr[pos.offset + 2] >> 1) + (*p_restadjust); int stackframe = (scr[pos.offset + 2] >> 1) + (*debugState.p_restadjust);
int argc = ((*p_sp)[- stackframe - 1]).offset; int argc = ((*debugState.p_sp)[- stackframe - 1]).offset;
if (!(s->_flags & GF_SCI0_OLD)) if (!(s->_flags & GF_SCI0_OLD))
argc += (*p_restadjust); argc += (*debugState.p_restadjust);
sciprintf(" Kernel params: ("); sciprintf(" Kernel params: (");
for (int j = 0; j < argc; j++) { 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) if (j + 1 < argc)
sciprintf(", "); sciprintf(", ");
} }
sciprintf(")\n"); sciprintf(")\n");
} else if ((opcode == op_send) || (opcode == op_self)) { } 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; int stackframe = (scr[pos.offset + 1] >> 1) + restmod;
reg_t *sb = *p_sp; reg_t *sb = *debugState.p_sp;
uint16 selector; uint16 selector;
reg_t fun_ref; reg_t fun_ref;
while (stackframe > 0) { while (stackframe > 0) {
int argc = sb[- stackframe + 1].offset; int argc = sb[- stackframe + 1].offset;
const char *name = NULL; const char *name = NULL;
reg_t called_obj_addr = *p_objp; reg_t called_obj_addr = *debugState.p_objp;
if (opcode == op_send) if (opcode == op_send)
called_obj_addr = s->r_acc; called_obj_addr = s->r_acc;
else if (opcode == op_self) else if (opcode == op_self)
called_obj_addr = *p_objp; called_obj_addr = *debugState.p_objp;
selector = sb[- stackframe].offset; 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; int old_debugstate = g_debugstate_valid;
p_var_segs = segids; debugState.p_var_segs = segids;
p_vars = variables; debugState.p_vars = variables;
p_var_max = variables_nr; debugState.p_var_max = variables_nr;
p_var_base = variables_base; debugState.p_var_base = variables_base;
p_pc = pc; debugState.p_pc = pc;
p_sp = sp; debugState.p_sp = sp;
p_pp = pp; debugState.p_pp = pp;
p_objp = objp; debugState.p_objp = objp;
p_restadjust = restadjust; debugState.p_restadjust = restadjust;
sciprintf("%d: acc=%04x:%04x ", script_step_counter, PRINT_REG(s->r_acc)); sciprintf("%d: acc=%04x:%04x ", script_step_counter, PRINT_REG(s->r_acc));
g_debugstate_valid = 1; g_debugstate_valid = 1;
disassemble(s, *pc, 0, 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); g_debugstate_valid = (g_debug_step_running == 0);
if (g_debugstate_valid) { if (g_debugstate_valid) {
p_pc = pc; debugState.p_pc = pc;
p_sp = sp; debugState.p_sp = sp;
p_pp = pp; debugState.p_pp = pp;
p_objp = objp; debugState.p_objp = objp;
p_restadjust = restadjust; debugState.p_restadjust = restadjust;
p_var_segs = segids; debugState.p_var_segs = segids;
p_vars = variables; debugState.p_vars = variables;
p_var_max = variables_nr; debugState.p_var_max = variables_nr;
p_var_base = variables_base; debugState.p_var_base = variables_base;
sciprintf("Step #%d\n", script_step_counter); sciprintf("Step #%d\n", script_step_counter);
disassemble(s, *pc, 0, 1); disassemble(s, *pc, 0, 1);