[m-dev.] for review: interface tracing, part 1

Zoltan Somogyi zs at cs.mu.OZ.AU
Fri May 15 17:36:26 AEST 1998


> By the way, have you got some benchmarks for us -- how much bigger
> and slower is it with interface tracing and full tracing?

I haven't done timings yet. As far as sizes are concerned:

text	data	bss
9338880 6766592 98944   full tracing
7692288 3973120 103792	interface tracing
4276224 827392  104400  no tracing

> > -globals__set_options(globals(_, B, C, D, E, F), Options,
> > -globals__set_gc_method(globals(A, _, C, D, E, F), GC_Method,
> > -globals__set_tags_method(globals(A, B, _, D, E, F), TagsMethod,
> > -globals__set_args_method(globals(A, B, C, _, E, F), ArgsMethod,
> > -globals__set_prolog_dialect(globals(A, B, C, D, _, F), PrologDialect,
> > -globals__set_termination_norm(globals(A, B, C, D, E, _), TerminationNorm,
> 
> Any particular reason for removing these?

globals__set_options is only modified, not removed, since in some parts of the
compiler we temporarily disable certain options. The others are never used,
and they *should* never be used. If the gc, tags or args methods is modified
after startup, the results would be inconsistent. The dialect and the norm
are each used only in one phase, in which inconsistent setting does not make
sense.

> These options are a bit ungrammatical.

Well, you *were* the one who suggested those names.

If someone can suggest a better alternative than --trace full, fine.
However --trace partial is not on, since it does not say *what* part is
traced.

> `--trace full', but I can't think of a reasonable replacement
> for `--trace minimal'.

Me neither, unless it is

	--trace all
	--trace interfaces
	--trace minimum

> I think it would be better to use FALSE and TRUE rather than 0 and 1.
> 
> There's a compilation time vs readability tradeoff here.
> But I think the increase in compilation time is likely to be
> pretty negligable and I think readability and consistency
> are more important.

This is in automatically generated C code. Readability and consistency
are already gone :-(, but I have done as you asked.

> The documentation should explain the effect of each of these
> different tracing levels.
> 
> (In addition, the user guide should probably have a new section
> on debugging.  But that can be committed as a seperate change.)

The documentation of the option cannot contain a *full* discussion
of the trace levels, since that would require duplicating a large part
of that future debugging section.

What follows is a relative diff for both parts 1 & 2.

Zoltan.

--- Log.was	Fri May 15 19:23:52 1998
+++ Log	Fri May 15 19:23:55 1998
@@ -91,6 +91,9 @@
 doc/user_guide.texi:
 	Update the documentation for --trace.
 
+runtime/mercury_types.h:
+	Add the type Unsigned.
+
 runtime/mercury_goto.h:
 	Use the shorter layout prefix.
 
@@ -144,7 +147,8 @@
 	Create separate functions for printing port names and determinisms.
 
 runtime/mercury_wrapper.h:
-	Disable the tracing of the initialization code written in Mercury.
+	Disable the tracing of the initialization and finalization code
+	written in Mercury.
 
 runtime/Mmakefile:
 	Update for the new source and header files.
diff -u /home/staff/zs/mer/ws8/compiler/stack_layout.m /home/staff/zs/mer/ws2/compiler/stack_layout.m
--- /home/staff/zs/mer/ws8/compiler/stack_layout.m	Fri May 15 15:58:00 1998
+++ /home/staff/zs/mer/ws2/compiler/stack_layout.m	Fri May 15 16:33:35 1998
@@ -303,10 +303,9 @@
 		{ MaybeRvals = MaybeRvals1 }
 	),
 
-	{ Exported = no },	% With the new profiler, we will need to
+	{ Exported = no },	% XXX With the new profiler, we will need to
 				% set this to `yes' if the profiling option
 				% is given and if the procedure is exported.
-				% XXX
 	{ CModule = c_data(ModuleName, stack_layout(Label), Exported,
 		MaybeRvals, []) },
 	stack_layout__add_cmodule(CModule, Label).
diff -u /home/staff/zs/mer/ws8/compiler/trace.m /home/staff/zs/mer/ws2/compiler/trace.m
--- /home/staff/zs/mer/ws8/compiler/trace.m	Fri May 15 15:58:02 1998
+++ /home/staff/zs/mer/ws2/compiler/trace.m	Fri May 15 17:11:31 1998
@@ -206,13 +206,13 @@
 	(
 		TraceType = interface_trace(_),
 		TraceCode = node([
-			c_code("MR_trace_from_full = 0;\n") - "",
+			c_code("MR_trace_from_full = FALSE;\n") - "",
 			c_code(ResetDepthStmt) - ""
 		])
 	;
 		TraceType = full_trace,
 		TraceCode = node([
-			c_code("MR_trace_from_full = 1;\n") - "",
+			c_code("MR_trace_from_full = TRUE;\n") - "",
 			c_code(ResetDepthStmt) - ""
 		])
 	).
@@ -318,7 +318,7 @@
 	trace__port_to_string(Port, PortStr),
 	(
 		TraceType = full_trace,
-		FlagStr = "1"				% meaning true
+		FlagStr = "TRUE"
 	;
 		TraceType = interface_trace(CallFromFullLval),
 		trace__stackref_to_string(CallFromFullLval, FlagStr)
diff -u /home/staff/zs/mer/ws8/runtime/mercury_stack_layout.h /home/staff/zs/mer/ws2/runtime/mercury_stack_layout.h
--- /home/staff/zs/mer/ws8/runtime/mercury_stack_layout.h	Fri May 15 15:53:42 1998
+++ /home/staff/zs/mer/ws2/runtime/mercury_stack_layout.h	Fri May 15 16:40:25 1998
@@ -161,20 +161,20 @@
 */ 
 
 #ifdef MR_USE_STACK_LAYOUTS
- #define MR_MAKE_STACK_LAYOUT_ENTRY(l) 					\
- const struct mercury_data__layout__##l##_struct {			\
+  #define MR_MAKE_STACK_LAYOUT_ENTRY(l) 				\
+  const struct mercury_data__layout__##l##_struct {			\
 	Code * f1;							\
 	Integer f2;							\
 	Integer f3;							\
 	Integer f4;							\
- } mercury_data__layout__##l = {					\
+  } mercury_data__layout__##l = {					\
 	STATIC(l),							\
 	(Integer) -1, 	/* Unknown determinism */			\
 	(Integer) -1,	/* Unknown number of stack slots */		\
         (Integer) MR_LVAL_TYPE_UNKNOWN 	/* Unknown succip location */	\
- };
+  };
 #else
- #define MR_MAKE_STACK_LAYOUT_ENTRY(l)        
+  #define MR_MAKE_STACK_LAYOUT_ENTRY(l)        
 #endif	/* MR_USE_STACK_LAYOUTS */
 
 /*
@@ -184,11 +184,11 @@
 */
 
 #ifdef	NATIVE_GC
-#define	UNKNOWN_INTERNAL_LABEL_FIELD	Integer f2;
-#define	UNKNOWN_INTERNAL_LABEL_NUMBER	(Integer) -1,
+  #define	UNKNOWN_INTERNAL_LABEL_FIELD	Integer f2;
+  #define	UNKNOWN_INTERNAL_LABEL_NUMBER	(Integer) -1,
 #else
-#define	UNKNOWN_INTERNAL_LABEL_FIELD
-#define	UNKNOWN_INTERNAL_LABEL_NUMBER
+  #define	UNKNOWN_INTERNAL_LABEL_FIELD
+  #define	UNKNOWN_INTERNAL_LABEL_NUMBER
 #endif
 
 /*
@@ -200,18 +200,18 @@
 */ 
 
 #ifdef MR_USE_STACK_LAYOUTS
- #define MR_MAKE_STACK_LAYOUT_INTERNAL_WITH_ENTRY(l, e)			\
- const struct mercury_data__layout__##l##_struct {			\
+  #define MR_MAKE_STACK_LAYOUT_INTERNAL_WITH_ENTRY(l, e)		\
+  const struct mercury_data__layout__##l##_struct {			\
 	const Word * f1;						\
 	UNKNOWN_INTERNAL_LABEL_FIELD					\
 	Integer f3;							\
- } mercury_data__layout__##l = {					\
+  } mercury_data__layout__##l = {					\
 	(const Word *) &mercury_data__layout__##e,			\
 	UNKNOWN_INTERNAL_LABEL_NUMBER					\
 	(Integer) 0		/* No live values */			\
- };
+  };
 #else
- #define MR_MAKE_STACK_LAYOUT_INTERNAL_WITH_ENTRY(l, e)        
+  #define MR_MAKE_STACK_LAYOUT_INTERNAL_WITH_ENTRY(l, e)        
 #endif	/* MR_USE_STACK_LAYOUTS */
 
 /*
@@ -231,18 +231,18 @@
 */ 
 
 #ifdef MR_USE_STACK_LAYOUTS
- #define MR_MAKE_STACK_LAYOUT_INTERNAL(e, x)				\
- const struct mercury_data__layout__##e##_i##x##_struct {		\
+  #define MR_MAKE_STACK_LAYOUT_INTERNAL(e, x)				\
+  const struct mercury_data__layout__##e##_i##x##_struct {		\
 	const Word * f1;						\
 	UNKNOWN_INTERNAL_LABEL_FIELD					\
 	Integer f3;							\
- } mercury_data__layout__##e##_i##x = {					\
+  } mercury_data__layout__##e##_i##x = {				\
 	(const Word *) &mercury_data__layout__##e,			\
 	UNKNOWN_INTERNAL_LABEL_NUMBER					\
 	(Integer) 0		/* No live values */			\
- };
+  };
 #else
- #define MR_MAKE_STACK_LAYOUT_INTERNAL(l, x)        
+  #define MR_MAKE_STACK_LAYOUT_INTERNAL(l, x)        
 #endif	/* MR_USE_STACK_LAYOUTS */
 
 /*
diff -u /home/staff/zs/mer/ws8/runtime/mercury_trace.c /home/staff/zs/mer/ws2/runtime/mercury_trace.c
--- /home/staff/zs/mer/ws8/runtime/mercury_trace.c	Fri May 15 15:53:44 1998
+++ /home/staff/zs/mer/ws2/runtime/mercury_trace.c	Fri May 15 17:10:09 1998
@@ -49,7 +49,7 @@
 ** with MR_trace_enabled set to FALSE.
 */
 
-Word	MR_trace_enabled = FALSE;
+bool		MR_trace_enabled = FALSE;
 
 /*
 ** MR_trace_call_seqno counts distinct calls. The prologue of every
@@ -69,8 +69,8 @@
 ** variables.
 */
 
-Word	MR_trace_call_seqno = 0;
-Word	MR_trace_call_depth = 0;
+Unsigned	MR_trace_call_seqno = 0;
+Unsigned	MR_trace_call_depth = 0;
 
 /*
 ** MR_trace_event_number is a simple counter of events. This is used in
@@ -79,7 +79,7 @@
 ** can zero in on the source of the problem more quickly.
 */
 
-Word	MR_trace_event_number = 0;
+Unsigned	MR_trace_event_number = 0;
 
 /*
 ** MR_trace_from_full is a boolean that is set before every call;
@@ -94,17 +94,17 @@
 ** control in the debugger when main/2 is called.
 */
 
-Word	MR_trace_from_full = 1;
+Bool	MR_trace_from_full = 1;
 
 static	MR_trace_cmd_info	MR_trace_ctrl = { MR_CMD_GOTO, 0, 0, FALSE };
 
 static	void	MR_trace_event(MR_trace_cmd_info *cmd,
 			const MR_Stack_Layout_Label *layout,
-			MR_trace_port port, Word seqno, Word depth,
+			MR_trace_port port, Unsigned seqno, Unsigned depth,
 			const char *path, int max_r_num);
 
 static	void	MR_trace_event_report(const MR_Stack_Layout_Label *layout,
-			MR_trace_port port, Word seqno, Word depth,
+			MR_trace_port port, Unsigned seqno, Unsigned depth,
 			const char *path, int max_r_num);
 
 void
@@ -117,14 +117,30 @@
 }
 
 void
-MR_trace_end(void)
+MR_trace_final(void)
 {
 #ifdef MR_USE_EXTERNAL_DEBUGGER
 	if (MR_trace_handler == MR_TRACE_EXTERNAL)
-		MR_trace_end_external();
+		MR_trace_final_external();
 #endif
 }
 
+void
+MR_trace_start(bool enabled)
+{
+	MR_trace_event_number = 0;
+	MR_trace_call_seqno = 0;
+	MR_trace_call_depth = 0;
+	MR_trace_from_full = TRUE;
+	MR_trace_enabled = enabled;
+}
+
+void
+MR_trace_end(void)
+{
+	MR_trace_enabled = FALSE;
+}
+
 /*
 ** This function is called from compiled code whenever an event to be traced
 ** occurs.
@@ -132,8 +148,8 @@
 
 void
 MR_trace(const MR_Stack_Layout_Label *layout, MR_trace_port port,
-	Word seqno, Word depth, const char *path, int max_r_num,
-	int trace_this)
+	Unsigned seqno, Unsigned depth, const char *path, int max_r_num,
+	bool trace_this)
 {
 	if (! (MR_trace_enabled && trace_this))
 		return;
@@ -198,7 +214,7 @@
 static void
 MR_trace_event(MR_trace_cmd_info *cmd,
 	const MR_Stack_Layout_Label *layout, MR_trace_port port,
-	Word seqno, Word depth, const char *path, int max_r_num)
+	Unsigned seqno, Unsigned depth, const char *path, int max_r_num)
 {
 	int	max_mr_num;
 
@@ -228,7 +244,7 @@
 
 static void
 MR_trace_event_report(const MR_Stack_Layout_Label *layout, MR_trace_port port,
-	Word seqno, Word depth, const char *path, int max_r_num)
+	Unsigned seqno, Unsigned depth, const char *path, int max_r_num)
 {
 #ifdef MR_USE_EXTERNAL_DEBUGGER
 	if (MR_trace_debugger == MR_TRACE_EXTERNAL) {
diff -u /home/staff/zs/mer/ws8/runtime/mercury_trace.h /home/staff/zs/mer/ws2/runtime/mercury_trace.h
--- /home/staff/zs/mer/ws8/runtime/mercury_trace.h	Fri May 15 15:53:44 1998
+++ /home/staff/zs/mer/ws2/runtime/mercury_trace.h	Fri May 15 17:11:46 1998
@@ -54,7 +54,7 @@
 	Word,			/* call depth */
 	const char *,		/* path to event goal within procedure */
 	int,			/* highest numbered rN register in use */
-	int);			/* is this event supposed to be traced */
+	bool);			/* is this event supposed to be traced */
 
 /*
 ** These functions will report the number of the last event,
@@ -66,13 +66,28 @@
 
 /*
 ** MR_trace_init() is called from mercury_runtime_init()
-** when the debuggee programs begins.
-** MR_trace_end() is called from mercury_runtime_terminate()
-** when the debuggee programs is exiting.
+** when the debuggee programs begins, to perform any initialization
+** that must be done before any traced Mercury code is executed.
+** This includes the initialization code written in Mercury as well as main.
+**
+** MR_trace_start(enabled) is called from mercury_runtime_init()
+** after the initialization code written in Mercury is executed,
+** when we are about to start executing main. The argument says
+** whether tracing is enabled for main (it is never enabled for
+** initialization and finalization routines).
+**
+** MR_trace_end() is called from mercury_runtime_terminate() just
+** after main has terminated and just before we call the finalization
+** code written in Mercury.
+**
+** MR_trace_final() is called from mercury_runtime_terminate()
+** after all Mercury code, including finalization code, has terminated.
 */
 
 extern	void	MR_trace_init(void);
+extern	void	MR_trace_start(bool enabled);
 extern	void	MR_trace_end(void);
+extern	void	MR_trace_final(void);
 
 typedef	enum {
 	MR_TRACE_INTERNAL,
@@ -80,11 +95,11 @@
 } MR_trace_type;
 
 extern	MR_trace_type	MR_trace_handler;
-extern	Word		MR_trace_enabled;
+extern	bool		MR_trace_enabled;
 
-extern	Word		MR_trace_event_number;
+extern	Unsigned	MR_trace_event_number;
 
-extern	Word		MR_trace_from_full;
+extern	Bool		MR_trace_from_full;
 
 /* The interface between the debuggers and the tracing subsystem. */
 
@@ -118,8 +133,8 @@
 
 typedef struct {
 	MR_trace_cmd_type	MR_trace_cmd;	
-	Word			MR_trace_stop_seqno;
-	Word			MR_trace_stop_event;
+	Unsigned		MR_trace_stop_seqno;
+	Unsigned		MR_trace_stop_event;
 	bool			MR_trace_print_intermediate;
 } MR_trace_cmd_info;
 
diff -u /home/staff/zs/mer/ws8/runtime/mercury_trace_external.c /home/staff/zs/mer/ws2/runtime/mercury_trace_external.c
--- /home/staff/zs/mer/ws8/runtime/mercury_trace_external.c	Fri May 15 15:53:44 1998
+++ /home/staff/zs/mer/ws2/runtime/mercury_trace_external.c	Fri May 15 16:58:13 1998
@@ -59,11 +59,11 @@
 			Integer *debugger_request_type_ptr);
 	
 static bool	MR_found_match(const MR_Stack_Layout_Label *layout,
-			MR_trace_port port, int seqno, int depth,
+			MR_trace_port port, Unsigned seqno, Unsigned depth,
 			/* XXX registers */
 			const char *path, Word search_data);
 static void	MR_output_current(const MR_Stack_Layout_Label *layout,
-			MR_trace_port port, int seqno, int depth,
+			MR_trace_port port, Unsigned seqno, Unsigned depth,
 			Word var_list,
 			const char *path, Word current_request);
 
@@ -283,7 +283,7 @@
 }
 
 void
-MR_trace_end_external(void)
+MR_trace_final_external(void)
 {
 	/*
 	** This can only happen during a forward_move(),
@@ -303,7 +303,7 @@
 
 void
 MR_trace_event_external(const MR_Stack_Layout_Label *layout,
-	MR_trace_port port, int seqno, int depth, const char *path)
+	MR_trace_port port, Unsigned seqno, Unsigned depth, const char *path)
 {
 	static bool searching = FALSE;
 	static Word search_data;
@@ -367,7 +367,7 @@
 
 static void
 MR_output_current(const MR_Stack_Layout_Label *layout,
-	MR_trace_port port, int seqno, int depth,
+	MR_trace_port port, Unsigned seqno, Unsigned depth,
 	Word var_list,
 	const char *path, Word current_request)
 {
@@ -402,7 +402,7 @@
 
 static bool
 MR_found_match(const MR_Stack_Layout_Label *layout,
-	MR_trace_port port, int seqno, int depth,
+	MR_trace_port port, Unsigned seqno, Unsigned depth,
 	/* XXX live vars */
 	const char *path, Word search_data)
 {
diff -u /home/staff/zs/mer/ws8/runtime/mercury_trace_external.h /home/staff/zs/mer/ws2/runtime/mercury_trace_external.h
--- /home/staff/zs/mer/ws8/runtime/mercury_trace_external.h	Fri May 15 15:53:44 1998
+++ /home/staff/zs/mer/ws2/runtime/mercury_trace_external.h	Fri May 15 16:58:18 1998
@@ -10,9 +10,9 @@
 #ifdef	MR_USE_EXTERNAL_DEBUGGER
 
 extern	void	MR_trace_init_external(void);
-extern	void	MR_trace_end_external(void);
+extern	void	MR_trace_final_external(void);
 extern	void	MR_trace_event_external(const MR_Stack_Layout_Label *layout,
-			MR_trace_port port, int seqno, int depth,
+			MR_trace_port port, Unsigned seqno, Unsigned depth,
 			const char *path);
 
 #endif	/* MR_USE_EXTERNAL_DEBUGGER */
diff -u /home/staff/zs/mer/ws8/runtime/mercury_types.h /home/staff/zs/mer/ws2/runtime/mercury_types.h
--- /home/staff/zs/mer/ws8/runtime/mercury_types.h	Fri May 15 15:53:45 1998
+++ /home/staff/zs/mer/ws2/runtime/mercury_types.h	Fri May 15 17:01:04 1998
@@ -23,6 +23,7 @@
 typedef	unsigned WORD_TYPE	Word;
 typedef WORD_TYPE		Integer;
 typedef unsigned WORD_TYPE	Unsigned;
+typedef WORD_TYPE		Bool;
 typedef void			Code;	/* code addresses are `void *' */
 
 /*
diff -u /home/staff/zs/mer/ws8/runtime/mercury_wrapper.c /home/staff/zs/mer/ws2/runtime/mercury_wrapper.c
--- /home/staff/zs/mer/ws8/runtime/mercury_wrapper.c	Fri May 15 15:53:45 1998
+++ /home/staff/zs/mer/ws2/runtime/mercury_wrapper.c	Fri May 15 16:53:34 1998
@@ -158,7 +158,7 @@
 void
 mercury_runtime_init(int argc, char **argv)
 {
-	int	saved_trace_enabled;
+	bool	saved_trace_enabled;
 
 #if NUM_REAL_REGS > 0
 	Word c_regs[NUM_REAL_REGS];
@@ -200,8 +200,10 @@
 	*/
 	(*address_of_init_gc)();
 
-	/* double-check that the garbage collector knows about
-	   global variables in shared libraries */
+	/*
+	** Double-check that the garbage collector knows about
+	** global variables in shared libraries.
+	*/
 	GC_is_visible(fake_reg);
 
 	/* The following code is necessary to tell the conservative */
@@ -262,12 +264,11 @@
 	/* initialize the Mercury library */
 	(*MR_library_initializer)();
 
-	/* now the real tracing starts */
-	MR_trace_event_number = 0;
-	MR_trace_call_seqno = 0;
-	MR_trace_call_depth = 0;
-	MR_trace_from_full = 1;
-	MR_trace_enabled = saved_trace_enabled;
+	/*
+	** Now the real tracing starts; undo any updates to the trace state
+	** made by the trace code in the library initializer.
+	*/
+	MR_trace_start(saved_trace_enabled);
 
 	/*
 	** Restore the callee-save registers before returning,
@@ -991,6 +992,8 @@
 	MR_trace_end();
 
 	(*MR_library_finalizer)();
+
+	MR_trace_final();
 
 	if (MR_profiling) MR_prof_finish();
 
diff -u /home/staff/zs/mer/ws8/tests/debugger/runtests /home/staff/zs/mer/ws2/tests/debugger/runtests
--- /home/staff/zs/mer/ws8/tests/debugger/runtests	Fri May 15 16:59:16 1998
+++ /home/staff/zs/mer/ws2/tests/debugger/runtests	Fri May 15 16:59:29 1998
@@ -19,7 +19,7 @@
 	. ../shutdown
 	exit 0
 else
-	/bin/rm *.res
+	rm *.res
 	eval mmake -k $jfactor $gradeopt $flagsopt $cflagsopt check_lib
 	checkstatus=$?
 



More information about the developers mailing list