diff options
| author | Filippos Karapetis | 2009-07-02 23:58:05 +0000 | 
|---|---|---|
| committer | Filippos Karapetis | 2009-07-02 23:58:05 +0000 | 
| commit | c3403ac7395cf9df9c4dad57b42e600b200660b5 (patch) | |
| tree | 3795df52aaa5052473792548b7d7fdae8f0566e6 | |
| parent | 80cb18e87fb2a0a6ecc3c7f96c5b8366550648ea (diff) | |
| download | scummvm-rg350-c3403ac7395cf9df9c4dad57b42e600b200660b5.tar.gz scummvm-rg350-c3403ac7395cf9df9c4dad57b42e600b200660b5.tar.bz2 scummvm-rg350-c3403ac7395cf9df9c4dad57b42e600b200660b5.zip | |
Moved some more debug state related variables in the DebugState struct
svn-id: r42044
| -rw-r--r-- | engines/sci/console.cpp | 70 | ||||
| -rw-r--r-- | engines/sci/console.h | 9 | ||||
| -rw-r--r-- | engines/sci/debug.h | 28 | ||||
| -rw-r--r-- | engines/sci/engine/kevent.cpp | 12 | ||||
| -rw-r--r-- | engines/sci/engine/kmisc.cpp | 5 | ||||
| -rw-r--r-- | engines/sci/engine/scriptdebug.cpp | 34 | ||||
| -rw-r--r-- | engines/sci/engine/vm.cpp | 15 | 
7 files changed, 86 insertions, 87 deletions
| diff --git a/engines/sci/console.cpp b/engines/sci/console.cpp index 9433b5a625..002acbae86 100644 --- a/engines/sci/console.cpp +++ b/engines/sci/console.cpp @@ -50,10 +50,6 @@ 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  extern DebugState debugState;  Console::Console(SciEngine *vm) : GUI::Debugger() { @@ -193,6 +189,12 @@ Console::Console(SciEngine *vm) : GUI::Debugger() {  	con_hook_int(&(gfx_options.dirty_frames), "dirty_frames",  		"Dirty frames management\n");  	*/ + +	debugState.isValid = false; +	debugState.seeking = kDebugSeekNothing; +	debugState.seekLevel = 0; +	debugState.runningStep = 0; +	debugState.stopOnEvent = false;  }  Console::~Console() { @@ -833,7 +835,7 @@ bool Console::cmdRestoreGame(int argc, const char **argv) {  		_vm->_gamestate->successor = newstate; // Set successor  		script_abort_flag = 2; // Abort current game with replay -		g_debugstate_valid = 0; +		debugState.isValid = false;  		shrink_execution_stack(_vm->_gamestate, _vm->_gamestate->execution_stack_base + 1);  		return 0; @@ -864,7 +866,7 @@ bool Console::cmdRestartGame(int argc, const char **argv) {  	_vm->_gamestate->restarting_flags |= SCI_GAME_IS_RESTARTING_NOW;  	script_abort_flag = 1; -	g_debugstate_valid = 0; +	debugState.isValid = false;  	return false;  } @@ -2086,24 +2088,24 @@ bool Console::cmdBacktrace(int argc, const char **argv) {  }  bool Console::cmdStep(int argc, const char **argv) { -	g_debugstate_valid = 0; +	debugState.isValid = false;  	if (argc == 2 && atoi(argv[1]) > 0) -		g_debug_step_running = atoi(argv[1]) - 1; +		debugState.runningStep = atoi(argv[1]) - 1;  	return true;  }  bool Console::cmdStepEvent(int argc, const char **argv) { -	g_stop_on_event = 1; -	g_debugstate_valid = 0; +	debugState.stopOnEvent = true; +	debugState.isValid = false;  	return true;  }  bool Console::cmdStepRet(int argc, const char **argv) { -	g_debug_seeking = kDebugSeekLevelRet; -	g_debug_seek_level = _vm->_gamestate->_executionStack.size() - 1; -	g_debugstate_valid = 0; +	debugState.seeking = kDebugSeekLevelRet; +	debugState.seekLevel = _vm->_gamestate->_executionStack.size() - 1; +	debugState.isValid = false;  	return true;  } @@ -2115,9 +2117,9 @@ bool Console::cmdStepGlobal(int argc, const char **argv) {  		return true;  	} -	g_debug_seeking = kDebugSeekGlobal; -	g_debug_seek_special = atoi(argv[1]); -	g_debugstate_valid = 0; +	debugState.seeking = kDebugSeekGlobal; +	debugState.seekSpecial = atoi(argv[1]); +	debugState.isValid = false;  	return true;  } @@ -2145,12 +2147,12 @@ bool Console::cmdStepCallk(int argc, const char **argv) {  			}  		} -		g_debug_seeking = kDebugSeekSpecialCallk; -		g_debug_seek_special = callk_index; -		g_debugstate_valid = 0; +		debugState.seeking = kDebugSeekSpecialCallk; +		debugState.seekSpecial = callk_index; +		debugState.isValid = false;  	} else { -		g_debug_seeking = kDebugSeekCallk; -		g_debugstate_valid = 0; +		debugState.seeking = kDebugSeekCallk; +		debugState.isValid = false;  	}  	return true; @@ -2326,8 +2328,8 @@ bool Console::cmdSend(int argc, const char **argv) {  }  bool Console::cmdGo(int argc, const char **argv) { -	g_debug_seeking = 0; -	g_debugstate_valid = 0; +	debugState.seeking = kDebugSeekNothing; +	debugState.isValid = false;  	return true;  } @@ -2741,9 +2743,9 @@ bool Console::cmdExit(int argc, const char **argv) {  	if (!scumm_stricmp(argv[1], "game")) {  		// Quit gracefully  		script_abort_flag = 1; // Terminate VM -		g_debugstate_valid = 0; -		g_debug_seeking = 0; -		g_debug_step_running = 0; +		debugState.isValid = false; +		debugState.seeking = kDebugSeekNothing; +		debugState.runningStep = 0;  	} else if (!scumm_stricmp(argv[1], "now")) {  		// Quit ungracefully @@ -3231,34 +3233,34 @@ int c_stepover(EngineState *s, const Common::Array<cmd_param_t> &cmdParams) {  		return 1;  	} -	g_debugstate_valid = 0; +	debugState.isValid = false;  	opcode = s->_heap[*p_pc];  	opnumber = opcode >> 1;  	if (opnumber == 0x22 /* callb */ || opnumber == 0x23 /* calle */ ||  	        opnumber == 0x25 /* send */ || opnumber == 0x2a /* self */ || opnumber == 0x2b /* super */) { -		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 +		debugState.seeking = kDebugSeekSO; +		debugState.seekLevel = s->_executionStack.size()-1; +		// Store in debugState.seekSpecial the offset of the next command after send  		switch (opcode) {  		case 0x46: // calle W -			g_debug_seek_special = *p_pc + 5; +			debugState.seekSpecial = *p_pc + 5;  			break;  		case 0x44: // callb W  		case 0x47: // calle B  		case 0x56: // super W -			g_debug_seek_special = *p_pc + 4; +			debugState.seekSpecial = *p_pc + 4;  			break;  		case 0x45: // callb B  		case 0x57: // super B  		case 0x4A: // send W  		case 0x54: // self W -			g_debug_seek_special = *p_pc + 3; +			debugState.seekSpecial = *p_pc + 3;  			break;  		default: -			g_debug_seek_special = *p_pc + 2; +			debugState.seekSpecial = *p_pc + 2;  		}  	} diff --git a/engines/sci/console.h b/engines/sci/console.h index 22b5505bf2..c45202de16 100644 --- a/engines/sci/console.h +++ b/engines/sci/console.h @@ -35,15 +35,6 @@ namespace Sci {  class SciEngine;  struct List; -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 -}; -  // Refer to the "addresses" command on how to pass address parameters  int parse_reg_t(EngineState *s, const char *str, reg_t *dest);  int printObject(EngineState *s, reg_t pos); diff --git a/engines/sci/debug.h b/engines/sci/debug.h index 2be28ac905..60bf938300 100644 --- a/engines/sci/debug.h +++ b/engines/sci/debug.h @@ -29,23 +29,27 @@  namespace Sci {  // Various global variables used for debugging are declared here - -extern int g_stop_on_event; - -extern int g_debugstate_valid; -extern int g_debug_seeking; -extern int g_debug_step_running; -  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; + +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 +};  struct DebugState { +	bool isValid; +	bool stopOnEvent; +	DebugSeeking seeking;		// Stepping forward until some special condition is met +	int runningStep;			// Set to > 0 to allow multiple stepping +	int seekLevel;				// Used for seekers that want to check their exec stack depth +	int seekSpecial;			// Used for special seeks  	reg_t *p_pc;  	StackPtr *p_sp;  	StackPtr *p_pp; @@ -54,7 +58,7 @@ struct DebugState {  	SegmentId *p_var_segs;  	reg_t **p_vars;  	reg_t **p_var_base; -	int *p_var_max; // May be NULL even in valid state! +	int *p_var_max;				// May be NULL even in valid state!  };  } // End of namespace Sci diff --git a/engines/sci/engine/kevent.cpp b/engines/sci/engine/kevent.cpp index d5a725a230..3b37506e6c 100644 --- a/engines/sci/engine/kevent.cpp +++ b/engines/sci/engine/kevent.cpp @@ -33,7 +33,7 @@  namespace Sci { -int g_stop_on_event = 0; +extern DebugState debugState;  #define SCI_VARIABLE_GAME_SPEED 3 @@ -90,10 +90,12 @@ reg_t kGetEvent(EngineState *s, int funct_nr, int argc, reg_t *argv) {  	case SCI_EVT_KEYBOARD:  		if ((e.buckybits & SCI_EVM_LSHIFT) && (e.buckybits & SCI_EVM_RSHIFT) && (e.data == '-')) {  			sciprintf("Debug mode activated\n"); -			g_debug_seeking = g_debug_step_running = 0; +			debugState.seeking = kDebugSeekNothing; +			debugState.runningStep = 0;  		} else if ((e.buckybits & SCI_EVM_CTRL) && (e.data == '`')) {  			sciprintf("Debug mode activated\n"); -			g_debug_seeking = g_debug_step_running = 0; +			debugState.seeking = kDebugSeekNothing; +			debugState.runningStep = 0;  		} else {  			PUT_SEL32V(obj, type, SCI_EVT_KEYBOARD); // Keyboard event  			s->r_acc = make_reg(0, 1); @@ -137,8 +139,8 @@ reg_t kGetEvent(EngineState *s, int funct_nr, int argc, reg_t *argv) {  		s->r_acc = NULL_REG; // Unknown or no event  	} -	if ((s->r_acc.offset) && (g_stop_on_event)) { -		g_stop_on_event = 0; +	if ((s->r_acc.offset) && (debugState.stopOnEvent)) { +		debugState.stopOnEvent = false;  		// A SCI event occured, and we have been asked to stop, so open the debug console  		GUI::Debugger *con = ((Sci::SciEngine*)g_engine)->getDebugger(); diff --git a/engines/sci/engine/kmisc.cpp b/engines/sci/engine/kmisc.cpp index 7954dc5783..99665bae7d 100644 --- a/engines/sci/engine/kmisc.cpp +++ b/engines/sci/engine/kmisc.cpp @@ -93,10 +93,13 @@ reg_t kFlushResources(EngineState *s, int funct_nr, int argc, reg_t *argv) {  	return s->r_acc;  } +extern DebugState debugState; +  reg_t kSetDebug(EngineState *s, int funct_nr, int argc, reg_t *argv) {  	sciprintf("Debug mode activated\n"); -	g_debug_seeking = g_debug_step_running = 0; +	debugState.seeking = kDebugSeekNothing; +	debugState.runningStep = 0;  	return s->r_acc;  } diff --git a/engines/sci/engine/scriptdebug.cpp b/engines/sci/engine/scriptdebug.cpp index 0bd1442cf4..dbcd778160 100644 --- a/engines/sci/engine/scriptdebug.cpp +++ b/engines/sci/engine/scriptdebug.cpp @@ -32,10 +32,6 @@  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 -extern int g_debug_seek_special; -  extern const char *selector_name(EngineState *s, int selector);  DebugState debugState; @@ -101,7 +97,7 @@ reg_t disassemble(EngineState *s, reg_t pos, int print_bw_tag, int print_bytecod  	opsize = scr[pos.offset];  	opcode = opsize >> 1; -	if (!g_debugstate_valid) { +	if (!debugState.isValid) {  		sciprintf("Not in debug state\n");  		return retval;  	} @@ -321,7 +317,7 @@ void script_debug(EngineState *s, reg_t *pc, StackPtr *sp, StackPtr *pp, reg_t *  	SegmentId *segids, reg_t **variables, reg_t **variables_base, int *variables_nr, int bp) {  	// Do we support a separate console? -	int old_debugstate = g_debugstate_valid; +	bool old_debugstate = debugState.isValid;  	debugState.p_var_segs = segids;  	debugState.p_vars = variables; @@ -333,15 +329,15 @@ void script_debug(EngineState *s, reg_t *pc, StackPtr *sp, StackPtr *pp, reg_t *  	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; +	debugState.isValid = true;  	disassemble(s, *pc, 0, 1); -	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])); +	if (debugState.seeking == kDebugSeekGlobal) +		sciprintf("Global %d (0x%x) = %04x:%04x\n", debugState.seekSpecial, +		          debugState.seekSpecial, PRINT_REG(s->script_000->locals_block->_locals[debugState.seekSpecial])); -	g_debugstate_valid = old_debugstate; +	debugState.isValid = old_debugstate; -	if (g_debug_seeking && !bp) { // Are we looking for something special? +	if (debugState.seeking && !bp) { // Are we looking for something special?  		MemObject *mobj = GET_SEGMENT(*s->seg_manager, pc->segment, MEM_OBJ_SCRIPT);  		if (mobj) { @@ -353,9 +349,9 @@ void script_debug(EngineState *s, reg_t *pc, StackPtr *sp, StackPtr *pp, reg_t *  			int paramb1 = pc->offset + 1 >= code_buf_size ? 0 : code_buf[pc->offset + 1];  			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) { +			switch (debugState.seeking) {  			case kDebugSeekSpecialCallk: -				if (paramb1 != g_debug_seek_special) +				if (paramb1 != debugState.seekSpecial)  					return;  			case kDebugSeekCallk: { @@ -365,7 +361,7 @@ void script_debug(EngineState *s, reg_t *pc, StackPtr *sp, StackPtr *pp, reg_t *  			}  			case kDebugSeekLevelRet: { -				if ((op != op_ret) || (g_debug_seek_level < (int)s->_executionStack.size()-1)) +				if ((op != op_ret) || (debugState.seekLevel < (int)s->_executionStack.size()-1))  					return;  				break;  			} @@ -377,20 +373,20 @@ void script_debug(EngineState *s, reg_t *pc, StackPtr *sp, StackPtr *pp, reg_t *  					return; // param or temp  				if ((op & 0x3) && s->_executionStack.back().local_segment > 0)  					return; // locals and not running in script.000 -				if (paramf1 != g_debug_seek_special) +				if (paramf1 != debugState.seekSpecial)  					return; // CORRECT global?  				break;  			} -			g_debug_seeking = kDebugSeekNothing; +			debugState.seeking = kDebugSeekNothing;  			// OK, found whatever we were looking for  		}  	} -	g_debugstate_valid = (g_debug_step_running == 0); +	debugState.isValid = (debugState.runningStep == 0); -	if (g_debugstate_valid) { +	if (debugState.isValid) {  		debugState.p_pc = pc;  		debugState.p_sp = sp;  		debugState.p_pp = pp; diff --git a/engines/sci/engine/vm.cpp b/engines/sci/engine/vm.cpp index cbd0b0cfbb..30b2f07edd 100644 --- a/engines/sci/engine/vm.cpp +++ b/engines/sci/engine/vm.cpp @@ -49,7 +49,7 @@ reg_t NULL_REG = {0, 0};  int script_abort_flag = 0; // Set to 1 to abort execution. Set to 2 to force a replay afterwards	// FIXME: Avoid non-const global vars  int script_step_counter = 0; // Counts the number of steps executed	// FIXME: Avoid non-const global vars  int script_gc_interval = GC_INTERVAL; // Number of steps in between gcs	// FIXME: Avoid non-const global vars - +extern DebugState debugState;  static bool breakpointFlag = false;	// FIXME: Avoid non-const global vars  static reg_t _dummy_register;		// FIXME: Avoid non-const global vars @@ -396,7 +396,7 @@ ExecStack *send_selector(EngineState *s, reg_t send_obj, reg_t work_obj, StackPt  			default:  				sciprintf("Send error: Variable selector %04x in %04x:%04x called with %04x params\n", selector, PRINT_REG(send_obj), argc);  				script_debug_flag = 1; // Enter debug mode -				g_debug_seeking = g_debug_step_running = 0; +				debugState.seeking = debugState.runningStep = 0;  #endif  			}  			break; @@ -1427,8 +1427,8 @@ void run_vm(EngineState *s, int restoring) {  #if 0  		if (script_error_flag) { -			g_debug_step_running = 0; // Stop multiple execution -			g_debug_seeking = 0; // Stop special seeks +			debugState.runningStep = 0; // Stop multiple execution +			debugState.seeking = 0; // Stop special seeks  			xs->addr.pc.offset = old_pc_offset;  			xs->sp = old_sp;  		} else @@ -2057,11 +2057,12 @@ const char *obj_get_name(EngineState *s, reg_t pos) {  	return name;  } +  void quit_vm() {  	script_abort_flag = 1; // Terminate VM -	g_debugstate_valid = 0; -	g_debug_seeking = 0; -	g_debug_step_running = 0; +	debugState.isValid = false; +	debugState.seeking = kDebugSeekNothing; +	debugState.runningStep = 0;  }  void shrink_execution_stack(EngineState *s, uint size) { | 
