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

waltervn at users.sourceforge.net waltervn at users.sourceforge.net
Tue May 19 22:40:21 CEST 2009


Revision: 40732
          http://scummvm.svn.sourceforge.net/scummvm/?rev=40732&view=rev
Author:   waltervn
Date:     2009-05-19 20:40:21 +0000 (Tue, 19 May 2009)

Log Message:
-----------
SCI: Some debugger fixes and cleanup.

Modified Paths:
--------------
    scummvm/trunk/engines/sci/engine/sciconsole.cpp
    scummvm/trunk/engines/sci/engine/scriptdebug.cpp
    scummvm/trunk/engines/sci/engine/vm.cpp
    scummvm/trunk/engines/sci/engine/vm.h

Modified: scummvm/trunk/engines/sci/engine/sciconsole.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/sciconsole.cpp	2009-05-19 20:30:57 UTC (rev 40731)
+++ scummvm/trunk/engines/sci/engine/sciconsole.cpp	2009-05-19 20:40:21 UTC (rev 40732)
@@ -328,21 +328,19 @@
 				}
 
 				if (valid) {
-					char *objname = (char *)obj->base
-					                + obj->_variables[SCRIPT_NAME_SELECTOR].offset;
+					const char *objname = obj_get_name(s, objpos);
 					if (!strcmp(objname, str_objname)) {
 						// Found a match!
-						if (index < 0 ||
-						        times_found == index)
-							*dest = objpos;
-						else if (times_found < 0 && index) {
-							if (index == 1) {
+						if ((index < 0) && (times_found > 0)) {
+							if (times_found == 1) {
 								// First time we realized the ambiguity
 								sciprintf("Ambiguous:\n");
 								sciprintf("  %3x: ["PREG"] %s\n", 0, PRINT_REG(*dest), str_objname);
 							}
-							sciprintf("  %3x: ["PREG"] %s\n", index, PRINT_REG(objpos), str_objname);
+							sciprintf("  %3x: ["PREG"] %s\n", times_found, PRINT_REG(objpos), str_objname);
 						}
+						if (index < 0 || times_found == index)
+							*dest = objpos;
 						++times_found;
 					}
 				}

Modified: scummvm/trunk/engines/sci/engine/scriptdebug.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/scriptdebug.cpp	2009-05-19 20:30:57 UTC (rev 40731)
+++ scummvm/trunk/engines/sci/engine/scriptdebug.cpp	2009-05-19 20:40:21 UTC (rev 40732)
@@ -89,11 +89,12 @@
 		+ s->_classtable[species].class_offset)
 #endif
 
-const char *_debug_get_input_default() {
+static const char *_debug_get_input() {
 	char newinpbuf[256];
 	
 	printf("> ");
-	fgets(newinpbuf, 254, stdin);
+	if (!fgets(newinpbuf, 254, stdin))
+		return NULL;
 
 	size_t l = strlen(newinpbuf);
 	if (l > 0 && newinpbuf[0] != '\n') {
@@ -276,8 +277,6 @@
 	return 0;
 }
 
-const char *(*_debug_get_input)(void) = _debug_get_input_default;
-
 int c_segtable(EngineState *s, const Common::Array<cmd_param_t> &cmdParams) {
 	uint i;
 
@@ -341,8 +340,13 @@
 	return 0;
 }
 
-static void print_obj_head(EngineState *s, Object *obj) {
-	sciprintf(PREG" %s : %3d vars, %3d methods\n", PRINT_REG(obj->pos), obj_get_name(s, obj->pos),
+static void print_obj_head(EngineState *s, reg_t pos) {
+	Object *obj = obj_get(s, pos);
+
+	if (!obj)
+		return;
+
+	sciprintf("["PREG"] %s : %3d vars, %3d methods\n", PRINT_REG(pos), obj_get_name(s, pos),
 				obj->_variables.size(), obj->methods_nr);
 }
 
@@ -380,7 +384,14 @@
 	sciprintf("\t>\n");
 }
 
-static void _c_single_seg_info(EngineState *s, MemObject *mobj) {
+static bool _c_single_seg_info(EngineState *s, int nr) {
+	sciprintf("[%04x] ", nr);
+
+	if ((nr < 0) || ((uint)nr >= s->seg_manager->_heap.size()) || !s->seg_manager->_heap[nr])
+		return false;
+
+	MemObject *mobj = s->seg_manager->_heap[nr];
+
 	switch (mobj->getType()) {
 
 	case MEM_OBJ_SCRIPT: {
@@ -401,7 +412,7 @@
 		sciprintf("  Objects: %4d\n", scr->_objects.size());
 		for (uint i = 0; i < scr->_objects.size(); i++) {
 			sciprintf("    ");
-			print_obj_head(s, &scr->_objects[i]);
+			print_obj_head(s, scr->_objects[i].pos);
 		}
 	}
 	break;
@@ -439,8 +450,11 @@
 
 		for (uint i = 0; i < ct->_table.size(); i++)
 			if (ct->isValidEntry(i)) {
-				sciprintf("  [%04x] ", i);
-				print_obj_head(s, &(ct->_table[i]));
+				reg_t objpos;
+				objpos.offset = i;
+				objpos.segment = nr;
+				sciprintf("  [%04x] %s; copy of ", i, obj_get_name(s, objpos));
+				print_obj_head(s, ct->_table[i].pos);
 			}
 	}
 	break;
@@ -490,6 +504,9 @@
 		sciprintf("Invalid type %d\n", mobj->getType());
 		break;
 	}
+
+	sciprintf("\n");
+	return true;
 }
 
 static int show_node(EngineState *s, reg_t addr) {
@@ -665,21 +682,14 @@
 	if (cmdParams.size()) {
 		while (i < cmdParams.size()) {
 			int nr = cmdParams[i++].val;
-			if (nr < 0 || (uint)nr >= s->seg_manager->_heap.size() || !s->seg_manager->_heap[nr]) {
+			if (!_c_single_seg_info(s, nr))
 				sciprintf("Segment %04x does not exist\n", nr);
-				return 1;
-			}
-			sciprintf("[%04x] ", nr);
-			_c_single_seg_info(s, s->seg_manager->_heap[nr]);
 		}
-	} else
+	} else {
 		for (i = 0; i < s->seg_manager->_heap.size(); i++) {
-			if (s->seg_manager->_heap[i]) {
-				sciprintf("[%04x] ", i);
-				_c_single_seg_info(s, s->seg_manager->_heap[i]);
-				sciprintf("\n");
-			}
+			_c_single_seg_info(s, i);
 		}
+	}
 
 	return 0;
 }
@@ -2526,25 +2536,31 @@
 	Object *var_container = obj;
 	int i;
 
-	sciprintf("["PREG"]: ", PRINT_REG(pos));
 	if (!obj) {
-		sciprintf("Not an object.");
+		sciprintf("["PREG"]: Not an object.", PRINT_REG(pos));
 		return 1;
 	}
 
-	print_obj_head(s, obj);
+	print_obj_head(s, pos);
 
 	if (!(obj->_variables[SCRIPT_INFO_SELECTOR].offset & SCRIPT_INFO_CLASS))
 		var_container = obj_get(s, obj->_variables[SCRIPT_SUPERCLASS_SELECTOR]);
 	sciprintf("  -- member variables:\n");
 	for (i = 0; (uint)i < obj->_variables.size(); i++) {
 		sciprintf("    ");
-		if (i < var_container->variable_names_nr)
+		if (i < var_container->variable_names_nr) {
 			sciprintf("[%03x] %s = ", VM_OBJECT_GET_VARSELECTOR(var_container, i), selector_name(s, VM_OBJECT_GET_VARSELECTOR(var_container, i)));
-		else
+		} else
 			sciprintf("p#%x = ", i);
 
-		sciprintf(PREG"\n", PRINT_REG(obj->_variables[i]));
+		reg_t val = obj->_variables[i];
+		sciprintf(PREG, PRINT_REG(val));
+
+		Object *ref = obj_get(s, val);
+		if (ref)
+			sciprintf(" (%s)", obj_get_name(s, val));
+
+		sciprintf("\n");
 	}
 	sciprintf("  -- methods:\n");
 	for (i = 0; i < obj->methods_nr; i++) {

Modified: scummvm/trunk/engines/sci/engine/vm.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/vm.cpp	2009-05-19 20:30:57 UTC (rev 40731)
+++ scummvm/trunk/engines/sci/engine/vm.cpp	2009-05-19 20:40:21 UTC (rev 40732)
@@ -2075,11 +2075,18 @@
 
 const char *obj_get_name(EngineState *s, reg_t pos) {
 	Object *obj = obj_get(s, pos);
-
 	if (!obj)
 		return "<no such object>";
 
-	return (const char *)(obj->base + obj->_variables[SCRIPT_NAME_SELECTOR].offset);
+	reg_t nameReg = obj->_variables[SCRIPT_NAME_SELECTOR];
+	if (nameReg.isNull())
+		return "<no name>";
+
+	const char *name = (const char*)s->seg_manager->dereference(obj->_variables[SCRIPT_NAME_SELECTOR], NULL);
+	if (!name)
+		return "<invalid name>";
+
+	return name;
 }
 
 void quit_vm() {

Modified: scummvm/trunk/engines/sci/engine/vm.h
===================================================================
--- scummvm/trunk/engines/sci/engine/vm.h	2009-05-19 20:30:57 UTC (rev 40731)
+++ scummvm/trunk/engines/sci/engine/vm.h	2009-05-19 20:40:21 UTC (rev 40732)
@@ -815,9 +815,6 @@
 extern int script_step_counter;
 
 
-/** The function used to get input for debugging */
-extern const char *(*_debug_get_input)(void);
-
 extern int _debugstate_valid;
 extern int _debug_seeking;
 extern int _debug_step_running;


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