[m-dev.] For review: calling MR_collect_filter() in MR_trace_real()

Erwan Jahier Erwan.Jahier at irisa.fr
Wed Mar 7 01:01:14 AEDT 2001


| > Since MR_COLLECT_filter() is called just between MR_copy_regs_to_saved_regs()
| > and MR_copy_saved_regs_to_regs(),
| 
| No, it's not; there are calls to MR_list_empty() and MR_trace_make_var_list(),
| both of which can allocate heap.  They increment the real MR_hp,
| whereas the Mercury code that you're calling will expect the heap
| pointer to be in the saved copy of MR_hp, so it will overwrite
| the heap space that they allocate.

ok.

| Please send another diff when you've fixed that one
| and the stuff mentioned in my other mail.

Here it is.

Index: trace/mercury_trace.c
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace.c,v
retrieving revision 1.39
diff -u -d -u -r1.39 mercury_trace.c
--- trace/mercury_trace.c	2001/03/05 03:52:29	1.39
+++ trace/mercury_trace.c	2001/03/06 13:52:17
@@ -57,7 +57,8 @@
 	0,	/* stop event */
 	MR_PRINT_LEVEL_SOME,
 	FALSE,	/* not strict */
-	TRUE	/* must check */
+	TRUE,	/* must check */
+	NULL    /* pointer to filter/4 for collect queries */
 };
 
 MR_Code 		*MR_trace_real(const MR_Label_Layout *layout);
@@ -166,6 +167,44 @@
 #endif	/* MR_TRACE_HISTOGRAM */
 
 	switch (MR_trace_ctrl.MR_trace_cmd) {
+		case MR_CMD_COLLECT:
+		  {
+		        MR_Event_Info	event_info;
+			Word		*saved_regs = event_info.MR_saved_regs;
+			int		max_r_num;
+			const char	*path;
+			bool    	stop_collecting = FALSE;
+
+			max_r_num = layout->MR_sll_entry->MR_sle_max_r_num;
+			if (max_r_num + MR_NUM_SPECIAL_REG > 
+					MR_MAX_SPECIAL_REG_MR) 
+			{
+				event_info.MR_max_mr_num = 
+					max_r_num + MR_NUM_SPECIAL_REG;
+			} else {
+				event_info.MR_max_mr_num = 
+					MR_MAX_SPECIAL_REG_MR;
+			}
+			
+			port = (MR_Trace_Port) layout->MR_sll_port;
+			path = layout->MR_sll_entry->MR_sle_module_layout
+				->MR_ml_string_table + layout->MR_sll_goal_path;
+			MR_copy_regs_to_saved_regs(event_info.MR_max_mr_num, 
+				saved_regs);
+			MR_trace_init_point_vars(layout, saved_regs, port);
+			MR_COLLECT_filter(MR_trace_ctrl.MR_filter_ptr, seqno,
+				depth, port, layout, path, &stop_collecting);
+			MR_copy_saved_regs_to_regs(event_info.MR_max_mr_num, 
+				saved_regs);
+			if (stop_collecting) {
+				MR_trace_ctrl.MR_trace_cmd = MR_CMD_GOTO;
+				return MR_trace_event(&MR_trace_ctrl, TRUE,
+                                               layout, port, seqno, depth);
+			}
+
+			goto check_stop_print;
+		  }	
+
 		case MR_CMD_GOTO:
 			if (MR_trace_event_number >=
 					MR_trace_ctrl.MR_trace_stop_event)
Index: trace/mercury_trace.h
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace.h,v
retrieving revision 1.21
diff -u -d -u -r1.21 mercury_trace.h
--- trace/mercury_trace.h	2001/02/13 08:28:27	1.21
+++ trace/mercury_trace.h	2001/03/06 13:52:17
@@ -129,6 +129,10 @@
 ** MR_trace_cmd says what mode the tracer is in, i.e. how events should be
 ** treated.
 **
+** If MR_trace_cmd == MR_CMD_COLLECT, the event handler calls MR_COLLECT_filter()
+** until the end of the execution is reached or until the `stop_collecting'
+** variable is set to TRUE. It is the tracer mode after a `collect' request.
+**
 ** If MR_trace_cmd == MR_CMD_GOTO, the event handler will stop at the next
 ** event whose event number is equal to or greater than MR_trace_stop_event.
 **
@@ -162,6 +166,7 @@
 */
 
 typedef enum {
+	MR_CMD_COLLECT,
 	MR_CMD_GOTO,
 	MR_CMD_NEXT,
 	MR_CMD_FINISH,
@@ -180,6 +185,17 @@
 	MR_PRINT_LEVEL_ALL	/* all events                              */
 } MR_Trace_Print_Level;
 
+/*
+** Type of pointers to filter/4 procedures for collect request
+*/
+
+typedef void (*MR_FilterFuncPtr)(MR_Integer, MR_Integer,
+	MR_Integer, MR_Word, MR_Word, MR_String, MR_String, MR_String,
+	MR_Integer, MR_Integer, MR_Word, MR_Integer, MR_String, MR_Word,
+	MR_Word *, MR_Char *);
+
 typedef struct {
 	MR_Trace_Cmd_Type	MR_trace_cmd;	
 				/*
@@ -202,7 +218,14 @@
 				** MR_trace_print_level != MR_PRINT_LEVEL_NONE
 				*/
 	bool			MR_trace_must_check;
+
+				/*
+				** The MR_filter_ptr field points to the filter/4
+				** procedure during a collect request
+				*/
+	MR_FilterFuncPtr	MR_filter_ptr;
 } MR_Trace_Cmd_Info;
+
 
 #define	MR_port_is_final(port)		((port) == MR_PORT_EXIT || \
 					 (port) == MR_PORT_FAIL || \
Index: trace/mercury_trace_external.c
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_external.c,v
retrieving revision 1.53
diff -u -d -u -r1.53 mercury_trace_external.c
--- trace/mercury_trace_external.c	2001/01/18 01:19:15	1.53
+++ trace/mercury_trace_external.c	2001/03/06 13:52:18
@@ -203,14 +203,6 @@
 static void	MR_get_variable_name(MR_Word debugger_request,
 			MR_String *var_name_ptr);
 static void	MR_trace_browse_one_external(MR_Var_Spec which_var);
-static void	MR_COLLECT_filter(void (*filter_ptr)(MR_Integer, MR_Integer,
-			MR_Integer, MR_Word, MR_Word, MR_String, MR_String,
-			MR_String, MR_Integer, MR_Integer, MR_Word, MR_Integer,
-			MR_String, MR_Word, MR_Word *, MR_Char *),
-			MR_Unsigned seqno, MR_Unsigned depth,
-			MR_Trace_Port port, 
-			const MR_Label_Layout *layout, const char *path, 
-			bool *stop_collecting);
 static void	MR_send_collect_result(void);
 
 #if 0
@@ -477,17 +469,11 @@
 MR_Code *
 MR_trace_event_external(MR_Trace_Cmd_Info *cmd, MR_Event_Info *event_info)
 {
-	static	MR_Word		search_data;
-	static	void		(*initialize_ptr)(MR_Word *);
-	static	void    	(*filter_ptr)(MR_Integer, MR_Integer,
-					MR_Integer, MR_Word, MR_Word,
-					MR_String, MR_String, MR_String,
-					MR_Integer, MR_Integer, MR_Word,
-					MR_Integer, MR_String, MR_Word,
-					MR_Word *, MR_Char *);
-	static	void		(*get_collect_var_type_ptr)(MR_Word *);
-	static	bool    	collect_linked = FALSE;
-	bool    		stop_collecting = FALSE;
+	static MR_Word	search_data;
+	static void	(*initialize_ptr)(MR_Word *);
+	static void	(*get_collect_var_type_ptr)(MR_Word *);
+	static bool    	collect_linked = FALSE;
+	bool    	stop_collecting = FALSE;
 	MR_Integer		debugger_request_type;
 	MR_Word			debugger_request;
 	MR_Word			var_list;
@@ -544,17 +530,10 @@
 			break;
 
 		case MR_collecting:
-		 
-			MR_COLLECT_filter(*filter_ptr, seqno, depth, port,
-				layout, path, &stop_collecting);
+		        MR_send_collect_result(); 
+			MR_send_message_to_socket("execution_continuing");
+			break;
 
-			if (stop_collecting) {
-				MR_send_collect_result();
-				MR_send_message_to_socket("execution_continuing");
-				break;
-			} else {
-				goto done;
-			}
 		case MR_reading_request:
 			break;
 
@@ -784,7 +763,7 @@
 				MR_TRACE_CALL_MERCURY(
 					ML_CL_link_collect(
 			       		    MR_object_file_name,
-					    (MR_Word *) &filter_ptr,
+					    (MR_Word *) &cmd->MR_filter_ptr,
 					    (MR_Word *) &initialize_ptr,
 					    (MR_Word *) &send_collect_result_ptr,
 					    (MR_Word *) &get_collect_var_type_ptr,
@@ -827,8 +806,9 @@
 					** the current event, we need to call 
 					** filter once here.
 					*/
-					MR_COLLECT_filter(*filter_ptr, seqno, depth,
-						port, layout, path, &stop_collecting);
+					MR_COLLECT_filter(cmd->MR_filter_ptr,
+						seqno, depth, port, layout, path, 
+						&stop_collecting);
 					
 					if (stop_collecting) {
 						MR_send_collect_result();
@@ -836,6 +816,16 @@
 							"execution_continuing");
 						break;
 					} else {
+					/*
+					** For efficiency, the remaining calls
+					** to MR_COLLECT_filter() are done in 
+					** MR_trace_real().
+					*/
+					        cmd->MR_trace_cmd = MR_CMD_COLLECT;
+						cmd->MR_trace_must_check = FALSE;
+						cmd->MR_trace_strict = TRUE;
+						cmd->MR_trace_print_level = 
+						 	MR_PRINT_LEVEL_NONE;
 						goto done;
 					}
 				} else {
@@ -1477,13 +1467,10 @@
 ** This function calls the collect filtering predicate defined by the user
 ** and dynamically link with the execution.
 */
-static void
-MR_COLLECT_filter(void (*filter_ptr)(MR_Integer, MR_Integer, MR_Integer,
-	MR_Word, MR_Word, MR_String, MR_String, MR_String, MR_Integer,
-	MR_Integer, MR_Word, MR_Integer, MR_String, MR_Word, MR_Word *,
-	MR_Char *), MR_Unsigned seqno, MR_Unsigned depth, MR_Trace_Port port, 
-	const MR_Label_Layout *layout, const char *path, 
-	bool *stop_collecting)
+void
+MR_COLLECT_filter(MR_FilterFuncPtr filter_ptr, MR_Unsigned seqno, 
+	MR_Unsigned depth, MR_Trace_Port port, const MR_Label_Layout *layout, 
+	const char *path, bool *stop_collecting)
 {
 	MR_Char	result;		
 	MR_Word	arguments;
Index: trace/mercury_trace_external.h
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_external.h,v
retrieving revision 1.9
diff -u -d -u -r1.9 mercury_trace_external.h
--- trace/mercury_trace_external.h	2001/02/13 08:28:27	1.9
+++ trace/mercury_trace_external.h	2001/03/06 13:52:18
@@ -18,6 +18,10 @@
 extern	void	MR_trace_final_external(void);
 extern	MR_Code	*MR_trace_event_external(MR_Trace_Cmd_Info *cmd,
 			MR_Event_Info *event_info);
+extern void	MR_COLLECT_filter(MR_FilterFuncPtr filter_ptr, MR_Unsigned seqno, 
+			MR_Unsigned depth, MR_Trace_Port port, 
+			const MR_Label_Layout *layout, const char *path, 
+			bool *stop_collecting);
 
 /*
 ** External debugger socket streams.


-- 
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