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

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Tue Jul 13 01:20:34 CEST 2010


Revision: 50836
          http://scummvm.svn.sourceforge.net/scummvm/?rev=50836&view=rev
Author:   fingolfin
Date:     2010-07-12 23:20:33 +0000 (Mon, 12 Jul 2010)

Log Message:
-----------
SCI: Turn global object g_debugState into SciEngine member var

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
    scummvm/trunk/engines/sci/sci.cpp
    scummvm/trunk/engines/sci/sci.h

Modified: scummvm/trunk/engines/sci/console.cpp
===================================================================
--- scummvm/trunk/engines/sci/console.cpp	2010-07-12 23:19:56 UTC (rev 50835)
+++ scummvm/trunk/engines/sci/console.cpp	2010-07-12 23:20:33 UTC (rev 50836)
@@ -66,8 +66,8 @@
 // Refer to the "addresses" command on how to pass address parameters
 static int parse_reg_t(EngineState *s, const char *str, reg_t *dest, bool mayBeValue);
 
-Console::Console(SciEngine *engine) : GUI::Debugger() {
-	_engine = engine;
+Console::Console(SciEngine *engine) : GUI::Debugger(),
+	_engine(engine), _debugState(engine->_debugState) {
 
 	// Variables
 	DVar_Register("sleeptime_factor",	&g_debug_sleeptime_factor, DVAR_INT, 0);
@@ -196,14 +196,14 @@
 	DCmd_Register("active_object",		WRAP_METHOD(Console, cmdViewActiveObject));
 	DCmd_Register("acc_object",			WRAP_METHOD(Console, cmdViewAccumulatorObject));
 
-	g_debugState.seeking = kDebugSeekNothing;
-	g_debugState.seekLevel = 0;
-	g_debugState.runningStep = 0;
-	g_debugState.stopOnEvent = false;
-	g_debugState.debugging = false;
-	g_debugState.breakpointWasHit = false;
-	g_debugState._breakpoints.clear(); // No breakpoints defined
-	g_debugState._activeBreakpointTypes = 0;
+	_debugState.seeking = kDebugSeekNothing;
+	_debugState.seekLevel = 0;
+	_debugState.runningStep = 0;
+	_debugState.stopOnEvent = false;
+	_debugState.debugging = false;
+	_debugState.breakpointWasHit = false;
+	_debugState._breakpoints.clear(); // No breakpoints defined
+	_debugState._activeBreakpointTypes = 0;
 }
 
 Console::~Console() {
@@ -2307,31 +2307,31 @@
 
 bool Console::cmdTrace(int argc, const char **argv) {
 	if (argc == 2 && atoi(argv[1]) > 0)
-		g_debugState.runningStep = atoi(argv[1]) - 1;
-	g_debugState.debugging = true;
+		_debugState.runningStep = atoi(argv[1]) - 1;
+	_debugState.debugging = true;
 
 	return false;
 }
 
 bool Console::cmdStepOver(int argc, const char **argv) {
-	g_debugState.seeking = kDebugSeekStepOver;
-	g_debugState.seekLevel = _engine->_gamestate->_executionStack.size();
-	g_debugState.debugging = true;
+	_debugState.seeking = kDebugSeekStepOver;
+	_debugState.seekLevel = _engine->_gamestate->_executionStack.size();
+	_debugState.debugging = true;
 
 	return false;
 }
 
 bool Console::cmdStepEvent(int argc, const char **argv) {
-	g_debugState.stopOnEvent = true;
-	g_debugState.debugging = true;
+	_debugState.stopOnEvent = true;
+	_debugState.debugging = true;
 
 	return false;
 }
 
 bool Console::cmdStepRet(int argc, const char **argv) {
-	g_debugState.seeking = kDebugSeekLevelRet;
-	g_debugState.seekLevel = _engine->_gamestate->_executionStack.size() - 1;
-	g_debugState.debugging = true;
+	_debugState.seeking = kDebugSeekLevelRet;
+	_debugState.seekLevel = _engine->_gamestate->_executionStack.size() - 1;
+	_debugState.debugging = true;
 
 	return false;
 }
@@ -2343,9 +2343,9 @@
 		return true;
 	}
 
-	g_debugState.seeking = kDebugSeekGlobal;
-	g_debugState.seekSpecial = atoi(argv[1]);
-	g_debugState.debugging = true;
+	_debugState.seeking = kDebugSeekGlobal;
+	_debugState.seekSpecial = atoi(argv[1]);
+	_debugState.debugging = true;
 
 	return false;
 }
@@ -2373,12 +2373,12 @@
 			}
 		}
 
-		g_debugState.seeking = kDebugSeekSpecialCallk;
-		g_debugState.seekSpecial = callk_index;
+		_debugState.seeking = kDebugSeekSpecialCallk;
+		_debugState.seekSpecial = callk_index;
 	} else {
-		g_debugState.seeking = kDebugSeekCallk;
+		_debugState.seeking = kDebugSeekCallk;
 	}
-	g_debugState.debugging = true;
+	_debugState.debugging = true;
 
 	return false;
 }
@@ -2560,7 +2560,7 @@
 
 bool Console::cmdGo(int argc, const char **argv) {
 	// CHECKME: is this necessary?
-	g_debugState.seeking = kDebugSeekNothing;
+	_debugState.seeking = kDebugSeekNothing;
 
 	return Cmd_Exit(argc, argv);
 }
@@ -2571,8 +2571,8 @@
 
 	DebugPrintf("Breakpoint list:\n");
 
-	Common::List<Breakpoint>::const_iterator bp = g_debugState._breakpoints.begin();
-	Common::List<Breakpoint>::const_iterator end = g_debugState._breakpoints.end();
+	Common::List<Breakpoint>::const_iterator bp = _debugState._breakpoints.begin();
+	Common::List<Breakpoint>::const_iterator end = _debugState._breakpoints.end();
 	for (; bp != end; ++bp) {
 		DebugPrintf("  #%i: ", i);
 		switch (bp->type) {
@@ -2603,16 +2603,16 @@
 	}
 
 	if (strcmp(argv[1], "*") == 0) {
-		g_debugState._breakpoints.clear();
-		g_debugState._activeBreakpointTypes = 0;
+		_debugState._breakpoints.clear();
+		_debugState._activeBreakpointTypes = 0;
 		return true;
 	}
 
 	const int idx = atoi(argv[1]);
 
 	// Find the breakpoint at index idx.
-	Common::List<Breakpoint>::iterator bp = g_debugState._breakpoints.begin();
-	const Common::List<Breakpoint>::iterator end = g_debugState._breakpoints.end();
+	Common::List<Breakpoint>::iterator bp = _debugState._breakpoints.begin();
+	const Common::List<Breakpoint>::iterator end = _debugState._breakpoints.end();
 	for (int i = 0; bp != end && i < idx; ++bp, ++i) {
 		// do nothing
 	}
@@ -2623,15 +2623,15 @@
 	}
 
 	// Delete it
-	g_debugState._breakpoints.erase(bp);
+	_debugState._breakpoints.erase(bp);
 
 	// Update EngineState::_activeBreakpointTypes.
 	int type = 0;
-	for (bp = g_debugState._breakpoints.begin(); bp != end; ++bp) {
+	for (bp = _debugState._breakpoints.begin(); bp != end; ++bp) {
 		type |= bp->type;
 	}
 
-	g_debugState._activeBreakpointTypes = type;
+	_debugState._activeBreakpointTypes = type;
 
 	return true;
 }
@@ -2653,8 +2653,8 @@
 	bp.type = BREAK_SELECTOR;
 	bp.name = argv[1];
 
-	g_debugState._breakpoints.push_back(bp);
-	g_debugState._activeBreakpointTypes |= BREAK_SELECTOR;
+	_debugState._breakpoints.push_back(bp);
+	_debugState._activeBreakpointTypes |= BREAK_SELECTOR;
 
 	return true;
 }
@@ -2674,8 +2674,8 @@
 	bp.type = BREAK_EXPORT;
 	bp.address = (atoi(argv[1]) << 16 | atoi(argv[2]));
 
-	g_debugState._breakpoints.push_back(bp);
-	g_debugState._activeBreakpointTypes |= BREAK_EXPORT;
+	_debugState._breakpoints.push_back(bp);
+	_debugState._activeBreakpointTypes |= BREAK_EXPORT;
 
 	return true;
 }
@@ -2876,8 +2876,8 @@
 	if (!scumm_stricmp(argv[1], "game")) {
 		// Quit gracefully
 		_engine->_gamestate->abortScriptProcessing = kAbortQuitGame; // Terminate VM
-		g_debugState.seeking = kDebugSeekNothing;
-		g_debugState.runningStep = 0;
+		_debugState.seeking = kDebugSeekNothing;
+		_debugState.runningStep = 0;
 
 	} else if (!scumm_stricmp(argv[1], "now")) {
 		// Quit ungracefully

Modified: scummvm/trunk/engines/sci/console.h
===================================================================
--- scummvm/trunk/engines/sci/console.h	2010-07-12 23:19:56 UTC (rev 50835)
+++ scummvm/trunk/engines/sci/console.h	2010-07-12 23:20:33 UTC (rev 50836)
@@ -157,6 +157,7 @@
 
 private:
 	SciEngine *_engine;
+	DebugState &_debugState;
 	bool _mouseVisible;
 	Common::String _videoFile;
 	int _videoFrameDelay;

Modified: scummvm/trunk/engines/sci/debug.h
===================================================================
--- scummvm/trunk/engines/sci/debug.h	2010-07-12 23:19:56 UTC (rev 50835)
+++ scummvm/trunk/engines/sci/debug.h	2010-07-12 23:20:33 UTC (rev 50836)
@@ -26,8 +26,8 @@
 #ifndef SCI_DEBUG_H
 #define SCI_DEBUG_H
 
+#include "common/list.h"
 #include "sci/engine/vm_types.h"	// for StackPtr
-#include "sci/engine/vm.h"			// for ExecStack
 
 namespace Sci {
 
@@ -79,7 +79,6 @@
 extern int g_debug_sleeptime_factor;
 extern int g_debug_simulated_key;
 extern bool g_debug_track_mouse_clicks;
-extern DebugState g_debugState;
 
 } // End of namespace Sci
 

Modified: scummvm/trunk/engines/sci/engine/kevent.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/kevent.cpp	2010-07-12 23:19:56 UTC (rev 50835)
+++ scummvm/trunk/engines/sci/engine/kevent.cpp	2010-07-12 23:20:33 UTC (rev 50836)
@@ -78,8 +78,8 @@
 	switch (curEvent.type) {
 	case SCI_EVENT_QUIT:
 		s->abortScriptProcessing = kAbortQuitGame; // Terminate VM
-		g_debugState.seeking = kDebugSeekNothing;
-		g_debugState.runningStep = 0;
+		g_sci->_debugState.seeking = kDebugSeekNothing;
+		g_sci->_debugState.runningStep = 0;
 		break;
 
 	case SCI_EVENT_KEYBOARD:
@@ -124,8 +124,8 @@
 		s->r_acc = NULL_REG; // Unknown or no event
 	}
 
-	if ((s->r_acc.offset) && (g_debugState.stopOnEvent)) {
-		g_debugState.stopOnEvent = false;
+	if ((s->r_acc.offset) && (g_sci->_debugState.stopOnEvent)) {
+		g_sci->_debugState.stopOnEvent = false;
 
 		// A SCI event occurred, and we have been asked to stop, so open the debug console
 		Console *con = g_sci->getSciDebugger();

Modified: scummvm/trunk/engines/sci/engine/kmisc.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/kmisc.cpp	2010-07-12 23:19:56 UTC (rev 50835)
+++ scummvm/trunk/engines/sci/engine/kmisc.cpp	2010-07-12 23:20:33 UTC (rev 50836)
@@ -154,8 +154,8 @@
 reg_t kSetDebug(EngineState *s, int argc, reg_t *argv) {
 	printf("Debug mode activated\n");
 
-	g_debugState.seeking = kDebugSeekNothing;
-	g_debugState.runningStep = 0;
+	g_sci->_debugState.seeking = kDebugSeekNothing;
+	g_sci->_debugState.runningStep = 0;
 	return s->r_acc;
 }
 

Modified: scummvm/trunk/engines/sci/engine/scriptdebug.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/scriptdebug.cpp	2010-07-12 23:19:56 UTC (rev 50835)
+++ scummvm/trunk/engines/sci/engine/scriptdebug.cpp	2010-07-12 23:20:33 UTC (rev 50836)
@@ -63,8 +63,6 @@
 	   "-sli",      "-sti",     "-spi"
 };
 
-DebugState g_debugState;	// FIXME: Avoid non-const global vars
-
 // Disassembles one command from the heap, returns address of next command or 0 if a ret was encountered.
 reg_t disassemble(EngineState *s, reg_t pos, int print_bw_tag, int print_bytecode) {
 	SegmentObj *mobj = s->_segMan->getSegment(pos.segment, SEG_TYPE_SCRIPT);
@@ -277,30 +275,32 @@
 }
 
 
-void script_debug(EngineState *s) {
-	if (g_debugState.seeking && !g_debugState.breakpointWasHit) { // Are we looking for something special?
-		if (g_debugState.seeking == kDebugSeekStepOver) {
+void SciEngine::scriptDebug() {
+	EngineState *s = _gamestate;
+	if (_debugState.seeking && !_debugState.breakpointWasHit) { // Are we looking for something special?
+		if (_debugState.seeking == kDebugSeekStepOver) {
 			// are we above seek-level? resume then
-			if (g_debugState.seekLevel < (int)s->_executionStack.size())
+			if (_debugState.seekLevel < (int)s->_executionStack.size())
 				return;
-			g_debugState.seeking = kDebugSeekNothing;
+			_debugState.seeking = kDebugSeekNothing;
 		}
 
-		if (g_debugState.seeking != kDebugSeekNothing) {
-			SegmentObj *mobj = s->_segMan->getSegment(s->xs->addr.pc.segment, SEG_TYPE_SCRIPT);
+		if (_debugState.seeking != kDebugSeekNothing) {
+			const reg_t pc = s->xs->addr.pc;
+			SegmentObj *mobj = s->_segMan->getSegment(pc.segment, SEG_TYPE_SCRIPT);
 
 			if (mobj) {
 				Script *scr = (Script *)mobj;
 				const byte *code_buf = scr->getBuf();
 				int code_buf_size = scr->getBufSize();
-				int opcode = s->xs->addr.pc.offset >= code_buf_size ? 0 : code_buf[s->xs->addr.pc.offset];
+				int opcode = pc.offset >= code_buf_size ? 0 : code_buf[pc.offset];
 				int op = opcode >> 1;
-				int paramb1 = s->xs->addr.pc.offset + 1 >= code_buf_size ? 0 : code_buf[s->xs->addr.pc.offset + 1];
-				int paramf1 = (opcode & 1) ? paramb1 : (s->xs->addr.pc.offset + 2 >= code_buf_size ? 0 : (int16)READ_SCI11ENDIAN_UINT16(code_buf + s->xs->addr.pc.offset + 1));
+				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_SCI11ENDIAN_UINT16(code_buf + pc.offset + 1));
 
-				switch (g_debugState.seeking) {
+				switch (_debugState.seeking) {
 				case kDebugSeekSpecialCallk:
-					if (paramb1 != g_debugState.seekSpecial)
+					if (paramb1 != _debugState.seekSpecial)
 						return;
 
 				case kDebugSeekCallk:
@@ -309,7 +309,7 @@
 					break;
 
 				case kDebugSeekLevelRet:
-					if ((op != op_ret) || (g_debugState.seekLevel < (int)s->_executionStack.size()-1))
+					if ((op != op_ret) || (_debugState.seekLevel < (int)s->_executionStack.size()-1))
 						return;
 					break;
 
@@ -320,7 +320,7 @@
 						return; // param or temp
 					if ((op & 0x3) && s->_executionStack.back().local_segment > 0)
 						return; // locals and not running in script.000
-					if (paramf1 != g_debugState.seekSpecial)
+					if (paramf1 != _debugState.seekSpecial)
 						return; // CORRECT global?
 					break;
 
@@ -328,7 +328,7 @@
 					break;
 				}
 
-				g_debugState.seeking = kDebugSeekNothing;
+				_debugState.seeking = kDebugSeekNothing;
 			}
 		}
 		// OK, found whatever we were looking for
@@ -337,15 +337,14 @@
 	printf("Step #%d\n", s->scriptStepCounter);
 	disassemble(s, s->xs->addr.pc, 0, 1);
 
-	if (g_debugState.runningStep) {
-		g_debugState.runningStep--;
+	if (_debugState.runningStep) {
+		_debugState.runningStep--;
 		return;
 	}
 
-	g_debugState.debugging = false;
+	_debugState.debugging = false;
 
-	Console *con = ((Sci::SciEngine *)g_engine)->getSciDebugger();
-	con->attach();
+	_console->attach();
 }
 
 void Kernel::dumpScriptObject(char *data, int seeker, int objsize) {

Modified: scummvm/trunk/engines/sci/engine/vm.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/vm.cpp	2010-07-12 23:19:56 UTC (rev 50835)
+++ scummvm/trunk/engines/sci/engine/vm.cpp	2010-07-12 23:20:33 UTC (rev 50836)
@@ -30,7 +30,6 @@
 
 #include "sci/sci.h"
 #include "sci/console.h"
-#include "sci/debug.h"	// for g_debugState
 #include "sci/resource.h"
 #include "sci/engine/features.h"
 #include "sci/engine/state.h"
@@ -474,18 +473,18 @@
 	}
 
 	// Check if a breakpoint is set on this method
-	if (g_debugState._activeBreakpointTypes & BREAK_EXPORT) {
+	if (g_sci->_debugState._activeBreakpointTypes & BREAK_EXPORT) {
 		uint32 bpaddress;
 
 		bpaddress = (script << 16 | pubfunct);
 
 		Common::List<Breakpoint>::const_iterator bp;
-		for (bp = g_debugState._breakpoints.begin(); bp != g_debugState._breakpoints.end(); ++bp) {
+		for (bp = g_sci->_debugState._breakpoints.begin(); bp != g_sci->_debugState._breakpoints.end(); ++bp) {
 			if (bp->type == BREAK_EXPORT && bp->address == bpaddress) {
 				Console *con = g_sci->getSciDebugger();
 				con->DebugPrintf("Break on script %d, export %d\n", script, pubfunct);
-				g_debugState.debugging = true;
-				g_debugState.breakpointWasHit = true;
+				g_sci->_debugState.debugging = true;
+				g_sci->_debugState.breakpointWasHit = true;
 				break;
 			}
 		}
@@ -553,13 +552,13 @@
 		}
 
 		// Check if a breakpoint is set on this method
-		if (g_debugState._activeBreakpointTypes & BREAK_SELECTOR) {
+		if (g_sci->_debugState._activeBreakpointTypes & BREAK_SELECTOR) {
 			char method_name[256];
 
 			sprintf(method_name, "%s::%s", s->_segMan->getObjectName(send_obj), g_sci->getKernel()->getSelectorName(selector).c_str());
 
 			Common::List<Breakpoint>::const_iterator bp;
-			for (bp = g_debugState._breakpoints.begin(); bp != g_debugState._breakpoints.end(); ++bp) {
+			for (bp = g_sci->_debugState._breakpoints.begin(); bp != g_sci->_debugState._breakpoints.end(); ++bp) {
 				int cmplen = bp->name.size();
 				if (bp->name.lastChar() != ':')
 					cmplen = 256;
@@ -568,8 +567,8 @@
 					Console *con = g_sci->getSciDebugger();
 					con->DebugPrintf("Break on %s (in [%04x:%04x])\n", method_name, PRINT_REG(send_obj));
 					printSendActions = true;
-					g_debugState.debugging = true;
-					g_debugState.breakpointWasHit = true;
+					g_sci->_debugState.debugging = true;
+					g_sci->_debugState.breakpointWasHit = true;
 					break;
 				}
 			}
@@ -1003,8 +1002,8 @@
 		int var_type; // See description below
 		int var_number;
 
-		g_debugState.old_pc_offset = s->xs->addr.pc.offset;
-		g_debugState.old_sp = s->xs->sp;
+		g_sci->_debugState.old_pc_offset = s->xs->addr.pc.offset;
+		g_sci->_debugState.old_sp = s->xs->sp;
 
 		if (s->abortScriptProcessing != kAbortNone || g_engine->shouldQuit())
 			return; // Stop processing
@@ -1046,9 +1045,9 @@
 
 		// Debug if this has been requested:
 		// TODO: re-implement sci_debug_flags
-		if (g_debugState.debugging /* sci_debug_flags*/) {
-			script_debug(s);
-			g_debugState.breakpointWasHit = false;
+		if (g_sci->_debugState.debugging /* sci_debug_flags*/) {
+			g_sci->scriptDebug();
+			g_sci->_debugState.breakpointWasHit = false;
 		}
 		Console *con = g_sci->getSciDebugger();
 		if (con->isAttached()) {

Modified: scummvm/trunk/engines/sci/sci.cpp
===================================================================
--- scummvm/trunk/engines/sci/sci.cpp	2010-07-12 23:19:56 UTC (rev 50835)
+++ scummvm/trunk/engines/sci/sci.cpp	2010-07-12 23:20:33 UTC (rev 50836)
@@ -448,12 +448,12 @@
 GUI::Debugger *SciEngine::getDebugger() {
 	if (_gamestate) {
 		ExecStack *xs = &(_gamestate->_executionStack.back());
-		xs->addr.pc.offset = g_debugState.old_pc_offset;
-		xs->sp = g_debugState.old_sp;
+		xs->addr.pc.offset = _debugState.old_pc_offset;
+		xs->sp = _debugState.old_sp;
 	}
 
-	g_debugState.runningStep = 0; // Stop multiple execution
-	g_debugState.seeking = kDebugSeekNothing; // Stop special seeks
+	_debugState.runningStep = 0; // Stop multiple execution
+	_debugState.seeking = kDebugSeekNothing; // Stop special seeks
 
 	return _console;
 }

Modified: scummvm/trunk/engines/sci/sci.h
===================================================================
--- scummvm/trunk/engines/sci/sci.h	2010-07-12 23:19:56 UTC (rev 50835)
+++ scummvm/trunk/engines/sci/sci.h	2010-07-12 23:20:33 UTC (rev 50836)
@@ -28,7 +28,8 @@
 
 #include "engines/engine.h"
 #include "common/util.h"
-#include "engine/vm_types.h"	// for Selector
+#include "sci/engine/vm_types.h"	// for Selector
+#include "sci/debug.h"	// for DebugState
 
 struct ADGameDescription;
 
@@ -243,6 +244,8 @@
 
 	void sleep(uint32 msecs);
 
+	void scriptDebug();
+
 public:
 
 	/**
@@ -290,6 +293,8 @@
 	SoundCommandParser *_soundCmd;
 	GameFeatures *_features;
 
+	DebugState _debugState;
+
 private:
 	/**
 	 * Initializes a SCI game


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