[m-dev.] for review: number mdb variables from 1

Fergus Henderson fjh at cs.mu.OZ.AU
Mon Jun 21 18:18:27 AEST 1999


Erwan, is this change going to break the external debugger?

--------------------

Estimated hours taken: 0.5

trace/mercury_trace_vars.c:
	Change things so that variable numbers for the `print' and `browse'
	commands start from one rather than from zero.  This makes more
	sense for most users, particluarly at "call" ports, where you want
	e.g. `print 3' to show the third argument, not the second argument.

Workspace: /home/mercury0/fjh/mercury
Index: trace/mercury_trace_vars.c
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_vars.c,v
retrieving revision 1.6
diff -u -r1.6 mercury_trace_vars.c
--- mercury_trace_vars.c	1999/06/07 21:53:45	1.6
+++ mercury_trace_vars.c	1999/06/21 08:16:09
@@ -523,7 +523,7 @@
 	}
 
 	for (i = 0; i < MR_point.MR_point_var_count; i++) {
-		fprintf(out, "%9d ", i);
+		fprintf(out, "%9d ", i + 1);
 		MR_trace_print_var_name(out, &MR_point.MR_point_vars[i]);
 		fprintf(out, "\n");
 	}
@@ -535,24 +535,29 @@
 MR_trace_return_var_info(int var_number, const char **name_ptr,
 	Word *type_info_ptr, Word *value_ptr)
 {
+	const MR_Var_Details *details;
+
 	if (MR_point.MR_point_problem != NULL) {
 		return MR_point.MR_point_problem;
 	}
 
-	if (var_number >= MR_point.MR_point_var_count) {
+	if (var_number < 1) {
+		return "invalid variable number";
+	}
+	if (var_number > MR_point.MR_point_var_count) {
 		return "there aren't that many variables";
 	}
 
+	details = &MR_point.MR_point_vars[var_number - 1];
+	
 	if (name_ptr != NULL) {
-		*name_ptr = MR_point.MR_point_vars[var_number].MR_var_fullname;
+		*name_ptr = details->MR_var_fullname;
 	}
-
 	if (type_info_ptr != NULL) {
-		*type_info_ptr = MR_point.MR_point_vars[var_number].MR_var_type;
+		*type_info_ptr = details->MR_var_type;
 	}
-
 	if (value_ptr != NULL) {
-		*value_ptr = MR_point.MR_point_vars[var_number].MR_var_value;
+		*value_ptr = details->MR_var_value;
 	}
 
 	return NULL;
@@ -570,13 +575,15 @@
 	}
 
 	if (var_spec.MR_var_spec_kind == MR_VAR_SPEC_NUMBER) {
-		if (var_spec.MR_var_spec_number < MR_point.MR_point_var_count)
+		if (var_spec.MR_var_spec_number < 1) {
+			return "invalid variable number";
+		}
+		if (var_spec.MR_var_spec_number > MR_point.MR_point_var_count)
 		{
-			MR_trace_browse_var(out, &MR_point.MR_point_vars
-				[var_spec.MR_var_spec_number], browser);
-		} else {
 			return "there aren't that many variables";
 		}
+		MR_trace_browse_var(out, &MR_point.MR_point_vars
+			[var_spec.MR_var_spec_number - 1], browser);
 	} else if (var_spec.MR_var_spec_kind == MR_VAR_SPEC_NAME) {
 		found = FALSE;
 		for (i = 0; i < MR_point.MR_point_var_count; i++) {

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3        |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list