for review: debugger initialization

Zoltan Somogyi zs at cs.mu.OZ.AU
Fri Nov 13 20:29:15 AEDT 1998


Since I am going home for the weekend, I will commit this now.
Fergus can fix anything he dislikes at his leasure.

Estimated hours taken: 2

Change the initialization sequence of the debugger to match more people's
expectations: it now reads, in order:

	the file named by the MERCURY_DEBUGGER_INIT environment variable
	~/.mdbrc 
	.mdbrc

The first should exist; the others need not.

Note that since ~/.mdbrc is always sourced if it exists, you cannot put
anything in your ~/.mdbrc that interferes with the test cases in the
tests/debugger directory if you want your bootchecks to work.

doc/user_guide.texi:
	Document the initialization sequence. This completes the debugger
	invocation section.

scripts/mdb.in:
	Set up MERCURY_DEBUGGER_INIT before invoking the executable
	being debugged.

trace/mercury_trace_internal.c:
	Change to the above initialization sequence.

Zoltan.

cvs diff: Diffing .
cvs diff: Diffing bindist
cvs diff: Diffing boehm_gc
cvs diff: Diffing boehm_gc/Mac_files
cvs diff: Diffing boehm_gc/cord
cvs diff: Diffing boehm_gc/cord/private
cvs diff: Diffing boehm_gc/include
cvs diff: Diffing boehm_gc/include/private
cvs diff: Diffing browser
cvs diff: Diffing bytecode
cvs diff: Diffing bytecode/test
cvs diff: Diffing compiler
cvs diff: Diffing compiler/notes
cvs diff: Diffing doc
Index: doc/user_guide.texi
===================================================================
RCS file: /home/mercury1/repository/mercury/doc/user_guide.texi,v
retrieving revision 1.145
diff -u -u -r1.145 user_guide.texi
--- user_guide.texi	1998/11/13 08:44:31	1.145
+++ user_guide.texi	1998/11/13 09:19:41
@@ -3172,9 +3172,27 @@
 because you do not get a chance
 to specify the command line of the program later.
 
- at c XXX more to come
- at c environment variables controlling debugger startup
- at c sourcing of .mdbrc files
+When the debugger starts up, as part of its initialization
+it executes commands from the following three sources, in order:
+ at table @emph
+ at item
+The file named by the @samp{MERCURY_DEBUGGER_INIT} environment variable.
+Usually, @samp{mdb} sets this variable to point to a file
+that provides documentation for all the debugger commands
+and defines a small set of aliases.
+However, if @samp{MERCURY_DEBUGGER_INIT} is already defined
+when @samp{mdb} is invoked, it will leave its value unchanged.
+You can use this override ability to provide alternate documentation.
+If the file named by @samp{MERCURY_DEBUGGER_INIT} cannot be read,
+ at samp{mdb} will print a warning,
+since in that case, that usual online documentation will not be available.
+ at item
+The file named @samp{.mdbrc} in your home directory.
+You can put your usual aliases and settings here.
+ at item
+The file named @samp{.mdbrc} in the current working directory.
+You can put program-specific aliases and settings here.
+ at end table
 
 @node Mercury debugger concepts
 @section Mercury debugger concepts
@@ -3903,6 +3921,12 @@
 @sp 1
 @item MERCURY_MKINIT
 Filename of the program to create the @file{*_init.c} file.
+
+ at sp 1
+ at item MERCURY_DEBUGGER_INIT
+Name of a file that contains startup commands for the Mercury debugger.
+This file should contain documentation for the debugger command set,
+and possibly a set of default aliases.
 
 @sp 1
 @item MERCURY_OPTIONS
cvs diff: Diffing extras
cvs diff: Diffing extras/cgi
cvs diff: Diffing extras/complex_numbers
cvs diff: Diffing extras/complex_numbers/samples
cvs diff: Diffing extras/complex_numbers/tests
cvs diff: Diffing extras/exceptions
cvs diff: Diffing extras/graphics
cvs diff: Diffing extras/graphics/mercury_opengl
cvs diff: Diffing extras/graphics/mercury_tcltk
cvs diff: Diffing extras/graphics/samples
cvs diff: Diffing extras/graphics/samples/calc
cvs diff: Diffing extras/graphics/samples/maze
cvs diff: Diffing extras/graphics/samples/pent
cvs diff: Diffing extras/odbc
cvs diff: Diffing extras/references
cvs diff: Diffing extras/references/samples
cvs diff: Diffing extras/references/tests
cvs diff: Diffing extras/trailed_update
cvs diff: Diffing extras/trailed_update/samples
cvs diff: Diffing extras/trailed_update/tests
cvs diff: Diffing library
cvs diff: Diffing lp_solve
cvs diff: Diffing lp_solve/lp_examples
cvs diff: Diffing profiler
cvs diff: Diffing runtime
cvs diff: Diffing runtime/GETOPT
cvs diff: Diffing runtime/machdeps
cvs diff: Diffing samples
cvs diff: Diffing samples/c_interface
cvs diff: Diffing samples/c_interface/c_calls_mercury
cvs diff: Diffing samples/c_interface/cplusplus_calls_mercury
cvs diff: Diffing samples/c_interface/mercury_calls_c
cvs diff: Diffing samples/c_interface/mercury_calls_cplusplus
cvs diff: Diffing samples/c_interface/mercury_calls_fortran
cvs diff: Diffing samples/c_interface/simpler_c_calls_mercury
cvs diff: Diffing samples/c_interface/simpler_cplusplus_calls_mercury
cvs diff: Diffing samples/diff
cvs diff: Diffing samples/muz
cvs diff: Diffing scripts
Index: scripts/mdb.in
===================================================================
RCS file: /home/mercury1/repository/mercury/scripts/mdb.in,v
retrieving revision 1.1
diff -u -u -r1.1 mdb.in
--- mdb.in	1998/10/16 06:19:24	1.1
+++ mdb.in	1998/11/13 08:52:25
@@ -20,7 +20,7 @@
 	Otherwise, mdb will execute the command line as if the mdb prefix
 	weren't there.
 Environment variables:
-	MERCURY_OPTIONS.
+	MERCURY_OPTIONS, MERCURY_DEBUGGER_INIT.
 "
 
 case $# in
@@ -36,6 +36,6 @@
 
 MERCURY_OPTIONS="$MERCURY_OPTIONS -Di"
 export MERCURY_OPTIONS
-DEFAULT_MERCURY_DEBUGGER_INIT=@DEFAULT_MERCURY_DEBUGGER_INIT_DIR@/mdbrc
-export DEFAULT_MERCURY_DEBUGGER_INIT
+MERCURY_DEBUGGER_INIT=${MERCURY_DEBUGGER_INIT- at DEFAULT_MERCURY_DEBUGGER_INIT_DIR@/mdbrc}
+export MERCURY_DEBUGGER_INIT
 exec "$@"
cvs diff: Diffing tests
cvs diff: Diffing tests/benchmarks
cvs diff: Diffing tests/debugger
cvs diff: Diffing tests/general
cvs diff: Diffing tests/hard_coded
cvs diff: Diffing tests/hard_coded/sub-modules
cvs diff: Diffing tests/hard_coded/typeclasses
cvs diff: Diffing tests/invalid
cvs diff: Diffing tests/misc_tests
cvs diff: Diffing tests/tabling
cvs diff: Diffing tests/term
cvs diff: Diffing tests/valid
cvs diff: Diffing tests/warnings
cvs diff: Diffing tools
cvs diff: Diffing trace
Index: trace/mercury_trace_internal.c
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_internal.c,v
retrieving revision 1.13
diff -u -u -r1.13 mercury_trace_internal.c
--- mercury_trace_internal.c	1998/11/13 08:40:47	1.13
+++ mercury_trace_internal.c	1998/11/13 09:02:38
@@ -119,10 +119,9 @@
 } MR_Var_Spec;
 
 static	void	MR_trace_internal_ensure_init(void);
-static	bool	MR_trace_internal_init_from_env(const char *env_var);
-static	bool	MR_trace_internal_init_from_file(const char *filename);
-static	bool	MR_trace_internal_init_from_env_dir(const char *env_var,
-			const char *filename);
+static	void	MR_trace_internal_init_from_env(void);
+static	void	MR_trace_internal_init_from_local(void);
+static	void	MR_trace_internal_init_from_home_dir(void);
 static	MR_Next	MR_trace_debug_cmd(char *line, MR_Trace_Cmd_Info *cmd,
 			const MR_Stack_Layout_Label *layout,
 			Word *saved_regs, MR_Event_Details *event_details,
@@ -289,95 +288,62 @@
 			MR_scroll_limit = n;
 		}
 
-		/*
-		** Look for an initialization file in the following places,
-		** in order:
-		** 
-		** - the file named by the MERCURY_DEBUGGER_INIT environment
-		**   variable, which can be set by the user
-		**
-		** - the file .mdbrc in the current directory
-		**
-		** - the file .mdbrc in the user's home directory
-		**
-		** - the file named by the DEFAULT_MERCURY_DEBUGGER_INIT
-		**   environment variable, which is set by the mdb script
-		**   to point to the system's default init script
-		**
-		** We stop as soon as we find and source one.
-		**
-		** XXX Several aspects of how we find these locations
-		** are too Unix specific.
-		*/
-
-		if (! (MR_trace_internal_init_from_env("MERCURY_DEBUGGER_INIT")
-		|| MR_trace_internal_init_from_file(MDBRC_FILENAME)
-		|| MR_trace_internal_init_from_env_dir("HOME", MDBRC_FILENAME)
-		|| MR_trace_internal_init_from_env(
-				"DEFAULT_MERCURY_DEBUGGER_INIT")))
-		{
-			printf("mdb: warning, "
-				"cannot find any initialization file.\n");
-		}
+		MR_trace_internal_init_from_env();
+		MR_trace_internal_init_from_local();
+		MR_trace_internal_init_from_home_dir();
 
 		MR_trace_internal_initialized = TRUE;
 	}
 }
 
-static bool
-MR_trace_internal_init_from_env(const char *env_var)
+static void
+MR_trace_internal_init_from_env(void)
 {
 	char	*init;
 
-	init = getenv(env_var);
+	init = getenv("MERCURY_DEBUGGER_INIT");
 	if (init != NULL) {
-		return MR_trace_source(init);
-	} else {
-		return FALSE;
+		(void) MR_trace_source(init);
+		/* If the source failed, the error message has been printed. */
 	}
 }
 
-static bool
-MR_trace_internal_init_from_file(const char *filename)
+static void
+MR_trace_internal_init_from_local(void)
 {
 	FILE	*fp;
 
-	if ((fp = fopen(filename, "r")) != NULL) {
+	if ((fp = fopen(MDBRC_FILENAME, "r")) != NULL) {
 		MR_trace_source_from_open_file(fp);
 		fclose(fp);
-		return TRUE;
-	} else {
-		return FALSE;
 	}
 }
 
-static bool
-MR_trace_internal_init_from_env_dir(const char *env_var, const char *filename)
+static void
+MR_trace_internal_init_from_home_dir(void)
 {
 	char	*env;
 	char	*buf;
 	int	len;
 	FILE	*fp;
 
-	env = getenv(env_var);
+	/* XXX This code is too Unix specific. */
+
+	env = getenv("HOME");
 	if (env == NULL) {
-		return FALSE;
+		return;
 	}
 
-	/* XXX This code is too Unix specific. */
-	buf = checked_malloc(strlen(env) + strlen(filename) + 2);
+	buf = checked_malloc(strlen(env) + strlen(MDBRC_FILENAME) + 2);
 	(void) strcpy(buf, env);
 	(void) strcat(buf, "/");
-	(void) strcat(buf, filename);
+	(void) strcat(buf, MDBRC_FILENAME);
 	if ((fp = fopen(buf, "r")) != NULL) {
 		MR_trace_source_from_open_file(fp);
 		fclose(fp);
-		free(buf);
-		return TRUE;
-	} else {
-		free(buf);
-		return FALSE;
 	}
+
+	free(buf);
 }
 
 static MR_Next
cvs diff: Diffing trial
cvs diff: Diffing util



More information about the developers mailing list