[m-rev.] for review: allow comments and blank lines in mdb scripts

Ian MacLarty maclarty at csse.unimelb.edu.au
Fri Jun 15 14:39:48 AEST 2007


Ignore empty lines, or lines that start with `#', in sourced mdb scripts.
This is useful for formatting and documenting mdb scripts.

Create a local copy of the mdbrc file so that we can test new mdb scripts
in the test suite.

NEWS:
	Mention the changes.

configure.in:
	Create a copy of mdbrc.in in the tests directory and create an mdbrc
	from this file using different substitutions than those used for the
	mdbrc that will be installed.  This is necessary so that we can use
	the local mdbrc file when running the tests.  Previously if the mdbrc
	file was changed (for example a new alias was added), then we had to
	install it before testing.

doc/user_guide.texi:
	Document the new behaviour of the source command.

scripts/mdb_grep:
scripts/mdb_open:
scripts/mdb_track:
	Add comments to these mdb scripts.

scripts/mdbrc.in:
	Use a different substitution variable for the location of mdb_doc,
	since for the test version of mdbrc mdb_doc will be in a different
	location to the other scripts.

tests/Mmake.common:
	Get mdb to use the local mdbrc when invoked for the tests.

	Clean mdbrc and mdbrc.in.

tests/debugger/Mercury.options:
tests/debugger/Mmakefile:
tests/debugger/scripts.exp:
tests/debugger/scripts.inp:
tests/debugger/scripts.m:
	Add a test case for the three existing mdb scripts.

trace/mercury_trace_readline.c:
trace/mercury_trace_readline.h:
	Rename MR_trace_readline_expand_args to MR_trace_readline_from_script
	and get it to ignore comment lines and blank lines.

trace/mercury_trace_internal.c:
	Adapt to changes in mercury_trace_readline.h.

Index: NEWS
===================================================================
RCS file: /home/mercury1/repository/mercury/NEWS,v
retrieving revision 1.466
diff -u -r1.466 NEWS
--- NEWS	12 Jun 2007 06:06:25 -0000	1.466
+++ NEWS	15 Jun 2007 04:29:57 -0000
@@ -213,6 +213,9 @@
 
 * You can now put breakpoints on individual events inside procedures.
 
+* mdb now ignores empty lines, or lines beginning with a `#' character
+  in sourced files.  This is useful for formatting and commenting mdb scripts.
+
 DETAILED LISTING
 ================
 
@@ -304,6 +307,9 @@
   will cause execution to stop only at the specified port in the specified
   procedure. If there is more than event of the given port type in the
   procedure, mdb will prompt the user to select one.
+
+* mdb now ignores empty lines, or lines beginning with a `#' character
+  in sourced files.  This is useful for formatting and commenting mdb scripts.
 
 NEWS for Mercury 0.13.1
 -----------------------
Index: configure.in
===================================================================
RCS file: /home/mercury1/repository/mercury/configure.in,v
retrieving revision 1.492
diff -u -r1.492 configure.in
--- configure.in	12 Jun 2007 04:22:39 -0000	1.492
+++ configure.in	15 Jun 2007 04:29:58 -0000
@@ -135,6 +135,8 @@
 AC_SUBST(LIBDIR)
 DEFAULT_MERCURY_DEBUGGER_INIT_DIR=$LIBDIR/mdb
 AC_SUBST(DEFAULT_MERCURY_DEBUGGER_INIT_DIR)
+DEFAULT_MERCURY_DEBUGGER_DOC=$DEFAULT_MERCURY_DEBUGGER_INIT_DIR/mdb_doc
+AC_SUBST(DEFAULT_MERCURY_DEBUGGER_DOC)
 #-----------------------------------------------------------------------------#
 case "$host" in
 	mips-sgi-irix5.*)
@@ -4450,23 +4452,45 @@
 
 #-----------------------------------------------------------------------------#
 
-# We should only set up TESTS_FLAGS if the tests directory is accessible.
-# It can be in one of two places:
+# We should only set up TESTS_FLAGS and the test mdbrc file if the tests
+# directory is accessible.  It can be in one of two places:
 # (a) in the mercury directory
 # (b) a sibling of the mercury directory
 
 if test -e tests/TESTS_FLAGS.in
 then
 	test_flags="tests/TESTS_FLAGS"
+	test_mdbrc="tests/mdbrc"
 else
 	if test -e ../tests/TESTS_FLAGS.in
 	then
 		test_flags="../tests/TESTS_FLAGS"
+		test_mdbrc="../tests/mdbrc"
 	else
 		test_flags=""
+		test_mdbrc=""
 	fi
 fi
 
+# When running the debugger tests we want to use the local mdbrc
+# file, not the installed one, so that we can test changes
+# to this file without having to install first.  We therefore create
+# a copy of the mdbrc.in for use with the test suite.
+#
+case $test_mdbrc in
+	"")
+	;;
+	*)
+		m4 -P -DDEFAULT_MERCURY_DEBUGGER_INIT_DIR=TESTS_MDB_INIT_DIR  \
+			-DDEFAULT_MERCURY_DEBUGGER_DOC=TESTS_MDB_DOC          \
+			`pwd`/scripts/mdbrc.in > $test_mdbrc.in
+	;;
+esac
+TESTS_MDB_INIT_DIR=`pwd`/scripts
+TESTS_MDB_DOC=`pwd`/doc/mdb_doc
+AC_SUBST(TESTS_MDB_INIT_DIR)
+AC_SUBST(TESTS_MDB_DOC)
+
 # The references to $conf_h_copy and $had_old_conf_h below are in code that
 # autoconf puts into a subshell, so we must export them.
 conf_h_copy=/tmp/mercury_conf.h.$$
@@ -4509,6 +4533,7 @@
 profiler/PROF_FLAGS
 deep_profiler/DEEP_FLAGS
 "$test_flags"
+"$test_mdbrc"
 ,
 [
 # Only do this when compiling the source, not when reconfiguring
Index: doc/user_guide.texi
===================================================================
RCS file: /home/mercury1/repository/mercury/doc/user_guide.texi,v
retrieving revision 1.526
diff -u -r1.526 user_guide.texi
--- doc/user_guide.texi	13 Jun 2007 02:48:46 -0000	1.526
+++ doc/user_guide.texi	15 Jun 2007 04:29:58 -0000
@@ -2004,6 +2004,9 @@
 The file named @samp{.mdbrc} in the current working directory.
 You can put program-specific aliases and settings here.
 @end enumerate
+mdb will ignore blank lines,
+or lines that start with the character #,
+in any of the files mentioned above.
 
 mdb accepts the following options from the command line.  The options
 should be given to mdb before the name of the executable to be debugged.
@@ -4276,6 +4279,11 @@
 Occurrences of the strings "$1" to "$9" in the sourced file
 will be replaced by the corresponding arguments given in the source
 command before the commands in the sourced file are executed.
+ at sp 1
+Lines containing only whitespace,
+or lines that start with zero or more whitespace characters followed by a hash
+(#) character are ignored.
+Hash characters can be used to place comments in your mdb scripts.
 @sp 1
 The option @samp{-i} or @samp{--ignore-errors} tells @samp{mdb}
 not to complain if the named file does not exist or is not readable.
Index: scripts/mdb_grep
===================================================================
RCS file: /home/mercury1/repository/mercury/scripts/mdb_grep,v
retrieving revision 1.2
diff -u -r1.2 mdb_grep
--- scripts/mdb_grep	25 Jul 2006 08:42:47 -0000	1.2
+++ scripts/mdb_grep	15 Jun 2007 04:29:58 -0000
@@ -1,3 +1,8 @@
+# This script saves a term to a file and then invokes grep on the file.
+# It is useful for checking if a data structure contains a particular value.
+# $1 is a regular expression to search for.
+# $2 is any valid term reference accepted by the dump command.
+
 dump $2 .mdb_grep_tmp
 shell grep $1 .mdb_grep_tmp
 shell rm .mdb_grep_tmp
Index: scripts/mdb_open
===================================================================
RCS file: /home/mercury1/repository/mercury/scripts/mdb_open,v
retrieving revision 1.2
diff -u -r1.2 mdb_open
--- scripts/mdb_open	25 Jul 2006 08:42:47 -0000	1.2
+++ scripts/mdb_open	15 Jun 2007 04:29:58 -0000
@@ -1,3 +1,7 @@
+# This script saves a term to a file and then opens the file with an
+# editor.
+# $1 is any valid term reference accepted by the dump command.
+
 dump $1 .mdb_open_tmp
 shell ${EDITOR-vi} .mdb_open_tmp
 shell rm .mdb_open_tmp
Index: scripts/mdb_track
===================================================================
RCS file: /home/mercury1/repository/mercury/scripts/mdb_track,v
retrieving revision 1.1
diff -u -r1.1 mdb_track
--- scripts/mdb_track	29 May 2007 08:18:26 -0000	1.1
+++ scripts/mdb_track	15 Jun 2007 04:29:58 -0000
@@ -1,3 +1,7 @@
+# This script invokes the declarative debugger's track command.
+# $1 is the argument the term to track is in.
+# $2 is the path to the term in the argument.
+
 dd
 browse $1
 cd $2
Index: scripts/mdbrc.in
===================================================================
RCS file: /home/mercury1/repository/mercury/scripts/mdbrc.in,v
retrieving revision 1.8
diff -u -r1.8 mdbrc.in
--- scripts/mdbrc.in	29 May 2007 08:18:26 -0000	1.8
+++ scripts/mdbrc.in	15 Jun 2007 04:29:58 -0000
@@ -1,4 +1,4 @@
-source @DEFAULT_MERCURY_DEBUGGER_INIT_DIR@/mdb_doc
+source @DEFAULT_MERCURY_DEBUGGER_DOC@
 alias	s	step
 alias	g	goto
 alias	f	finish
Index: tests/Mmake.common
===================================================================
RCS file: /home/mercury1/repository/tests/Mmake.common,v
retrieving revision 1.49
diff -u -r1.49 Mmake.common
--- tests/Mmake.common	14 May 2007 08:13:57 -0000	1.49
+++ tests/Mmake.common	15 Jun 2007 04:29:58 -0000
@@ -57,7 +57,8 @@
 # may get different version numbers printed in it. This would otherwise be
 # the source of irrelevant difference between the actual and expected outputs.
 
-MDB = HOME=/nonexistent MERCURY_SUPPRESS_MDB_BANNER=yes mdb
+MDB = HOME=/nonexistent MERCURY_SUPPRESS_MDB_BANNER=yes \
+	MERCURY_DEBUGGER_INIT=$(TESTS_DIR)/mdbrc mdb
 
 # Debugger test cases can standardize the reported event numbers and call
 # sequence numbers by using $(MDB_STD) instead of $(MDB) on the command line.
@@ -189,7 +190,10 @@
 ERROR_OUTPUT_FILE = runtests.errs
 
 realclean_local: clean_logs clean_errors
+	-rm mdbrc
+
 clean_local: clean_out clean_res clean_zip clean_trace_counts
+	-rm mdbrc.in
 
 # XXX what is this target for??
 clean_mc: clean_c clean_o clean_out clean_res 
Index: tests/debugger/Mercury.options
===================================================================
RCS file: /home/mercury1/repository/tests/debugger/Mercury.options,v
retrieving revision 1.23
diff -u -r1.23 Mercury.options
--- tests/debugger/Mercury.options	1 May 2007 06:31:24 -0000	1.23
+++ tests/debugger/Mercury.options	15 Jun 2007 04:29:58 -0000
@@ -16,6 +16,7 @@
 MCFLAGS-poly_io_retry = --trace-table-io-all
 MCFLAGS-poly_io_retry2 = --trace-table-io-all
 MCFLAGS-queens_rep = --trace rep
+MCFLAGS-scripts = --trace rep
 MCFLAGS-shallow = --trace shallow
 MCFLAGS-shallow2 = --trace deep
 MCFLAGS-tabled_read = --trace-table-io-all
Index: tests/debugger/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/debugger/Mmakefile,v
retrieving revision 1.136
diff -u -r1.136 Mmakefile
--- tests/debugger/Mmakefile	6 Jun 2007 01:48:08 -0000	1.136
+++ tests/debugger/Mmakefile	15 Jun 2007 04:29:58 -0000
@@ -12,6 +12,7 @@
 	mdb_command_test		\
 	queens				\
 	retry				\
+	scripts				\
 	tabled_read			\
 	tabled_read_unitize		\
 	tabled_read_decl
@@ -501,6 +502,9 @@
 	    sed 's/^alias open source.*$$/alias open source ZZZ\/mdb_open/' | \
 	    sed 's/^alias track source.*$$/alias track source ZZZ\/mdb_track/'\
 	    > save.out 2>&1
+
+scripts.out: scripts scripts.inp
+	EDITOR=cat $(MDB_STD) ./scripts < scripts.inp > scripts.out 2>&1
 
 shallow.out: shallow shallow.inp
 	$(MDB) ./shallow < shallow.inp > shallow.out 2>&1
Index: tests/debugger/scripts.exp
===================================================================
RCS file: tests/debugger/scripts.exp
diff -N tests/debugger/scripts.exp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/debugger/scripts.exp	15 Jun 2007 04:29:58 -0000
@@ -0,0 +1,26 @@
+      E1:     C1 CALL pred scripts.main/2-0 (det) scripts.m:16
+mdb> echo on
+Command echo enabled.
+mdb> register --quiet
+mdb> step
+      E2:     C2 CALL pred scripts.p/1-0 (det) scripts.m:23 (scripts.m:17)
+mdb> finish
+      E3:     C2 EXIT pred scripts.p/1-0 (det) scripts.m:23 (scripts.m:17)
+mdb> track 1
+p(type1(1, "foo"))
+q(type1(1, "foo"))
+Context of current question : scripts.m:27 (scripts.m:23)
+Search mode                 : top down                   
+The current question was chosen because the marked subterm was bound by
+the unification inside the predicate scripts.q/1 (scripts.m:27). The
+path to the subterm in the atom is 1.
+      E4:     C3 EXIT pred scripts.q/1-0 (det) scripts.m:27 (scripts.m:23)
+mdb> open 1
+type1(
+ 1,
+ "foo"
+)
+mdb> grep foo 1
+ "foo"
+mdb> continue
+type1(1, "foo")
Index: tests/debugger/scripts.inp
===================================================================
RCS file: tests/debugger/scripts.inp
diff -N tests/debugger/scripts.inp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/debugger/scripts.inp	15 Jun 2007 04:29:58 -0000
@@ -0,0 +1,8 @@
+echo on
+register --quiet
+step
+finish
+track 1
+open 1
+grep foo 1
+continue
Index: tests/debugger/scripts.m
===================================================================
RCS file: tests/debugger/scripts.m
diff -N tests/debugger/scripts.m
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/debugger/scripts.m	15 Jun 2007 04:29:58 -0000
@@ -0,0 +1,27 @@
+% This module is used to test the mdb scripts.
+%
+:- module scripts.
+
+:- interface.
+
+:- import_module io.
+
+:- pred main(io::di, io::uo) is det.
+
+:- implementation.
+
+:- type type1
+	--->	type1(int, string).
+
+main(!IO) :-
+	p(T),
+	io.write(T, !IO),
+	io.nl(!IO).
+
+:- pred p(type1::out) is det.
+
+p(T) :- q(T).
+
+:- pred q(type1::out) is det.
+
+q(type1(1, "foo")).
Index: trace/mercury_trace_internal.c
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_internal.c,v
retrieving revision 1.234
diff -u -r1.234 mercury_trace_internal.c
--- trace/mercury_trace_internal.c	2 May 2007 02:16:01 -0000	1.234
+++ trace/mercury_trace_internal.c	15 Jun 2007 04:29:58 -0000
@@ -711,7 +711,7 @@
     ** preserving their order in the sourced file.
     */
 
-    while ((contents = MR_trace_readline_expand_args(fp, args, num_args))
+    while ((contents = MR_trace_readline_from_script(fp, args, num_args))
         != NULL)
     {
         line = MR_NEW(MR_Line);
Index: trace/mercury_trace_readline.c
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_readline.c,v
retrieving revision 1.11
diff -u -r1.11 mercury_trace_readline.c
--- trace/mercury_trace_readline.c	10 Nov 2006 03:24:17 -0000	1.11
+++ trace/mercury_trace_readline.c	15 Jun 2007 04:29:58 -0000
@@ -166,9 +166,10 @@
 }
 
 char *
-MR_trace_readline_expand_args(FILE *fp, char **args, int num_args)
+MR_trace_readline_from_script(FILE *fp, char **args, int num_args)
 {
     char    *line;
+    char    *orig_line = NULL;
     size_t  line_length;
     int     line_index;
     size_t  expanded_line_length;
@@ -178,11 +179,23 @@
     size_t  arg_length;
     char    *arg;
 
-    line = MR_trace_readline_raw(fp);
-    if (line == NULL) {
-        return NULL;
-    }
-    line_length = strlen(line);
+    do {
+        if (orig_line != NULL) {
+            MR_free(orig_line);
+        }
+        orig_line = MR_trace_readline_raw(fp);
+        line = orig_line;
+        if (line == NULL) {
+            return NULL;
+        }
+        /*
+        ** Chomp whitespace.
+        */
+        while (MR_isspace(*line)) {
+            line++;
+        }
+        line_length = strlen(line);
+    } while (line_length == 0 || *line == '#');
 
     expanded_line_length = line_length;
     expanded_line = (char*) MR_malloc(line_length + 1);
@@ -218,7 +231,7 @@
         }
     }
 
-    MR_free(line);
+    MR_free(orig_line);
     expanded_line[expanded_line_index] = '\0';
 
     return expanded_line;
Index: trace/mercury_trace_readline.h
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_readline.h,v
retrieving revision 1.4
diff -u -r1.4 mercury_trace_readline.h
--- trace/mercury_trace_readline.h	10 Nov 2006 03:24:17 -0000	1.4
+++ trace/mercury_trace_readline.h	15 Jun 2007 04:29:58 -0000
@@ -35,15 +35,17 @@
 extern  char    *MR_trace_readline_raw(FILE *in);
 
 /*
-** Read a line from a file and replace occurrences of the strings "$1" to
-** "$9" with the corresponding values in the args array.  If there is no
-** value in the args array, then the "$n" string is replaced by the empty
-** string.
+** Read a line from an mdb script.
+** Ocurrences of the strings "$1" to
+** "$9" are replaced with the corresponding values in the args array.
+** If there is no value in the args array, then the "$n" string is replaced
+** by the empty string.
+** Lines beginning with '#' and empty lines are ignored.
 ** Return a pointer to a MR_malloc'd buffer holding the new string (without
 ** the final newline).  If EOF occurs on a nonempty line, treat the EOF as a
 ** newline; if EOF occurs on an empty line, return NULL.  
 ** Don't use GNU readline.
 */
 
-extern  char    *MR_trace_readline_expand_args(FILE *fp, char **args,
+extern  char    *MR_trace_readline_from_script(FILE *fp, char **args,
                     int num_args);
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list