diff: add mdb `browse' command

Fergus Henderson fjh at cs.mu.OZ.AU
Mon Nov 16 00:59:28 AEDT 1998


This does not yet
	- preserve the browser state across multiple invocations from
	  within a single mdb session
	- do anything about limiting the size of things output by
	  the `print' command

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

Estimated hours taken: 2

Add an mdb command to invoke the term browser.

trace/mercury_trace_internal.c:
	Add code to implement a new command `browse', which invokes
	the interactive term browser in browser/browse.m.

doc/mdb_categories:
doc/user_guide.texi:
	Document the new `browse' mdb command.
	Also simplify the documentation on the `print' command.

browser/browse.m:
	Change browse/3 so that it takes an argument of type `T' rather
	than `univ'.

library/std_util.m:
	Modify ML_expand() so that it does not abort for values of type
	c_pointer, type_info, or array(T).  This is to prevent the
	browser from aborting when trying to display values of those types.


Index: browser/browse.m
===================================================================
RCS file: /home/mercury1/repository/mercury/browser/browse.m,v
retrieving revision 1.1
diff -u -r1.1 browse.m
--- browse.m	1998/10/25 07:16:37	1.1
+++ browse.m	1998/11/15 13:35:36
@@ -24,12 +24,13 @@
 :- import_module io, std_util, list.
 
 	% The interactive term browser.
-:- pred browse__browse(univ, io__state, io__state).
+:- pred browse__browse(T, io__state, io__state).
 :- mode browse__browse(in, di, uo) is det.
 
 :- pred browse__portray_root(browser_state, string).
 :- mode browse__portray_root(in, out) is det.
 
+
 :- type browser_state
 	--->	browser_state(
 			univ,	% term to browse (as univ)
@@ -50,7 +51,8 @@
 :- pragma export(browse__browse(in, di, uo), "ML_browse").
 
 
-browse__browse(Univ) -->
+browse__browse(Object) -->
+	{ type_to_univ(Object, Univ) },
 	{ default_state(Univ, State) },
 	% startup_message,
 	browse_2(State).
Index: doc/mdb_categories
===================================================================
RCS file: /home/mercury1/repository/mercury/doc/mdb_categories,v
retrieving revision 1.2
diff -u -r1.2 mdb_categories
--- mdb_categories	1998/10/28 05:31:43	1.2
+++ mdb_categories	1998/11/15 07:43:35
@@ -15,8 +15,8 @@
 end
 document_category 400 browsing
 browsing   - Commands that let users explore the state of the computation.
-             The browsing commands are `vars', `print', `stack', `up', `down',
-	     `level', and `current'.
+             The browsing commands are `vars', `print', `browse',
+	     `stack', `up', `down', `level', and `current'.
 
 end
 document_category 500 breakpoint
Index: doc/user_guide.texi
===================================================================
RCS file: /home/mercury1/repository/mercury/doc/user_guide.texi,v
retrieving revision 1.147
diff -u -r1.147 user_guide.texi
--- user_guide.texi	1998/11/15 07:20:07	1.147
+++ user_guide.texi	1998/11/15 08:04:09
@@ -3533,30 +3533,34 @@
 Prints the names of all the known variables in the current environment,
 together with an ordinal number for each variable.
 @sp 1
- at item print @var{num}
-Prints the value of the variable
-with the given ordinal number in the current environment.
- at sp 1
-At the moment this command prints the entire value of the variable,
-even if this is very big. Later it will merely invoke a configurable
-dynamic term browser, which will eventually have its own sublanguage.
- at sp 1
 @item print @var{name}
-Prints the value of the variable
-with the given name in the current environment.
-Report an error if the name is ambiguous
-or if there is no information available about a variable with that name.
+ at itemx print @var{num}
+Prints the value of the variable in the current environment
+with the given name, or with the given ordinal number.
 @sp 1
 At the moment this command prints the entire value of the variable,
-even if this is very big. Later it will merely invoke a configurable
-dynamic term browser, which will eventually have its own sublanguage.
+even if this is very big.
 @sp 1
 @item print *
 Prints the values of all the known variables in the current environment.
 @sp 1
 At the moment this command prints the entire value of every variable,
-even if this is very big. Later it will merely invoke a configurable
-dynamic term browser, which will eventually have its own sublanguage.
+even if this is very big.
+ at sp 1
+ at item browse @var{name}
+ at itemx browse @var{num}
+Invokes an interactive term browser to browse the value of the
+variable in the current environment with the given ordinal number or
+with the given name.
+ at sp 1
+Unlike the @samp{print} command, the depth and size of printed terms
+may be controlled.  The interactive term browser allows you
+to selectively examine particular subterms. 
+The displayed terms may also be clipped to fit
+within a single screen.
+ at sp 1
+For further documentation on the interactive term browser,
+type @samp{help} at the @samp{browser>} prompt.
 @sp 1
 @item stack [-d]
 Prints the names of the ancestors of the call
Index: library/std_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/std_util.m,v
retrieving revision 1.134
diff -u -r1.134 std_util.m
--- std_util.m	1998/11/12 03:16:18	1.134
+++ std_util.m	1998/11/15 09:04:54
@@ -2427,18 +2427,43 @@
                 ((Word *) data_word)[UNIV_OFFSET_FOR_TYPEINFO], 
                 &((Word *) data_word)[UNIV_OFFSET_FOR_DATA], info);
             break;
+
         case MR_DATAREP_VOID:
-		    fatal_error(""ML_expand: cannot expand void types"");
-            break;
+	    /*
+	    ** There's no way to create values of type `void',
+	    ** so this should never happen.
+	    */
+	    fatal_error(""ML_expand: cannot expand void types"");
+
         case MR_DATAREP_ARRAY:
-		    fatal_error(""ML_expand: cannot expand array types"");
+            if (info->need_functor) {
+                make_aligned_string(info->functor, ""<<array>>"");
+            }
+	    /* XXX should we return the arguments here? */
+            info->argument_vector = NULL;
+            info->type_info_vector = NULL;
+            info->arity = 0;
             break;
+
         case MR_DATAREP_TYPEINFO:
-		    fatal_error(""ML_expand: cannot expand typeinfo types"");
+            if (info->need_functor) {
+                make_aligned_string(info->functor, ""<<typeinfo>>"");
+            }
+	    /* XXX should we return the arguments here? */
+            info->argument_vector = NULL;
+            info->type_info_vector = NULL;
+            info->arity = 0;
             break;
+
         case MR_DATAREP_C_POINTER:
-		    fatal_error(""ML_expand: cannot expand c_pointer types"");
+            if (info->need_functor) {
+                make_aligned_string(info->functor, ""<<c_pointer>>"");
+            }
+            info->argument_vector = NULL;
+            info->type_info_vector = NULL;
+            info->arity = 0;
             break;
+
         case MR_DATAREP_UNKNOWN:    /* fallthru */
         default:
             fatal_error(""ML_expand: cannot expand -- unknown data type"");
Index: trace/mercury_trace_internal.c
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_internal.c,v
retrieving revision 1.14
diff -u -r1.14 mercury_trace_internal.c
--- mercury_trace_internal.c	1998/11/13 09:31:11	1.14
+++ mercury_trace_internal.c	1998/11/15 13:46:03
@@ -21,6 +21,7 @@
 #include "mercury_layout_util.h"
 #include "mercury_array_macros.h"
 #include "mercury_getopt.h"
+#include "browse.h"
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -159,13 +160,13 @@
 			*top_layout, Word *saved_regs, int ancestor_level);
 static	void	MR_trace_browse_one(const MR_Stack_Layout_Label *top_layout,
 			Word *saved_regs, int ancestor_level,
-			MR_Var_Spec which_var);
+			MR_Var_Spec which_var, bool browse);
 static	void	MR_trace_browse_all(const MR_Stack_Layout_Label *top_layout,
 			Word *saved_regs, int ancestor_level);
 static	void	MR_trace_browse_var(const char *name,
 			const MR_Stack_Layout_Var *var,
 			Word *saved_regs, Word *base_sp, Word *base_curfr,
-			Word *type_params);
+			Word *type_params, bool browse);
 static	const char *MR_trace_validate_var_count(const MR_Stack_Layout_Label
 			*layout, int *var_count_ptr);
 static	const char *MR_trace_find_var(const MR_Stack_Layout_Label *layout,
@@ -698,16 +699,34 @@
 				var_spec.MR_var_spec_kind = VAR_NUMBER;
 				var_spec.MR_var_spec_number = n;
 				MR_trace_browse_one(layout, saved_regs,
-					*ancestor_level, var_spec);
+					*ancestor_level, var_spec, FALSE);
 			} else {
 				var_spec.MR_var_spec_kind = VAR_NAME;
 				var_spec.MR_var_spec_name = words[1];
 				MR_trace_browse_one(layout, saved_regs,
-					*ancestor_level, var_spec);
+					*ancestor_level, var_spec, FALSE);
 			}
 		} else {
 			MR_trace_usage("browsing", "print");
 		}
+	} else if (streq(words[0], "browse")) {
+		if (word_count == 2) {
+			MR_Var_Spec	var_spec;
+
+			if (MR_trace_is_number(words[1], &n)) {
+				var_spec.MR_var_spec_kind = VAR_NUMBER;
+				var_spec.MR_var_spec_number = n;
+				MR_trace_browse_one(layout, saved_regs,
+					*ancestor_level, var_spec, TRUE);
+			} else {
+				var_spec.MR_var_spec_kind = VAR_NAME;
+				var_spec.MR_var_spec_name = words[1];
+				MR_trace_browse_one(layout, saved_regs,
+					*ancestor_level, var_spec, TRUE);
+			}
+		} else {
+			MR_trace_usage("browsing", "browse");
+		}
 	} else if (streq(words[0], "stack")) {
 		bool	include_trace_data;
 
@@ -1632,7 +1651,8 @@
 
 static void
 MR_trace_browse_one(const MR_Stack_Layout_Label *top_layout,
-	Word *saved_regs, int ancestor_level, MR_Var_Spec var_spec)
+	Word *saved_regs, int ancestor_level, MR_Var_Spec var_spec,
+	bool browse)
 {
 	const MR_Stack_Layout_Label	*level_layout;
 	Word				*base_sp;
@@ -1670,7 +1690,7 @@
 				valid_saved_regs, base_sp, base_curfr);
 	MR_trace_browse_var(MR_name_if_present(vars, which_var),
 		&vars->MR_slvs_pairs[which_var], valid_saved_regs,
-		base_sp, base_curfr, type_params);
+		base_sp, base_curfr, type_params, browse);
 	free(type_params);
 }
 
@@ -1717,7 +1737,7 @@
 	for (i = 0; i < var_count; i++) {
 		MR_trace_browse_var(MR_name_if_present(vars, i),
 			&vars->MR_slvs_pairs[i], valid_saved_regs,
-			base_sp, base_curfr, type_params);
+			base_sp, base_curfr, type_params, FALSE);
 	}
 
 	free(type_params);
@@ -1725,7 +1745,8 @@
 
 static void
 MR_trace_browse_var(const char *name, const MR_Stack_Layout_Var *var,
-	Word *saved_regs, Word *base_sp, Word *base_curfr, Word *type_params)
+	Word *saved_regs, Word *base_sp, Word *base_curfr, Word *type_params,
+	bool browse)
 {
 	Word	value;
 	Word	type_info;
@@ -1749,13 +1770,16 @@
 	/* The initial blanks are to visually separate */
 	/* the variable names from the prompt. */
 
-	if (name != NULL) {
-		printf("%7s%-21s\t", "", name);
-	} else {
-		printf("%7s%-21s\t", "", "anonymous variable");
+	if (!browse) {
+		if (name != NULL) {
+			printf("%7s%-21s\t", "", name);
+		} else {
+			printf("%7s%-21s\t", "", "anonymous variable");
+		}
+
+		fflush(stdout);
 	}
 
-	fflush(stdout);
 
 	/*
 	** "variables" representing the saved values of succip, hp etc,
@@ -1766,12 +1790,20 @@
 	print_value = MR_get_type_and_value_base(var, saved_regs,
 			base_sp, base_curfr, type_params, &type_info, &value);
 	if (print_value) {
-		printf("\t");
-		MR_TRACE_CALL_MERCURY(
-			MR_write_variable(type_info, value);
-		);
+		if (browse) {
+			MR_TRACE_CALL_MERCURY(
+				ML_browse(type_info, value);
+			);
+		} else {
+			printf("\t");
+			fflush(stdout);
+			MR_TRACE_CALL_MERCURY(
+				MR_write_variable(type_info, value);
+			);
+		}
 	}
 
+	/* XXX if browse? */
 	printf("\n");
 }
 

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "Binaries may die
WWW: <http://www.cs.mu.oz.au/~fjh>  |   but source code lives forever"
PGP: finger fjh at 128.250.37.3        |     -- leaked Microsoft memo.



More information about the developers mailing list