for review: fix to tracing for machines with transient regs

Zoltan Somogyi zs at cs.mu.OZ.AU
Sun Feb 8 16:55:13 AEDT 1998


Fergus should review this.

Estimated hours taken: 2

compiler/trace.m:
	Save the transient registers before calling MR_trace,
	since the call will clobber them.

	Pass the first arg to MR_trace as a MR_stack_layout_entry*
	instead of a Word*, since this way gdb prints it in a more
	conveninent way.

runtime/mercury_trace.[ch]:
	Reserve space for the transient registers saved by client programs
	just before they call MR_trace. Restore transient registers
	where appropriate, and thus fix a bug that prevented tracing
	from working on machines with transient registers.

	Expect the first arg to MR_trace as a MR_stack_layout_entry*.

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 bytecode
cvs diff: Diffing bytecode/test
cvs diff: Diffing compiler
Index: compiler/trace.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/trace.m,v
retrieving revision 1.7
diff -u -u -r1.7 trace.m
--- 1.7	1998/02/03 08:18:35
+++ trace.m	1998/02/06 07:18:19
@@ -107,15 +107,16 @@
 	;
 		PathStr = ""
 	),
+	SaveStmt = "save_transient_regs_to_mem(MR_trace_transient_save);\n",
 	string__append_list([
-		"MR_trace(",
-		"(const Word *) &mercury_data__stack_layout__", LabelStr, Comma,
+		"MR_trace((const MR_stack_layout_entry *) ",
+		"&mercury_data__stack_layout__", LabelStr, Comma,
 		PortStr, Comma,
 		CallNumStr, Comma,
 		CallDepthStr, Comma,
 		Quote, PathStr, Quote, ");\n"],
 		TraceStmt),
-	TraceCode = node([c_code(TraceStmt) - ""])
+	TraceCode = node([c_code(SaveStmt) - "", c_code(TraceStmt) - ""])
 	}.
 
 %-----------------------------------------------------------------------------%
cvs diff: Diffing compiler/notes
cvs diff: Diffing doc
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/graphics
cvs diff: Diffing extras/graphics/Togl-1.2
cvs diff: Diffing extras/graphics/samples
cvs diff: Diffing extras/graphics/samples/calc
cvs diff: Diffing extras/graphics/samples/maze
cvs diff: Diffing extras/odbc
cvs diff: Diffing extras/references
cvs diff: Diffing extras/trailed_update
cvs diff: Diffing extras/trailed_update/samples
cvs diff: Diffing library
cvs diff: Diffing lp_solve
cvs diff: Diffing lp_solve/lp_examples
cvs diff: Diffing profiler
cvs diff: Diffing runtime
Index: runtime/mercury_trace.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_trace.c,v
retrieving revision 1.7
diff -u -u -r1.7 mercury_trace.c
--- 1.7	1998/02/04 03:55:31
+++ mercury_trace.c	1998/02/07 08:58:24
@@ -21,6 +21,20 @@
 #include <stdio.h>
 
 /*
+** Since the call to MR_trace will clobber the transient registers
+** on architectures that have them, the caller will save them first.
+** The registers will be restored several times, with calls to the
+** browser intervening between saves. Saving the transient registers
+** in the fake_reg array would be incorrect, since the browser will
+** clobber fake_reg. We therefore provide our own area.
+**
+** Warning: if any part of the the browser function is itself traced,
+** MR_trace_transient_save will be overwritten, leading to a crash later on.
+*/
+
+Word	MR_trace_transient_save[NUM_REAL_REGS];
+
+/*
 ** MR_trace_call_seqno counts distinct calls. The prologue of every
 ** procedure assigns the current value of this counter as the sequence number
 ** of that invocation and increments the counter. This is the only way that
@@ -96,14 +110,11 @@
 */
 
 void
-MR_trace(const Word *layout_word, MR_trace_port port,
+MR_trace(const MR_stack_layout_entry *layout, MR_trace_port port,
 	int seqno, int depth, const char *path)
 {
-	const MR_stack_layout_entry	*layout;
 	MR_trace_interact		interact;
 
-	layout = (const MR_stack_layout_entry *) layout_word;
-
 	MR_trace_event_number++;
 	switch (MR_trace_cmd) {
 		case MR_CMD_NEXT:
@@ -341,6 +352,15 @@
 	}
 
 	/*
+	** On machines with register windows, some of the registers
+	** are clobbered by C function calls. Before calling MR_trace,
+	** the program will have saved these in MR_trace_transient_save.
+	** We now restore them so that they can be saved with the others.
+	*/
+
+	restore_transient_regs_from_mem(MR_trace_transient_save);
+
+	/*
 	** In the process of browsing, we call Mercury code,
 	** which may clobber the contents of the registers,
 	** both the control registers and the general purpose registers.
@@ -464,10 +484,18 @@
 		** avoid going through call_engine, but for some unknown
 		** reason, that seems to cause the Mercury code in the
 		** browser to clobber part of the C stack.
+		**
+		** call_engine expects the transient registers to be
+		** in fake_reg, others in their normal homes.
+		** The code below works by placing r1, r2 and all other
+		** transient registers both in their normal homes and
+		** and in fake_reg as well.
 		*/
 
+		restore_transient_regs_from_mem(MR_trace_transient_save);
 		r1 = (Word) var->MR_slv_shape->MR_sls_type;
 		r2 = (Word) value;
+		save_transient_registers();
 		call_engine(MR_library_trace_browser);
 	}
 
Index: runtime/mercury_trace.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_trace.h,v
retrieving revision 1.5
diff -u -u -r1.5 mercury_trace.h
--- 1.5	1998/02/03 08:17:26
+++ mercury_trace.h	1998/02/07 08:56:22
@@ -20,6 +20,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	Word	MR_trace_transient_save[];
+
 extern	int	MR_trace_call_seqno;
 extern	int	MR_trace_call_depth;
 
@@ -29,7 +31,7 @@
 } MR_trace_port;
 
 extern	void	MR_trace(
-	const Word *,		/* pointer to stack layout info */
+	const MR_stack_layout_entry *,	/* layout info for the procedure */
 	MR_trace_port,
 	int,			/* call sequence number */
 	int,			/* call depth */
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/simpler_c_calls_mercury
cvs diff: Diffing samples/c_interface/simpler_cplusplus_calls_mercury
cvs diff: Diffing samples/diff
cvs diff: Diffing scripts
cvs diff: Diffing tests
cvs diff: Diffing tests/benchmarks
cvs diff: Diffing tests/general
cvs diff: Diffing tests/hard_coded
cvs diff: Diffing tests/hard_coded/typeclasses
cvs diff: Diffing tests/invalid
cvs diff: Diffing tests/misc_tests
cvs diff: Diffing trial
cvs diff: Diffing util



More information about the developers mailing list