for review: interface tracing, part 2

Zoltan Somogyi zs at cs.mu.OZ.AU
Thu May 14 17:31:01 AEST 1998


This is a diff of runtime/mercury_trace* relative to my previous post
on the breakup of mercury_trace.c (which did not pass the debugger tests,
and which therefore couldn't be committed separately).

Zoltan.

diff -u /home/staff/zs/mer/ws3/runtime/mercury_trace.c runtime/mercury_trace.c
--- /home/staff/zs/mer/ws3/runtime/mercury_trace.c	Wed May 13 16:06:37 1998
+++ runtime/mercury_trace.c	Mon May 11 12:16:01 1998
@@ -49,7 +49,7 @@
 ** with MR_trace_enabled set to FALSE.
 */
 
-bool	MR_trace_enabled = FALSE;
+Word	MR_trace_enabled = FALSE;
 
 /*
 ** MR_trace_call_seqno counts distinct calls. The prologue of every
@@ -69,8 +69,8 @@
 ** variables.
 */
 
-int	MR_trace_call_seqno = 0;
-int	MR_trace_call_depth = 0;
+Word	MR_trace_call_seqno = 0;
+Word	MR_trace_call_depth = 0;
 
 /*
 ** MR_trace_event_number is a simple counter of events. This is used in
@@ -79,13 +79,32 @@
 ** can zero in on the source of the problem more quickly.
 */
 
-int	MR_trace_event_number = 0;
+Word	MR_trace_event_number = 0;
+
+/*
+** MR_trace_from_full is a boolean that is set before every call;
+** it states whether the caller is being fully traced, or only interface
+** traced. If the called code is interface traced, it will generate
+** call, exit and fail trace events only if MR_trace_from_full is true.
+** (It will never generate internal events.) If the called code is fully
+** traced, it will always generate all trace events, external and internal,
+** regardless of the setting of this variable on entry.
+**
+** The initial value is set to TRUE to allow the programmer to gain
+** control in the debugger when main/2 is called.
+*/
+
+Word	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, int seqno, int depth,
+			MR_trace_port port, Word seqno, Word 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,
 			const char *path, int max_r_num);
 
 void
@@ -113,9 +132,14 @@
 
 void
 MR_trace(const MR_Stack_Layout_Label *layout, MR_trace_port port,
-	int seqno, int depth, const char *path, int max_r_num)
+	Word seqno, Word depth, const char *path, int max_r_num,
+	int trace_this)
 {
+	if (! (MR_trace_enabled && trace_this))
+		return;
+
 	MR_trace_event_number++;
+
 	switch (MR_trace_ctrl.MR_trace_cmd) {
 		case MR_CMD_FINISH:
 			if (MR_trace_ctrl.MR_trace_stop_seqno == seqno
@@ -124,7 +148,7 @@
 					port, seqno, depth, path, max_r_num);
 
 			} else if (MR_trace_ctrl.MR_trace_print_intermediate) {
-				MR_trace_event(NULL, layout,
+				MR_trace_event_report(layout,
 					port, seqno, depth, path, max_r_num);
 			}
 
@@ -137,7 +161,7 @@
 				MR_trace_event(&MR_trace_ctrl, layout,
 					port, seqno, depth, path, max_r_num);
 			} else if (MR_trace_ctrl.MR_trace_print_intermediate) {
-				MR_trace_event(NULL, layout,
+				MR_trace_event_report(layout,
 					port, seqno, depth, path, max_r_num);
 			}
 
@@ -148,7 +172,7 @@
 				MR_trace_event(&MR_trace_ctrl, layout,
 					port, seqno, depth, path, max_r_num);
 			} else if (MR_trace_ctrl.MR_trace_print_intermediate) {
-				MR_trace_event(NULL, layout,
+				MR_trace_event_report(layout,
 					port, seqno, depth, path, max_r_num);
 			}
 
@@ -159,7 +183,7 @@
 				MR_trace_event(&MR_trace_ctrl, layout,
 					port, seqno, depth, path, max_r_num);
 			} else if (MR_trace_ctrl.MR_trace_print_intermediate) {
-				MR_trace_event(NULL, layout,
+				MR_trace_event_report(layout,
 					port, seqno, depth, path, max_r_num);
 			}
 
@@ -174,7 +198,7 @@
 static void
 MR_trace_event(MR_trace_cmd_info *cmd,
 	const MR_Stack_Layout_Label *layout, MR_trace_port port,
-	int seqno, int depth, const char *path, int max_r_num)
+	Word seqno, Word depth, const char *path, int max_r_num)
 {
 	int	max_mr_num;
 
@@ -202,6 +226,27 @@
 	MR_copy_saved_regs_to_regs(max_mr_num);
 }
 
+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)
+{
+#ifdef MR_USE_EXTERNAL_DEBUGGER
+	if (MR_trace_debugger == MR_TRACE_EXTERNAL) {
+		fatal_abort("trying to report an event to external debugger");
+	} else {
+		MR_trace_event_internal_report(layout,
+			port, seqno, depth, path);
+	}
+#else
+	/*
+	** We should get here only if MR_trace_debugger == MR_TRACE_INTERNAL.
+	** This is enforced by mercury_wrapper.c.
+	*/
+
+	MR_trace_event_internal_report(layout, port, seqno, depth, path);
+#endif
+}
+
 void
 MR_trace_report(FILE *fp)
 {
@@ -211,8 +256,8 @@
 		** which implies that the user wants trace info on abort.
 		*/
 
-		fprintf(fp, "Last trace event was event #%d.\n",
-			MR_trace_event_number);
+		fprintf(fp, "Last trace event was event #%ld.\n",
+			(long) MR_trace_event_number);
 	}
 }
 
@@ -227,8 +272,8 @@
 		** which implies that the user wants trace info on abort.
 		*/
 
-		sprintf(buf, "Last trace event was event #%d.\n",
-			MR_trace_event_number);
+		sprintf(buf, "Last trace event was event #%ld.\n",
+			(long) MR_trace_event_number);
 		write(fd, buf, strlen(buf));
 	}
 }
Only in /home/staff/zs/mer/ws3/runtime: mercury_trace.c.orig
diff -u /home/staff/zs/mer/ws3/runtime/mercury_trace.h runtime/mercury_trace.h
--- /home/staff/zs/mer/ws3/runtime/mercury_trace.h	Wed May 13 16:07:11 1998
+++ runtime/mercury_trace.h	Mon May 11 11:53:31 1998
@@ -27,8 +27,8 @@
 #define	MR_trace_incr_depth()	(++MR_trace_call_depth)
 #define	MR_trace_reset_depth(d)	do { MR_trace_call_depth = (d); } while (0)
 
-extern	int	MR_trace_call_seqno;
-extern	int	MR_trace_call_depth;
+extern	Word	MR_trace_call_seqno;
+extern	Word	MR_trace_call_depth;
 
 /*
 ** This enum should exactly match the definition of the `trace_port' type in
@@ -50,10 +50,11 @@
 extern	void	MR_trace(
 	const MR_Stack_Layout_Label *,	/* layout info for the event */
 	MR_trace_port,
-	int,			/* call sequence number */
-	int,			/* call depth */
+	Word,			/* call sequence number */
+	Word,			/* call depth */
 	const char *,		/* path to event goal within procedure */
-	int);			/* highest numbered rN register in use */
+	int,			/* highest numbered rN register in use */
+	int);			/* is this event supposed to be traced */
 
 /*
 ** These functions will report the number of the last event,
@@ -79,9 +80,11 @@
 } MR_trace_type;
 
 extern	MR_trace_type	MR_trace_handler;
-extern	bool		MR_trace_enabled;
+extern	Word		MR_trace_enabled;
 
-extern	int		MR_trace_event_number;
+extern	Word		MR_trace_event_number;
+
+extern	Word		MR_trace_from_full;
 
 /* The interface between the debuggers and the tracing subsystem. */
 
@@ -115,8 +118,8 @@
 
 typedef struct {
 	MR_trace_cmd_type	MR_trace_cmd;	
-	int			MR_trace_stop_seqno;
-	int			MR_trace_stop_event;
+	Word			MR_trace_stop_seqno;
+	Word			MR_trace_stop_event;
 	bool			MR_trace_print_intermediate;
 } MR_trace_cmd_info;
 
Only in /home/staff/zs/mer/ws3/runtime: mercury_trace.h.orig
Binary files /home/staff/zs/mer/ws3/runtime/mercury_trace.o and runtime/mercury_trace.o differ
Binary files /home/staff/zs/mer/ws3/runtime/mercury_trace_external.o and runtime/mercury_trace_external.o differ
diff -u /home/staff/zs/mer/ws3/runtime/mercury_trace_internal.c runtime/mercury_trace_internal.c
--- /home/staff/zs/mer/ws3/runtime/mercury_trace_internal.c	Wed May 13 16:08:11 1998
+++ runtime/mercury_trace_internal.c	Tue May 12 20:55:25 1998
@@ -30,19 +30,22 @@
 static	MR_spy_point	MR_spy_points[MR_MAX_SPY_POINTS];
 static	int		MR_next_spy_point = 0;
 
-static void	MR_trace_browse(int var_count,
+static	void	MR_trace_browse(int var_count,
 			const MR_Stack_Layout_Vars *var_info);
-static void	MR_trace_browse_var(const char *name,
+static	void	MR_trace_browse_var(const char *name,
 			const MR_Stack_Layout_Var *var, Word *type_params);
 
-static void	MR_add_spy_point(void);
-static void	MR_list_spy_points(void);
-static void	MR_change_spy_point_status(bool status);
-
-static int	MR_trace_skip_spaces(int c);
-static void	MR_trace_discard_to_eol(int c);
-static int	MR_trace_get_word(int *c, char word[], int len);
-static void	MR_trace_help(void);
+static	void	MR_add_spy_point(void);
+static	void	MR_list_spy_points(void);
+static	void	MR_change_spy_point_status(bool status);
+
+static	int	MR_trace_skip_spaces(int c);
+static	void	MR_trace_discard_to_eol(int c);
+static	int	MR_trace_get_word(int *c, char word[], int len);
+static	void	MR_trace_help(void);
+
+static	void	MR_trace_print_port(MR_trace_port port);
+static	void	MR_trace_print_detism(Word detism);
 
 void
 MR_trace_event_internal(MR_trace_cmd_info *cmd,
@@ -53,101 +56,16 @@
 	int	c;
 	int	count;
 	bool	count_given;
-
-	printf("%8d: %6d %2d ", MR_trace_event_number, seqno, depth);
-
-	switch (port) {
-		case MR_PORT_CALL:
-			printf("CALL ");
-			break;
-
-		case MR_PORT_EXIT:
-			printf("EXIT ");
-			break;
-
-		case MR_PORT_FAIL:
-			printf("FAIL ");
-			break;
-
-		case MR_PORT_THEN:
-			printf("THEN ");
-			break;
-
-		case MR_PORT_ELSE:
-			printf("ELSE ");
-			break;
-
-		case MR_PORT_DISJ:
-			printf("DISJ ");
-			break;
-
-		case MR_PORT_SWITCH:
-			printf("SWTC ");
-			break;
-
-		case MR_PORT_PRAGMA_FIRST:
-			printf("FRST ");
-			break;
-
-		case MR_PORT_PRAGMA_LATER:
-			printf("LATR ");
-			break;
-
-		default:
-			fatal_error("MR_trace_event_internal called "
-					"with bad port");
-	}
-
-	switch ((int) layout->MR_sll_entry->MR_sle_detism) {
-		case MR_DETISM_DET:
-			printf("DET   ");
-			break;
-
-		case MR_DETISM_SEMI:
-			printf("SEMI  ");
-			break;
-
-		case MR_DETISM_NON:
-			printf("NON   ");
-			break;
-
-		case MR_DETISM_MULTI:
-			printf("MUL   ");
-			break;
-
-		case MR_DETISM_ERRONEOUS:
-			printf("ERR   ");
-			break;
-
-		case MR_DETISM_FAILURE:
-			printf("FAIL  ");
-			break;
-
-		case MR_DETISM_CCNON:
-			printf("CCNON ");
-			break;
-
-		case MR_DETISM_CCMULTI:
-			printf("CCMUL ");
-			break;
-		
-		default:
-			printf("BAD DETERMINISM\n");
-			break;
-	}
-
-	/*
-	** The following should be a full identification of the procedure
-	** provided (a) there was no intermodule optimization and (b) we are
-	** not interested in tracing compiler-generated procedures.
-	*/
-
-	printf("%s:%s/%ld-%ld %s\n",
-		layout->MR_sll_entry->MR_sle_def_module,
-		layout->MR_sll_entry->MR_sle_name,
-		(long) layout->MR_sll_entry->MR_sle_arity,
-		(long) layout->MR_sll_entry->MR_sle_mode,
-		path);
+	Word	saved_seqno;
+	Word	saved_depth;
+	Word	saved_event;
+
+	MR_trace_event_internal_report(layout, port, seqno, depth, path);
+
+	/* these globals can be overwritten when we call Mercury code */
+	saved_seqno = MR_trace_call_seqno;
+	saved_depth = MR_trace_call_depth;
+	saved_event = MR_trace_event_number;
 
 	for (;;) {
 		printf("mtrace> ");
@@ -307,6 +225,10 @@
 
 		break;
 	}
+
+	MR_trace_call_seqno = saved_seqno;
+	MR_trace_call_depth = saved_depth;
+	MR_trace_event_number = saved_event;
 }
 
 static void
@@ -544,6 +466,118 @@
 	}
 
 	return FALSE;
+}
+
+void
+MR_trace_event_internal_report(const MR_Stack_Layout_Label *layout,
+	MR_trace_port port, int seqno, int depth, const char *path)
+{
+	printf("%8ld: %6ld %2ld ",
+		(long) MR_trace_event_number, (long) seqno, (long) depth);
+
+	MR_trace_print_port(port);
+	MR_trace_print_detism(layout->MR_sll_entry->MR_sle_detism);
+
+	/*
+	** The following should be a full identification of the procedure
+	** provided (a) there was no intermodule optimization and (b) we are
+	** not interested in tracing compiler-generated procedures.
+	*/
+
+	printf("%s:%s/%ld-%ld %s\n",
+		layout->MR_sll_entry->MR_sle_def_module,
+		layout->MR_sll_entry->MR_sle_name,
+		(long) layout->MR_sll_entry->MR_sle_arity,
+		(long) layout->MR_sll_entry->MR_sle_mode,
+		path);
+}
+
+static void
+MR_trace_print_port(MR_trace_port port)
+{
+	switch (port) {
+		case MR_PORT_CALL:
+			printf("CALL ");
+			break;
+
+		case MR_PORT_EXIT:
+			printf("EXIT ");
+			break;
+
+		case MR_PORT_FAIL:
+			printf("FAIL ");
+			break;
+
+		case MR_PORT_THEN:
+			printf("THEN ");
+			break;
+
+		case MR_PORT_ELSE:
+			printf("ELSE ");
+			break;
+
+		case MR_PORT_DISJ:
+			printf("DISJ ");
+			break;
+
+		case MR_PORT_SWITCH:
+			printf("SWTC ");
+			break;
+
+		case MR_PORT_PRAGMA_FIRST:
+			printf("FRST ");
+			break;
+
+		case MR_PORT_PRAGMA_LATER:
+			printf("LATR ");
+			break;
+
+		default:
+			fatal_error("MR_trace_event_internal called "
+					"with bad port");
+	}
+}
+
+static void
+MR_trace_print_detism(Word detism)
+{
+	switch ((int) detism) {
+		case MR_DETISM_DET:
+			printf("DET   ");
+			break;
+
+		case MR_DETISM_SEMI:
+			printf("SEMI  ");
+			break;
+
+		case MR_DETISM_NON:
+			printf("NON   ");
+			break;
+
+		case MR_DETISM_MULTI:
+			printf("MUL   ");
+			break;
+
+		case MR_DETISM_ERRONEOUS:
+			printf("ERR   ");
+			break;
+
+		case MR_DETISM_FAILURE:
+			printf("FAIL  ");
+			break;
+
+		case MR_DETISM_CCNON:
+			printf("CCNON ");
+			break;
+
+		case MR_DETISM_CCMULTI:
+			printf("CCMUL ");
+			break;
+		
+		default:
+			printf("BAD DETERMINISM\n");
+			break;
+	}
 }
 
 static void
diff -u /home/staff/zs/mer/ws3/runtime/mercury_trace_internal.h runtime/mercury_trace_internal.h
--- /home/staff/zs/mer/ws3/runtime/mercury_trace_internal.h	Wed May 13 16:08:23 1998
+++ runtime/mercury_trace_internal.h	Wed Apr 22 19:22:07 1998
@@ -12,6 +12,11 @@
 			MR_trace_port port, int seqno, int depth,
 			const char *path);
 
+extern	void	MR_trace_event_internal_report(
+			const MR_Stack_Layout_Label *layout,
+			MR_trace_port port, int seqno, int depth,
+			const char *path);
+
 extern	bool	MR_event_matches_spy_point(const MR_Stack_Layout_Label *layout);
 
 #endif	/* MERCURY_TRACE_INTERNAL_H */



More information about the developers mailing list