For review: another change to the external debugger

Erwan Jahier Erwan.Jahier at irisa.fr
Sat Jul 25 02:00:55 AEST 1998


There are 2 parts in that change (1) make the retrieval of arguments and
other slots done separately and (2) do not test whether or not an
attribute is wanted to retrieve it. The rational for (2) is that for non
argument attributes, as they are very small, we can always send them all
to the socket without too much pain whereas testing each time whether or
not an attribute is wanted can be very expensive (in time). Since the
retrieval of arguments can be much more expensive (in place), we
retrieve that slot separately (and we test in the debugger process if
arguments are wanted).


library/debugger_interface.m: 
	Split 'current' requests into 'current_var' and 'current_slots';
	'current_var' requests for live variables and 'current_slots' for the
	other slots.

	output_current_slots/13 is a new predicate that sends to the debugger
	all the slots of the current event, except the argument slot.

	output_current_var/5 is a new predicate that sends to the debugger the
	list of currently live variables and the list of their internal names.

runtime/mercury_trace_external.c:
	Delete MR_output_current(); define MR_output_current_slots() and 
	MR_output_current_var().

	Define a function MR_trace_make_var_name_list() that returns the list
	of the internal name of the currently live variables.

runtime/mercury_init.h:
	Declare prototypes of ML_DI_output_current_var() and
	ML_DI_output_current_slots().

runtime/mercury_wrapper.h:
	Declare prototypes of MR_DI_output_current_var() and
	MR_DI_output_current_slots().


Index: debugger_interface.m
===================================================================
RCS file:
/home/mercury1/repository/mercury/library/debugger_interface.m,v
retrieving revision 1.3
diff -u -r1.3 debugger_interface.m
--- debugger_interface.m	1998/07/16 14:28:45	1.3
+++ debugger_interface.m	1998/07/24 15:39:01
@@ -20,7 +20,7 @@
 %	ML_DI_output_current
 %	ML_DI_found_match
 %	ML_DI_read_request_from_socket
-% These are used by runtime/mercury_trace.c.
+% These are used by runtime/mercury_trace_external.c.
 
 :- pred dummy_pred_to_avoid_warning_about_nothing_exported is det.
 
@@ -86,26 +86,19 @@
 			match(goal_path_string)
 		)
 
-		% A `current' request instructs the debuggee to
-		% retrieve the specified attributes of the current
-		% trace event and report them to the debugger
-		% via the socket.
-	;	current(
-			wanted,	% event_number
-			wanted,	% call_number
-			wanted,	% depth_number
-			wanted,	% port
-			wanted,	% module name
-			wanted,	% pred name
-			wanted,	% arity
-			wanted,	% proc_id (mode number)
-			wanted,	% determinism
-			wanted,	% arguments
-				% XXX should provide a way of getting
+		% A `current_slots' request instructs the debuggee to
+		% retrieve the attributes of the current trace
+		% event (except for argument slot) and report them 
+		% to the debugger via the socket.
+	;	current_slots
+		% A `current_var' request instructs the debuggee to
+		% retrieve the list of live variables of the current event
+		% and the list of the corresponding internal variable names
+		% and report it to the debugger via the socket.
+	;	current_var     % 
+ 				% XXX should provide a way of getting
 				% just part of the arguments
				% (to reduce unnecessary socket traffic)
-			wanted	% goal_path_string
-		)
 	;	abort_prog
 			% just abort the program
 	;	no_trace
@@ -144,19 +137,21 @@
 	;	forward_move_match_found
 	;	forward_move_match_not_found
 	% responses to current 
-	;	current(
-			maybe(event_number),
-			maybe(call_number),
-			maybe(depth_number),
-			maybe(trace_port_type),
-			maybe(string),	% module name
-			maybe(string),	% pred name
-			maybe(arity),
-			maybe(int),	% mode number
-			maybe(determinism),
-			maybe(list(univ)),
-			maybe(goal_path_string)
-		)
+	% responses to current_slots 
+	;	current_slots(
+			event_number,
+			call_number,
+			depth_number,
+			trace_port_type,
+			string,		% module name
+			string,		% pred name
+			arity,
+			int,		% mode number
+			determinism,
+			goal_path_string
+ 		)
+	% responses to current_var
+	;	current_var(list(univ), list(string))
 	;	last_event
 	% responses to abort_prog or no_trace
 	;	ok
@@ -164,77 +159,54 @@
 	;	error(string)
 	.
 
-% `wanted' is called "current status" in the Opium documentation
-:- type wanted == bool.
-
-

%-----------------------------------------------------------------------------%
-
-% output_currentML_DI_output_current":
 %	send to the debugger (e.g. Opium) the wanted features.
 
-:- pragma export(output_current(in, in, in, in, in, in, in, in, in, in,
-		in, in, in, di, uo), "ML_DI_output_current").
+% output_current_slots "ML_DI_output_current_slots":
+%	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, di, uo), "ML_DI_output_current_slots").
 			
-:- pred output_current(event_number, call_number, depth_number,
trace_port_type,
-	/* module name */ string, /* pred name */ string, arity,
-	/* mode num */ int, determinism, /* the arguments */ list(univ),
-	goal_path_string, debugger_request,
+:- pred output_current_slots(event_number, call_number, depth_number, 
+	trace_port_type, /* module name */ string, /* pred name */ string, 
+	arity, /* mode num */ int, determinism, goal_path_string, 
 	io__output_stream, io__state, io__state).
-:- mode output_current(in, in, in, in, in, in, in, in, in, in, in, in,
in,
-	di, uo) is det.
+:- mode output_current_slots(in, in, in, in, in, in, in, in, in, in,
in,
+ 	di, uo) is det.
 
-output_current(EventNumber, CallNumber, DepthNumber, Port,
-		ModuleName, PredName, Arity, ModeNum, Determinism, Args,
-		Path, DebuggerRequest, OutputStream) -->
-	(
-		{ DebuggerRequest = current(WantEventNumber,
-			WantCallNumber, WantDepthNumber, WantPort,
-			WantModuleName, WantPredName, WantArity,
-			WantModeNum, WantDeterminism, WantArgs, WantPath) }
-	->
-		{
-		get_if_wanted(WantEventNumber, EventNumber,
-				MaybeEventNumber),
-		get_if_wanted(WantCallNumber, CallNumber, MaybeCallNumber),
-		get_if_wanted(WantDepthNumber, DepthNumber,
-				MaybeDepthNumber),
-		get_if_wanted(WantPort, Port, MaybePort),
-		get_if_wanted(WantModuleName, ModuleName, MaybeModuleName),
-		get_if_wanted(WantPredName, PredName, MaybePredName),
-		get_if_wanted(WantArity, Arity, MaybeArity),
-		get_if_wanted(WantModeNum, ModeNum, MaybeModeNum),
-		get_if_wanted(WantDeterminism, Determinism,
-				MaybeDeterminism),
-		get_if_wanted(WantArgs, Args, MaybeArgs),
-		get_if_wanted(WantPath, Path, MaybePath),
-		CurrentTraceInfo = current(MaybeEventNumber,
-			MaybeCallNumber, MaybeDepthNumber, MaybePort,
-			MaybeModuleName, MaybePredName, MaybeArity,
-			MaybeModeNum, MaybeDeterminism, MaybeArgs,
-			MaybePath)
-		},
-		/****
-		io__print("debugger_interface: Send to Opium: "),
-		io__write(CurrentTraceInfo),
-		io__print(".\n"),	
-		****/
-		io__write(OutputStream, CurrentTraceInfo),
-		io__print(OutputStream, ".\n"),
-		io__flush_output(OutputStream)
-	;
-		{ error("output_current: current expected") }
-	).
 
-:- pred get_if_wanted(wanted, T, maybe(T)).
-:- mode get_if_wanted(in, in, out) is det.
-% get_if_wanted(Wanted, Value, MaybeValue).
-get_if_wanted(yes, X, yes(X)).
-get_if_wanted(no, _, no).
+output_current_slots(EventNumber, CallNumber, DepthNumber, Port,
+	ModuleName, PredName, Arity, ModeNum, Determinism,
+	Path, OutputStream) -->
+	
+	{ CurrentTraceInfo = current_slots(EventNumber, CallNumber, 
+		DepthNumber, Port, ModuleName, PredName, Arity,
+		ModeNum, Determinism, Path) },
+	io__write(OutputStream, CurrentTraceInfo),
+	io__print(OutputStream, ".\n"),
+	io__flush_output(OutputStream).
 
+% output_current_var "ML_DI_output_current_var":
+%	send to the debugger the list of the live arguments of the current
event.
+
+:- pragma export(output_current_var(in, in, in, di, uo),
"ML_DI_output_current_var").
+			
+:- pred output_current_var(list(univ), list(string), io__output_stream,
io__state, io__state).
+:- mode output_current_var(in, in, in, di, uo) is det.
+
+
+output_current_var(VarList, StringList, OutputStream) -->
+		
+	{ CurrentTraceInfo = current_var(VarList, StringList) },
+	io__write(OutputStream, CurrentTraceInfo),
+	io__print(OutputStream, ".\n"),
+	io__flush_output(OutputStream).
+

%-----------------------------------------------------------------------------%
 
-:- pragma export(found_match(in, in, in, in, in, in, in, in, in,  in,
+:- pragma export(found_match(in, in, in, in, in, in, in, in, in, in,
 			in, in), "ML_DI_found_match").
 			
 :- pred found_match(event_number, call_number, depth_number,
trace_port_type,
@@ -243,12 +215,12 @@
 				% 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)
+:- mode found_match(in, in, in, in, in, in, in, in, in, in, in, in)
 	is semidet.
 
-found_match(EventNumber, CallNumber, DepthNumber, Port,
-		ModuleName, PredName, Arity, ModeNum, Determinism, Args,
-		Path, DebuggerRequest) :-
+found_match(EventNumber, CallNumber, DepthNumber, Port, ModuleName, 
+		PredName, Arity, ModeNum, Determinism, Args, Path, 
+		DebuggerRequest) :-
 	(
 		DebuggerRequest = forward_move(MatchEventNumber,
 			MatchCallNumber, MatchDepthNumber, MatchPort,
@@ -324,13 +296,15 @@
 :- mode classify_request(in, out) is det.
 
 % the numbers here should match the definition of
-% MR_debugger_request_type in runtime/mercury_trace.c.
+% MR_debugger_request_type in runtime/mercury_trace_external.c.
 
 classify_request(hello_reply, 0).
 classify_request(forward_move(_, _, _, _, _, _, _, _, _, _, _), 1).
-classify_request(current(_, _, _, _, _, _, _, _, _, _, _), 2).
-classify_request(abort_prog, 3).
+classify_request(current_var, 2).
+classify_request(current_slots, 3).
 classify_request(no_trace, 4).
-classify_request(error(_), 5).
+classify_request(abort_prog, 5).
+classify_request(error(_), 6).
+
 

%-----------------------------------------------------------------------------%


Index: mercury_trace_external.c
===================================================================
RCS file:
/home/mercury1/repository/mercury/runtime/mercury_trace_external.c,v
retrieving revision 1.5
diff -u -r1.5 mercury_trace_external.c
--- mercury_trace_external.c	1998/07/23 20:12:25	1.5
+++ mercury_trace_external.c	1998/07/24 15:23:05
@@ -43,12 +43,14 @@
 */
 
 typedef enum {
-	MR_REQUEST_HELLO_REPLY = 0,  /* initiate debugging session	    */
-	MR_REQUEST_FORWARD_MOVE = 1, /* go to the next matching trace event */
-	MR_REQUEST_CURRENT = 2,	     /* report data for current trace event */
-	MR_REQUEST_NO_TRACE = 3,     /* continue to end, not tracing	    */
-	MR_REQUEST_ABORT_PROG = 4,   /* abort the current execution	    */
-	MR_REQUEST_ERROR = 5         /* something went wrong                */
+	MR_REQUEST_HELLO_REPLY   = 0, /* initiate debugging session	      */
+	MR_REQUEST_FORWARD_MOVE  = 1, /* go to the next matching trace event 
*/
+	MR_REQUEST_CURRENT_VAR   = 2, /* report data for current_var query   
*/
+	MR_REQUEST_CURRENT_SLOTS = 3, /* report data for current_slots query 
*/
+	MR_REQUEST_NO_TRACE      = 4, /* continue to end, not tracing	      */
+	MR_REQUEST_ABORT_PROG    = 5, /* abort the current execution	      */
+	MR_REQUEST_ERROR         = 6, /* something went wrong                
*/
+
 } MR_debugger_request_type;
 
 static MercuryFile MR_debugger_socket_in;
@@ -63,10 +65,11 @@
 			MR_trace_port port, Unsigned seqno, Unsigned depth,
 			/* XXX registers */
 			const char *path, Word search_data);
-static void	MR_output_current(const MR_Stack_Layout_Label *layout,
-			MR_trace_port port, Unsigned seqno, Unsigned depth,
-			Word var_list,
-			const char *path, Word current_request);
+static void	MR_output_current_slots(const MR_Stack_Layout_Label
*layout,
+			MR_trace_port port, int seqno, int depth, 
+			const char *path);
+static void	MR_output_current_var(Word var_list, Word string_list);
+static Word	MR_trace_make_var_name_list(const MR_Stack_Layout_Label
*layout);
 
 #if 0
 This pseudocode should go in the debugger process:
@@ -236,7 +239,7 @@
 	/*
 	** Convert the socket fd to a Mercury stream
 	*/
-	file_in = fdopen(fd, "r"); 
+	file_in = fdopen(fd, "r");
 	file_out = fdopen(fd, "w");
 	if ((file_in == NULL)||(file_out == NULL)) {
 		fprintf(stderr, "Mercury runtime: fdopen() failed: %s\n",
@@ -277,7 +280,7 @@
 	** Send start to start the synchronous communication with the debugger
 	*/
 
-	MR_send_message_to_socket("start"); 
+	MR_send_message_to_socket("start");
 	if (MR_debug_socket) {
 		fprintf(stderr, "Mercury runtime: start send\n");
 	}
@@ -311,7 +314,7 @@
 	static Word search_data;
 	Word debugger_request;
 	Integer debugger_request_type;
-	Word var_list;
+	Word var_list, var_name_list;
 
 	if (searching) {
 		/* XXX should also pass registers here,
@@ -344,17 +347,29 @@
 				search_data = debugger_request;
 			        searching = TRUE;
 				return;
-			       			      		
-			case MR_REQUEST_CURRENT:
+
+			case MR_REQUEST_CURRENT_VAR:
 				if (MR_debug_socket) {
 					fprintf(stderr, "\nMercury runtime: "
 						"REQUEST_CURRENT\n");
 				}
 				var_list = MR_trace_make_var_list(layout);
-				MR_output_current(layout, port, seqno, depth,
-					var_list, path, debugger_request);
+				var_name_list = MR_trace_make_var_name_list(layout);
+				MR_output_current_var(var_list, var_name_list);
+				break;
+
+			case MR_REQUEST_CURRENT_SLOTS:
+				if (MR_debug_socket) {
+					fprintf(stderr, "\nMercury runtime: "
+						"REQUEST_CURRENT\n");
+				}
+				MR_output_current_slots(layout, 
+							port, 
+							seqno, 
+							depth, 
+							path);
 				break;
-				
+
 			case MR_REQUEST_NO_TRACE:
 				cmd->MR_trace_cmd = MR_CMD_TO_END;
 				return;
@@ -366,13 +381,13 @@
 	}
 }
 
+
+
 static void
-MR_output_current(const MR_Stack_Layout_Label *layout,
-	MR_trace_port port, Unsigned seqno, Unsigned depth,
-	Word var_list,
-	const char *path, Word current_request)
+MR_output_current_slots(const MR_Stack_Layout_Label *layout,
+	MR_trace_port port, int seqno, int depth, const char *path)
 {
-	MR_DI_output_current(
+	MR_DI_output_current_slots(
 		MR_trace_event_number,
 		seqno,
 		depth,
@@ -382,13 +397,21 @@
 		layout->MR_sll_entry->MR_sle_arity,
 		layout->MR_sll_entry->MR_sle_mode,
 		layout->MR_sll_entry->MR_sle_detism,
-		var_list,
 		(String) (Word) path,
-		current_request,
 		(Word) &MR_debugger_socket_out);
 }
 
 static void
+MR_output_current_var(Word var_list, Word string_list)
+{
+	MR_DI_output_current_var(
+		var_list,
+		string_list,
+		(Word) &MR_debugger_socket_out);
+}
+
+
+static void
 MR_read_request_from_socket(
 			Word *debugger_request_ptr, 
 			Integer *debugger_request_type_ptr)
@@ -410,7 +433,7 @@
 	bool result;
 
 	/* XXX get live vars from registers */
-	Word arguments = /* XXX FIXME!!! */ 0; 
+	Word arguments = /* XXX FIXME!!! */ 0;
 	result = MR_DI_found_match(
 		MR_trace_event_number,
 		seqno,
@@ -434,5 +457,42 @@
 	fflush(MR_debugger_socket_out.file);
 	MR_debugger_socket_out.line_number++;
 }
+
+
+
+/*
+**
+** This function returns the list of the internal names of currently
live
+** variables.
+**
+*/
+
+static Word
+MR_trace_make_var_name_list(const MR_Stack_Layout_Label *layout)
+{
+	int 				var_count;
+	const MR_Stack_Layout_Vars 	*vars;
+	int				i;
+	const char			*name;
+
+	Word				var_name_list;
+
+	var_count = layout->MR_sll_var_count;
+	vars = &layout->MR_sll_var_info;
+
+	restore_transient_registers();
+	var_name_list = list_empty();
+	save_transient_registers();
+	for (i = var_count - 1; i >= 0; i--) {
+
+		name = MR_name_if_present(vars, i);
+		restore_transient_registers();
+		var_name_list = list_cons(name, var_name_list);
+		save_transient_registers();
+	}
+
+	return var_name_list;
+}
+
 
 #endif /* MR_USE_EXTERNAL_DEBUGGER */


Index: mercury_init.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_init.h,v
retrieving revision 1.3
diff -u -r1.3 mercury_init.h
--- mercury_init.h	1998/03/11 22:07:29	1.3
+++ mercury_init.h	1998/07/24 15:25:52
@@ -98,9 +98,11 @@
 extern	void	ML_io_finalize_state(void);	/* in the Mercury library */
 
 /* in library/debugger_interface.m */
-void	ML_DI_output_current(Integer, Integer, Integer, Word, String,
-		String, Integer, Integer, Integer, Word, String, Word, Word);
-		/* normally ML_DI_output_current (output_current/13) */
+void	ML_DI_output_current_var(Word, Word, Word);
+		/* normally ML_DI_output_current_var (output_current_var/4) */
+void	ML_DI_output_current_slots(Integer, Integer, Integer, Word,
String,
+		String, Integer, Integer, Integer, String, Word);
+		/* normally ML_DI_output_current_slots (output_current_slots/13) */
 bool	ML_DI_found_match(Integer, Integer, Integer, Word, String, String,
 		Integer, Integer, Integer, Word, String, Word);
 		/* normally ML_DI_found_match (found_match/12) */


Index: mercury_wrapper.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_wrapper.h,v
retrieving revision 1.10
diff -u -r1.10 mercury_wrapper.h
--- mercury_wrapper.h	1998/07/22 07:53:38	1.10
+++ mercury_wrapper.h	1998/07/24 15:29:13
@@ -57,12 +57,14 @@
 ** Similarly, these are for the debugger interface; they're defined in
 ** library/debugger_interface.m.
 */
-void	(*MR_DI_output_current)(Integer, Integer, Integer, Word, String,
-		String, Integer, Integer, Integer, Word, String, Word, Word);
-		/* normally ML_DI_output_current (output_current/13) */
+void	(*MR_DI_output_current_var)(Word, Word, Word);
+		/* normally ML_DI_output_current_var (output_current_var/3) */
+void	(*MR_DI_output_current_slots)(Integer, Integer, Integer, Word,
String,
+		String, Integer, Integer, Integer, String, Word);
+		/* normally ML_DI_output_current_slots (output_current_slots/13) */
 bool	(*MR_DI_found_match)(Integer, Integer, Integer, Word, String,
String,
 		Integer, Integer, Integer, Word, String, Word);
-		/* normally ML_DI_found_match (output_current/12) */
+		/* normally ML_DI_found_match (found_match/12) */
 void	(*MR_DI_read_request_from_socket)(Word, Word *, Integer *);
 		/* normally ML_DI_read_request_from_socket
 		   (read_request_from_socket/5) */





-- 
R1.



More information about the developers mailing list