[m-dev.] Re: your mail

Erwan Jahier Erwan.Jahier at irisa.fr
Thu Feb 11 08:03:56 AEDT 1999


Many thanks for your comments Fergus.

| > trace/mercury_trace.[ch]:
| > trace/mercury_trace_internal.[ch]:
| > 	Move MR_trace_retry() and MR_trace_find_input_arg() from 
| > 	mercury_trace_internal.c to mercury_trace.c since they are also needed
| > 	in the external debugger.
| > 
| > 	MR_trace_retry() now returns TRUE if the retry proceeded correctly 
| > 	and FALSE otherwise.
| 
| It would probably be better for it to return a `char *' pointer which
| is either NULL if the retry proceeds correctly or an error message
| if it fails.

Good idea.

| > +extern bool
| > +MR_trace_retry(const MR_Stack_Layout_Label *this_label, Word *saved_regs,
| > +	MR_Event_Details *event_details, int seqno, int depth,
| > +	int *max_mr_num, Code **jumpaddr)
| > +{
| 
| `extern' linkage is the default for functions,
| and using it on function definitions seems misleading,
| since it seems to imply "defined somewhere else", when
| in fact the function is defined right here.
| So I recommend not using an explicit `extern' on function definitions.

Ok.

| ...
| > +	if (call_label->MR_sll_var_count < 0) {
| > +		printf("Cannot perform retry because information about "
| > +			"the input arguments is not available.\n");
| > +		return FALSE;
| > +	}
| 
| This should not use printf().
| For the internal debugger, it should use
| 
| 	fflush(mdb_out);
| 	fprintf(mdb_err, ...)
| 
| instead. For the external debugger, printing anything at
| all is probably wrong.  Better to just return the error
| message, as I suggested above.

Ok.

| mercury_trace_external.c:
| > -		len = SUN_LEN(&unix_address);
| > -	} else {
| > +		len = sizeof(&unix_address);
| > +	}  else {
| 
| That change isn't documented in the log message.
| 
| The additional space before the "else" is probably a mistake.
| 
| I don't remember what SUN_LEN() was supposed to be --
| it may be worth checking Stevens, "Advanced Programming in
| the UNIX environment", which is probably where it came from --
| but the use of `sizeof(&unix_address)' looks to me like it could
| well wrong; I think maybe `sizeof(unix_address)' might be
| what was intended.

I haven't test the inet socket stuff anyway. I'll left this unchanged for the
time being and fix that in another change.

| 
| Apart from that, your change looks fine.
| But I would like to see another diff when you have addressed
| those issues.

Here is a relative diff and the new diff

________________________________________________________________

Index: trace/mercury_trace_external.c
--- 0.4/trace/mercury_trace_external.c Tue, 09 Feb 1999 18:11:37 +0100 jahier (submitdiff/5_mercury_tr 1.3 640)
+++ 0.5(w)/trace/mercury_trace_external.c Wed, 10 Feb 1999 21:45:19 +0100 jahier (submitdiff/5_mercury_tr 1.4 640)
@@ -66,6 +66,8 @@
 static MercuryFile MR_debugger_socket_out;
 
 static void	MR_send_message_to_socket(const char *message);
+static void	MR_send_message_to_socket_format(const char *format, 
+			const char *message);
 static void	MR_read_request_from_socket(
 			Word *debugger_request_ptr, 
 			Integer *debugger_request_type_ptr);
@@ -192,8 +194,8 @@
 		unix_address.sun_family = AF_UNIX;
 		strcpy(unix_address.sun_path, unix_socket);
 		addr = (struct sockaddr *) &unix_address;
-		len = sizeof(&unix_address);
-	}  else {
+		len = SUN_LEN(&unix_address);
+	} else {
 		char hostname[255];
 		char port_string[255];
 		unsigned short port;
@@ -193,7 +195,7 @@
 		strcpy(unix_address.sun_path, unix_socket);
 		addr = (struct sockaddr *) &unix_address;
 		len = sizeof(&unix_address);
-	}  else {
+	} else {
 		char hostname[255];
 		char port_string[255];
 		unsigned short port;
@@ -339,8 +341,9 @@
 	Word		var_names_list;
 	Word		type_list;
 	Word		var;
-	Code		*jumpaddr= NULL;
+	Code		*jumpaddr = NULL;
 	MR_Event_Details	event_details;
+	char		*message;
 
 	event_details.MR_call_seqno = MR_trace_call_seqno;
 	event_details.MR_call_depth = MR_trace_call_depth;
@@ -427,21 +430,20 @@
 					fprintf(stderr, "\nMercury runtime: "
 						"REQUEST_RETRY\n");
 				}
-				if (MR_trace_retry(layout, saved_regs, 
+				message = MR_trace_retry(layout, saved_regs, 
 					&event_details, seqno, depth, 
-					max_mr_num, &jumpaddr)) 
-
-				  {
-				    MR_send_message_to_socket("ok");
-				    cmd->MR_trace_cmd = MR_CMD_GOTO;
-				    cmd->MR_trace_stop_event = 
-					MR_trace_event_number + 1;
-				    return jumpaddr;
-				  }
-				else
-				  {
-				    MR_send_message_to_socket("retry_failed");
-				  }
+					max_mr_num, &jumpaddr);
+				if (message == NULL)
+				{
+					MR_send_message_to_socket("ok");
+					cmd->MR_trace_cmd = MR_CMD_GOTO;
+					cmd->MR_trace_stop_event = 
+						MR_trace_event_number + 1;
+					return jumpaddr;
+				} else {
+					MR_send_message_to_socket_format(
+						"\"error(%s)\".\n", message);
+				}
 				break;
 
 			case MR_REQUEST_NO_TRACE:
@@ -579,6 +581,15 @@
 
 	return result;
 }
+
+static void
+MR_send_message_to_socket_format(const char *format, const char *message)
+{
+	fprintf(MR_debugger_socket_out.file, format, message);
+	fflush(MR_debugger_socket_out.file);
+	MR_debugger_socket_out.line_number++;
+}
+
 
 static void
 MR_send_message_to_socket(const char *message)
Index: trace/mercury_trace_internal.c
--- 0.4/trace/mercury_trace_internal.c Tue, 09 Feb 1999 00:52:33 +0100 jahier (submitdiff/10_mercury_tr 1.1 640)
+++ 0.5(w)/trace/mercury_trace_internal.c Wed, 10 Feb 1999 21:39:23 +0100 jahier (submitdiff/10_mercury_tr 1.2 640)
@@ -661,6 +661,7 @@
 		}
 	} else if (streq(words[0], "retry")) {
 		int	stop_depth;
+		char   *message;
 
 		if (word_count == 2 && MR_trace_is_number(words[1], &n)) {
 			stop_depth = depth - n;
@@ -672,8 +673,11 @@
 		}
 
 		if (stop_depth == depth && MR_port_is_final(port)) {
-			MR_trace_retry(layout, saved_regs, event_details,
+			message = MR_trace_retry(layout, saved_regs, event_details,
 				seqno, depth, max_mr_num, jumpaddr);
+			fflush(MR_mdb_out);
+			fprintf(MR_mdb_err, message);
+			fprintf(MR_mdb_err, "\n");
 
 			cmd->MR_trace_cmd = MR_CMD_GOTO;
 			cmd->MR_trace_stop_event = MR_trace_event_number + 1;
Index: trace/mercury_trace.h
--- 0.4/trace/mercury_trace.h Tue, 09 Feb 1999 18:11:37 +0100 jahier (submitdiff/11_mercury_tr 1.2 640)
+++ 0.5(w)/trace/mercury_trace.h Wed, 10 Feb 1999 18:55:01 +0100 jahier (submitdiff/11_mercury_tr 1.3 640)
@@ -30,11 +30,11 @@
 /* The initial size of arrays of argument values. */
 #define	MR_INIT_ARG_COUNT	20
 
-extern	bool	MR_trace_retry(const MR_Stack_Layout_Label *layout,
+char *	MR_trace_retry(const MR_Stack_Layout_Label *layout,
 			Word *saved_regs, MR_Event_Details *event_details,
 			int seqno, int depth, int *max_mr_num,
 			Code **jumpaddr);
-extern  Word	MR_trace_find_input_arg(const MR_Stack_Layout_Label *label, 
+Word	MR_trace_find_input_arg(const MR_Stack_Layout_Label *label, 
 			Word *saved_regs, const char *name, bool *succeeded);
 
 /*
Index: trace/mercury_trace.c
--- 0.4/trace/mercury_trace.c Tue, 09 Feb 1999 18:11:37 +0100 jahier (submitdiff/12_mercury_tr 1.2 640)
+++ 0.5(w)/trace/mercury_trace.c Wed, 10 Feb 1999 21:46:40 +0100 jahier (submitdiff/12_mercury_tr 1.3 640)
@@ -281,7 +281,7 @@
 	return jumpaddr;
 }
 
-extern bool
+char *
 MR_trace_retry(const MR_Stack_Layout_Label *this_label, Word *saved_regs,
 	MR_Event_Details *event_details, int seqno, int depth,
 	int *max_mr_num, Code **jumpaddr)
@@ -295,14 +295,15 @@
 	Word				arg_value;
 	int				i;
 	bool				succeeded;
+	char			        *message;
 
 	entry = this_label->MR_sll_entry;
 	call_label = entry->MR_sle_call_label;
 
 	if (call_label->MR_sll_var_count < 0) {
-		printf("Cannot perform retry because information about "
-			"the input arguments is not available.\n");
-		return FALSE;
+		message = "Cannot perform retry because information about "
+		          "the input arguments is not available.";
+		return message;
 	}
 
 	input_args = &call_label->MR_sll_var_info;
@@ -323,9 +324,9 @@
 				input_args->MR_slvs_names[i], &succeeded);
 
 		if (! succeeded) {
-			printf("Cannot perform retry because the values of "
-				"some input arguments are missing.\n");
-			return FALSE;
+			message = "Cannot perform retry because the values of "
+				  "some input arguments are missing.";
+			return message;
 		}
 
 		arg_num = MR_get_register_number(
@@ -403,7 +404,7 @@
 	event_details->MR_call_depth = MR_trace_call_depth;
 	event_details->MR_event_number = MR_trace_event_number;
 
-	return TRUE;
+	return NULL;
 }

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

Estimated hours taken: 10

This change implement the retry command for the external debugger.


trace/mercury_trace.[ch]:
trace/mercury_trace_internal.[ch]:
	Move MR_trace_retry() and MR_trace_find_input_arg() from 
	mercury_trace_internal.c to mercury_trace.c since they are also needed
	in the external debugger.

	MR_trace_retry() now returns a `char *' pointer which is either 
	NULL if the retry proceeds correctly or an error message if it fails.
	
trace/mercury_trace_internal.h:
trace/mercury_trace.h:
	Move the definition of the type MR_Event_Details from 
	mercury_trace_internal.h to mercury_trace.h since both are also 
	needed in the external debugger.
 
	Idem for the constant MR_INIT_ARG_COUNT.


trace/mercury_trace.c:
trace/mercury_trace_external.[ch]:
	MR_trace_external() now returns a code address to jump in.

	Pass the integer max_mr_num in argument of MR_trace_external() since
	it is needed by MR_trace_retry().

	Add a MR_send_message_to_socket_format() that allows to send formated
	message to the socket. I need that because the error message send to the 
	socket must be a prolog term.

trace/mercury_trace_external.c:
	Implement the retry command in MR_trace_event_external().


browse/debugger_interface.m:
	Add support for the retry port.

	Make all the lines fits in 80 colums.


Index: trace/mercury_trace.c
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace.c,v
retrieving revision 1.3
diff -u -r1.3 mercury_trace.c
--- mercury_trace.c	1998/12/14 16:05:17	1.3
+++ mercury_trace.c	1999/02/09 00:13:28
@@ -1,5 +1,5 @@
 /*
-** Copyright (C) 1997-1998 The University of Melbourne.
+** Copyright (C) 1997-1999 The University of Melbourne.
 ** This file may only be copied under the terms of the GNU Library General
 ** Public License - see the file COPYING.LIB in the Mercury distribution.
 */
@@ -246,9 +246,8 @@
 			fatal_error("reporting event for external debugger");
 		}
 
-		MR_trace_event_external(cmd, layout, saved_regs,
-			port, seqno, depth, path);
-		jumpaddr = NULL;
+		jumpaddr = MR_trace_event_external(cmd, layout, saved_regs,
+				port, seqno, depth, path, &max_mr_num);
 	} else {
 		jumpaddr = MR_trace_event_internal(cmd, interactive,
 				layout, saved_regs, port, seqno,
@@ -280,4 +279,156 @@
 	MR_saved_global_hp(saved_regs) = MR_global_hp;
 	MR_copy_saved_regs_to_regs(max_mr_num, saved_regs);
 	return jumpaddr;
+}
+
+extern bool
+MR_trace_retry(const MR_Stack_Layout_Label *this_label, Word *saved_regs,
+	MR_Event_Details *event_details, int seqno, int depth,
+	int *max_mr_num, Code **jumpaddr)
+{
+	const MR_Stack_Layout_Entry	*entry;
+	const MR_Stack_Layout_Label	*call_label;
+	const MR_Stack_Layout_Vars	*input_args;
+	Word				*args;
+	int				arg_max;
+	int				arg_num;
+	Word				arg_value;
+	int				i;
+	bool				succeeded;
+
+	entry = this_label->MR_sll_entry;
+	call_label = entry->MR_sle_call_label;
+
+	if (call_label->MR_sll_var_count < 0) {
+		printf("Cannot perform retry because information about "
+			"the input arguments is not available.\n");
+		return FALSE;
+	}
+
+	input_args = &call_label->MR_sll_var_info;
+
+	/*
+	** With the Boehm collector, args need not be considered a root, 
+	** since its contents are just copies of values from elsewhere,
+	** With the native collector, it need not be considered a root
+	** because its lifetime spans only this function, in which
+	** no native garbage collection can be triggered.
+	*/
+
+	args = NULL;
+	arg_max = 0;
+
+	for (i = 0; i < call_label->MR_sll_var_count; i++) {
+		arg_value = MR_trace_find_input_arg(this_label, saved_regs,
+				input_args->MR_slvs_names[i], &succeeded);
+
+		if (! succeeded) {
+			printf("Cannot perform retry because the values of "
+				"some input arguments are missing.\n");
+			return FALSE;
+		}
+
+		arg_num = MR_get_register_number(
+			input_args->MR_slvs_pairs[i].MR_slv_locn);
+		if (arg_num > 0) {
+			MR_ensure_big_enough(arg_num, arg, Word,
+				MR_INIT_ARG_COUNT);
+			args[arg_num] = arg_value;
+		} else {
+			fatal_error("illegal location for input argument");
+		}
+	}
+
+	MR_trace_call_seqno = seqno - 1;
+	MR_trace_call_depth = depth - 1;
+
+	if (MR_DETISM_DET_STACK(entry->MR_sle_detism)) {
+		MR_Live_Lval	location;
+		Word		*this_frame;
+
+		/*
+		** We are at a final port, so both curfr and maxfr
+		** must already have been reset to their original values.
+		** We only need to set up the succip register for the "call",
+		** and then remove this frame from the det stack.
+		*/
+
+		location = entry->MR_sle_succip_locn;
+		if (MR_LIVE_LVAL_TYPE(location) != MR_LVAL_TYPE_STACKVAR) {
+			fatal_error("illegal location for stored succip");
+		}
+
+		this_frame = MR_saved_sp(saved_regs);
+		MR_saved_succip(saved_regs) = (Word *)
+				MR_based_stackvar(this_frame,
+				MR_LIVE_LVAL_NUMBER(location));
+		MR_saved_sp(saved_regs) -= entry->MR_sle_stack_slots;
+		MR_trace_event_number = MR_event_num_stackvar(this_frame);
+	} else {
+		Word	*this_frame;
+
+		/*
+		** We are at a final port, so sp must already have been reset
+		** to its original value. We only need to set up the succip
+		** and curfr registers for the "call", and remove this frame,
+		** and any other frames above it, from the nondet stack.
+		*/
+
+		this_frame = MR_saved_curfr(saved_regs);
+
+		MR_saved_succip(saved_regs) = MR_succip_slot(this_frame);
+		MR_saved_curfr(saved_regs) = MR_succfr_slot(this_frame);
+		MR_saved_maxfr(saved_regs) = MR_prevfr_slot(this_frame);
+		MR_trace_event_number = MR_event_num_framevar(this_frame);
+	}
+
+	for (i = 1; i < arg_max; i++) {
+		saved_reg(saved_regs, i) = args[i];
+	}
+
+	if (args != NULL) {
+		free(args);
+	}
+
+	*max_mr_num = max(*max_mr_num, arg_max);
+	*jumpaddr = entry->MR_sle_code_addr;
+
+	/*
+	** Overriding MR_trace_call_seqno etc is not enough, because
+	** we will restore the values of those variables later. We must
+	** also override the saved copies.
+	*/
+
+	event_details->MR_call_seqno = MR_trace_call_seqno;
+	event_details->MR_call_depth = MR_trace_call_depth;
+	event_details->MR_event_number = MR_trace_event_number;
+
+	return TRUE;
+}
+
+
+extern Word
+MR_trace_find_input_arg(const MR_Stack_Layout_Label *label, Word *saved_regs,
+	const char *name, bool *succeeded)
+{
+	const MR_Stack_Layout_Vars	*vars;
+	int				i;
+
+	vars = &label->MR_sll_var_info;
+	if (vars->MR_slvs_names == NULL) {
+		*succeeded = FALSE;
+		return 0;
+	}
+
+	for (i = 0; i < label->MR_sll_var_count; i++) {
+		if (streq(vars->MR_slvs_names[i], name)) {
+			return MR_lookup_live_lval_base(
+				vars->MR_slvs_pairs[i].MR_slv_locn, saved_regs,
+				MR_saved_sp(saved_regs),
+				MR_saved_curfr(saved_regs), succeeded);
+		}
+	}
+
+	*succeeded = FALSE;
+	return 0;
 }
Index: trace/mercury_trace.h
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace.h,v
retrieving revision 1.3
diff -u -r1.3 mercury_trace.h
--- mercury_trace.h	1998/12/14 16:05:19	1.3
+++ mercury_trace.h	1999/02/09 00:13:28
@@ -1,5 +1,5 @@
 /*
-** Copyright (C) 1997-1998 The University of Melbourne.
+** Copyright (C) 1997-1999 The University of Melbourne.
 ** This file may only be copied under the terms of the GNU Library General
 ** Public License - see the file COPYING.LIB in the Mercury distribution.
 */
@@ -20,6 +20,22 @@
 
 #ifndef MERCURY_TRACE_H
 #define MERCURY_TRACE_H
+
+typedef struct MR_Event_Details_Struct {
+	int			MR_call_seqno;
+	int			MR_call_depth;
+	int			MR_event_number;
+} MR_Event_Details;
+
+/* The initial size of arrays of argument values. */
+#define	MR_INIT_ARG_COUNT	20
+
+extern	bool	MR_trace_retry(const MR_Stack_Layout_Label *layout,
+			Word *saved_regs, MR_Event_Details *event_details,
+			int seqno, int depth, int *max_mr_num,
+			Code **jumpaddr);
+extern  Word	MR_trace_find_input_arg(const MR_Stack_Layout_Label *label, 
+			Word *saved_regs, const char *name, bool *succeeded);
 
 /*
 ** MR_trace_cmd says what mode the tracer is in, i.e. how events should be
Index: trace/mercury_trace_external.c
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_external.c,v
retrieving revision 1.5
diff -u -r1.5 mercury_trace_external.c
--- mercury_trace_external.c	1998/11/08 23:11:32	1.5
+++ mercury_trace_external.c	1999/02/09 00:13:29
@@ -1,5 +1,5 @@
 /*
-** Copyright (C) 1998 The University of Melbourne.
+** Copyright (C) 1998-1999 The University of Melbourne.
 ** This file may only be copied under the terms of the GNU Library General
 ** Public License - see the file COPYING.LIB in the Mercury distribution.
 */
@@ -55,8 +55,10 @@
 				 = 7, /* report data for 
 					 current_live_var_names query */
 	MR_REQUEST_CURRENT_NTH_VAR 
-				 = 8  /* report data for 
+				 = 8, /* report data for 
 					 current_nth_var query */
+	MR_REQUEST_RETRY	 = 9  /* restart the execution to the call 
+					 port of the current event	      */
 
 } MR_debugger_request_type;
 
@@ -190,8 +192,8 @@
 		unix_address.sun_family = AF_UNIX;
 		strcpy(unix_address.sun_path, unix_socket);
 		addr = (struct sockaddr *) &unix_address;
-		len = SUN_LEN(&unix_address);
-	} else {
+		len = sizeof(&unix_address);
+	}  else {
 		char hostname[255];
 		char port_string[255];
 		unsigned short port;
@@ -202,7 +204,8 @@
 		** It should be in the format "<hostname> <port>",
 		** where <hostname> is numeric (e.g. "123.456.78.90").
 		*/
-		if (sscanf(inet_socket, "%254s %254s", hostname, port_string)
+
+		if (sscanf(inet_socket, "%254s %254s", hostname, port_string) 
 			!= 2)
 		{
 			fatal_error("MERCURY_DEBUGGER_INET_SOCKET invalid");
@@ -321,16 +324,27 @@
 	*/
 }
 
-void
+Code *
 MR_trace_event_external(MR_Trace_Cmd_Info *cmd, 
 	const MR_Stack_Layout_Label *layout, Word *saved_regs,
-	MR_Trace_Port port, Unsigned seqno, Unsigned depth, const char *path)
+	MR_Trace_Port port, Unsigned seqno, Unsigned depth, const char *path, 
+	int *max_mr_num)
 {
-	static bool searching = FALSE;
-	static Word search_data;
-	Word debugger_request;
-	Integer debugger_request_type, live_var_number;
-	Word var_list, var_names_list, type_list, var;
+	static bool	searching = FALSE;
+	static Word	search_data;
+	Integer		debugger_request_type;
+	Integer		live_var_number;
+	Word		debugger_request;
+	Word		var_list;
+	Word		var_names_list;
+	Word		type_list;
+	Word		var;
+	Code		*jumpaddr= NULL;
+	MR_Event_Details	event_details;
+
+	event_details.MR_call_seqno = MR_trace_call_seqno;
+	event_details.MR_call_depth = MR_trace_call_depth;
+	event_details.MR_event_number = MR_trace_event_number;
 
 	if (searching) {
 		/* XXX should also pass registers here,
@@ -342,7 +356,7 @@
 			MR_send_message_to_socket("forward_move_match_found");
 			searching = FALSE;
 		} else {
-			return;
+			return jumpaddr;
 		}
 	}
 
@@ -362,7 +376,7 @@
 				}
 				search_data = debugger_request;
 			        searching = TRUE;
-				return;
+				return jumpaddr;
 
 			case MR_REQUEST_CURRENT_LIVE_VAR_NAMES:
 				if (MR_debug_socket) {
@@ -408,15 +422,46 @@
 							depth, path);
 				break;
 
+			case MR_REQUEST_RETRY:
+				if (MR_debug_socket) {
+					fprintf(stderr, "\nMercury runtime: "
+						"REQUEST_RETRY\n");
+				}
+				if (MR_trace_retry(layout, saved_regs, 
+					&event_details, seqno, depth, 
+					max_mr_num, &jumpaddr)) 
+
+				  {
+				    MR_send_message_to_socket("ok");
+				    cmd->MR_trace_cmd = MR_CMD_GOTO;
+				    cmd->MR_trace_stop_event = 
+					MR_trace_event_number + 1;
+				    return jumpaddr;
+				  }
+				else
+				  {
+				    MR_send_message_to_socket("retry_failed");
+				  }
+				break;
+
 			case MR_REQUEST_NO_TRACE:
 				cmd->MR_trace_cmd = MR_CMD_TO_END;
-				return;
+				return jumpaddr;
 
 			default:
 				fatal_error("unexpected request read from "
 					"debugger socket");
 		}
 	}
+
+	cmd->MR_trace_must_check = (! cmd->MR_trace_strict) ||
+			(cmd->MR_trace_print_level != MR_PRINT_LEVEL_NONE);
+
+	MR_trace_call_seqno = event_details.MR_call_seqno;
+	MR_trace_call_depth = event_details.MR_call_depth;
+	MR_trace_event_number = event_details.MR_event_number;
+
+	return jumpaddr;
 }
 
 
@@ -610,7 +655,7 @@
 		}
 
 		MR_TRACE_CALL_MERCURY(
-			type_info_string = MR_type_name(type_info);
+			type_info_string = ML_type_name(type_info);
 		);
 	        MR_TRACE_USE_HP(
 			type_list = list_cons(type_info_string, type_list);
Index: trace/mercury_trace_external.h
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_external.h,v
retrieving revision 1.2
diff -u -r1.2 mercury_trace_external.h
--- mercury_trace_external.h	1998/10/16 06:20:15	1.2
+++ mercury_trace_external.h	1999/02/09 00:13:29
@@ -1,5 +1,5 @@
 /*
-** Copyright (C) 1998 The University of Melbourne.
+** Copyright (C) 1998-1999 The University of Melbourne.
 ** This file may only be copied under the terms of the GNU Library General
 ** Public License - see the file COPYING.LIB in the Mercury distribution.
 */
@@ -11,10 +11,10 @@
 
 extern	void	MR_trace_init_external(void);
 extern	void	MR_trace_final_external(void);
-extern	void	MR_trace_event_external(MR_Trace_Cmd_Info *cmd,
+extern	Code   *MR_trace_event_external(MR_Trace_Cmd_Info *cmd,
 			const MR_Stack_Layout_Label *layout,
 			Word *saved_regs, MR_Trace_Port port, Unsigned seqno,
-			Unsigned depth, const char *path);
+			Unsigned depth, const char *path, int *max_mr_num);
 
 #endif	/* MR_USE_EXTERNAL_DEBUGGER */
 
Index: trace/mercury_trace_internal.c
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_internal.c,v
retrieving revision 1.23
diff -u -r1.23 mercury_trace_internal.c
--- mercury_trace_internal.c	1999/02/04 20:42:10	1.23
+++ mercury_trace_internal.c	1999/02/09 00:13:35
@@ -33,9 +33,6 @@
 /* The initial size of the spy points table. */
 #define	MR_INIT_SPY_POINTS	10
 
-/* The initial size of arrays of argument values. */
-#define	MR_INIT_ARG_COUNT	20
-
 /* The initial size of arrays of words. */
 #define	MR_INIT_WORD_COUNT	20
 
@@ -165,8 +162,6 @@
 static	bool	MR_trace_options_confirmed(bool *confirmed, char ***words,
 			int *word_count, const char *cat, const char *item);
 static	void	MR_trace_usage(const char *cat, const char *item);
-static	Word	MR_trace_find_input_arg(const MR_Stack_Layout_Label *label,
-			Word *saved_regs, const char *name, bool *succeeded);
 static	void	MR_trace_internal_add_spy_point(MR_Spy_When when,
 			MR_Spy_Action action,
 			const MR_Stack_Layout_Entry *entry,
@@ -1518,160 +1513,6 @@
 		item, item);
 }
 
-void
-MR_trace_retry(const MR_Stack_Layout_Label *this_label, Word *saved_regs,
-	MR_Event_Details *event_details, int seqno, int depth,
-	int *max_mr_num, Code **jumpaddr)
-{
-	const MR_Stack_Layout_Entry	*entry;
-	const MR_Stack_Layout_Label	*call_label;
-	const MR_Stack_Layout_Vars	*input_args;
-	Word				*args;
-	int				arg_max;
-	int				arg_num;
-	Word				arg_value;
-	int				i;
-	bool				succeeded;
-
-	entry = this_label->MR_sll_entry;
-	call_label = entry->MR_sle_call_label;
-
-	if (call_label->MR_sll_var_count < 0) {
-		fflush(MR_mdb_out);
-		fprintf(MR_mdb_err,
-			"Cannot perform retry, because information about "
-			"the input arguments is not available.\n");
-		return;
-	}
-
-	input_args = &call_label->MR_sll_var_info;
-
-	/*
-	** With the Boehm collector, args need not be considered a root, 
-	** since its contents are just copies of values from elsewhere,
-	** With the native collector, it need not be considered a root
-	** because its lifetime spans only this function, in which
-	** no native garbage collection can be triggered.
-	*/
-
-	args = NULL;
-	arg_max = 0;
-
-	for (i = 0; i < call_label->MR_sll_var_count; i++) {
-		arg_value = MR_trace_find_input_arg(this_label, saved_regs,
-				input_args->MR_slvs_names[i], &succeeded);
-
-		if (! succeeded) {
-			fflush(MR_mdb_out);
-			fprintf(MR_mdb_err,
-				"Cannot perform retry because the values of "
-				"some input arguments are missing.\n");
-			return;
-		}
-
-		arg_num = MR_get_register_number(
-			input_args->MR_slvs_pairs[i].MR_slv_locn);
-		if (arg_num > 0) {
-			MR_ensure_big_enough(arg_num, arg, Word,
-				MR_INIT_ARG_COUNT);
-			args[arg_num] = arg_value;
-		} else {
-			fatal_error("illegal location for input argument");
-		}
-	}
-
-	MR_trace_call_seqno = seqno - 1;
-	MR_trace_call_depth = depth - 1;
-
-	MR_trace_from_full = TRUE;
-
-	if (MR_DETISM_DET_STACK(entry->MR_sle_detism)) {
-		MR_Live_Lval	location;
-		Word		*this_frame;
-
-		/*
-		** We are at a final port, so both curfr and maxfr
-		** must already have been reset to their original values.
-		** We only need to set up the succip register for the "call",
-		** and then remove this frame from the det stack.
-		*/
-
-		location = entry->MR_sle_succip_locn;
-		if (MR_LIVE_LVAL_TYPE(location) != MR_LVAL_TYPE_STACKVAR) {
-			fatal_error("illegal location for stored succip");
-		}
-
-		this_frame = MR_saved_sp(saved_regs);
-		MR_saved_succip(saved_regs) = (Word *)
-				MR_based_stackvar(this_frame,
-				MR_LIVE_LVAL_NUMBER(location));
-		MR_saved_sp(saved_regs) -= entry->MR_sle_stack_slots;
-		MR_trace_event_number = MR_event_num_stackvar(this_frame);
-	} else {
-		Word	*this_frame;
-
-		/*
-		** We are at a final port, so sp must already have been reset
-		** to its original value. We only need to set up the succip
-		** and curfr registers for the "call", and remove this frame,
-		** and any other frames above it, from the nondet stack.
-		*/
-
-		this_frame = MR_saved_curfr(saved_regs);
-
-		MR_saved_succip(saved_regs) = MR_succip_slot(this_frame);
-		MR_saved_curfr(saved_regs) = MR_succfr_slot(this_frame);
-		MR_saved_maxfr(saved_regs) = MR_prevfr_slot(this_frame);
-		MR_trace_event_number = MR_event_num_framevar(this_frame);
-	}
-
-	for (i = 1; i < arg_max; i++) {
-		saved_reg(saved_regs, i) = args[i];
-	}
-
-	if (args != NULL) {
-		free(args);
-	}
-
-	*max_mr_num = max(*max_mr_num, arg_max);
-	*jumpaddr = entry->MR_sle_code_addr;
-
-	/*
-	** Overriding MR_trace_call_seqno etc is not enough, because
-	** we will restore the values of those variables later. We must
-	** also override the saved copies.
-	*/
-
-	event_details->MR_call_seqno = MR_trace_call_seqno;
-	event_details->MR_call_depth = MR_trace_call_depth;
-	event_details->MR_event_number = MR_trace_event_number;
-}
-
-static Word
-MR_trace_find_input_arg(const MR_Stack_Layout_Label *label, Word *saved_regs,
-	const char *name, bool *succeeded)
-{
-	const MR_Stack_Layout_Vars	*vars;
-	int				i;
-
-	vars = &label->MR_sll_var_info;
-	if (vars->MR_slvs_names == NULL) {
-		*succeeded = FALSE;
-		return 0;
-	}
-
-	for (i = 0; i < label->MR_sll_var_count; i++) {
-		if (streq(vars->MR_slvs_names[i], name)) {
-			return MR_lookup_live_lval_base(
-				vars->MR_slvs_pairs[i].MR_slv_locn, saved_regs,
-				MR_saved_sp(saved_regs),
-				MR_saved_curfr(saved_regs), succeeded);
-		}
-	}
-
-	*succeeded = FALSE;
-	return 0;
-}
 
 static void
 MR_trace_internal_add_spy_point(MR_Spy_When when, MR_Spy_Action action,
Index: trace/mercury_trace_internal.h
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_internal.h,v
retrieving revision 1.4
diff -u -r1.4 mercury_trace_internal.h
--- mercury_trace_internal.h	1999/01/11 03:52:33	1.4
+++ mercury_trace_internal.h	1999/02/09 00:13:35
@@ -10,12 +10,6 @@
 #include "mercury_types.h"
 #include "mercury_trace.h"
 
-typedef struct MR_Event_Details_Struct {
-	int			MR_call_seqno;
-	int			MR_call_depth;
-	int			MR_event_number;
-} MR_Event_Details;
-
 #ifdef  MR_USE_DECLARATIVE_DEBUGGER
 
 /*
@@ -48,10 +42,6 @@
 			int seqno, int depth,
 			const char *path, int *max_mr_num);
 
-extern	void	MR_trace_retry(const MR_Stack_Layout_Label *layout,
-			Word *saved_regs, MR_Event_Details *event_details,
-			int seqno, int depth, int *max_mr_num,
-			Code **jumpaddr);
 
 extern	Code	*MR_trace_event_internal_report(MR_Trace_Cmd_Info *cmd,
 			const MR_Stack_Layout_Label *layout, Word *saved_regs,
Index: browser/debugger_interface.m
===================================================================
RCS file: /home/mercury1/repository/mercury/browser/debugger_interface.m,v
retrieving revision 1.4
diff -u -r1.4 debugger_interface.m
--- debugger_interface.m	1998/12/14 16:05:02	1.4
+++ debugger_interface.m	1999/02/09 00:13:36
@@ -1,6 +1,5 @@
-
 %-----------------------------------------------------------------------------%
-% Copyright (C) 1998 The University of Melbourne.
+% Copyright (C) 1998-1999 The University of Melbourne.
 % This file may only be copied under the terms of the GNU Library General
 % Public License - see the file COPYING.LIB in the Mercury distribution.
 %-----------------------------------------------------------------------------%
@@ -18,7 +17,10 @@
 :- interface. 
 
 % This module exports the following C functions:
-%	ML_DI_output_current
+% 	ML_DI_output_current_slots
+% 	ML_DI_output_current_vars
+% 	ML_DI_output_current_nth_var
+% 	ML_DI_output_current_live_var_names
 %	ML_DI_found_match
 %	ML_DI_read_request_from_socket
 % These are used by runtime/mercury_trace_external.c.
@@ -109,13 +111,16 @@
 		% A 'current_nth_var' request instructs the debuggee to 
 		% retrieve the specified live variable.
 	;	current_nth_var(int)
-	;	abort_prog
 			% just abort the program
-	;	no_trace
+	;	abort_prog
 			% stop tracing, and run the program to completion
-	;	error(string)
+	;	no_trace
+			% restarts execution at the call port of the call 
+			% corresponding to the current event
+	;	retry
 			% something went wrong when trying to get the
 			% next request
+	;	error(string)
 	.
 
 :- type event_number == int.
@@ -206,7 +211,8 @@
 % output_current_vars "ML_DI_output_current_vars":
 %	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").
+:- pragma export(output_current_vars(in, in, in, di, uo), 
+	"ML_DI_output_current_vars").
 			
 :- pred output_current_vars(list(univ), list(string), 
 	io__output_stream, io__state, io__state).
@@ -223,7 +229,8 @@
 % output_current_nth_var "ML_DI_output_current_nth_var":
 %	send to the debugger the requested live variable of the current event.
 
-:- pragma export(output_current_nth_var(in, in, di, uo), "ML_DI_output_current_nth_var").
+:- pragma export(output_current_nth_var(in, in, di, uo), 
+	"ML_DI_output_current_nth_var").
 			
 :- pred output_current_nth_var(univ, io__output_stream, io__state, io__state).
 :- mode output_current_nth_var(in, in, di, uo) is det.
@@ -375,6 +382,7 @@
 classify_request(error(_), 6).
 classify_request(current_live_var_names, 7).
 classify_request(current_nth_var(_), 8).
+classify_request(retry, 9).
 
 
 %-----------------------------------------------------------------------------%

Index: browser/debugger_interface.m
===================================================================
RCS file: /home/mercury1/repository/mercury/browser/debugger_interface.m,v
retrieving revision 1.4
diff -u -r1.4 debugger_interface.m
--- debugger_interface.m	1998/12/14 16:05:02	1.4
+++ debugger_interface.m	1999/02/10 20:53:38
@@ -1,6 +1,5 @@
-
 %-----------------------------------------------------------------------------%
-% Copyright (C) 1998 The University of Melbourne.
+% Copyright (C) 1998-1999 The University of Melbourne.
 % This file may only be copied under the terms of the GNU Library General
 % Public License - see the file COPYING.LIB in the Mercury distribution.
 %-----------------------------------------------------------------------------%
@@ -18,7 +17,10 @@
 :- interface. 
 
 % This module exports the following C functions:
-%	ML_DI_output_current
+% 	ML_DI_output_current_slots
+% 	ML_DI_output_current_vars
+% 	ML_DI_output_current_nth_var
+% 	ML_DI_output_current_live_var_names
 %	ML_DI_found_match
 %	ML_DI_read_request_from_socket
 % These are used by runtime/mercury_trace_external.c.
@@ -109,13 +111,16 @@
 		% A 'current_nth_var' request instructs the debuggee to 
 		% retrieve the specified live variable.
 	;	current_nth_var(int)
-	;	abort_prog
 			% just abort the program
-	;	no_trace
+	;	abort_prog
 			% stop tracing, and run the program to completion
-	;	error(string)
+	;	no_trace
+			% restarts execution at the call port of the call 
+			% corresponding to the current event
+	;	retry
 			% something went wrong when trying to get the
 			% next request
+	;	error(string)
 	.
 
 :- type event_number == int.
@@ -206,7 +211,8 @@
 % output_current_vars "ML_DI_output_current_vars":
 %	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").
+:- pragma export(output_current_vars(in, in, in, di, uo), 
+	"ML_DI_output_current_vars").
 			
 :- pred output_current_vars(list(univ), list(string), 
 	io__output_stream, io__state, io__state).
@@ -223,7 +229,8 @@
 % output_current_nth_var "ML_DI_output_current_nth_var":
 %	send to the debugger the requested live variable of the current event.
 
-:- pragma export(output_current_nth_var(in, in, di, uo), "ML_DI_output_current_nth_var").
+:- pragma export(output_current_nth_var(in, in, di, uo), 
+	"ML_DI_output_current_nth_var").
 			
 :- pred output_current_nth_var(univ, io__output_stream, io__state, io__state).
 :- mode output_current_nth_var(in, in, di, uo) is det.
@@ -375,6 +382,7 @@
 classify_request(error(_), 6).
 classify_request(current_live_var_names, 7).
 classify_request(current_nth_var(_), 8).
+classify_request(retry, 9).
 
 
 %-----------------------------------------------------------------------------%
Index: trace/mercury_trace.c
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace.c,v
retrieving revision 1.3
diff -u -r1.3 mercury_trace.c
--- mercury_trace.c	1998/12/14 16:05:17	1.3
+++ mercury_trace.c	1999/02/10 20:53:50
@@ -1,5 +1,5 @@
 /*
-** Copyright (C) 1997-1998 The University of Melbourne.
+** Copyright (C) 1997-1999 The University of Melbourne.
 ** This file may only be copied under the terms of the GNU Library General
 ** Public License - see the file COPYING.LIB in the Mercury distribution.
 */
@@ -246,9 +246,8 @@
 			fatal_error("reporting event for external debugger");
 		}
 
-		MR_trace_event_external(cmd, layout, saved_regs,
-			port, seqno, depth, path);
-		jumpaddr = NULL;
+		jumpaddr = MR_trace_event_external(cmd, layout, saved_regs,
+				port, seqno, depth, path, &max_mr_num);
 	} else {
 		jumpaddr = MR_trace_event_internal(cmd, interactive,
 				layout, saved_regs, port, seqno,
@@ -280,4 +279,157 @@
 	MR_saved_global_hp(saved_regs) = MR_global_hp;
 	MR_copy_saved_regs_to_regs(max_mr_num, saved_regs);
 	return jumpaddr;
+}
+
+char *
+MR_trace_retry(const MR_Stack_Layout_Label *this_label, Word *saved_regs,
+	MR_Event_Details *event_details, int seqno, int depth,
+	int *max_mr_num, Code **jumpaddr)
+{
+	const MR_Stack_Layout_Entry	*entry;
+	const MR_Stack_Layout_Label	*call_label;
+	const MR_Stack_Layout_Vars	*input_args;
+	Word				*args;
+	int				arg_max;
+	int				arg_num;
+	Word				arg_value;
+	int				i;
+	bool				succeeded;
+	char			        *message;
+
+	entry = this_label->MR_sll_entry;
+	call_label = entry->MR_sle_call_label;
+
+	if (call_label->MR_sll_var_count < 0) {
+		message = "Cannot perform retry because information about "
+		          "the input arguments is not available.";
+		return message;
+	}
+
+	input_args = &call_label->MR_sll_var_info;
+
+	/*
+	** With the Boehm collector, args need not be considered a root, 
+	** since its contents are just copies of values from elsewhere,
+	** With the native collector, it need not be considered a root
+	** because its lifetime spans only this function, in which
+	** no native garbage collection can be triggered.
+	*/
+
+	args = NULL;
+	arg_max = 0;
+
+	for (i = 0; i < call_label->MR_sll_var_count; i++) {
+		arg_value = MR_trace_find_input_arg(this_label, saved_regs,
+				input_args->MR_slvs_names[i], &succeeded);
+
+		if (! succeeded) {
+			message = "Cannot perform retry because the values of "
+				  "some input arguments are missing.";
+			return message;
+		}
+
+		arg_num = MR_get_register_number(
+			input_args->MR_slvs_pairs[i].MR_slv_locn);
+		if (arg_num > 0) {
+			MR_ensure_big_enough(arg_num, arg, Word,
+				MR_INIT_ARG_COUNT);
+			args[arg_num] = arg_value;
+		} else {
+			fatal_error("illegal location for input argument");
+		}
+	}
+
+	MR_trace_call_seqno = seqno - 1;
+	MR_trace_call_depth = depth - 1;
+
+	if (MR_DETISM_DET_STACK(entry->MR_sle_detism)) {
+		MR_Live_Lval	location;
+		Word		*this_frame;
+
+		/*
+		** We are at a final port, so both curfr and maxfr
+		** must already have been reset to their original values.
+		** We only need to set up the succip register for the "call",
+		** and then remove this frame from the det stack.
+		*/
+
+		location = entry->MR_sle_succip_locn;
+		if (MR_LIVE_LVAL_TYPE(location) != MR_LVAL_TYPE_STACKVAR) {
+			fatal_error("illegal location for stored succip");
+		}
+
+		this_frame = MR_saved_sp(saved_regs);
+		MR_saved_succip(saved_regs) = (Word *)
+				MR_based_stackvar(this_frame,
+				MR_LIVE_LVAL_NUMBER(location));
+		MR_saved_sp(saved_regs) -= entry->MR_sle_stack_slots;
+		MR_trace_event_number = MR_event_num_stackvar(this_frame);
+	} else {
+		Word	*this_frame;
+
+		/*
+		** We are at a final port, so sp must already have been reset
+		** to its original value. We only need to set up the succip
+		** and curfr registers for the "call", and remove this frame,
+		** and any other frames above it, from the nondet stack.
+		*/
+
+		this_frame = MR_saved_curfr(saved_regs);
+
+		MR_saved_succip(saved_regs) = MR_succip_slot(this_frame);
+		MR_saved_curfr(saved_regs) = MR_succfr_slot(this_frame);
+		MR_saved_maxfr(saved_regs) = MR_prevfr_slot(this_frame);
+		MR_trace_event_number = MR_event_num_framevar(this_frame);
+	}
+
+	for (i = 1; i < arg_max; i++) {
+		saved_reg(saved_regs, i) = args[i];
+	}
+
+	if (args != NULL) {
+		free(args);
+	}
+
+	*max_mr_num = max(*max_mr_num, arg_max);
+	*jumpaddr = entry->MR_sle_code_addr;
+
+	/*
+	** Overriding MR_trace_call_seqno etc is not enough, because
+	** we will restore the values of those variables later. We must
+	** also override the saved copies.
+	*/
+
+	event_details->MR_call_seqno = MR_trace_call_seqno;
+	event_details->MR_call_depth = MR_trace_call_depth;
+	event_details->MR_event_number = MR_trace_event_number;
+
+	return NULL;
+}
+
+
+extern Word
+MR_trace_find_input_arg(const MR_Stack_Layout_Label *label, Word *saved_regs,
+	const char *name, bool *succeeded)
+{
+	const MR_Stack_Layout_Vars	*vars;
+	int				i;
+
+	vars = &label->MR_sll_var_info;
+	if (vars->MR_slvs_names == NULL) {
+		*succeeded = FALSE;
+		return 0;
+	}
+
+	for (i = 0; i < label->MR_sll_var_count; i++) {
+		if (streq(vars->MR_slvs_names[i], name)) {
+			return MR_lookup_live_lval_base(
+				vars->MR_slvs_pairs[i].MR_slv_locn, saved_regs,
+				MR_saved_sp(saved_regs),
+				MR_saved_curfr(saved_regs), succeeded);
+		}
+	}
+
+	*succeeded = FALSE;
+	return 0;
 }
Index: trace/mercury_trace.h
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace.h,v
retrieving revision 1.3
diff -u -r1.3 mercury_trace.h
--- mercury_trace.h	1998/12/14 16:05:19	1.3
+++ mercury_trace.h	1999/02/10 20:53:50
@@ -1,5 +1,5 @@
 /*
-** Copyright (C) 1997-1998 The University of Melbourne.
+** Copyright (C) 1997-1999 The University of Melbourne.
 ** This file may only be copied under the terms of the GNU Library General
 ** Public License - see the file COPYING.LIB in the Mercury distribution.
 */
@@ -20,6 +20,22 @@
 
 #ifndef MERCURY_TRACE_H
 #define MERCURY_TRACE_H
+
+typedef struct MR_Event_Details_Struct {
+	int			MR_call_seqno;
+	int			MR_call_depth;
+	int			MR_event_number;
+} MR_Event_Details;
+
+/* The initial size of arrays of argument values. */
+#define	MR_INIT_ARG_COUNT	20
+
+char *	MR_trace_retry(const MR_Stack_Layout_Label *layout,
+			Word *saved_regs, MR_Event_Details *event_details,
+			int seqno, int depth, int *max_mr_num,
+			Code **jumpaddr);
+Word	MR_trace_find_input_arg(const MR_Stack_Layout_Label *label, 
+			Word *saved_regs, const char *name, bool *succeeded);
 
 /*
 ** MR_trace_cmd says what mode the tracer is in, i.e. how events should be
Index: trace/mercury_trace_external.c
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_external.c,v
retrieving revision 1.5
diff -u -r1.5 mercury_trace_external.c
--- mercury_trace_external.c	1998/11/08 23:11:32	1.5
+++ mercury_trace_external.c	1999/02/10 20:53:52
@@ -1,5 +1,5 @@
 /*
-** Copyright (C) 1998 The University of Melbourne.
+** Copyright (C) 1998-1999 The University of Melbourne.
 ** This file may only be copied under the terms of the GNU Library General
 ** Public License - see the file COPYING.LIB in the Mercury distribution.
 */
@@ -55,8 +55,10 @@
 				 = 7, /* report data for 
 					 current_live_var_names query */
 	MR_REQUEST_CURRENT_NTH_VAR 
-				 = 8  /* report data for 
+				 = 8, /* report data for 
 					 current_nth_var query */
+	MR_REQUEST_RETRY	 = 9  /* restart the execution to the call 
+					 port of the current event	      */
 
 } MR_debugger_request_type;
 
@@ -64,6 +66,8 @@
 static MercuryFile MR_debugger_socket_out;
 
 static void	MR_send_message_to_socket(const char *message);
+static void	MR_send_message_to_socket_format(const char *format, 
+			const char *message);
 static void	MR_read_request_from_socket(
 			Word *debugger_request_ptr, 
 			Integer *debugger_request_type_ptr);
@@ -202,7 +206,8 @@
 		** It should be in the format "<hostname> <port>",
 		** where <hostname> is numeric (e.g. "123.456.78.90").
 		*/
-		if (sscanf(inet_socket, "%254s %254s", hostname, port_string)
+
+		if (sscanf(inet_socket, "%254s %254s", hostname, port_string) 
 			!= 2)
 		{
 			fatal_error("MERCURY_DEBUGGER_INET_SOCKET invalid");
@@ -321,16 +326,28 @@
 	*/
 }
 
-void
+Code *
 MR_trace_event_external(MR_Trace_Cmd_Info *cmd, 
 	const MR_Stack_Layout_Label *layout, Word *saved_regs,
-	MR_Trace_Port port, Unsigned seqno, Unsigned depth, const char *path)
+	MR_Trace_Port port, Unsigned seqno, Unsigned depth, const char *path, 
+	int *max_mr_num)
 {
-	static bool searching = FALSE;
-	static Word search_data;
-	Word debugger_request;
-	Integer debugger_request_type, live_var_number;
-	Word var_list, var_names_list, type_list, var;
+	static bool	searching = FALSE;
+	static Word	search_data;
+	Integer		debugger_request_type;
+	Integer		live_var_number;
+	Word		debugger_request;
+	Word		var_list;
+	Word		var_names_list;
+	Word		type_list;
+	Word		var;
+	Code		*jumpaddr = NULL;
+	MR_Event_Details	event_details;
+	char		*message;
+
+	event_details.MR_call_seqno = MR_trace_call_seqno;
+	event_details.MR_call_depth = MR_trace_call_depth;
+	event_details.MR_event_number = MR_trace_event_number;
 
 	if (searching) {
 		/* XXX should also pass registers here,
@@ -342,7 +359,7 @@
 			MR_send_message_to_socket("forward_move_match_found");
 			searching = FALSE;
 		} else {
-			return;
+			return jumpaddr;
 		}
 	}
 
@@ -362,7 +379,7 @@
 				}
 				search_data = debugger_request;
 			        searching = TRUE;
-				return;
+				return jumpaddr;
 
 			case MR_REQUEST_CURRENT_LIVE_VAR_NAMES:
 				if (MR_debug_socket) {
@@ -408,15 +425,45 @@
 							depth, path);
 				break;
 
+			case MR_REQUEST_RETRY:
+				if (MR_debug_socket) {
+					fprintf(stderr, "\nMercury runtime: "
+						"REQUEST_RETRY\n");
+				}
+				message = MR_trace_retry(layout, saved_regs, 
+					&event_details, seqno, depth, 
+					max_mr_num, &jumpaddr);
+				if (message == NULL)
+				{
+					MR_send_message_to_socket("ok");
+					cmd->MR_trace_cmd = MR_CMD_GOTO;
+					cmd->MR_trace_stop_event = 
+						MR_trace_event_number + 1;
+					return jumpaddr;
+				} else {
+					MR_send_message_to_socket_format(
+						"\"error(%s)\".\n", message);
+				}
+				break;
+
 			case MR_REQUEST_NO_TRACE:
 				cmd->MR_trace_cmd = MR_CMD_TO_END;
-				return;
+				return jumpaddr;
 
 			default:
 				fatal_error("unexpected request read from "
 					"debugger socket");
 		}
 	}
+
+	cmd->MR_trace_must_check = (! cmd->MR_trace_strict) ||
+			(cmd->MR_trace_print_level != MR_PRINT_LEVEL_NONE);
+
+	MR_trace_call_seqno = event_details.MR_call_seqno;
+	MR_trace_call_depth = event_details.MR_call_depth;
+	MR_trace_event_number = event_details.MR_event_number;
+
+	return jumpaddr;
 }
 
 
@@ -536,6 +583,15 @@
 }
 
 static void
+MR_send_message_to_socket_format(const char *format, const char *message)
+{
+	fprintf(MR_debugger_socket_out.file, format, message);
+	fflush(MR_debugger_socket_out.file);
+	MR_debugger_socket_out.line_number++;
+}
+
+
+static void
 MR_send_message_to_socket(const char *message)
 {
 	fprintf(MR_debugger_socket_out.file, "%s.\n", message);
@@ -610,7 +666,7 @@
 		}
 
 		MR_TRACE_CALL_MERCURY(
-			type_info_string = MR_type_name(type_info);
+			type_info_string = ML_type_name(type_info);
 		);
 	        MR_TRACE_USE_HP(
 			type_list = list_cons(type_info_string, type_list);
Index: trace/mercury_trace_external.h
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_external.h,v
retrieving revision 1.2
diff -u -r1.2 mercury_trace_external.h
--- mercury_trace_external.h	1998/10/16 06:20:15	1.2
+++ mercury_trace_external.h	1999/02/10 20:53:52
@@ -1,5 +1,5 @@
 /*
-** Copyright (C) 1998 The University of Melbourne.
+** Copyright (C) 1998-1999 The University of Melbourne.
 ** This file may only be copied under the terms of the GNU Library General
 ** Public License - see the file COPYING.LIB in the Mercury distribution.
 */
@@ -11,10 +11,10 @@
 
 extern	void	MR_trace_init_external(void);
 extern	void	MR_trace_final_external(void);
-extern	void	MR_trace_event_external(MR_Trace_Cmd_Info *cmd,
+extern	Code   *MR_trace_event_external(MR_Trace_Cmd_Info *cmd,
 			const MR_Stack_Layout_Label *layout,
 			Word *saved_regs, MR_Trace_Port port, Unsigned seqno,
-			Unsigned depth, const char *path);
+			Unsigned depth, const char *path, int *max_mr_num);
 
 #endif	/* MR_USE_EXTERNAL_DEBUGGER */
 
Index: trace/mercury_trace_internal.c
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_internal.c,v
retrieving revision 1.23
diff -u -r1.23 mercury_trace_internal.c
--- mercury_trace_internal.c	1999/02/04 20:42:10	1.23
+++ mercury_trace_internal.c	1999/02/10 20:53:56
@@ -33,9 +33,6 @@
 /* The initial size of the spy points table. */
 #define	MR_INIT_SPY_POINTS	10
 
-/* The initial size of arrays of argument values. */
-#define	MR_INIT_ARG_COUNT	20
-
 /* The initial size of arrays of words. */
 #define	MR_INIT_WORD_COUNT	20
 
@@ -165,8 +162,6 @@
 static	bool	MR_trace_options_confirmed(bool *confirmed, char ***words,
 			int *word_count, const char *cat, const char *item);
 static	void	MR_trace_usage(const char *cat, const char *item);
-static	Word	MR_trace_find_input_arg(const MR_Stack_Layout_Label *label,
-			Word *saved_regs, const char *name, bool *succeeded);
 static	void	MR_trace_internal_add_spy_point(MR_Spy_When when,
 			MR_Spy_Action action,
 			const MR_Stack_Layout_Entry *entry,
@@ -666,6 +661,7 @@
 		}
 	} else if (streq(words[0], "retry")) {
 		int	stop_depth;
+		char   *message;
 
 		if (word_count == 2 && MR_trace_is_number(words[1], &n)) {
 			stop_depth = depth - n;
@@ -677,8 +673,11 @@
 		}
 
 		if (stop_depth == depth && MR_port_is_final(port)) {
-			MR_trace_retry(layout, saved_regs, event_details,
+			message = MR_trace_retry(layout, saved_regs, event_details,
 				seqno, depth, max_mr_num, jumpaddr);
+			fflush(MR_mdb_out);
+			fprintf(MR_mdb_err, message);
+			fprintf(MR_mdb_err, "\n");
 
 			cmd->MR_trace_cmd = MR_CMD_GOTO;
 			cmd->MR_trace_stop_event = MR_trace_event_number + 1;
@@ -1518,160 +1517,6 @@
 		item, item);
 }
 
-void
-MR_trace_retry(const MR_Stack_Layout_Label *this_label, Word *saved_regs,
-	MR_Event_Details *event_details, int seqno, int depth,
-	int *max_mr_num, Code **jumpaddr)
-{
-	const MR_Stack_Layout_Entry	*entry;
-	const MR_Stack_Layout_Label	*call_label;
-	const MR_Stack_Layout_Vars	*input_args;
-	Word				*args;
-	int				arg_max;
-	int				arg_num;
-	Word				arg_value;
-	int				i;
-	bool				succeeded;
-
-	entry = this_label->MR_sll_entry;
-	call_label = entry->MR_sle_call_label;
-
-	if (call_label->MR_sll_var_count < 0) {
-		fflush(MR_mdb_out);
-		fprintf(MR_mdb_err,
-			"Cannot perform retry, because information about "
-			"the input arguments is not available.\n");
-		return;
-	}
-
-	input_args = &call_label->MR_sll_var_info;
-
-	/*
-	** With the Boehm collector, args need not be considered a root, 
-	** since its contents are just copies of values from elsewhere,
-	** With the native collector, it need not be considered a root
-	** because its lifetime spans only this function, in which
-	** no native garbage collection can be triggered.
-	*/
-
-	args = NULL;
-	arg_max = 0;
-
-	for (i = 0; i < call_label->MR_sll_var_count; i++) {
-		arg_value = MR_trace_find_input_arg(this_label, saved_regs,
-				input_args->MR_slvs_names[i], &succeeded);
-
-		if (! succeeded) {
-			fflush(MR_mdb_out);
-			fprintf(MR_mdb_err,
-				"Cannot perform retry because the values of "
-				"some input arguments are missing.\n");
-			return;
-		}
-
-		arg_num = MR_get_register_number(
-			input_args->MR_slvs_pairs[i].MR_slv_locn);
-		if (arg_num > 0) {
-			MR_ensure_big_enough(arg_num, arg, Word,
-				MR_INIT_ARG_COUNT);
-			args[arg_num] = arg_value;
-		} else {
-			fatal_error("illegal location for input argument");
-		}
-	}
-
-	MR_trace_call_seqno = seqno - 1;
-	MR_trace_call_depth = depth - 1;
-
-	MR_trace_from_full = TRUE;
-
-	if (MR_DETISM_DET_STACK(entry->MR_sle_detism)) {
-		MR_Live_Lval	location;
-		Word		*this_frame;
-
-		/*
-		** We are at a final port, so both curfr and maxfr
-		** must already have been reset to their original values.
-		** We only need to set up the succip register for the "call",
-		** and then remove this frame from the det stack.
-		*/
-
-		location = entry->MR_sle_succip_locn;
-		if (MR_LIVE_LVAL_TYPE(location) != MR_LVAL_TYPE_STACKVAR) {
-			fatal_error("illegal location for stored succip");
-		}
-
-		this_frame = MR_saved_sp(saved_regs);
-		MR_saved_succip(saved_regs) = (Word *)
-				MR_based_stackvar(this_frame,
-				MR_LIVE_LVAL_NUMBER(location));
-		MR_saved_sp(saved_regs) -= entry->MR_sle_stack_slots;
-		MR_trace_event_number = MR_event_num_stackvar(this_frame);
-	} else {
-		Word	*this_frame;
-
-		/*
-		** We are at a final port, so sp must already have been reset
-		** to its original value. We only need to set up the succip
-		** and curfr registers for the "call", and remove this frame,
-		** and any other frames above it, from the nondet stack.
-		*/
-
-		this_frame = MR_saved_curfr(saved_regs);
-
-		MR_saved_succip(saved_regs) = MR_succip_slot(this_frame);
-		MR_saved_curfr(saved_regs) = MR_succfr_slot(this_frame);
-		MR_saved_maxfr(saved_regs) = MR_prevfr_slot(this_frame);
-		MR_trace_event_number = MR_event_num_framevar(this_frame);
-	}
-
-	for (i = 1; i < arg_max; i++) {
-		saved_reg(saved_regs, i) = args[i];
-	}
-
-	if (args != NULL) {
-		free(args);
-	}
-
-	*max_mr_num = max(*max_mr_num, arg_max);
-	*jumpaddr = entry->MR_sle_code_addr;
-
-	/*
-	** Overriding MR_trace_call_seqno etc is not enough, because
-	** we will restore the values of those variables later. We must
-	** also override the saved copies.
-	*/
-
-	event_details->MR_call_seqno = MR_trace_call_seqno;
-	event_details->MR_call_depth = MR_trace_call_depth;
-	event_details->MR_event_number = MR_trace_event_number;
-}
-
-static Word
-MR_trace_find_input_arg(const MR_Stack_Layout_Label *label, Word *saved_regs,
-	const char *name, bool *succeeded)
-{
-	const MR_Stack_Layout_Vars	*vars;
-	int				i;
-
-	vars = &label->MR_sll_var_info;
-	if (vars->MR_slvs_names == NULL) {
-		*succeeded = FALSE;
-		return 0;
-	}
-
-	for (i = 0; i < label->MR_sll_var_count; i++) {
-		if (streq(vars->MR_slvs_names[i], name)) {
-			return MR_lookup_live_lval_base(
-				vars->MR_slvs_pairs[i].MR_slv_locn, saved_regs,
-				MR_saved_sp(saved_regs),
-				MR_saved_curfr(saved_regs), succeeded);
-		}
-	}
-
-	*succeeded = FALSE;
-	return 0;
-}
 
 static void
 MR_trace_internal_add_spy_point(MR_Spy_When when, MR_Spy_Action action,
Index: trace/mercury_trace_internal.h
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_internal.h,v
retrieving revision 1.4
diff -u -r1.4 mercury_trace_internal.h
--- mercury_trace_internal.h	1999/01/11 03:52:33	1.4
+++ mercury_trace_internal.h	1999/02/10 20:53:56
@@ -10,12 +10,6 @@
 #include "mercury_types.h"
 #include "mercury_trace.h"
 
-typedef struct MR_Event_Details_Struct {
-	int			MR_call_seqno;
-	int			MR_call_depth;
-	int			MR_event_number;
-} MR_Event_Details;
-
 #ifdef  MR_USE_DECLARATIVE_DEBUGGER
 
 /*
@@ -48,10 +42,6 @@
 			int seqno, int depth,
 			const char *path, int *max_mr_num);
 
-extern	void	MR_trace_retry(const MR_Stack_Layout_Label *layout,
-			Word *saved_regs, MR_Event_Details *event_details,
-			int seqno, int depth, int *max_mr_num,
-			Code **jumpaddr);
 
 extern	Code	*MR_trace_event_internal_report(MR_Trace_Cmd_Info *cmd,
 			const MR_Stack_Layout_Label *layout, Word *saved_regs,


 

-- 
R1.





More information about the developers mailing list