[m-dev.] For review: another change to the external debugger

Erwan Jahier Erwan.Jahier at irisa.fr
Mon Jul 27 23:12:18 AEST 1998


Erwan Jahier wrote:

> I will send another diff when you are happy with my log message.

Here's a revised diff taking into account Fergus suggestions.

------------------------------

Estimated hours taken: 40

There are 2 parts in this change (1) do not test whether or not an
attribute is wanted to retrieve it and (2) make the retrieval of
arguments and other slots done separately. The rationale for (1) is to
reduce the average size of the messages sent to the socket; for small
fields, it takes less socket traffic to always send the value, since it
avoids the need to send a `bool' in the request and a `maybe(T)' in the
response. The rationale for (2) is that since arguments slot can be very
big, we still want to be able to retrieve any slot without retrieving
arguments; so we retrieve that slot separately.



library/debugger_interface.m: 
	Split 'current' requests into 'current_vars' and 'current_slots';
	'current_vars' 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_vars/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_vars().

	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_vars and
	ML_DI_output_current_slots.

runtime/mercury_wrapper.h:
	Declare prototypes of MR_DI_output_current_vars and
	MR_DI_output_current_slots.

util/mkinit.c:
	

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/27 12:34:33
@@ -1,3 +1,4 @@
+

%-----------------------------------------------------------------------------%
 % Copyright (C) 1998 The University of Melbourne.
 % This file may only be copied under the terms of the GNU Library
General
@@ -20,7 +21,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 +87,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_vars' 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_vars    % 
+ 				% XXX should provide a way of getting
 				% just part of the arguments
-				% (to reduce unnecessary socket traffic)
-			wanted	% goal_path_string
-		)
+ 				% (to reduce unnecessary socket traffic)
 	;	abort_prog
 			% just abort the program
 	;	no_trace
@@ -144,19 +138,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_vars
+	;	current_vars(list(univ), list(string))
 	;	last_event
 	% responses to abort_prog or no_trace
 	;	ok
@@ -164,77 +160,55 @@
 	;	error(string)
 	.
 
-% `wanted' is called "current status" in the Opium documentation
-:- type wanted == bool.
+%-----------------------------------------------------------------------------%
+%	send to the debugger (e.g. Opium) the wanted features.
 
+% 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_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_slots(in, in, in, in, in, in, in, in, in, in,
in,
+ 	di, uo) is det.
 
-% 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(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_vars "ML_DI_output_current_vars":
+%	send to the debugger the list of the live arguments of the current
event.
+
+:- pragma export(output_current_vars(in, in, in, di, uo),
"ML_DI_output_current_vars").
 			
-:- 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_vars(list(univ), list(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_vars(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_vars(VarList, StringList, OutputStream) -->
+		
+	{ CurrentTraceInfo = current_vars(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 +217,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 +298,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_vars, 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/27 12:56:26
@@ -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_VARS  = 2, /* report data for current_vars 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, Unsigned seqno, Unsigned depth, 
+			const char *path);
+static void	MR_output_current_vars(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");
 	}
@@ -310,8 +313,8 @@
 	static bool searching = FALSE;
 	static Word search_data;
 	Word debugger_request;
-	Integer debugger_request_type;
-	Word var_list;
+	Integer debugger_request_type, live_var_number;
+	Word var_list, var_name_list, type_list, var;
 
 	if (searching) {
 		/* XXX should also pass registers here,
@@ -344,17 +347,26 @@
 				search_data = debugger_request;
 			        searching = TRUE;
 				return;
-			       			      		
-			case MR_REQUEST_CURRENT:
+
+			case MR_REQUEST_CURRENT_VARS:
 				if (MR_debug_socket) {
 					fprintf(stderr, "\nMercury runtime: "
-						"REQUEST_CURRENT\n");
+						"REQUEST_CURRENT_VARS\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_vars(var_list, var_name_list);
+				break;
+
+			case MR_REQUEST_CURRENT_SLOTS:
+				if (MR_debug_socket) {
+					fprintf(stderr, "\nMercury runtime: "
+						"REQUEST_CURRENT_SLOTS\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 +378,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, Unsigned seqno, Unsigned depth, const char *path)
 {
-	MR_DI_output_current(
+	MR_DI_output_current_slots(
 		MR_trace_event_number,
 		seqno,
 		depth,
@@ -382,13 +394,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_vars(Word var_list, Word string_list)
+{
+	MR_DI_output_current_vars(
+		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 +430,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 +454,40 @@
 	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/27 12:32:58
@@ -97,10 +97,13 @@
 extern	void	ML_io_init_state(void);		/* in the Mercury library */
 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_vars(Word, Word, Word);
+		/* normally ML_DI_output_current_vars (output_current_vars/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/27 12:33:29
@@ -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_vars)(Word, Word, Word);
+		/* normally ML_DI_output_current_vars (output_current_vars/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) */

Index: mkinit.c
===================================================================
RCS file: /home/mercury1/repository/mercury/util/mkinit.c,v
retrieving revision 1.36
diff -u -r1.36 mkinit.c
--- mkinit.c	1998/07/12 07:08:37	1.36
+++ mkinit.c	1998/07/27 12:33:10
@@ -136,7 +136,14 @@
 	"	MR_library_finalizer = ML_io_finalize_state;\n"
 	"	MR_library_trace_browser = ENTRY(mercury__io__print_3_0);\n"
 	"#ifdef MR_USE_EXTERNAL_DEBUGGER\n"
-	"	MR_DI_output_current = ML_DI_output_current;\n"
+	"	MR_DI_output_current_vars = ML_DI_output_current_vars;\n"
+	"	MR_DI_output_current_slots = ML_DI_output_current_slots;\n"
 	"	MR_DI_found_match = ML_DI_found_match;\n"
 	"	MR_DI_read_request_from_socket = ML_DI_read_request_from_socket;\n"
 	"#endif\n"


-- 
R1.



More information about the developers mailing list