For review: Fix a bug in the external debugger

Erwan Jahier Erwan.Jahier at irisa.fr
Fri Feb 19 11:49:36 AEDT 1999


Estimated hours taken: 4

Fix a bug in the external debugger. The execution was crashing during the
printing of polymorphic arguments. In runtime/mercury_layout_util.c,
MR_get_type_filtered() and MR_get_type_and_value_filtered() were calling
MR_get_type() and MR_get_type_and_value() without type_info information (third
argument set to NULL), which is needed to retrieve polymorphic types.

runtime/mercury_layout_util.[ch]:
	Pass down type_info in argument of MR_get_type_and_value_filtered() and
	MR_get_type_filtered() to be able to call MR_get_type_and_value() and
	MR_get_type() with type_info information.

runtime/mercury_layout_util.c
	Filter out variables which names begin by "TypeClassInfo" in
	MR_get_type_and_value_filtered() (as it was already done in
	MR_get_type_filtered()).

runtime/mercury_layout_util.c
trace/mercury_trace_external.c:
	In a few functions, do not try to retrieve information about live
	variables if it does not exist any.

trace/mercury_trace_external.c:
	Pass type_info in argument of MR_get_type_and_value_filtered()
	and MR_get_type_filtered().

	Filter out in MR_trace_make_var_names_list() the variable names
	that are also filtered in MR_get_type_and_value_filtered().




Index: runtime/mercury_layout_util.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_layout_util.c,v
retrieving revision 1.2
diff -u -r1.2 mercury_layout_util.c
--- mercury_layout_util.c	1998/10/23 00:41:28	1.2
+++ mercury_layout_util.c	1999/02/19 00:44:48
@@ -119,14 +119,31 @@
 	Word				univ, value;
 	MR_Live_Type			live_type;
 	Word				type_info;
+	Word				*base_sp;
+	Word				*base_curfr;
+	Word				*type_params;
 
 	var_count = layout->MR_sll_var_count;
 	vars = &layout->MR_sll_var_info;
+	base_sp = MR_saved_sp(saved_regs);
+	base_curfr = MR_saved_curfr(saved_regs);
 
 	/* build up the live variable list, starting from the end */
 	restore_transient_registers();
 	univ_list = list_empty();
 	save_transient_registers();
+
+	/* 
+	** If no information on live variables is available, return the 
+	** empty list 
+	*/
+	if (layout->MR_sll_var_count <= 0) {
+		return univ_list;
+	} 
+		
+	type_params = MR_materialize_typeinfos_base(vars,
+	       	saved_regs, base_sp, base_curfr);
+    
 	for (i = var_count - 1; i >= 0; i--) {
 		/*
 		** Look up the name, the type and value
@@ -146,7 +163,7 @@
 		*/
 
 		if (! MR_get_type_and_value_filtered(var, saved_regs,
-			name, &type_info, &value))
+			name, type_params, &type_info, &value))
 		{
 			continue;
 		}
@@ -373,25 +390,27 @@
 
 bool
 MR_get_type_and_value_filtered(const MR_Stack_Layout_Var *var, 
-	Word *saved_regs, const char *name, Word *type_info, Word *value)
+	Word *saved_regs, const char *name, Word *type_params, 
+	Word *type_info, Word *value)
 {
 	return ((strncmp(name, "TypeInfo", 8) != 0)
+	       && (strncmp(name, "TypeClassInfo", 13) != 0)
 	       && (strncmp(name, "ModuleInfo", 10) != 0)
 	       && (strncmp(name, "HLDS", 4) != 0)
-	       && MR_get_type_and_value(var, saved_regs, NULL,
+	       && MR_get_type_and_value(var, saved_regs, type_params,
 			type_info, value));
 }
 
 
 bool
 MR_get_type_filtered(const MR_Stack_Layout_Var *var, Word *saved_regs,
-	const char *name, Word *type_info)
+	const char *name, Word *type_params, Word *type_info)
 {
 	return ((strncmp(name, "TypeInfo", 8) != 0)
 	       && (strncmp(name, "TypeClassInfo", 13) != 0)
 	       && (strncmp(name, "ModuleInfo", 10) != 0)
 	       && (strncmp(name, "HLDS", 4) != 0)
-	       && MR_get_type(var, saved_regs, NULL, type_info));
+	       && MR_get_type(var, saved_regs, type_params, type_info));
 }
 
 void
Index: runtime/mercury_layout_util.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_layout_util.h,v
retrieving revision 1.3
diff -u -r1.3 mercury_layout_util.h
--- mercury_layout_util.h	1998/11/09 10:24:37	1.3
+++ mercury_layout_util.h	1999/02/19 00:44:48
@@ -126,9 +126,11 @@
 			Word *type_params, Word *type_info);
 extern	bool	MR_get_type_and_value_filtered(
 			const MR_Stack_Layout_Var *var, Word *saved_regs,
-			const char *name, Word *type_info, Word *value);
+			const char *name, Word *type_params, Word *type_info, 
+			Word *value);
 extern	bool	MR_get_type_filtered(const MR_Stack_Layout_Var *var, 
-			Word *saved_regs, const char *name, Word *type_info);
+			Word *saved_regs, const char *name, Word *type_params, 
+			Word *type_info);
 
 /*
 ** MR_write_variable:
Index: trace/mercury_trace_external.c
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_external.c,v
retrieving revision 1.7
diff -u -r1.7 mercury_trace_external.c
--- mercury_trace_external.c	1999/02/18 23:32:57	1.7
+++ mercury_trace_external.c	1999/02/19 00:44:50
@@ -709,6 +709,14 @@
 	var_names_list = list_empty();
 	for (i = var_count - 1; i >= 0; i--) {
 		name = MR_name_if_present(vars, i);
+		if ((strncmp(name, "TypeInfo", 8) == 0)
+		    || (strncmp(name, "TypeClassInfo", 13) == 0)
+		    || (strncmp(name, "ModuleInfo", 10) == 0)
+		    || (strncmp(name, "HLDS", 4) == 0)
+		    ) {
+		  continue;
+		}
+
 		var_names_list = list_cons(name, var_names_list);
 	}
     );
@@ -732,21 +740,40 @@
 	MR_Stack_Layout_Var*		var;
 	Word				type_info;
 	String		      		type_info_string;
+	Word				*base_sp;
+	Word				*base_curfr;
+	Word				*type_params;
 
 	Word				type_list;
 
 	var_count = layout->MR_sll_var_count;
 	vars = &layout->MR_sll_var_info;
 
+	base_sp = MR_saved_sp(saved_regs);
+	base_curfr = MR_saved_curfr(saved_regs);
+
         MR_TRACE_USE_HP(
 		type_list = list_empty();
         );
+
+	/* 
+	** If no information on live variables is available, return the 
+	** empty list 
+	*/
+	if (layout->MR_sll_var_count <= 0) {
+		return type_list;
+	}
+
+	type_params = MR_materialize_typeinfos_base(vars,
+	      	saved_regs, base_sp, base_curfr);
+
 	for (i = var_count - 1; i >= 0; i--) {
 
 		name = MR_name_if_present(vars, i);
 		var = &vars->MR_slvs_pairs[i];
 
-		if (! MR_get_type_filtered(var, saved_regs, name, &type_info))
+		if (! MR_get_type_filtered(var, saved_regs, name, type_params, 
+			&type_info))
 		{
 			continue;
 		}
@@ -779,6 +806,9 @@
 	int				i;
 	Word				value;
 	Word				type_info;
+	Word				*base_sp;
+	Word				*base_curfr;
+	Word				*type_params;
 
 	Word				univ;
 
@@ -788,13 +818,26 @@
 	vars = &layout->MR_sll_var_info;
 	name = MR_name_if_present(vars, var_number);
 	var = &vars->MR_slvs_pairs[var_number];
+	base_sp = MR_saved_sp(saved_regs);
+	base_curfr = MR_saved_curfr(saved_regs);
+	
+	/*
+	** Should never occur since we check in the external debugger
+	** process if a variable is live before retrieving it.
+	*/
+	if (layout->MR_sll_var_count <= 0) {
+		fatal_error("try to retrieve a non-live variable");
+	}
+
+       	type_params = MR_materialize_typeinfos_base(vars,
+	       	saved_regs, base_sp, base_curfr);
 
 	MR_TRACE_USE_HP(
 		incr_hp(univ, 2);
 	);
 
 	if (MR_get_type_and_value_filtered(var, saved_regs, name,
-			&type_info, &value))
+			type_params, &type_info, &value))
 	{
 		field(mktag(0), univ, UNIV_OFFSET_FOR_TYPEINFO) = type_info;
 		field(mktag(0), univ, UNIV_OFFSET_FOR_DATA) = value;
@@ -832,8 +875,9 @@
 ** 2) For each procedure in the stack that is not generated by the compiler, the
 **    debuggee sends: 
 **	- level(int) (the level of the procedure in the stack)
-**	- detail(unsigned long, unsigned long, unsigned long) (the call event
-**	  number, call sequence number and depth of the goal of the procedure)
+**	- detail(unsigned long, unsigned long, unsigned long) if available
+**	  (the call event number, call sequence number and depth of the goal 
+**	  of the procedure)
 **	- the atom 'pred' or 'func' depending if the procedure is a function 
 **	  or not
 **	- proc('string:string'/long-long) (the name of the procedure)
@@ -919,7 +963,7 @@
 
 	if (MR_ENTRY_LAYOUT_COMPILER_GENERATED(entry)) {
 		MR_send_message_to_socket_format(
-                       /* XXX Names with ' may cause some problems here */
+			/* XXX Names with ' may cause some problems here */
 			"proc('%s for %s:%s'/%ld-%ld).\n",
 			entry->MR_sle_comp.MR_comp_pred_name,
 			entry->MR_sle_comp.MR_comp_type_module,
@@ -946,7 +990,7 @@
 		}
 		
 		MR_send_message_to_socket_format(
-                       /* XXX Names with ' may cause some problems here */
+			/* XXX Names with ' may cause some problems here */
 			"proc('%s:%s'/%ld-%ld).\n",
 			entry->MR_sle_user.MR_user_decl_module,
 			entry->MR_sle_user.MR_user_name,


-- 
R1.





More information about the developers mailing list