[m-dev.] For review: Incorporate the term brower stuff in the external debugger. [part 2/2]

Erwan Jahier Erwan.Jahier at irisa.fr
Fri May 21 00:09:05 AEST 1999


Index: browser/debugger_interface.m
===================================================================
RCS file: /home/mercury1/repository/mercury/browser/debugger_interface.m,v
retrieving revision 1.9
diff -u -r1.9 debugger_interface.m
--- debugger_interface.m	1999/04/22 06:58:47	1.9
+++ debugger_interface.m	1999/05/20 12:03:15
@@ -169,6 +169,8 @@
 	;	io_query(imports)
 			% options to compile queries with
 	;	mmc_options(options)
+			% to call the term browser
+	;	browse(string)
 	.
 
 %-----------------------------------------------------------------------------%
@@ -573,6 +575,23 @@
 
 init_mercury_string("").
 
+%-----------------------------------------------------------------------------%
+
+:- pred get_variable_name(debugger_request, string).
+:- mode get_variable_name(in, out) is det.
+
+:- pragma export(get_variable_name(in, out), "ML_DI_get_variable_name").
+	% Predicate that allows to retrieve the name of the variable to browse
+	% from a `browse(var_name)' request in mercury_trace_external.c.
+get_variable_name(DebuggerRequest, Options) :-
+	(
+		DebuggerRequest = browse(Options1)
+	->
+		Options = Options1
+	;
+		error("get_variable_name: not a browse request")
+	).
+
 %------------------------------------------------------------------------------%
 
 :- pred classify_request(debugger_request, int).
@@ -598,6 +617,7 @@
 classify_request(cc_query(_),14).
 classify_request(io_query(_),15).
 classify_request(mmc_options(_),16).
+classify_request(browse(_),17).
 
 
 %-----------------------------------------------------------------------------%
Index: browser/parse.m
===================================================================
RCS file: /home/mercury1/repository/mercury/browser/parse.m,v
retrieving revision 1.3
diff -u -r1.3 parse.m
--- parse.m	1999/05/14 02:24:37	1.3
+++ parse.m	1999/05/20 12:03:16
@@ -7,9 +7,12 @@
 % file: parse.m:
 % author: aet
 
-% This file contains the parser for the mdb browser command language.
-% This parses the stuff you type at the "browser> " prompt after
-% typing "browse" from the mdb prompt.
+% This file contains the parser for the term browser command language.
+% If the term browser is called from mdb, it parses the stuff you type 
+% at the "browser> " prompt after typing "browse" from the mdb prompt.
+% If it is called from the external debugger, then it parses the stuff
+% contained in a term `external_request(<string to parse>)' send by the
+% external debugger.
 
 %---------------------------------------------------------------------------%
 
@@ -99,9 +102,17 @@
 	;	pretty
 	;	verbose.
 
+% If the term browser is called from the external debugger, the term browser
+% commands are send through the socket via terms of type external_request.
+:- type external_request 
+	---> external_request(string).
+
 :- pred parse__read_command(string, command, io__state, io__state).
 :- mode parse__read_command(in, out, di, uo) is det.
 
+:- pred parse__read_command_external(command, io__state, io__state).
+:- mode parse__read_command_external(out, di, uo) is det.
+
 :- pred default_depth(int).
 :- mode default_depth(out) is det.
 
@@ -127,6 +138,24 @@
 parse__read_command(Prompt, Comm) -->
 	util__trace_getline(Prompt, Result),
 	( { Result = ok(Cs) } ->
+		{ lexer(Cs, Tokens) },
+		( { parse(Tokens, Comm2) } ->
+			{ Comm = Comm2 }
+		;
+			{ Comm = unknown }
+		)
+	; { Result = eof } ->
+		{ Comm = quit }
+	;
+		{ Comm = unknown }
+	).
+
+parse__read_command_external(Comm) -->
+	io__read(Result),
+	( 
+		{ Result = ok(external_request(StringToParse)) }
+	->
+		{ string__to_char_list(StringToParse, Cs) },
 		{ lexer(Cs, Tokens) },
 		( { parse(Tokens, Comm2) } ->
 			{ Comm = Comm2 }
Index: runtime/mercury_layout_util.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_layout_util.c,v
retrieving revision 1.8
diff -u -r1.8 mercury_layout_util.c
--- mercury_layout_util.c	1999/05/07 08:09:04	1.8
+++ mercury_layout_util.c	1999/05/20 12:03:25
@@ -517,3 +517,75 @@
 	(*MR_io_stdout_stream)(&stdout_stream);
 	(*MR_io_print_to_stream)(type_info, stdout_stream, value);
 }
+
+/*
+** Find and validate the number of a variable given by a variable
+** specification in the given layout. If successful, return the
+** number of the variable in *which_var_ptr, and a NULL string;
+** otherwise return a string containing an error message.
+*/
+
+const char *
+MR_trace_find_var(const MR_Stack_Layout_Label *layout,
+	MR_Var_Spec var_spec, int *which_var_ptr)
+{
+	int		var_count;
+	const char 	*problem;
+
+	problem = MR_trace_validate_var_count(layout, &var_count);
+	if (problem != NULL) {
+		return problem;
+	}
+
+	if (var_spec.MR_var_spec_kind == VAR_NUMBER) {
+		*which_var_ptr = var_spec.MR_var_spec_number;
+		if (*which_var_ptr >= var_count) {
+			return "there is no such variable";
+		} else {
+			return NULL;	/* represents success */
+		}
+	} else if (var_spec.MR_var_spec_kind == VAR_NAME) {
+		const MR_Stack_Layout_Vars	*vars;
+		const char 			*name;
+		bool				collision = FALSE;
+		int				i;
+
+		vars = &layout->MR_sll_var_info;
+		*which_var_ptr = -1;
+		name = var_spec.MR_var_spec_name;
+		for (i = 0; i < var_count; i++) {
+			if (streq(name, MR_name_if_present(vars, i))) {
+				if (*which_var_ptr >= 0) {
+					collision = TRUE;
+				}
+
+				*which_var_ptr = i;
+			}
+		}
+
+		if (*which_var_ptr < 0) {
+			return "there is no variable with that name";
+		} else if (collision) {
+			return "variable name is not unique";
+		} else {
+			return NULL;	/* represents success */
+		}
+	} else {
+		return "internal error: bad var_spec kind";
+	}
+}
+
+const char *
+MR_trace_validate_var_count(const MR_Stack_Layout_Label *layout,
+	int *var_count_ptr)
+{
+	if (! MR_has_valid_var_count(&layout->MR_sll_var_info)) {
+		return "there is no information about live variables";
+	} else if (! MR_has_valid_var_info(&layout->MR_sll_var_info)) {
+		return "there are no live variables";
+	} else {
+		*var_count_ptr =
+			MR_all_desc_var_count(&layout->MR_sll_var_info);
+		return NULL;
+	}
+}
Index: runtime/mercury_layout_util.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_layout_util.h,v
retrieving revision 1.5
diff -u -r1.5 mercury_layout_util.h
--- mercury_layout_util.h	1999/04/30 06:21:20	1.5
+++ mercury_layout_util.h	1999/05/20 12:03:26
@@ -150,4 +150,32 @@
 
 extern	void	MR_write_variable(Word type_info, Word value);
 
+/*
+** Type used in the term browser call
+*/
+
+typedef	enum {
+	VAR_NUMBER,
+	VAR_NAME
+} MR_Var_Spec_Kind;
+
+typedef struct {
+	MR_Var_Spec_Kind	MR_var_spec_kind;
+	int			MR_var_spec_number; /* valid if VAR_NUMBER */
+	const char		*MR_var_spec_name;  /* valid if VAR_NAME   */
+} MR_Var_Spec;
+
+/*
+** Find and validate the number of a variable given by a variable
+** specification in the given layout. If successful, return the
+** number of the variable in *which_var_ptr, and a NULL string;
+** otherwise return a string containing an error message.
+*/
+
+extern	const char *MR_trace_find_var(const MR_Stack_Layout_Label *layout,
+			MR_Var_Spec var_spec, int *which_var_ptr);
+
+extern	const char *MR_trace_validate_var_count(const MR_Stack_Layout_Label
+			*layout, int *var_count_ptr);
+
 #endif	/* MERCURY_LAYOUT_UTIL_H */
Index: trace/mercury_trace_browse.c
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_browse.c,v
retrieving revision 1.4
diff -u -r1.4 mercury_trace_browse.c
--- mercury_trace_browse.c	1999/04/22 06:58:50	1.4
+++ mercury_trace_browse.c	1999/05/20 12:03:27
@@ -63,6 +63,28 @@
 				(Word *) MR_trace_browser_state_type);
 }
 
+	
+/*
+** MR_trace_browse_external() is the same as MR_trace_browse() except it 
+** uses debugger_socket_in and debugger_socket_out instead of mdb_in and 
+** mdb_out.
+*/
+
+void
+MR_trace_browse_external(Word type_info, Word value)
+{
+	MR_trace_browse_ensure_init();
+
+	MR_TRACE_CALL_MERCURY(
+		ML_BROWSE_browse_external(type_info, value,
+			(Word) &MR_debugger_socket_in, 
+			(Word) &MR_debugger_socket_out,
+			MR_trace_browser_state, &MR_trace_browser_state);
+	);
+	MR_trace_browser_state = MR_make_permanent(MR_trace_browser_state,
+				(Word *) MR_trace_browser_state_type);
+}
+
 void
 MR_trace_print(Word type_info, Word value)
 {
Index: trace/mercury_trace_browse.h
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_browse.h,v
retrieving revision 1.3
diff -u -r1.3 mercury_trace_browse.h
--- mercury_trace_browse.h	1999/04/22 06:58:50	1.3
+++ mercury_trace_browse.h	1999/05/20 12:03:27
@@ -8,7 +8,7 @@
 ** mercury_trace_browse.h
 **
 ** Defines the interface of the term browser and the interactive query
-** facility for the internal debugger.
+** facility for the internal and external debuggers.
 */
 
 #ifndef	MERCURY_TRACE_BROWSE_H
@@ -18,6 +18,7 @@
 ** Interactively browse a term.
 */
 extern 	void	MR_trace_browse(Word type_info, Word value);
+extern 	void	MR_trace_browse_external(Word type_info, Word value);
 
 /*
 ** Display a term (non-interactively).
Index: trace/mercury_trace_external.c
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_external.c,v
retrieving revision 1.16
diff -u -r1.16 mercury_trace_external.c
--- mercury_trace_external.c	1999/04/30 06:21:47	1.16
+++ mercury_trace_external.c	1999/05/20 12:03:32
@@ -74,8 +74,9 @@
 				 = 14,/* wait for a cc interactive query      */
 	MR_REQUEST_INTERACTIVE_QUERY_IO	 
 				 = 15,/* wait for a io interactive query      */
-	MR_REQUEST_MMC_OPTIONS	 = 16 /* pass down new options to compile
+	MR_REQUEST_MMC_OPTIONS	 = 16,/* pass down new options to compile
 					 queries with			      */
+	MR_REQUEST_BROWSE	 = 17 /* call the term browser	              */
 
 } MR_debugger_request_type;
 
@@ -129,6 +130,15 @@
 			Integer *modules_list_length_ptr, Word *modules_list_ptr);
 static void	MR_get_mmc_options(Word debugger_request, 
 			String *mmc_options_ptr);
+static void	MR_get_variable_name(Word debugger_request, String *var_name_ptr);
+static void	MR_trace_browse_one_external(
+			const MR_Stack_Layout_Label *top_layout,
+			Word *saved_regs, int ancestor_level,
+			MR_Var_Spec which_var);
+static void	MR_trace_browse_var_external(const char *name, 
+			const MR_Stack_Layout_Vars *vars, int i, 
+			Word *saved_regs, Word *base_sp, Word *base_curfr, 
+			Word *type_params);
 
 #if 0
 This pseudocode should go in the debugger process:
@@ -390,6 +400,7 @@
 	Word		*saved_regs = event_info->MR_saved_regs;
 	Integer		modules_list_length;
 	Word		modules_list;
+	int		ancestor_level;
 
 /* 
 ** MR_mmc_options contains the options to pass to mmc when compiling queries.
@@ -398,6 +409,9 @@
 	static String	MR_mmc_options;
 	MR_TRACE_CALL_MERCURY(ML_DI_init_mercury_string(&MR_mmc_options));
 
+/* by default, print variables from the current call */
+	ancestor_level = 0;
+
 	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;
@@ -605,6 +619,24 @@
 				MR_send_message_to_socket("mmc_options_ok");
 				break;
 
+			case MR_REQUEST_BROWSE:
+			  {
+				char		*var_name;
+				MR_Var_Spec	var_spec;
+
+				if (MR_debug_socket) {
+					fprintf(stderr, "\nMercury runtime: "
+						"REQUEST_BROWSE\n");
+				}
+				MR_get_variable_name(debugger_request, 
+					&var_name);
+				var_spec.MR_var_spec_kind = VAR_NAME;
+				var_spec.MR_var_spec_name = var_name;
+				MR_trace_browse_one_external(layout, saved_regs,
+					ancestor_level, var_spec);
+				MR_send_message_to_socket("browser_end");
+				break;
+			  }
 			case MR_REQUEST_NO_TRACE:
 				cmd->MR_trace_cmd = MR_CMD_TO_END;
 				return jumpaddr;
@@ -1146,5 +1178,104 @@
 			mmc_options_ptr);
 		);
 }
+
+static void
+MR_get_variable_name(Word debugger_request, String *var_name_ptr)
+{
+	MR_TRACE_CALL_MERCURY(
+		ML_DI_get_variable_name(
+			debugger_request, 
+			var_name_ptr);
+		);
+}
+
+
+/*
+** It is the same function as MR_trace_browse_one() defined in 
+** mercury_trace_internal.c except it sends/receives messages from/to 
+** the socket instead of sending it to mdb_in/mdb_out.
+*/
+
+static void
+MR_trace_browse_one_external(const MR_Stack_Layout_Label *top_layout,
+	Word *saved_regs, int ancestor_level, MR_Var_Spec var_spec)
+{
+	const MR_Stack_Layout_Label	*level_layout;
+	Word				*base_sp;
+	Word				*base_curfr;
+	Word				*type_params;
+	Word				*valid_saved_regs;
+	int				which_var;
+	const MR_Stack_Layout_Vars	*vars;
+	const char 			*problem;
+
+	base_sp = MR_saved_sp(saved_regs);
+	base_curfr = MR_saved_curfr(saved_regs);
+	level_layout = MR_find_nth_ancestor(top_layout, ancestor_level,
+				&base_sp, &base_curfr, &problem);
+
+	if (level_layout == NULL) {
+		MR_send_message_to_socket_format("error(\"%s\").\n", problem);
+		return;
+	}
+
+	problem = MR_trace_find_var(level_layout, var_spec, &which_var);
+	if (problem != NULL) {
+		MR_send_message_to_socket_format("error(\"%s\").\n", problem);
+		return;
+	}
+
+	if (ancestor_level == 0) {
+		valid_saved_regs = saved_regs;
+	} else {
+		valid_saved_regs = NULL;
+	}
+	vars = &level_layout->MR_sll_var_info;
+	type_params = MR_materialize_typeinfos_base(vars,
+				valid_saved_regs, base_sp, base_curfr);
+	MR_trace_browse_var_external(MR_name_if_present(vars, which_var),
+		vars, which_var, valid_saved_regs,
+		base_sp, base_curfr, type_params);
+	free(type_params);
+}
+
+
+/*
+** It is the same function as MR_trace_browse_var() defined in 
+** mercury_trace_internal.c except it always calls the term browser and it calls 
+** MR_trace_browse_external() instead of MR_trace_browse().
+*/
+
+static void
+MR_trace_browse_var_external(const char *name, const MR_Stack_Layout_Vars *vars,
+	int i, Word *saved_regs, Word *base_sp, Word *base_curfr, 
+	Word *type_params)
+{
+	Word	value;
+	Word	type_info;
+	bool	print_value;
+
+	/*
+	** XXX The printing of type_infos is buggy at the moment
+	** due to the fake arity of the type private_builtin:typeinfo/1.
+	*/
+
+	if ((strncmp(name, "TypeInfo", 8) == 0)
+	|| (strncmp(name, "TypeClassInfo", 13) == 0))
+		return;
+
+	/*
+	** "variables" representing the saved values of succip, hp etc,
+	** which are the "variables" for which get_type_and_value fails,
+	** are not of interest to the user.
+	*/
+
+	print_value = MR_get_type_and_value_base(vars, i, saved_regs,
+			base_sp, base_curfr, type_params, &type_info, &value);
+	if (print_value) {
+		MR_trace_browse_external(type_info, value);		
+	}
+}
+
 
 #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.42
diff -u -r1.42 mercury_trace_internal.c
--- mercury_trace_internal.c	1999/05/14 02:25:44	1.42
+++ mercury_trace_internal.c	1999/05/20 12:03:39
@@ -122,17 +122,6 @@
 	STOP_INTERACTING
 } MR_Next;
 
-typedef	enum {
-	VAR_NUMBER,
-	VAR_NAME
-} MR_Var_Spec_Kind;
-
-typedef struct {
-	MR_Var_Spec_Kind	MR_var_spec_kind;
-	int			MR_var_spec_number; /* valid if VAR_NUMBER */
-	const char		*MR_var_spec_name;  /* valid if VAR_NAME   */
-} MR_Var_Spec;
-
 #ifdef	MR_USE_DECLARATIVE_DEBUGGER
 
 MR_Trace_Mode MR_trace_decl_mode = MR_TRACE_INTERACTIVE;
@@ -186,10 +175,6 @@
 			const MR_Stack_Layout_Vars *vars, int i,
 			Word *saved_regs, Word *base_sp, Word *base_curfr,
 			Word *type_params, bool browse);
-static	const char *MR_trace_validate_var_count(const MR_Stack_Layout_Label
-			*layout, int *var_count_ptr);
-static	const char *MR_trace_find_var(const MR_Stack_Layout_Label *layout,
-			MR_Var_Spec var_spec, int *which_var_ptr);
 static	void	MR_trace_do_noop(void);
 
 static	const char *MR_trace_read_help_text(void);
@@ -1866,78 +1851,6 @@
 			/* XXX should use MR_mdb_out */
 			MR_trace_print(type_info, value);
 		}
-	}
-}
-
-static const char *
-MR_trace_validate_var_count(const MR_Stack_Layout_Label *layout,
-	int *var_count_ptr)
-{
-	if (! MR_has_valid_var_count(&layout->MR_sll_var_info)) {
-		return "there is no information about live variables";
-	} else if (! MR_has_valid_var_info(&layout->MR_sll_var_info)) {
-		return "there are no live variables";
-	} else {
-		*var_count_ptr =
-			MR_all_desc_var_count(&layout->MR_sll_var_info);
-		return NULL;
-	}
-}
-
-/*
-** Find and validate the number of a variable given by a variable
-** specification in the given layout. If successful, return the
-** number of the variable in *which_var_ptr, and a NULL string;
-** otherwise return a string containing an error message.
-*/
-
-static const char *
-MR_trace_find_var(const MR_Stack_Layout_Label *layout,
-	MR_Var_Spec var_spec, int *which_var_ptr)
-{
-	int		var_count;
-	const char 	*problem;
-
-	problem = MR_trace_validate_var_count(layout, &var_count);
-	if (problem != NULL) {
-		return problem;
-	}
-
-	if (var_spec.MR_var_spec_kind == VAR_NUMBER) {
-		*which_var_ptr = var_spec.MR_var_spec_number;
-		if (*which_var_ptr >= var_count) {
-			return "there is no such variable";
-		} else {
-			return NULL;	/* represents success */
-		}
-	} else if (var_spec.MR_var_spec_kind == VAR_NAME) {
-		const MR_Stack_Layout_Vars	*vars;
-		const char 			*name;
-		bool				collision = FALSE;
-		int				i;
-
-		vars = &layout->MR_sll_var_info;
-		*which_var_ptr = -1;
-		name = var_spec.MR_var_spec_name;
-		for (i = 0; i < var_count; i++) {
-			if (streq(name, MR_name_if_present(vars, i))) {
-				if (*which_var_ptr >= 0) {
-					collision = TRUE;
-				}
-
-				*which_var_ptr = i;
-			}
-		}
-
-		if (*which_var_ptr < 0) {
-			return "there is no variable with that name";
-		} else if (collision) {
-			return "variable name is not unique";
-		} else {
-			return NULL;	/* represents success */
-		}
-	} else {
-		return "internal error: bad var_spec kind";
 	}
 }
-- 
R1.


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



More information about the developers mailing list