[m-dev.] for review: handling layouts of compiler-generated procedures

Erwan Jahier Erwan.Jahier at irisa.fr
Sat Feb 20 22:08:58 AEDT 1999


| However, splitting up found_match() in the way that you
| have done is wrong -- it will not work.
| In particular, the code will call error/1 (in found_match_comp)
| whenever you get to an event for a compiler-generated procedure
| while processing a forward_move_user request.
| 
| The simplest thing to do really would be to leave
| the external debugger interface as it is, and for
| trace/mercury_trace_external.c to just ignore all
| events for compiler-generated procedures.

But they increment the event number rigth and users may wonder where do the
holes come from.
		
| But this may not be worth the effort.

Well, I think it is better to have as much possible informations as we can get 
since the filtering primitives of Opium-M are powerfull enough.

Here is the new diff.

Index: browser/debugger_interface.m
===================================================================
RCS file: /home/mercury1/repository/mercury/browser/debugger_interface.m,v
retrieving revision 1.7
diff -u -r1.7 debugger_interface.m
--- debugger_interface.m	1999/02/19 16:17:47	1.7
+++ debugger_interface.m	1999/02/20 10:50:51
@@ -17,11 +17,13 @@
 :- interface. 
 
 % This module exports the following C functions:
-% 	ML_DI_output_current_slots
+% 	ML_DI_output_current_slots_user
+% 	ML_DI_output_current_slots_comp
 % 	ML_DI_output_current_vars
 % 	ML_DI_output_current_nth_var
 % 	ML_DI_output_current_live_var_names
-%	ML_DI_found_match
+%	ML_DI_found_match_user
+%	ML_DI_found_match_comp
 %	ML_DI_read_request_from_socket
 % These are used by runtime/mercury_trace_external.c.
 
@@ -72,6 +74,26 @@
 	;	function.
 
 
+% Depending whether the Opium side is requesting for a user defined procedure
+% or a compiler generated one, the event has not exactly the same structure.
+% The differences between the two types of event are gathered in a forward_move
+% slot of that type.
+
+:- type pred_match --->	
+		% match user-defined preds only
+		match_user_pred(
+			match(pred_or_func),
+			match(string)		% declaration module name
+		)
+	;	
+		% match compiler-generated preds only
+		match_compiler_generated_pred(
+			match(string),		% type name
+			match(string)   	% type module name
+	;	
+		% match either user-defined or compiler-generated preds
+		match_any_pred.
+
 % This is known as "debugger_query" in the Opium documentation.
 % The debugger_request type is used for request sent
 % from the debugger process to the Mercury program being debugged.
@@ -87,8 +109,8 @@
 			match(call_number),
 			match(depth_number),
 			match(trace_port_type),
-			match(pred_or_func),
-			match(string),		% module name
+			pred_match,
+			match(string),		% definition module name
 			match(string),		% pred name
 			match(arity),
 			match(int),		% mode number
@@ -168,14 +190,30 @@
 	;	forward_move_match_found
 	;	forward_move_match_not_found
 	% responses to current 
-	% responses to current_slots 
-	;	current_slots(
+	% responses to current_slots for user event
+	;	current_slots_user(
 			event_number,
 			call_number,
 			depth_number,
 			trace_port_type,
 			pred_or_func,
-			string,		% module name
+			string,		% declaration module name
+			string,		% definition module name
+			string,		% pred name
+			arity,
+			int,		% mode number
+			determinism,
+			goal_path_string
+ 		)
+	% responses to current_slots for compiler generated event
+	;	current_slots_comp(
+			event_number,
+			call_number,
+			depth_number,
+			trace_port_type,
+			string,		% name type
+			string,		% module type
+			string,		% definition module
 			string,		% pred name
 			arity,
 			int,		% mode number
@@ -198,35 +236,64 @@
 
 %-----------------------------------------------------------------------------%
 %	send to the debugger (e.g. Opium) the wanted features.
+
+% output_current_slots_user "ML_DI_output_current_slots_user":
+%	send to the debugger (e.g. Opium) the attributes of the current event
+%	except the list of arguments.
+
+:- pragma export(output_current_slots_user(in, in, in, in, in, in, in, in, 
+	in, in, in, in, in, di, uo), "ML_DI_output_current_slots_user").
+			
+:- pred output_current_slots_user(event_number, call_number, depth_number, 
+	trace_port_type, pred_or_func, /* declarated module name */ string,
+	/* definition module name */ string, /* pred name */ string, arity, 
+	/* mode num */ int, determinism, goal_path_string, 
+	io__output_stream, io__state, io__state).
+:- mode output_current_slots_user(in, in, in, in, in, in, in, in, in, in, 
+	in, in, in,di, uo) is det.
+
+
+output_current_slots_user(EventNumber, CallNumber, DepthNumber, Port, 
+	PredOrFunc, DeclModuleName, DefModuleName, PredName, Arity, ModeNum, 
+	Determinism, Path, OutputStream) -->
+	
+	{ CurrentTraceInfo = current_slots_user(EventNumber, CallNumber, 
+		DepthNumber, Port, PredOrFunc, DeclModuleName, DefModuleName, 
+		PredName, Arity, ModeNum, Determinism, Path) },
+	io__write(OutputStream, CurrentTraceInfo),
+	io__print(OutputStream, ".\n"),
+	io__flush_output(OutputStream).
 
-% output_current_slots "ML_DI_output_current_slots":
+% output_current_slots_comp "ML_DI_output_current_slots_comp":
 %	send to the debugger (e.g. Opium) the attributes of the current event
 %	except the list of arguments.
 
-:- pragma export(output_current_slots(in, in, in, in, in, in, in, in, in, in,
-		in, in, di, uo), "ML_DI_output_current_slots").
+:- pragma export(output_current_slots_comp(in, in, in, in, in, in, in, 
+	in, in, in, in, in, in, di, uo), "ML_DI_output_current_slots_comp").
 			
-:- pred output_current_slots(event_number, call_number, depth_number, 
-	trace_port_type, pred_or_func, /* module name */ string,
-	/* pred name */ string, arity, /* mode num */ int, determinism, 
-	goal_path_string, io__output_stream, io__state, io__state).
-:- mode output_current_slots(in, in, in, in, in, in, in, in, in, in, in, in,
- 	di, uo) is det.
+:- pred output_current_slots_comp(event_number, call_number, depth_number, 
+	trace_port_type, /* name type */ string, /* module type */ string,
+	/* definition module */ string, /* pred name */ string, arity, 
+	/* mode num */ int, determinism, goal_path_string, 
+	io__output_stream, io__state, io__state).
+:- mode output_current_slots_comp(in, in, in, in, in, in, in, in, in, in, 
+	in, in, in, di, uo) is det.
 
 
-output_current_slots(EventNumber, CallNumber, DepthNumber, Port, PredOrFunc,
-	ModuleName, PredName, Arity, ModeNum, Determinism,
-	Path, OutputStream) -->
+output_current_slots_comp(EventNumber, CallNumber, DepthNumber, Port, 
+	NameType, ModuleType, DefModuleName, PredName, Arity, 
+	ModeNum, Determinism, Path, OutputStream) -->
 	
-	{ CurrentTraceInfo = current_slots(EventNumber, CallNumber, 
-		DepthNumber, Port, PredOrFunc, ModuleName, PredName, Arity,
-		ModeNum, Determinism, Path) },
+	{ CurrentTraceInfo = current_slots_comp(EventNumber, CallNumber, 
+		DepthNumber, Port, NameType, ModuleType, DefModuleName, 
+		PredName, Arity, ModeNum, Determinism, Path) },
 	io__write(OutputStream, CurrentTraceInfo),
 	io__print(OutputStream, ".\n"),
 	io__flush_output(OutputStream).
 
 % output_current_vars "ML_DI_output_current_vars":
-%	send to the debugger the list of the live variables of the current event.
+%	send to the debugger the list of the live variables of the current 
+%	event.
 
 :- pragma export(output_current_vars(in, in, in, di, uo), 
 	"ML_DI_output_current_vars").
@@ -298,26 +365,26 @@
 
 %-----------------------------------------------------------------------------%
 
-:- pragma export(found_match(in, in, in, in, in, in, in, in, in, in, in,
-			in, in), "ML_DI_found_match").
+:- pragma export(found_match_user(in, in, in, in, in, in, in, in, in, in, in,
+			in, in, in), "ML_DI_found_match_user").
 			
-:- pred found_match(event_number, call_number, depth_number, trace_port_type,
-	pred_or_func, /* module name */ string, 
-	/* pred name */ string, arity, /* mode num */ int, determinism, 
-	/* the arguments */ list(univ),
+:- pred found_match_user(event_number, call_number, depth_number, 
+	trace_port_type, pred_or_func, /* declarated module name */ string, 
+	/* defined module name */ string, /* pred name */ string, arity, 
+	/* mode num */ int, determinism, /* the arguments */ list(univ),
 				% XXX we could provide better ways of
 				% matching on arguments
 	goal_path_string, debugger_request).
-:- mode found_match(in, in, in, in, in, in, in, in, in, in, in, in, in)
+:- mode found_match_user(in, in, in, in, in, in, in, in, in, in, in, in, in, in)
 	is semidet.
 
-found_match(EventNumber, CallNumber, DepthNumber, Port, PredOrFunc, ModuleName, 
-		PredName, Arity, ModeNum, Determinism, Args, Path, 
-		DebuggerRequest) :-
+found_match_user(EventNumber, CallNumber, DepthNumber, Port, PredOrFunc, 
+		DeclModuleName, DefModuleName, PredName, Arity, ModeNum, 
+		Determinism, Args, Path, DebuggerRequest) :-
 	(
 		DebuggerRequest = forward_move(MatchEventNumber,
 			MatchCallNumber, MatchDepthNumber, MatchPort,
-			MatchPredOrFunc, MatchModuleName, MatchPredName, 
+			UserPredMatch, MatchDefModuleName, MatchPredName, 
 			MatchArity, MatchModeNum, MatchDeterminism, 
 			MatchArgs, MatchPath)
 	->
@@ -325,8 +392,15 @@
 		match(MatchCallNumber, CallNumber),
 		match(MatchDepthNumber, DepthNumber),
 		match(MatchPort, Port),
+		(	
+			UserPredMatch = match_user_pred(
+				MatchPredOrFunc, MatchDeclModuleName)
+		;
+			UserPredMatch = match_any_pred
+		),
 		match(MatchPredOrFunc, PredOrFunc),
-		match(MatchModuleName, ModuleName),
+		match(MatchDeclModuleName, DeclModuleName),
+		match(MatchDefModuleName, DefModuleName),
 		match(MatchPredName, PredName),
 		match(MatchArity, Arity),
 		match(MatchModeNum, ModeNum),
@@ -352,6 +426,54 @@
 	(LE = (<) ; LE = (=)),
 	compare(GE, X, Low), 
 	(GE = (>) ; GE = (=)).
+
+
+:- pragma export(found_match_comp(in, in, in, in, in, in, in, in, in, in, in,
+			in, in, in), "ML_DI_found_match_comp").
+			
+:- pred found_match_comp(event_number, call_number, depth_number, 
+	trace_port_type, /* name type */ string, /* module type */ string, 
+	/* definition module name */ string, /* pred name */ string, arity, 
+	/* mode num */ int, determinism, /* the arguments */ list(univ),
+				% XXX we could provide better ways of
+				% matching on arguments
+	goal_path_string, debugger_request).
+:- mode found_match_comp(in, in, in, in, in, in, in, in, in, in, in, in, in, in)
+	is semidet.
+
+found_match_comp(EventNumber, CallNumber, DepthNumber, Port, NameType, 
+		ModuleType, DefModuleName, PredName, Arity, ModeNum, 
+		Determinism, Args, Path, DebuggerRequest) :-
+	(
+		DebuggerRequest = forward_move(MatchEventNumber,
+			MatchCallNumber, MatchDepthNumber, MatchPort,
+			CompilerGeneratedPredMatch,
+			MatchDefModuleName, MatchPredName, MatchArity, 
+			MatchModeNum, MatchDeterminism, MatchArgs, MatchPath)
+	->
+		match(MatchEventNumber, EventNumber),
+		match(MatchCallNumber, CallNumber),
+		match(MatchDepthNumber, DepthNumber),
+		match(MatchPort, Port),
+		(
+			CompilerGeneratedPredMatch = 
+				match_compiler_generated_pred(MatchNameType, 
+					MatchModuleType)
+		;
+			UserPredMatch = match_any_pred
+		),
+		match(MatchNameType, NameType),
+		match(MatchModuleType, ModuleType),
+		match(MatchDefModuleName, DefModuleName),
+		match(MatchPredName, PredName),
+		match(MatchArity, Arity),
+		match(MatchModeNum, ModeNum),
+		match(MatchDeterminism, Determinism),
+		match(MatchArgs, Args),
+		match(MatchPath, Path)
+	;
+		error("found_match: forward_move expected")
+	).
 
 
 %-----------------------------------------------------------------------------%
Index: trace/mercury_trace_external.c
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_external.c,v
retrieving revision 1.9
diff -u -r1.9 mercury_trace_external.c
--- mercury_trace_external.c	1999/02/19 16:17:49	1.9
+++ mercury_trace_external.c	1999/02/20 10:50:53
@@ -553,29 +553,41 @@
 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 inter-module inlining,
-	** and either further generalized to handle compiler-generated
-	** procedures or to explicitly discard events involving
-	** compiler-generated procedures.
-	*/
-
-    MR_TRACE_CALL_MERCURY(
-	ML_DI_output_current_slots(
-		MR_trace_event_number,
-		seqno,
-		depth,
-		port,
-		layout->MR_sll_entry->MR_sle_user.MR_user_pred_or_func,
-		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);
-    );
+	if (MR_ENTRY_LAYOUT_COMPILER_GENERATED(layout->MR_sll_entry)) {
+		MR_TRACE_CALL_MERCURY(
+		    ML_DI_output_current_slots_comp(
+			MR_trace_event_number,
+			seqno,
+			depth,
+			port,
+			layout->MR_sll_entry->MR_sle_comp.MR_comp_type_name,
+			layout->MR_sll_entry->MR_sle_comp.MR_comp_type_module,
+			layout->MR_sll_entry->MR_sle_comp.MR_comp_def_module,
+			layout->MR_sll_entry->MR_sle_comp.MR_comp_pred_name,
+			layout->MR_sll_entry->MR_sle_comp.MR_comp_arity,
+			layout->MR_sll_entry->MR_sle_comp.MR_comp_mode,
+			layout->MR_sll_entry->MR_sle_detism,
+			(String) (Word) path,
+			(Word) &MR_debugger_socket_out);
+		    );
+	} else {
+		MR_TRACE_CALL_MERCURY(
+		    ML_DI_output_current_slots_user(
+			MR_trace_event_number,
+			seqno,
+			depth,
+			port,
+			layout->MR_sll_entry->MR_sle_user.MR_user_pred_or_func,
+			layout->MR_sll_entry->MR_sle_user.MR_user_decl_module,
+			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);
+		    );
+	}
 }
 
 static void
@@ -634,34 +646,45 @@
 {
 	bool result;
 
-	/*
-	** XXX This function and the Mercury predicates it calls
-	** ought to be generalized to handle inter-module inlining,
-	** and either further generalized to handle compiler-generated
-	** procedures or to explicitly discard events involving
-	** compiler-generated procedures.
-	*/
-
 	/* XXX get live vars from registers */
 	Word arguments = /* XXX FIXME!!! */ 0;
-
-    MR_TRACE_CALL_MERCURY(
-	result = ML_DI_found_match(
-		MR_trace_event_number,
-		seqno,
-		depth,
-		port,
-		layout->MR_sll_entry->MR_sle_user.MR_user_pred_or_func,
-		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,
-		search_data);
-    );
-
+	if (MR_ENTRY_LAYOUT_COMPILER_GENERATED(layout->MR_sll_entry)) {
+		MR_TRACE_CALL_MERCURY(
+		    result = ML_DI_found_match_comp(
+			MR_trace_event_number,
+			seqno,
+			depth,
+			port,
+			layout->MR_sll_entry->MR_sle_comp.MR_comp_type_name,
+			layout->MR_sll_entry->MR_sle_comp.MR_comp_type_module,
+			layout->MR_sll_entry->MR_sle_comp.MR_comp_def_module,
+			layout->MR_sll_entry->MR_sle_comp.MR_comp_pred_name,
+			layout->MR_sll_entry->MR_sle_comp.MR_comp_arity,
+			layout->MR_sll_entry->MR_sle_comp.MR_comp_mode,
+			layout->MR_sll_entry->MR_sle_detism,
+			arguments,
+			(String) (Word) path,
+			search_data);
+		    );
+	} else {
+		MR_TRACE_CALL_MERCURY(
+		    result = ML_DI_found_match_user(
+			MR_trace_event_number,
+			seqno,
+			depth,
+			port,
+			layout->MR_sll_entry->MR_sle_user.MR_user_pred_or_func,
+			layout->MR_sll_entry->MR_sle_user.MR_user_decl_module,
+			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,
+			search_data);
+		    );
+	}
 	return result;
 }
 


-- 
R1.





More information about the developers mailing list