[m-dev.] Add an bool argument to filter

Erwan Jahier Erwan.Jahier at irisa.fr
Wed Nov 3 22:13:19 AEDT 1999


I wrote:
| | On 29-Oct-1999, Erwan Jahier <Erwan.Jahier at irisa.fr> wrote:
| | > This change implements the Fergus suggestion; i.e. add an argument to filter 
| | > that returns a bool saying whether we stop collecting or not.
| | > 
| | > trace/mercury_trace_external.c:
| | > Opium-M/source/collect.in:
| | > Opium-M/source/collect.op:
| | > 	Add an new argument to filter that says saying whether we stop 
| | > 	collecting or not.
| | > 
| | > Opium-M/source/collect.op:
| | > 	Also improve the documentation by describing the event type.
| | > 
| | > Index: 0.4/mercury_trace_external.c
| | > --- 0.4/mercury_trace_external.c Fri, 29 Oct 1999 09:00:28 +0200 jahier (collect/3_mercury_tr 1.3 640)
| | > +++ 0.4(w)/mercury_trace_external.c Fri, 29 Oct 1999 11:41:39 +0200 jahier (collect/3_mercury_tr 1.3 640)
| | >  	static bool    	collect_linked = FALSE;
| | > +	static bool    	stop_collecting = FALSE;
| | >  	Integer		debugger_request_type;
| | >  	Integer		live_var_number;
| | >  	Word		debugger_request;
| | 
| | Why is the stop_collecting variable declared `static'?
| 
| It is an error.
| Removed.
| 
| | > +			if (stop_collecting) {
| | > +				(*send_collect_result_ptr)(
| | > +					(Word) MR_collecting_variable,
| | > +					(Word) &MR_debugger_socket_out);
| | > +				external_debugger_mode = MR_reading_request;
| | > +				#if defined(HAVE_DLFCN_H)&&defined(HAVE_DLCLOSE)
| | > +					dlclose((void *)handle);
| | > +				#endif
| | > +				break;
| | 
| | I detect some duplicate code here;
| | it might be a good idea to abstract that code out into
| | a separate function.
| 
| Done.
| 
| I'm waiting for the previous change (the collect implementation) to be 
| committed to show you the relative diff of that one.

Well, too much things have changed so the relative diff won't be helpful here. 
So I only post the new full diff taking the above Fergus review into account.

--
Estimated hours taken: 2

This change implements the Fergus suggestion; i.e. add an argument to filter 
saying whether we stop collecting or not.


browser/debugger_interface.m:
	Define two news debugger responses `execution_continuing' and 
	`execution_terminated' that respectively tells the debugger that
	the execution continues or is terminated after the response to collect
	has been sent.
	
browser/collect_lib.m:
	Update comments.


trace/mercury_trace_external.c:
Opium-M/source/collect.in:
Opium-M/source/collect.op:
	Add an new argument to filter that says saying whether we stop 
	collecting or not.

	
 Index: 0.8/debugger_interface.m
 --- 0.8/debugger_interface.m Tue, 02 Nov 1999 18:37:21 +0100 jahier (collect/1_debugger_i 1.6 640)
 +++ 0.8(w)/debugger_interface.m Wed, 03 Nov 1999 09:32:09 +0100 jahier (collect/1_debugger_i 1.6 640)
 @@ -286,6 +286,10 @@
		 % This is commented out because collected_type is unknown at  
		 % compile time since it is defined by users in the dynamically
		 % linked collect module.
 +	% sent if the execution is not terminated after a collect request
 +	;	execution_continuing
 +	% sent if the execution is terminated after a collect request
 +	;	execution_terminated
	 .

--- /tmp/mercury/browser/collect_lib.m	Wed Nov  3 10:19:41 1999
+++ collect_lib.m	Wed Nov  3 11:46:48 1999
@@ -18,25 +18,31 @@
 %		1) a `collected_type' which is the type of the collecting 
 %		   variable that will contain the result of the monitoring
 %		   activity.
-%		2) The predicate initialize/1 which initializes this 
+%		2) The predicate initialize/1 which initializes the 
 %		   collecting variable. initialize/1 should have the
 %		   following declarations:
 %			:- pred initialize(collected_type).
 %			:- mode initialize(out) is det.
-%		3) the predicate filter/3 which updates this collecting 
-%		   variable at each execution event. filter/3 should have the 
-%		   following declarations:
-%			:- pred filter(event, collected_type, collected_type).
-%			:- mode filter(in, di, uo) is det.
-%		4) and eventually the mode definition of the second and the 
-%		   third arguments of filter/3: `acc_in' and `acc_out'. Those
+%		3) The predicate filter/4 which updates the collecting  
+%		   variable at each execution event. filter/4 also outputs  
+%		   a variable that indicates whether to stop collecting.  
+%		   If this variable is set to `stop', the collect process  
+%		   stops; if it is set to `continue', it continues. If this  
+%		   variable is always set to `continue', the collecting will 
+%		   process until the last event is reached. filter/4 should 
+%		   follow the following declarations:
+%			:- pred filter(event, collected_type, collected_type,
+%				stop_or_continue).
+%			:- mode filter(in, di, uo, out) is det.
+%		4) And eventually the mode definition of the second and the 
+%		   third arguments of filter/4: `acc_in' and `acc_out'. Those
 %		   mode have `di' and `uo' respectively as default values.
 %
 % 	Then, this file is used to generate the Mercury module `collect.m',
 % 	which is compiled and dynamically linked with the current execution.
 % 	When a `collect' request is made from the external debugger, a variable
 % 	of type collected_type is first initialized (with initialize/1) and
-% 	then updated (with filter/3) for all the events of the remaining
+% 	then updated (with filter/4) for all the events of the remaining
 % 	execution. When the end of the execution is reached, the last value of
 % 	the collecting variable is send to the debugger.
 

Index: 0.8/mercury_trace_external.c
--- 0.8/mercury_trace_external.c Tue, 02 Nov 1999 18:37:21 +0100 jahier (collect/3_mercury_tr 1.7 640)
+++ 0.8(w)/mercury_trace_external.c Wed, 03 Nov 1999 11:53:46 +0100 jahier (collect/3_mercury_tr 1.7 640)
@@ -183,9 +183,11 @@
 static void	MR_trace_browse_one_external(MR_Var_Spec which_var);
 static void	MR_COLLECT_filter(void (*filter_ptr)(Integer, Integer, Integer, 
 			Word, Word, String, String, String, Integer, Integer, 
-			Integer, String, Word, Word *), Unsigned seqno, 
-			Unsigned depth,	MR_Trace_Port port, 
-			const MR_Stack_Layout_Label *layout, const char *path);
+			Integer, String, Word, Word *, Char *), Unsigned seqno, 
+			Unsigned depth, MR_Trace_Port port, 
+			const MR_Stack_Layout_Label *layout, const char *path, 
+			bool *stop_collecting);
+static void	MR_send_collect_result(void);
 
 #if 0
 This pseudocode should go in the debugger process:
@@ -435,14 +437,8 @@
 			break;
 
 		case MR_collecting:
-			MR_TRACE_CALL_MERCURY(
-				(*send_collect_result_ptr)(
-					MR_collecting_variable, 
-					(Word) &MR_debugger_socket_out));
-			#if defined(HAVE_DLFCN_H) && defined(HAVE_DLCLOSE)
-		       	MR_TRACE_CALL_MERCURY(
-				ML_CL_unlink_collect(collect_lib_maybe_handle));
-			#endif
+			MR_send_collect_result();
+			MR_send_message_to_socket("execution_terminated");
 			break;
 
 		default:
@@ -464,9 +460,10 @@
 	static void	(*initialize_ptr)(Word *);
 	static void    	(*filter_ptr)(Integer, Integer, Integer, Word,
 				Word, String, String, String, Integer,
-				Integer, Integer, String, Word, Word *);
+				Integer, Integer, String, Word, Word *, Char *);
 	static void	(*get_collect_var_type_ptr)(Word *);
 	static bool    	collect_linked = FALSE;
+	bool    	stop_collecting = FALSE;
 	Integer		debugger_request_type;
 	Integer		live_var_number;
 	Word		debugger_request;
@@ -534,9 +531,15 @@
 			** arguments = MR_make_var_list(layout, saved_regs);
 			*/
 			MR_COLLECT_filter(*filter_ptr, seqno, depth, port,
-				layout, path);
-			goto done;
+				layout, path, &stop_collecting);
 
+			if (stop_collecting) {
+				MR_send_collect_result();
+				MR_send_message_to_socket("execution_continuing");
+				break;
+			} else {
+				goto done;
+			}
 		case MR_reading_request:
 			break;
 
@@ -811,9 +814,16 @@
 					** filter once here.
 					*/
 					MR_COLLECT_filter(*filter_ptr, seqno, depth,
-						 port, layout, path);
+						port, layout, path, &stop_collecting);
 					
-					goto done;
+					if (stop_collecting) {
+						MR_send_collect_result();
+						MR_send_message_to_socket(
+							"execution_continuing");
+						break;
+					} else {
+						goto done;
+					}
 				} else {
 					MR_send_message_to_socket(
 						"collect_not_linked");
@@ -1428,10 +1438,13 @@
 */
 static void
 MR_COLLECT_filter(void (*filter_ptr)(Integer, Integer, Integer, Word, Word, 
-	String, String, String, Integer, Integer, Integer, String, Word, Word *), 
-       	Unsigned seqno, Unsigned depth, MR_Trace_Port port, 
-	const MR_Stack_Layout_Label *layout, const char *path)
-{		
+	String, String, String, Integer, Integer, Integer, String, Word, Word *,
+        Char *), Unsigned seqno, Unsigned depth, MR_Trace_Port port, 
+	const MR_Stack_Layout_Label *layout, const char *path, 
+	bool *stop_collecting)
+{
+	Char	result;		
+
 	MR_TRACE_CALL_MERCURY((*filter_ptr)(
 		MR_trace_event_number,
 		seqno,
@@ -1446,7 +1459,22 @@
 		layout->MR_sll_entry->MR_sle_detism,
 		(String) path,
 		MR_collecting_variable,
-		&MR_collecting_variable));
+		&MR_collecting_variable,
+		&result));
+	*stop_collecting = (result == 'y');
 }
 
+static void
+MR_send_collect_result(void)
+{
+	Word	*close_result;	
+
+	(*send_collect_result_ptr)(
+		MR_collecting_variable, 
+		(Word) &MR_debugger_socket_out);
+#if defined(HAVE_DLFCN_H) && defined(HAVE_DLCLOSE)
+	MR_TRACE_CALL_MERCURY(
+       		ML_CL_unlink_collect(collect_lib_maybe_handle));
+#endif
+}
 #endif /* MR_USE_EXTERNAL_DEBUGGER */
Index: 0.8/logmsg
--- 0.8/logmsg Tue, 02 Nov 1999 18:37:21 +0100 jahier (collect/4_logmsg 1.4 640)
+++ 0.8(w)/logmsg Wed, 03 Nov 1999 11:56:26 +0100 jahier (collect/4_logmsg 1.4 640)
@@ -1,61 +1,16 @@
 
 
Index: 0.8/collect.in
--- 0.8/collect.in Tue, 02 Nov 1999 18:37:21 +0100 jahier (collect/5_collect.in 1.1 640)
+++ 0.8(w)/collect.in Wed, 03 Nov 1999 11:54:58 +0100 jahier (collect/5_collect.in 1.1 640)
@@ -1,6 +1,7 @@
 :- module collect.
 
 :- interface.
+:- import_module char.
 
 :- type collected_type.
 
@@ -11,9 +12,9 @@
 :- pred filter(event_number, call_number, depth_number, trace_port_type,
         pred_or_func, declared_module_name, defined_module_name, proc_name,
         arity, mode_number, determinism, goal_path_string, collected_type,
-        collected_type).
+        collected_type, char).
 
-:- mode filter(in, in, in, in, in, in, in, in, in, in, in, in, acc_in, acc_out)
+:- mode filter(in, in, in, in, in, in, in, in, in, in, in, in, acc_in, acc_out, out)
         is det.
 
 :- pred send_collect_result(collected_type, io__output_stream, io__state,
@@ -27,7 +28,7 @@
 
 :- pragma export(initialize(out), "ML_COLLECT_initialize").
 :- pragma export(filter(in, in, in, in, in, in, in, in, in, in, in, in, 
-	acc_in, acc_out), "ML_COLLECT_filter").
+	acc_in, acc_out, out), "ML_COLLECT_filter").
 :- pragma export(send_collect_result(in, in, di, uo), 
 	"ML_COLLECT_send_collect_result").
 :- pragma export(collected_variable_type(out), 
@@ -168,12 +169,25 @@
 	Event = event(_, _, _, _, _, _, _, _, _, _, _, GoalPath).
 
 
+% Type of the fourth argument of filter/4 which tells whether to stop collecting
+% or not.
+:- type stop_or_continue --->
+		stop
+	;	continue.
+
 filter(EventNumber, CallNumber, DepthNumber, Port, PredOrFunc, DeclModuleName,
 		DefModuleName, PredName, Arity, ModeNum, Determinism, Path,
-		AccIn, AccOut) :- 
+		AccIn, AccOut, Char) :- 
 	filter(event(EventNumber, CallNumber, DepthNumber, Port, PredOrFunc,
 		DeclModuleName, DefModuleName, PredName, Arity, ModeNum,
-		Determinism, Path), AccIn, AccOut).
+		Determinism, Path), AccIn, AccOut, StopOrContinue),
+	(
+		StopOrContinue = continue,
+		Char = 'n'
+	;
+		StopOrContinue = stop,
+		Char = 'y'
+	).
 
 % This predicate retrieves the type of the collecting variable.
 collected_variable_type(Type) :- 
@@ -193,6 +207,6 @@
 	collected(collected_type).
 
 
-:- pred filter(event, collected_type, collected_type).
-:- mode filter(in, acc_in, acc_out) is det.
-:- pragma inline(filter/3).
+:- pred filter(event, collected_type, collected_type, stop_or_continue).
+:- mode filter(in, acc_in, acc_out, out) is det.
+:- pragma inline(filter/4).


-- 
R1.


--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list