for review: handling layouts of compiler-generated procedures

Zoltan Somogyi zs at cs.mu.OZ.AU
Tue Oct 27 16:53:12 AEDT 1998


Estimated hours taken: 3

compiler/stack_layout.m:
	Update a comment.

runtime/mercury_stack_layout.h:
	Introduce provisions for dealing with the procedure id section
	of the layout structures of compiler-generated procedures.

runtime/mercury_stack_trace.c:
	Use the new provisions to generalize the function that prints out
	procedure ids for both stack traces and the debugger, so that it now
	works for both user-written and compiler-generated procedure, and
	prints out the extra info needed for a full identification in cases
	where the defining and declaring modules are not the same. (This can
	happen due to intermodule inlining, or the generation of local
	unification procedures for imported types.)

trace/mercury_trace_tables.c:
	Update the code to conform to the changes in mercury_stack_layout.h.
	We still collect layout info only from user-written procedures,
	which means you can put breakpoints on only user-written procedures.

	Putting break-points on compiler-generated procedures would be
	unnecessary, even in the case of user-defined equality.

trace/mercury_trace_external.c:
	Update the code to conform to the changes in mercury_stack_layout.h,
	and add comments asking Erwan to eventually either generalize his code
	or explicitly restrict it to user-defined procedures.

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
Index: compiler/stack_layout.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/stack_layout.m,v
retrieving revision 1.20
diff -u -u -r1.20 stack_layout.m
--- stack_layout.m	1998/10/23 00:40:21	1.20
+++ stack_layout.m	1998/10/27 00:03:19
@@ -61,9 +61,9 @@
 %
 % The runtime system can figure out which form is present by testing
 % the value of the first slot. A value of 0 or 1 indicates the first form;
-% any higher value indicates the second form. A negative value indicates
-% that procid_stack_layout is not set, and that the later fields are not
-% present.
+% any higher value indicates the second form. The distinguished value -1
+% indicates that procid_stack_layout is not set, and that the later fields
+% are not present.
 %
 % The meanings of the fields in both forms are the same as in procedure labels.
 %
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/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
Index: runtime/mercury_stack_layout.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_stack_layout.h,v
retrieving revision 1.10
diff -u -u -r1.10 mercury_stack_layout.h
--- mercury_stack_layout.h	1998/10/23 00:41:31	1.10
+++ mercury_stack_layout.h	1998/10/27 00:19:23
@@ -248,12 +248,36 @@
 ** if MR_ENTRY_LAYOUT_HAS_EXEC_TRACE(entry) evaluates to true.
 **
 ** Group (2) fields have a different interpretation if the procedure is
-** compiler-generated. You can test for this via the macro
-** MR_ENTRY_LAYOUT_COMPILER_GENERATED.
+** compiler-generated. You can test whether this is the case by using the macro
+** MR_ENTRY_LAYOUT_COMPILER_GENERATED, but only after checking that
+** MR_ENTRY_LAYOUT_HAS_PROC_ID is true.
 **
 ** For further details on the semantics of the fields, see stack_layout.m.
 */
 
+typedef struct MR_Stack_Layout_User_Proc_Struct {
+	MR_PredFunc		MR_user_pred_or_func;
+	String			MR_user_decl_module;
+	String			MR_user_def_module;
+	String			MR_user_name;
+	Integer			MR_user_arity;
+	Integer			MR_user_mode;
+} MR_Stack_Layout_User_Proc;
+
+typedef struct MR_Stack_Layout_Compiler_Proc_Struct {
+	String			MR_comp_type_name;
+	String			MR_comp_type_module;
+	String			MR_comp_def_module;
+	String			MR_comp_pred_name;
+	Integer			MR_comp_arity;
+	Integer			MR_comp_mode;
+} MR_Stack_Layout_Compiler_Proc;
+
+typedef union MR_Stack_Layout_Proc_Id_Union {
+	MR_Stack_Layout_User_Proc	MR_proc_user;
+	MR_Stack_Layout_Compiler_Proc	MR_proc_comp;
+} MR_Stack_Layout_Proc_Id;
+
 typedef	struct MR_Stack_Layout_Entry_Struct {
 	/* stack traversal group */
 	Code			*MR_sle_code_addr;
@@ -262,12 +286,7 @@
 	MR_Live_Lval		MR_sle_succip_locn;
 
 	/* proc id group */
-	MR_PredFunc		MR_sle_pred_or_func;
-	String			MR_sle_decl_module;
-	String			MR_sle_def_module;
-	String			MR_sle_name;
-	Integer			MR_sle_arity;
-	Integer			MR_sle_mode;
+	MR_Stack_Layout_Proc_Id	MR_sle_proc_id;
 
 	/* exec trace group */
 	struct MR_Stack_Layout_Label_Struct
@@ -275,15 +294,19 @@
 	int			MR_sle_maybe_from_full;
 } MR_Stack_Layout_Entry;
 
+#define	MR_sle_user	MR_sle_proc_id.MR_proc_user
+#define	MR_sle_comp	MR_sle_proc_id.MR_proc_comp
+
 #define	MR_ENTRY_LAYOUT_HAS_PROC_ID(entry)			\
-		((Word) entry->MR_sle_pred_or_func != -1)
+		((Word) entry->MR_sle_user.MR_user_pred_or_func != -1)
 
 #define	MR_ENTRY_LAYOUT_HAS_EXEC_TRACE(entry)			\
 		(MR_ENTRY_LAYOUT_HAS_PROC_ID(entry)		\
 		&& entry->MR_sle_call_label != NULL)
 
 #define	MR_ENTRY_LAYOUT_COMPILER_GENERATED(entry)		\
-		((Unsigned) entry->MR_sle_pred_or_func > MR_FUNCTION)
+		((Unsigned) entry->MR_sle_user.MR_user_pred_or_func \
+		> MR_FUNCTION)
 
 /*
 ** Define a stack layout for a label that you know very little about.
Index: runtime/mercury_stack_trace.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_stack_trace.c,v
retrieving revision 1.18
diff -u -u -r1.18 mercury_stack_trace.c
--- mercury_stack_trace.c	1998/10/16 06:18:57	1.18
+++ mercury_stack_trace.c	1998/10/27 00:24:58
@@ -310,25 +310,53 @@
 }
 
 void
-MR_print_proc_id(FILE *fp, const MR_Stack_Layout_Entry *entry_layout,
+MR_print_proc_id(FILE *fp, const MR_Stack_Layout_Entry *entry,
 	const char *extra)
 {
-	/*
-	** The following should be a full identification of the procedure
-	** provided (a) there was no intermodule optimization and (b) we are
-	** not interested in the details of compiler-generated procedures.
-	**
-	** XXX We should make it work even if (a) and (b) are not true.
-	*/
+	if (! MR_ENTRY_LAYOUT_HAS_PROC_ID(entry)) {
+		fatal_error("cannot print procedure id without layout");
+	}
 
-	fprintf(fp, "%s %s:%s/%ld-%ld (%s)",
-		entry_layout->MR_sle_pred_or_func == MR_PREDICATE ?
-			"pred" : "func",
-		entry_layout->MR_sle_def_module,
-		entry_layout->MR_sle_name,
-		(long) entry_layout->MR_sle_arity,
-		(long) entry_layout->MR_sle_mode,
-		detism_names[entry_layout->MR_sle_detism]);
+	if (MR_ENTRY_LAYOUT_COMPILER_GENERATED(entry)) {
+		fprintf(fp, "%s for %s:%s/%ld-%ld",
+			entry->MR_sle_comp.MR_comp_pred_name,
+			entry->MR_sle_comp.MR_comp_type_module,
+			entry->MR_sle_comp.MR_comp_type_name,
+			(long) entry->MR_sle_comp.MR_comp_arity,
+			(long) entry->MR_sle_comp.MR_comp_mode);
+
+		if (strcmp(entry->MR_sle_comp.MR_comp_type_module,
+				entry->MR_sle_comp.MR_comp_def_module) != 0)
+		{
+			fprintf(fp, " {%s}",
+				entry->MR_sle_comp.MR_comp_def_module);
+		}
+	} else {
+		if (entry->MR_sle_user.MR_user_pred_or_func == MR_PREDICATE) {
+			fprintf(fp, "pred");
+		} else if (entry->MR_sle_user.MR_user_pred_or_func ==
+				MR_FUNCTION)
+		{
+			fprintf(fp, "func");
+		} else {
+			fatal_error("procedure is not pred or func");
+		}
+
+		fprintf(fp, " %s:%s/%ld-%ld",
+			entry->MR_sle_user.MR_user_decl_module,
+			entry->MR_sle_user.MR_user_name,
+			(long) entry->MR_sle_user.MR_user_arity,
+			(long) entry->MR_sle_user.MR_user_mode);
+
+		if (strcmp(entry->MR_sle_user.MR_user_decl_module,
+				entry->MR_sle_user.MR_user_def_module) != 0)
+		{
+			fprintf(fp, " {%s}",
+				entry->MR_sle_user.MR_user_def_module);
+		}
+	}
+
+	fprintf(fp, " (%s)", detism_names[entry->MR_sle_detism]);
 
 	if (extra != NULL) {
 		fprintf(fp, " %s\n", extra);
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 scripts
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/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_external.c
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_external.c,v
retrieving revision 1.2
diff -u -u -r1.2 mercury_trace_external.c
--- mercury_trace_external.c	1998/10/16 06:20:14	1.2
+++ mercury_trace_external.c	1998/10/27 03:14:26
@@ -424,15 +424,21 @@
 MR_output_current_slots(const MR_Stack_Layout_Label *layout,
 	MR_Trace_Port port, Unsigned seqno, Unsigned depth, const char *path)
 {
+	/*
+	** XXX This function and the Mercury predicates it calls
+	** ought to be generalized to handle all the cases handled
+	** by MR_print_proc_id in runtime/mercury_stack_trace.c.
+	*/
+
 	MR_DI_output_current_slots(
 		MR_trace_event_number,
 		seqno,
 		depth,
 		port,
-		layout->MR_sll_entry->MR_sle_def_module,
-		layout->MR_sll_entry->MR_sle_name,
-		layout->MR_sll_entry->MR_sle_arity,
-		layout->MR_sll_entry->MR_sle_mode,
+		layout->MR_sll_entry->MR_sle_user.MR_user_def_module,
+		layout->MR_sll_entry->MR_sle_user.MR_user_name,
+		layout->MR_sll_entry->MR_sle_user.MR_user_arity,
+		layout->MR_sll_entry->MR_sle_user.MR_user_mode,
 		layout->MR_sll_entry->MR_sle_detism,
 		(String) (Word) path,
 		(Word) &MR_debugger_socket_out);
@@ -485,6 +491,12 @@
 {
 	bool result;
 
+	/*
+	** XXX This function and the Mercury predicates it calls
+	** ought to be generalized to handle all the cases handled
+	** by MR_print_proc_id in runtime/mercury_stack_trace.c.
+	*/
+
 	/* XXX get live vars from registers */
 	Word arguments = /* XXX FIXME!!! */ 0;
 	result = MR_DI_found_match(
@@ -492,10 +504,10 @@
 		seqno,
 		depth,
 		port,
-		layout->MR_sll_entry->MR_sle_def_module,
-		layout->MR_sll_entry->MR_sle_name,
-		layout->MR_sll_entry->MR_sle_arity,
-		layout->MR_sll_entry->MR_sle_mode,
+		layout->MR_sll_entry->MR_sle_user.MR_user_def_module,
+		layout->MR_sll_entry->MR_sle_user.MR_user_name,
+		layout->MR_sll_entry->MR_sle_user.MR_user_arity,
+		layout->MR_sll_entry->MR_sle_user.MR_user_mode,
 		layout->MR_sll_entry->MR_sle_detism,
 		arguments,
 		(String) (Word) path,
Index: trace/mercury_trace_tables.c
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_tables.c,v
retrieving revision 1.1
diff -u -u -r1.1 mercury_trace_tables.c
--- mercury_trace_tables.c	1998/10/16 06:20:22	1.1
+++ mercury_trace_tables.c	1998/10/27 03:10:23
@@ -94,7 +94,7 @@
 			! MR_ENTRY_LAYOUT_COMPILER_GENERATED(entry))
 	{
 		module = MR_ensure_module_info_is_present(
-				entry->MR_sle_def_module);
+				entry->MR_sle_user.MR_user_decl_module);
 		MR_ensure_proc_node_is_present(module, entry);
 	}
 }
@@ -343,16 +343,20 @@
 }
 
 #define	match_name(spec, cur)	(((spec)->MR_proc_name == NULL) ||	\
-				streq((spec)->MR_proc_name, cur->MR_sle_name))
+				streq((spec)->MR_proc_name,		\
+					cur->MR_sle_user.MR_user_name))
 
 #define	match_arity(spec, cur)	(((spec)->MR_proc_arity < 0) ||		\
-				(spec)->MR_proc_arity == cur->MR_sle_arity)
+				(spec)->MR_proc_arity ==		\
+					cur->MR_sle_user.MR_user_arity)
 
 #define	match_mode(spec, cur)	(((spec)->MR_proc_mode < 0) ||		\
-				(spec)->MR_proc_mode == cur->MR_sle_mode)
+				(spec)->MR_proc_mode ==			\
+					cur->MR_sle_user.MR_user_mode)
 
 #define	match_pf(spec, cur)	(((int) (spec)->MR_proc_pf < 0) ||	\
-				(spec)->MR_proc_pf == cur->MR_sle_pred_or_func)
+				(spec)->MR_proc_pf ==			\
+					cur->MR_sle_user.MR_user_pred_or_func)
 
 static void
 MR_process_matching_procedures_in_module(MR_Module_Info *module,
cvs diff: Diffing trial
cvs diff: Diffing util



More information about the developers mailing list