[Scummvm-cvs-logs] SF.net SVN: scummvm:[42044] scummvm/trunk/engines/sci

thebluegr at users.sourceforge.net thebluegr at users.sourceforge.net
Fri Jul 3 01:58:05 CEST 2009


Revision: 42044
          http://scummvm.svn.sourceforge.net/scummvm/?rev=42044&view=rev
Author:   thebluegr
Date:     2009-07-02 23:58:05 +0000 (Thu, 02 Jul 2009)

Log Message:
-----------
Moved some more debug state related variables in the DebugState struct

Modified Paths:
--------------
    scummvm/trunk/engines/sci/console.cpp
    scummvm/trunk/engines/sci/console.h
    scummvm/trunk/engines/sci/debug.h
    scummvm/trunk/engines/sci/engine/kevent.cpp
    scummvm/trunk/engines/sci/engine/kmisc.cpp
    scummvm/trunk/engines/sci/engine/scriptdebug.cpp
    scummvm/trunk/engines/sci/engine/vm.cpp

Modified: scummvm/trunk/engines/sci/console.cpp
===================================================================
--- scummvm/trunk/engines/sci/console.cpp	2009-07-02 23:16:40 UTC (rev 42043)
+++ scummvm/trunk/engines/sci/console.cpp	2009-07-02 23:58:05 UTC (rev 42044)
@@ -50,10 +50,6 @@
 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 @@
 	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 @@
 		_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 @@
 
 	_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::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 @@
 		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 @@
 			}
 		}
 
-		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::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 @@
 	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 @@
 		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;
 		}
 	}
 

Modified: scummvm/trunk/engines/sci/console.h
===================================================================
--- scummvm/trunk/engines/sci/console.h	2009-07-02 23:16:40 UTC (rev 42043)
+++ scummvm/trunk/engines/sci/console.h	2009-07-02 23:58:05 UTC (rev 42044)
@@ -35,15 +35,6 @@
 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);

Modified: scummvm/trunk/engines/sci/debug.h
===================================================================
--- scummvm/trunk/engines/sci/debug.h	2009-07-02 23:16:40 UTC (rev 42043)
+++ scummvm/trunk/engines/sci/debug.h	2009-07-02 23:58:05 UTC (rev 42044)
@@ -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 @@
 	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

Modified: scummvm/trunk/engines/sci/engine/kevent.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/kevent.cpp	2009-07-02 23:16:40 UTC (rev 42043)
+++ scummvm/trunk/engines/sci/engine/kevent.cpp	2009-07-02 23:58:05 UTC (rev 42044)
@@ -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 @@
 	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 @@
 		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();

Modified: scummvm/trunk/engines/sci/engine/kmisc.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/kmisc.cpp	2009-07-02 23:16:40 UTC (rev 42043)
+++ scummvm/trunk/engines/sci/engine/kmisc.cpp	2009-07-02 23:58:05 UTC (rev 42044)
@@ -93,10 +93,13 @@
 	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;
 }
 

Modified: scummvm/trunk/engines/sci/engine/scriptdebug.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/scriptdebug.cpp	2009-07-02 23:16:40 UTC (rev 42043)
+++ scummvm/trunk/engines/sci/engine/scriptdebug.cpp	2009-07-02 23:58:05 UTC (rev 42044)
@@ -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 @@
 	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 @@
 	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 @@
 	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 @@
 			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 @@
 			}
 
 			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 @@
 					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;

Modified: scummvm/trunk/engines/sci/engine/vm.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/vm.cpp	2009-07-02 23:16:40 UTC (rev 42043)
+++ scummvm/trunk/engines/sci/engine/vm.cpp	2009-07-02 23:58:05 UTC (rev 42044)
@@ -49,8 +49,8 @@
 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 @@
 			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 @@
 
 #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 @@
 	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) {


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list