[m-rev.] For review: Made declarative debugger use mdb format settings

Ian MacLarty maclarty at cs.mu.OZ.AU
Thu Oct 21 18:36:34 AEST 2004


For review by anyone.

Estimated hours taken: 3
Branches: main

Made the declarative debugger respect the format settings of the procedural
debugger.  So the print format set in the procedural debugger will be used when
the declarative debugger asks questions and the browse format will be used when
browsing terms in the declarative debugger.  If the user changes the browser
format during a declarative debugging session the procedural debugger will
respect these changes.

This also means the declarative debugger will respect the settings in the
.mdbrc file.

browser/declarative_debugger.m
	Added term browser state arguments to main diagnosis predicate and
	initialisation predicate.

browser/declarative_oracle.m
	Added predicates to get and set the term browser state.
	Set the term browser state in the initialisation prediciate for the
	oracle state.

browser/declarative_user.m
	Added predicates to get and set the term browser state.
	Set the term browser state in the initialisation prediciate for the
	user state.

tests/debugger/declarative/dependency.exp
	This test sets the print format in the procedural debugger, so
	the declarative debugger now uses this format.

trace/mercury_trace_browse.c
trace/mercury_trace_browse.h
	Exported global which stores the state of the procedural debugger
	term browser and the function which initialises this state, so they can
	be used from mercury_trace_declarative.c.

trace/mercury_trace_declarative.c
	Pass the procedural debugger term browser state to the declarative 
	debugger and update the state when the declarative debugger is
	finished.

Index: browser/declarative_debugger.m
===================================================================
RCS file: /home/mercury1/repository/mercury/browser/declarative_debugger.m,v
retrieving revision 1.39
diff -u -r1.39 declarative_debugger.m
--- browser/declarative_debugger.m	20 Sep 2004 04:50:22 -0000	1.39
+++ browser/declarative_debugger.m	21 Oct 2004 07:30:53 -0000
@@ -41,6 +41,7 @@
 :- import_module mdb__declarative_execution.
 :- import_module mdb__io_action.
 :- import_module mdbcomp__program_representation.
+:- import_module mdb.browser_info.
 
 :- import_module io, bool, list, std_util, string.
 
@@ -218,11 +219,14 @@
 :- type diagnoser_state(R).
 
 :- pred diagnoser_state_init(io_action_map::in, io__input_stream::in,
-	io__output_stream::in, diagnoser_state(R)::out) is det.
+	io__output_stream::in, browser_info.browser_persistent_state::in,
+	diagnoser_state(R)::out) is det.
 
 :- pred diagnosis(S::in, R::in, int::in, int::in, int::in,
 	diagnoser_response::out,
 	diagnoser_state(R)::in, diagnoser_state(R)::out,
+	browser_info.browser_persistent_state::in,
+	browser_info.browser_persistent_state::out,
 	io__state::di, io__state::uo) is cc_multi <= annotated_trace(S, R).
 
 :- pred unravel_decl_atom(some_decl_atom::in, trace_atom::out,
@@ -304,36 +308,44 @@
 
 diagnoser_set_oracle(diagnoser(A, _), B, diagnoser(A, B)).
 
-diagnoser_state_init(IoActionMap, InStr, OutStr, Diagnoser) :-
+diagnoser_state_init(IoActionMap, InStr, OutStr, Browser, Diagnoser) :-
 	analyser_state_init(IoActionMap, Analyser),
-	oracle_state_init(InStr, OutStr, Oracle),
+	oracle_state_init(InStr, OutStr, Browser, Oracle),
 	Diagnoser = diagnoser(Analyser, Oracle).
 
 diagnosis(Store, NodeId, UseOldIoActionMap, IoActionStart, IoActionEnd,
-		Response, Diagnoser0, Diagnoser) -->
-	( { UseOldIoActionMap > 0 } ->
-		{ Diagnoser1 = Diagnoser0 }
+		Response, !Diagnoser, !Browser, !IO) :-
+	mdb.declarative_oracle.set_browser_state(!.Browser, !.Diagnoser ^
+		oracle_state, Oracle),
+	!:Diagnoser = !.Diagnoser ^ oracle_state := Oracle,
+	( 
+		UseOldIoActionMap > 0
+	->
+		true
 	;
-		make_io_action_map(IoActionStart, IoActionEnd, IoActionMap),
-		{ Analyser0 = Diagnoser0 ^ analyser_state },
-		{ analyser_state_replace_io_map(IoActionMap,
-			Analyser0, Analyser1) },
-		{ Diagnoser1 = Diagnoser0 ^ analyser_state := Analyser1 }
+		make_io_action_map(IoActionStart, IoActionEnd, IoActionMap, 
+			!IO),
+		Analyser0 = !.Diagnoser ^ analyser_state,
+		analyser_state_replace_io_map(IoActionMap,
+			Analyser0, Analyser1),
+		!:Diagnoser = !.Diagnoser ^ analyser_state := Analyser1
 	),
-	try_io(diagnosis_2(Store, NodeId, Diagnoser1), Result),
+	try_io(diagnosis_2(Store, NodeId, !.Diagnoser), Result, !IO),
 	(
-		{ Result = succeeded({Response, Diagnoser}) }
+		Result = succeeded({Response, !:Diagnoser})
 	;
-		{ Result = exception(UnivException) },
+		Result = exception(UnivException),
 		(
-			{ univ_to_type(UnivException, DiagnoserException) }
+			univ_to_type(UnivException, DiagnoserException)
 		->
 			handle_diagnoser_exception(DiagnoserException,
-				Response, Diagnoser1, Diagnoser)
+				Response, !Diagnoser, !IO)
 		;
-			{ rethrow(Result) }
+			rethrow(Result)
 		)
-	).
+	),
+	!:Browser = mdb.declarative_oracle.get_browser_state(
+		!.Diagnoser ^ oracle_state).
 
 :- pred diagnosis_2(S::in, R::in, diagnoser_state(R)::in,
 	{diagnoser_response, diagnoser_state(R)}::out,
@@ -452,15 +464,15 @@
 	% Export a monomorphic version of diagnosis_state_init/4, to
 	% make it easier to call from C code.
 	%
-:- pred diagnoser_state_init_store(io__input_stream, io__output_stream,
-		diagnoser_state(trace_node_id)).
-:- mode diagnoser_state_init_store(in, in, out) is det.
+:- pred diagnoser_state_init_store(io__input_stream::in, io__output_stream::in,
+	browser_info.browser_persistent_state::in, 
+	diagnoser_state(trace_node_id)::out) is det.
 
-:- pragma export(diagnoser_state_init_store(in, in, out),
+:- pragma export(diagnoser_state_init_store(in, in, in, out),
 		"MR_DD_decl_diagnosis_state_init").
 
-diagnoser_state_init_store(InStr, OutStr, Diagnoser) :-
-	diagnoser_state_init(map__init, InStr, OutStr, Diagnoser).
+diagnoser_state_init_store(InStr, OutStr, Browser, Diagnoser) :-
+	diagnoser_state_init(map__init, InStr, OutStr, Browser, Diagnoser).
 
 	% Export a monomorphic version of diagnosis/10, to make it
 	% easier to call from C code.
@@ -468,16 +480,18 @@
 :- pred diagnosis_store(trace_node_store::in, trace_node_id::in,
 	int::in, int::in, int::in, diagnoser_response::out,
 	diagnoser_state(trace_node_id)::in,
-	diagnoser_state(trace_node_id)::out, io__state::di, io__state::uo)
-	is cc_multi.
+	diagnoser_state(trace_node_id)::out, 
+	browser_info.browser_persistent_state::in, 
+	browser_info.browser_persistent_state::out, io__state::di, 
+	io__state::uo) is cc_multi.
 
-:- pragma export(diagnosis_store(in, in, in, in, in, out, in, out, di, uo),
-		"MR_DD_decl_diagnosis").
+:- pragma export(diagnosis_store(in, in, in, in, in, out, in, out, in, out, 
+	di, uo), "MR_DD_decl_diagnosis").
 
 diagnosis_store(Store, Node, UseOldIoActionMap, IoActionStart, IoActionEnd,
-		Response, State0, State) -->
+		Response, !State, !Browser, !IO) :-
 	diagnosis(Store, Node, UseOldIoActionMap, IoActionStart, IoActionEnd,
-		Response, State0, State).
+		Response, !State, !Browser, !IO).
 
 	% Export some predicates so that C code can interpret the
 	% diagnoser response.
Index: browser/declarative_oracle.m
===================================================================
RCS file: /home/mercury1/repository/mercury/browser/declarative_oracle.m,v
retrieving revision 1.26
diff -u -r1.26 declarative_oracle.m
--- browser/declarative_oracle.m	20 Sep 2004 07:43:37 -0000	1.26
+++ browser/declarative_oracle.m	21 Oct 2004 07:30:49 -0000
@@ -28,6 +28,7 @@
 
 :- import_module mdb__declarative_debugger.
 :- import_module mdb__declarative_execution.
+:- import_module mdb.browser_info.
 
 :- import_module list, io, bool, string.
 
@@ -47,8 +48,8 @@
 
 	% Produce a new oracle state.
 	%
-:- pred oracle_state_init(io__input_stream, io__output_stream, oracle_state).
-:- mode oracle_state_init(in, in, out) is det.
+:- pred oracle_state_init(io__input_stream::in, io__output_stream::in, 
+	browser_info.browser_persistent_state::in, oracle_state::out) is det.
 
 	% Add a module to the set of modules trusted by the oracle
 	%
@@ -96,6 +97,16 @@
 	decl_confirmation::out, oracle_state::in, oracle_state::out,
 	io__state::di, io__state::uo) is cc_multi.
 
+	% Returns the state of the term browser.
+	%
+:- func get_browser_state(oracle_state) 
+	= browser_info.browser_persistent_state.
+
+	% Sets the state of the term browser.
+	%
+:- pred set_browser_state(browser_info.browser_persistent_state::in,
+	oracle_state::in, oracle_state::out) is det.
+
 %-----------------------------------------------------------------------------%
 
 :- implementation.
@@ -219,10 +230,10 @@
 				% by the oracle.
 		).
 
-oracle_state_init(InStr, OutStr, Oracle) :-
+oracle_state_init(InStr, OutStr, Browser, Oracle) :-
 	oracle_kb_init(Current),
 	oracle_kb_init(Old),
-	user_state_init(InStr, OutStr, User),
+	user_state_init(InStr, OutStr, Browser, User),
 	set.init(TrustedModules),
 	Oracle = oracle(Current, Old, User, TrustedModules).
 	
@@ -581,3 +592,12 @@
 	),
 	KB = KB0 ^ kb_exceptions_map := ExceptionsMap.
 
+%-----------------------------------------------------------------------------%
+
+get_browser_state(Oracle) = 
+	mdb.declarative_user.get_browser_state(Oracle ^ user_state).
+
+set_browser_state(Browser, !Oracle) :-
+	mdb.declarative_user.set_browser_state(Browser, !.Oracle ^ user_state,
+		User),
+	!:Oracle = !.Oracle ^ user_state := User.
Index: browser/declarative_user.m
===================================================================
RCS file: /home/mercury1/repository/mercury/browser/declarative_user.m,v
retrieving revision 1.29
diff -u -r1.29 declarative_user.m
--- browser/declarative_user.m	9 Aug 2004 03:05:20 -0000	1.29
+++ browser/declarative_user.m	21 Oct 2004 07:31:04 -0000
@@ -17,6 +17,7 @@
 :- interface.
 
 :- import_module mdb__declarative_debugger.
+:- import_module mdb.browser_info.
 
 :- import_module list, io.
 
@@ -32,8 +33,8 @@
 
 :- type user_state.
 
-:- pred user_state_init(io__input_stream, io__output_stream, user_state).
-:- mode user_state_init(in, in, out) is det.
+:- pred user_state_init(io__input_stream::in, io__output_stream::in, 
+	browser_info.browser_persistent_state::in, user_state::out) is det.
 
 	% This predicate handles the interactive part of the declarative
 	% debugging process.  The user is presented with a question,
@@ -50,12 +51,20 @@
 	user_state::in, user_state::out, io__state::di, io__state::uo)
 	is cc_multi.
 
+	% Returns the state of the term browser.
+	%
+:- func get_browser_state(user_state) = browser_info.browser_persistent_state.
+
+	% Sets the state of the term browser.
+	%
+:- pred set_browser_state(browser_info.browser_persistent_state::in, 
+	user_state::in, user_state::out) is det.
+
 %-----------------------------------------------------------------------------%
 
 :- implementation.
 
 :- import_module mdb__browse.
-:- import_module mdb__browser_info.
 :- import_module mdb__browser_term.
 :- import_module mdb__io_action.
 :- import_module mdb__util.
@@ -71,9 +80,7 @@
 			browser	:: browser_persistent_state
 		).
 
-user_state_init(InStr, OutStr, User) :-
-	browser_info__init_persistent_state(Browser),
-	User = user(InStr, OutStr, Browser).
+user_state_init(InStr, OutStr, Browser, user(InStr, OutStr, Browser)).
 
 %-----------------------------------------------------------------------------%
 
@@ -748,5 +755,12 @@
 	Term = io_action_to_browser_term(IoAction),
 	browse__print_browser_term(Term, User ^ outstr, print_all,
 		User ^ browser, !IO).
+
+%-----------------------------------------------------------------------------%
+
+get_browser_state(User) = User ^ browser.
+
+set_browser_state(Browser, !User) :-
+	!:User = !.User ^ browser := Browser.
 
 %-----------------------------------------------------------------------------%
Index: tests/debugger/declarative/dependency.exp
===================================================================
RCS file: /home/mercury1/repository/tests/debugger/declarative/dependency.exp,v
retrieving revision 1.4
diff -u -r1.4 dependency.exp
--- tests/debugger/declarative/dependency.exp	20 Oct 2003 07:29:44 -0000	1.4
+++ tests/debugger/declarative/dependency.exp	21 Oct 2004 07:53:50 -0000
@@ -35,7 +35,7 @@
         ite_rep(atomic_goal_rep/5, atomic_goal_rep/5, atomic_goal_rep/5), 
         [|](atomic_goal_rep/5, [|](switch_rep([|]/2), [|](disj_rep([|]/2), [])))))))
 mdb> dd
-test([1, 3, 6, 1, 3])
+test([|](1, [|](3, [|](6, [|](1, [|](3, []))))))
 Valid? browse 1
 browser> ^1
 browser> mark
@@ -45,15 +45,15 @@
 Diagnosis aborted.
       18:      3  2 EXIT pred dependency.test/1-0 (cc_multi) dependency.m:19 (dependency.m:13)
 mdb> dd
-test([1, 3, 6, 1, 3])
+test([|](1, [|](3, [|](6, [|](1, [|](3, []))))))
 Valid? browse 1
 browser> ^2^1
 browser> mark
 Origin: output(r, any_head_var(4), [1])
-r(1, [3, 4], 3 - 4)
+r(1, [|](3, [|](4, [])), -(3, 4))
 Valid? browse 2
 browser> print
-[3, 4]
+[|](3, [|](4, []))
 browser> mark
 Origin: primitive_op("dependency.m", 29)
 p(1)
@@ -61,7 +61,7 @@
 Diagnosis aborted.
       18:      3  2 EXIT pred dependency.test/1-0 (cc_multi) dependency.m:19 (dependency.m:13)
 mdb> dd
-test([1, 3, 6, 1, 3])
+test([|](1, [|](3, [|](6, [|](1, [|](3, []))))))
 Valid? browse 1
 browser> ^2^2^1
 browser> mark
@@ -71,7 +71,7 @@
 Diagnosis aborted.
       18:      3  2 EXIT pred dependency.test/1-0 (cc_multi) dependency.m:19 (dependency.m:13)
 mdb> dd
-test([1, 3, 6, 1, 3])
+test([|](1, [|](3, [|](6, [|](1, [|](3, []))))))
 Valid? browse 1
 browser> ^2^2^2^1
 browser> mark
@@ -81,17 +81,17 @@
 Diagnosis aborted.
       18:      3  2 EXIT pred dependency.test/1-0 (cc_multi) dependency.m:19 (dependency.m:13)
 mdb> dd
-test([1, 3, 6, 1, 3])
+test([|](1, [|](3, [|](6, [|](1, [|](3, []))))))
 Valid? browse 1
 browser> ^2^2^2^2^1
 browser> mark
 Origin: output(r, any_head_var(4), [1])
-r(1, [3, 4], 3 - 4)
+r(1, [|](3, [|](4, [])), -(3, 4))
 Valid? abort
 Diagnosis aborted.
       18:      3  2 EXIT pred dependency.test/1-0 (cc_multi) dependency.m:19 (dependency.m:13)
 mdb> dd
-test([1, 3, 6, 1, 3])
+test([|](1, [|](3, [|](6, [|](1, [|](3, []))))))
 Valid? browse 1
 browser> ^2^2^2^2^2
 browser> mark
Index: trace/mercury_trace_browse.c
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_browse.c,v
retrieving revision 1.32
diff -u -r1.32 mercury_trace_browse.c
--- trace/mercury_trace_browse.c	9 Aug 2004 03:05:23 -0000	1.32
+++ trace/mercury_trace_browse.c	21 Oct 2004 03:58:52 -0000
@@ -38,10 +38,11 @@
 
 #include <stdio.h>
 
-static	MR_Word		MR_trace_browser_persistent_state;
 static	MR_TypeInfo	MR_trace_browser_persistent_state_type;
 
-static	void		MR_trace_browse_ensure_init(void);
+MR_Word	MR_trace_browser_persistent_state;
+
+void	MR_trace_browse_ensure_init(void);
 
 static	MR_bool		MR_trace_is_portray_format(const char *str,
 				MR_Browse_Format *format);
@@ -356,7 +357,7 @@
 	return MR_FALSE;
 }
 
-static void
+void
 MR_trace_browse_ensure_init(void)
 {
 	static	MR_bool	done = MR_FALSE;
Index: trace/mercury_trace_browse.h
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_browse.h,v
retrieving revision 1.16
diff -u -r1.16 mercury_trace_browse.h
--- trace/mercury_trace_browse.h	13 May 2004 08:50:32 -0000	1.16
+++ trace/mercury_trace_browse.h	21 Oct 2004 03:58:29 -0000
@@ -106,4 +106,8 @@
 			int num_imports, MR_Word imports_list);
 #endif
 
+extern	MR_Word	MR_trace_browser_persistent_state;
+
+extern	void	MR_trace_browse_ensure_init(void);
+
 #endif	/* MERCURY_TRACE_BROWSE_H */
Index: trace/mercury_trace_declarative.c
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_declarative.c,v
retrieving revision 1.71
diff -u -r1.71 mercury_trace_declarative.c
--- trace/mercury_trace_declarative.c	20 Sep 2004 04:50:25 -0000	1.71
+++ trace/mercury_trace_declarative.c	21 Oct 2004 04:34:53 -0000
@@ -1006,9 +1006,11 @@
 	MR_mercuryfile_init(MR_mdb_out, 1, &mdb_out);
 
 	if (! done) {
+		MR_trace_browse_ensure_init();
 		MR_TRACE_CALL_MERCURY(
 			MR_trace_node_store = 0;
 			MR_DD_decl_diagnosis_state_init(&mdb_in, &mdb_out,
+				MR_trace_browser_persistent_state,
 				&MR_trace_front_end_state);
 		);
 		done = MR_TRUE;
@@ -1333,7 +1335,9 @@
 				MR_io_action_map_cache_start,
 				MR_io_action_map_cache_end,
 				&response, MR_trace_front_end_state,
-				&MR_trace_front_end_state
+				&MR_trace_front_end_state,
+				MR_trace_browser_persistent_state,
+				&MR_trace_browser_persistent_state
 			);
 		bug_found = MR_DD_diagnoser_bug_found(response,
 				(MR_Integer *) &bug_event);
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list