diff: fix bug caused/exposed by my recent change

Fergus Henderson fjh at cs.mu.OZ.AU
Sat Mar 20 18:16:02 AEDT 1999


Estimated hours taken: 0.5

util/mkinit.c:
	Fix a bug where it was generating code that referred to
	`MR_trace_init_external' and `MR_trace_final_external',
	which are defined in the `trace' library (libmer_trace.a),
	even when `--trace' was not specified on the command line.
	I changed the code to set MR_address_of_init_external
	and MR_address_of_final_external to NULL instead of to those
	functions if tracing was not enabled via `--trace'.

runtime/mercury_trace_base.c:
	If MR_address_of_init_external or MR_address_of_final_external
	is NULL, and they are needed, print a message saying that
	the executable must be rebuilt with `-t' (or `--trace').

Index: runtime/mercury_trace_base.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_trace_base.c,v
retrieving revision 1.13
diff -u -r1.13 mercury_trace_base.c
--- mercury_trace_base.c	1999/02/28 06:33:55	1.13
+++ mercury_trace_base.c	1999/03/20 07:13:41
@@ -138,18 +138,26 @@
 			path, max_mr_num);
 }
 
-Code *
-MR_trace_fake(const MR_Stack_Layout_Label *layout, MR_Trace_Port port,
-	Unsigned seqno, Unsigned depth, const char * path, int max_mr_num)
+static void
+MR_tracing_not_enabled(void)
 {
 	fatal_error("This executable is not set up for debugging.\n"
 		"Rebuild the <main>_init.c file, "
-		"and give the `-t' flag to c2init when you do so.\n"
-		"If you are using mmake, you can do this by including "
-		"`-t' in C2INITFLAGS.\n"
+		"and give the `-t' (or `--trace')\n"
+		"option to c2init when you do so.  "
+		"If you are using mmake, you\n"
+		"can do this by including "
+		"`-t' (or `--trace') in C2INITFLAGS.\n"
 		"For further details, please see the \"Debugging\" chapter "
 		"of the\n"
 		"Mercury User's Guide.\n");
+}
+
+Code *
+MR_trace_fake(const MR_Stack_Layout_Label *layout, MR_Trace_Port port,
+	Unsigned seqno, Unsigned depth, const char * path, int max_mr_num)
+{
+	MR_tracing_not_enabled();
 	/*NOTREACHED*/
 	return NULL;
 }
@@ -158,8 +166,13 @@
 MR_trace_init(void)
 {
 #ifdef MR_USE_EXTERNAL_DEBUGGER
-	if (MR_trace_handler == MR_TRACE_EXTERNAL)
-		MR_address_of_trace_init_external();
+	if (MR_trace_handler == MR_TRACE_EXTERNAL) {
+		if (MR_address_of_trace_init_external != NULL) {
+			MR_address_of_trace_init_external();
+		} else {
+			MR_tracing_not_enabled();
+		}
+	}
 #endif
 }
 
@@ -167,8 +180,13 @@
 MR_trace_final(void)
 {
 #ifdef MR_USE_EXTERNAL_DEBUGGER
-	if (MR_trace_handler == MR_TRACE_EXTERNAL)
-		MR_address_of_trace_final_external();
+	if (MR_trace_handler == MR_TRACE_EXTERNAL) {
+		if (MR_address_of_trace_final_external != NULL) {
+			MR_address_of_trace_final_external();
+		} else {
+			MR_tracing_not_enabled();
+		}
+	}
 #endif
 }
 
Index: util/mkinit.c
===================================================================
RCS file: /home/mercury1/repository/mercury/util/mkinit.c,v
retrieving revision 1.46
diff -u -r1.46 mkinit.c
--- mkinit.c	1999/02/04 10:53:02	1.46
+++ mkinit.c	1999/03/20 06:58:51
@@ -91,6 +91,8 @@
 
 static const char mercury_funcs[] =
 	"\n"
+	"#define MR_TRACE_ENABLED %d\n"
+	"\n"
 	"Declare_entry(%s);\n"
 	"\n"
 	"#ifdef CONSERVATIVE_GC\n"
@@ -151,10 +153,19 @@
 	"	MR_io_print_to_cur_stream = ML_io_print_to_cur_stream;\n"
 	"	MR_io_print_to_stream = ML_io_print_to_stream;\n"
 	"#ifdef MR_USE_EXTERNAL_DEBUGGER\n"
+	"  #if MR_TRACE_ENABLED\n"
 	"	MR_address_of_trace_init_external = MR_trace_init_external;\n"
 	"	MR_address_of_trace_final_external = MR_trace_final_external;\n"
+	"  #else\n"
+	"	MR_address_of_trace_init_external = NULL;\n"
+	"	MR_address_of_trace_final_external = NULL;\n"
+	"  #endif\n"
+	"#endif\n"
+	"#if MR_TRACE_ENABLED\n"
+	"	MR_trace_func_ptr = MR_trace_real;\n"
+	"#else\n"
+	"	MR_trace_func_ptr = MR_trace_fake;\n"
 	"#endif\n"
-	"	MR_trace_func_ptr = %s;\n"
 	"#if defined(USE_GCC_NONLOCAL_GOTOS) && !defined(USE_ASM_LABELS)\n"
 	"	do_init_modules();\n"
 	"#endif\n"
@@ -396,10 +407,7 @@
 static void 
 output_main(void)
 {
-	const char *trace_func;
-
-	trace_func = (need_tracing ? "MR_trace_real" : "MR_trace_fake");
-	printf(mercury_funcs, entry_point, trace_func, entry_point);
+	printf(mercury_funcs, need_tracing, entry_point, entry_point);
 	if (output_main_func) {
 		fputs(main_func, stdout);
 	}

-- 
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.



More information about the developers mailing list