for review: workaround for the large term problem in the debugger

Zoltan Somogyi zs at cs.mu.OZ.AU
Fri Jun 12 18:10:45 AEST 1998


Tyson, please check this.

runtime/mercury_trace_internal.c:
	Separate the functionality of the old 'p'" command into two parts.
	The new 'v' command lists the live variables, giving a number to each.
	The new 'p' command takes an argument. If this argument is a number,
	it prints the variable with that number in the list produced by 'v'.
	If this argument is '*', it prints all variables.

Zoltan.

Index: mercury_trace_internal.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_trace_internal.c,v
retrieving revision 1.4
diff -u -u -r1.4 mercury_trace_internal.c
--- mercury_trace_internal.c	1998/06/08 08:27:11	1.4
+++ mercury_trace_internal.c	1998/06/12 07:58:15
@@ -44,8 +44,14 @@
 			const MR_Stack_Layout_Label *layout,
 			MR_trace_port port, int seqno, int depth,
 			const char *path);
-static	void	MR_trace_browse(int var_count,
+static	void	MR_trace_list_vars(int var_count,
 			const MR_Stack_Layout_Vars *var_info);
+static	void	MR_trace_browse_one(int which_var,
+			const MR_Stack_Layout_Vars *var_info);
+static	void	MR_trace_browse_all(int var_count,
+			const MR_Stack_Layout_Vars *var_info);
+static	Word	*MR_trace_materialize_typeinfos(const MR_Stack_Layout_Vars
+			*vars);
 static	void	MR_trace_browse_var(const char *name,
 			const MR_Stack_Layout_Var *var, Word *type_params);
 static	void	MR_trace_help(void);
@@ -258,14 +264,32 @@
 		} else {
 			printf("This command expects no argument.\n");
 		}
-	} else if (streq(words[0], "p")) {
+	} else if (streq(words[0], "v")) {
 		if (word_count == 1) {
-			MR_trace_browse((int)
-				layout->MR_sll_var_count,
+			MR_trace_list_vars((int) layout->MR_sll_var_count,
 				&layout->MR_sll_var_info);
 		} else {
 			printf("This command expects no argument.\n");
 		}
+	} else if (streq(words[0], "p")) {
+		if (word_count == 2) {
+			if (MR_trace_is_number(words[1], &n)) {
+				if (n < layout->MR_sll_var_count) {
+					MR_trace_browse_one(n,
+						&layout->MR_sll_var_info);
+				} else {
+					printf("There is no variable #%d.\n",
+						n);
+				}
+			} else {
+				MR_trace_browse_all((int)
+					layout->MR_sll_var_count,
+					&layout->MR_sll_var_info);
+			}
+		} else {
+			printf("This command expects one argument,\n");
+			printf("a variable number or a '*' indicating all variables.\n");
+		}
 	} else if (streq(words[0], "d")) {
 		if (word_count == 1) {
 			const char	*result;
@@ -398,7 +422,7 @@
 }
 
 static void
-MR_trace_browse(int var_count, const MR_Stack_Layout_Vars *vars)
+MR_trace_list_vars(int var_count, const MR_Stack_Layout_Vars *vars)
 {
 	Word	*type_params;
 	bool	succeeded;
@@ -410,6 +434,54 @@
 		return;
 	}
 
+	for (i = 0; i < var_count; i++) {
+		printf("%3d %s\n", i, MR_name_if_present(vars, i));
+	}
+}
+
+static void
+MR_trace_browse_one(int which_var, const MR_Stack_Layout_Vars *vars)
+{
+	Word	*type_params;
+	int	i;
+
+	type_params = MR_trace_materialize_typeinfos(vars);
+	MR_trace_browse_var(MR_name_if_present(vars, which_var),
+		&vars->MR_slvs_pairs[which_var], type_params);
+	free(type_params);
+}
+
+static void 
+MR_trace_browse_all(int var_count, const MR_Stack_Layout_Vars *vars)
+{
+	Word	*type_params;
+	bool	succeeded;
+	int	count;
+	int	i;
+
+	if (var_count == 0) {
+		printf("mtrace: no live variables\n");
+		return;
+	}
+
+	type_params = MR_trace_materialize_typeinfos(vars);
+
+	for (i = 0; i < var_count; i++) {
+		MR_trace_browse_var(MR_name_if_present(vars, i),
+			&vars->MR_slvs_pairs[i], type_params);
+	}
+
+	free(type_params);
+}
+
+static Word *
+MR_trace_materialize_typeinfos(const MR_Stack_Layout_Vars *vars)
+{
+	Word	*type_params;
+	bool	succeeded;
+	int	count;
+	int	i;
+
 	if (vars->MR_slvs_tvars != NULL) {
 		count = (int) (Integer) vars->MR_slvs_tvars[0];
 		type_params = checked_malloc((count + 1) * sizeof(Word));
@@ -427,16 +499,11 @@
 				}
 			}
 		}
-	} else {
-		type_params = NULL;
-	}
 
-	for (i = 0; i < var_count; i++) {
-		MR_trace_browse_var(MR_name_if_present(vars, i),
-			&vars->MR_slvs_pairs[i], type_params);
+		return type_params;
+	} else {
+		return NULL;
 	}
-
-	free(type_params);
 }
 
 static void
@@ -765,8 +832,10 @@
 		"\tgo to event #N, not printing the trace.\n"
 		"<N> G:\t\t"
 		"\tgo to event #N, printing the trace.\n"
-		"p:\t\t"
-		"\tprint the variables live at this point.\n"
+		"v:\t\t"
+		"\tlist the names of the variables live at this point.\n"
+		"p <n>:\t\t"
+		"\tprint variable #n (or all live vars if <n> is '*')\n"
 		"r:\t\t"
 		"\tcontinue until forward execution is resumed.\n"
 		"[<N>] [s]:\t"



More information about the developers mailing list