[m-dev.] for review: expand implicit trees in the debugger

Mark Anthony BROWN dougl at cs.mu.OZ.AU
Thu Mar 2 12:30:54 AEDT 2000


Hi,

This is for review by anyone.

Cheers,
Mark.

Estimated hours taken: 40

Implement the expanding of implicit subtrees in the declarative debugger.
When the maximum depth is reached by the front end, it now returns to
the back end a request for the missing subtree.  If the back end receives
such a request, it restarts declarative debugging with a different
topmost call and a deeper depth bound.

The EDT instance needs to know when to request expansion, so CALL nodes
need a flag to indicate whether they were at the maximum depth.  The
front end needs to be able to point out the bug and/or subtree to the
back end, so CALL, EXIT and FAIL nodes need to record the event number.

browser/declarative_execution.m:
	- Store the event number in CALL, EXIT and FAIL nodes.
	- Store a bool in CALL nodes which indicates whether the event
	  was at the maximum depth or not.

browser/declarative_debugger.m:
	- Store the event number of the buggy event in the reported bug,
	  and pass this event number to the back end so it can go back
	  to that event.
	- Add a case for expanding an implicit tree to the
	  diagnoser_response type, and handle this response properly.
	- Export procedures to C that allow acces to the diagnoser_response
	  type.
	- Accommodate the changes to the trace_node type.

browser/declarative_analyser.m:
	- Store the list of previous prime suspects in the analyser state.
	  That way they don't have to be specially dealt with when
	  restarting analysis with an expanded subtree.
	- When starting analysis, assume the top node is wrong; this
	  is not an unreasonable assumption, and the strategy works better
	  for the case when a subtree is expanded.

browser/declarative_user.m:
	- Accommodate changes to the reported bug.

trace/mercury_trace_declarative.c:
	- Change the depth step size to a reasonable number, now that
	  it works.  This also has the effect of testing the change,
	  since some test cases go deeper than the new limit.
	- Filter events outside the topmost call.  Rather than keep
	  track of the minimum depth, we record the topmost call sequence
	  number and use a global to keep track of whether we have entered
	  or left this procedure.
	- Factor out code in the existing mechanism for starting
	  declarative debugging, so that it can be used to re-start
	  debugging as well.
	- Accommodate the changes to the trace_node type.
	- Output error messages if declarative debugging fails to start
	  properly.
	- Handle the reponse from the diagnoser, by jumping to the buggy
	  event (if a bug is found) or re-executing to expand a subtree
	  (if one is requested).
	- Add a new checkpoint for events which are filtered out of
	  the annotated trace.

trace/mercury_trace_internal.c:
	- Don't report error messages when declarative debugging fails
	  to start.  Errors are now reported by the declarative debugger
	  before returning.

tests/debugger/declarative/*.inp:
tests/debugger/declarative/*.exp:
tests/debugger/declarative/*.exp2:
	- Update to reflect the removed questions.

tests/debugger/declarative/Mmakefile:
tests/debugger/declarative/filter.m:
tests/debugger/declarative/filter.inp:
tests/debugger/declarative/filter.exp:
	- New test case to cover the code which filters events which
	  are outside the topmost call.

? tests/debugger/declarative/filter.exp2
? tests/debugger/declarative/filter.inp
? tests/debugger/declarative/filter.m
? tests/debugger/declarative/filter.exp
Index: browser/declarative_analyser.m
===================================================================
RCS file: /home/mercury1/repository/mercury/browser/declarative_analyser.m,v
retrieving revision 1.3
diff -u -r1.3 declarative_analyser.m
--- browser/declarative_analyser.m	2000/03/01 04:17:23	1.3
+++ browser/declarative_analyser.m	2000/03/01 23:50:19
@@ -101,16 +101,18 @@
 
 				% Current suspects.
 				%
+			list(suspect(T)),
+
+				% Previous prime suspects.
+				%
 			list(suspect(T))
 	).
 
-analyser_state_init(analyser(no, [])).
+analyser_state_init(analyser(no, [], [])).
 
-start_analysis(Store, Tree, Response, _, Analyser) :-
-	edt_root_question(Store, Tree, Question),
-	Response = oracle_queries([Question]),
+start_analysis(Store, Tree, Response, Analyser0, Analyser) :-
 	create_suspect(Store, Tree, Suspect),
-	Analyser = analyser(no, [Suspect]).
+	make_new_prime_suspect(Store, Suspect, Response, Analyser0, Analyser).
 
 continue_analysis(Store, Answers, Response, Analyser0, Analyser) :-
 	(
@@ -131,7 +133,7 @@
 :- mode find_incorrect_suspect(in, in, out) is semidet.
 
 find_incorrect_suspect([Answer | Answers], Analyser, Child) :-
-	Analyser = analyser(_, Suspects),
+	Analyser = analyser(_, Suspects, _),
 	(
 		Answer = _ - no,
 		find_matching_suspects(Answer, Suspects, [Match | _], _)
@@ -149,12 +151,21 @@
 :- mode make_new_prime_suspect(in, in, out, in, out) is det.
 
 make_new_prime_suspect(Store, Suspect, Response, Analyser0, Analyser) :-
-	Analyser0 = analyser(MaybeOldPrime, _),
+	Analyser0 = analyser(MaybeOldPrime, _, OldPrimes0),
+	(
+		MaybeOldPrime = yes(OldPrime0)
+	->
+		prime_suspect_get_suspect(OldPrime0, OldPrime),
+		OldPrimes = [OldPrime | OldPrimes0]
+	;
+		OldPrimes = OldPrimes0
+	),
 	suspect_get_edt_node(Suspect, Tree),
-	create_prime_suspect(Suspect, MaybeOldPrime, Prime),
 	(
 		edt_children(Store, Tree, Children)
 	->
+		create_prime_suspect(Suspect, Prime),
+		MaybePrime = yes(Prime),
 		make_suspects(Store, Children, Suspects, Queries),
 		(
 			Queries = []
@@ -169,9 +180,10 @@
 			% just use the empty list.
 			%
 		Suspects = [],
+		MaybePrime = no,
 		Response = require_explicit(Tree)
 	),
-	Analyser = analyser(yes(Prime), Suspects).
+	Analyser = analyser(MaybePrime, Suspects, OldPrimes).
 
 :- pred make_suspects(S, list(T), list(suspect(T)), list(decl_question))
 		<= mercury_edt(S, T).
@@ -191,7 +203,7 @@
 :- mode remove_suspects(in, in, out, in, out) is det.
 
 remove_suspects(Store, [], Response, Analyser, Analyser) :-
-	Analyser = analyser(MaybePrime, Suspects),
+	Analyser = analyser(MaybePrime, Suspects, _),
 	(
 		Suspects = []
 	->
@@ -215,9 +227,9 @@
 	(
 		Answer = _ - yes
 	->
-		Analyser0 = analyser(MaybeTree, Suspects0),
+		Analyser0 = analyser(MaybePrime, Suspects0, OldPrimes),
 		find_matching_suspects(Answer, Suspects0, _, Suspects),
-		Analyser1 = analyser(MaybeTree, Suspects),
+		Analyser1 = analyser(MaybePrime, Suspects, OldPrimes),
 		remove_suspects(Store, Answers, Response, Analyser1, Analyser)
 	;
 		error("remove_suspects: unexpected incorrect node")
@@ -276,35 +288,26 @@
 				% is also included in the list of
 				% evidence.
 				%
-			maybe(suspect(T)),
-
-				% Previous prime suspects.
-				%
-			list(suspect(T))
+			maybe(suspect(T))
 		).
 
-	% Create a prime suspect from a suspect, and maybe the previous
-	% prime suspect (if there was one).
+	% Create a prime suspect from a suspect.
 	%
-:- pred create_prime_suspect(suspect(T), maybe(prime_suspect(T)),
-		prime_suspect(T)).
-:- mode create_prime_suspect(in, in, out) is det.
+:- pred create_prime_suspect(suspect(T), prime_suspect(T)).
+:- mode create_prime_suspect(in, out) is det.
 
-create_prime_suspect(Suspect, MaybeOldPrime, Prime) :-
-	(
-		MaybeOldPrime = yes(OldPrime)
-	->
-		OldPrime = prime_suspect(OldSuspect, _, _, Previous0),
-		PreviousPrimes = [OldSuspect | Previous0]
-	;
-		PreviousPrimes = []
-	),
-	Prime = prime_suspect(Suspect, [], no, PreviousPrimes).
+create_prime_suspect(Suspect, Prime) :-
+	Prime = prime_suspect(Suspect, [], no).
+
+:- pred prime_suspect_get_suspect(prime_suspect(T), suspect(T)).
+:- mode prime_suspect_get_suspect(in, out) is det.
+
+prime_suspect_get_suspect(prime_suspect(Suspect, _, _), Suspect).
 
 :- pred prime_suspect_get_edt_node(prime_suspect(T), T).
 :- mode prime_suspect_get_edt_node(in, out) is det.
 
-prime_suspect_get_edt_node(prime_suspect(Suspect, _, _, _), EDT) :-
+prime_suspect_get_edt_node(prime_suspect(Suspect, _, _), EDT) :-
 	suspect_get_edt_node(Suspect, EDT).
 
 	% Get all the suspects who are children of the prime suspect,
@@ -315,7 +318,7 @@
 		maybe(suspect(T))).
 :- mode prime_suspect_get_evidence(in, out, out) is det.
 
-prime_suspect_get_evidence(prime_suspect(_, E, M, _), E, M).
+prime_suspect_get_evidence(prime_suspect(_, E, M), E, M).
 
 	% Add to the evidence against the prime suspect a child who
 	% is deemed correct or inadmissible.
@@ -327,9 +330,9 @@
 :- mode prime_suspect_add_evidence(in, in, in, out) is det.
 
 prime_suspect_add_evidence(Prime0, Suspect, yes, Prime) :-
-	Prime0 = prime_suspect(S, Evidence0, M, P),
+	Prime0 = prime_suspect(S, Evidence0, M),
 	Evidence = [Suspect | Evidence0],
-	Prime = prime_suspect(S, Evidence, M, P).
+	Prime = prime_suspect(S, Evidence, M).
 
 prime_suspect_add_evidence(_, _, no, _) :-
 	error("prime_suspect_add_evidence: not evidence").
Index: browser/declarative_debugger.m
===================================================================
RCS file: /home/mercury1/repository/mercury/browser/declarative_debugger.m,v
retrieving revision 1.14
diff -u -r1.14 declarative_debugger.m
--- browser/declarative_debugger.m	2000/03/01 04:17:23	1.14
+++ browser/declarative_debugger.m	2000/03/01 23:50:24
@@ -56,11 +56,13 @@
 	--->	incorrect_contour(
 			decl_atom,	% The head of the clause, in its
 					% final state of instantiation.
-			decl_contour	% The path taken through the body.
+			decl_contour,	% The path taken through the body.
+			event_number	% The exit event.
 		)
 	;	partially_uncovered_atom(
-			decl_atom	% The called atom, in its initial
+			decl_atom,	% The called atom, in its initial
 					% state.
+			event_number	% The fail event.
 		).
 
 :- type decl_i_bug
@@ -69,8 +71,9 @@
 					% state.
 			decl_position,	% The location of the call in the
 					% parent's body.
-			decl_atom	% The inadmissible child, in its
+			decl_atom,	% The inadmissible child, in its
 					% initial state.
+			event_number	% The call event.
 		).
 
 	% XXX not yet implemented.
@@ -103,12 +106,29 @@
 	% The diagnoser eventually responds with a value of this type
 	% after it is called.
 	%
-	% XXX need to have a case for expanding an implicit tree.
-	%
 :- type diagnoser_response
-	--->	bug_found
-	;	no_bug_found.
+			
+			% There was a bug found and confirmed.  The
+			% event number is for a call port (inadmissible
+			% call), an exit port (incorrect contour),
+			% or a fail port (partially uncovered atom).
+			%
+	--->	bug_found(event_number)
+
+			% There was no symptom found, or the diagnoser
+			% aborted before finding a bug.
+			%
+	;	no_bug_found
 
+			% The analyser requires the back end to reproduce
+			% part of the annotated trace, with a greater
+			% depth bound.  The event number and sequence
+			% number are for the final event required (the
+			% first event required is the call event with
+			% the same sequence number).
+			%
+	;	require_subtree(event_number, sequence_number).
+
 :- type diagnoser_state(R).
 
 :- pred diagnoser_state_init(io__input_stream, io__output_stream,
@@ -190,9 +210,14 @@
 	handle_oracle_response(Store, OracleResponse, Response, Diagnoser1,
 			Diagnoser).
 
-handle_analyser_response(_, require_explicit(_), _, _, _) -->
-	{ error("diagnosis: implicit representation not yet implemented") }.
+handle_analyser_response(Store, require_explicit(Tree), Response,
+		Diagnoser, Diagnoser) -->
 
+	{
+		edt_subtree_details(Store, Tree, Event, Seqno),
+		Response = require_subtree(Event, Seqno)
+	}.
+
 :- pred handle_oracle_response(S, oracle_response, diagnoser_response,
 		diagnoser_state(R), diagnoser_state(R), io__state, io__state)
 			<= annotated_trace(S, R).
@@ -224,7 +249,8 @@
 	{ diagnoser_set_oracle(Diagnoser0, Oracle, Diagnoser) },
 	{
 		Confirmation = confirm_bug,
-		Response = bug_found
+		decl_bug_get_event_number(Bug, Event),
+		Response = bug_found(Event)
 	;
 		Confirmation = overrule_bug,
 		Response = no_bug_found
@@ -260,6 +286,25 @@
 diagnosis_store(Store, Node, Response, State0, State) -->
 	diagnosis(Store, Node, Response, State0, State).
 
+	% Export some predicates so that C code can interpret the
+	% diagnoser response.
+	%
+:- pred diagnoser_bug_found(diagnoser_response, event_number).
+:- mode diagnoser_bug_found(in, out) is semidet.
+
+:- pragma export(diagnoser_bug_found(in, out), "MR_DD_diagnoser_bug_found").
+
+diagnoser_bug_found(bug_found(Event), Event).
+
+:- pred diagnoser_require_subtree(diagnoser_response, event_number,
+		sequence_number).
+:- mode diagnoser_require_subtree(in, out, out) is semidet.
+
+:- pragma export(diagnoser_require_subtree(in, out, out),
+		"MR_DD_diagnoser_require_subtree").
+
+diagnoser_require_subtree(require_subtree(Event, SeqNo), Event, SeqNo).
+
 %-----------------------------------------------------------------------------%
 
 	%
@@ -287,20 +332,16 @@
 :- mode trace_root_question(in, in, out) is det.
 
 trace_root_question(wrap(Store), dynamic(Ref), Root) :-
-	det_trace_node_from_id(Store, Ref, Node),
+	det_edt_node_from_id(Store, Ref, Node),
 	(
-		Node = fail(_, CallId, RedoId)
-	->
+		Node = fail(_, CallId, RedoId, _),
 		call_node_from_id(Store, CallId, Call),
-		Call = call(_, _, CallAtom, _),
+		Call = call(_, _, CallAtom, _, _, _),
 		get_answers(Store, RedoId, [], Answers),
 		Root = missing_answer(CallAtom, Answers)
 	;
-		Node = exit(_, _, _, ExitAtom)
-	->
+		Node = exit(_, _, _, ExitAtom, _),
 		Root = wrong_answer(ExitAtom)
-	;
-		error("trace_root: not an EXIT or FAIL node")
 	).
 
 :- pred get_answers(S, R, list(decl_atom), list(decl_atom))
@@ -311,7 +352,7 @@
 	(
 		maybe_redo_node_from_id(Store, RedoId, redo(_, ExitId))
 	->
-		exit_node_from_id(Store, ExitId, exit(_, _, NextId, Atom)),
+		exit_node_from_id(Store, ExitId, exit(_, _, NextId, Atom, _)),
 		get_answers(Store, NextId, [Atom | As0], As)
 	;
 		As = As0
@@ -321,14 +362,16 @@
 		<= annotated_trace(S, R).
 :- mode trace_root_e_bug(in, in, out) is det.
 
-trace_root_e_bug(S, T, Bug) :-
-	trace_root_question(S, T, Q),
+trace_root_e_bug(wrap(S), dynamic(Ref), Bug) :-
+	det_edt_node_from_id(S, Ref, Node),
 	(
-		Q = wrong_answer(Atom),
-		Bug = incorrect_contour(Atom, unit)
+		Node = exit(_, _, _, Atom, Event),
+		Bug = incorrect_contour(Atom, unit, Event)
 	;
-		Q = missing_answer(Atom, _),
-		Bug = partially_uncovered_atom(Atom)
+		Node = fail(_, CallId, _, Event),
+		call_node_from_id(S, CallId, Call),
+		Call = call(_, _, CallAtom, _, _, _),
+		Bug = partially_uncovered_atom(CallAtom, Event)
 	).
 
 :- pred trace_children(wrap(S), edt_node(R), list(edt_node(R)))
@@ -336,25 +379,23 @@
 :- mode trace_children(in, in, out) is semidet.
 
 trace_children(wrap(Store), dynamic(Ref), Children) :-
-		
-		% This is meant to fail if the children are implicit,
-		% but this is not yet implemented.
-		%
-	semidet_succeed,
-
-	det_trace_node_from_id(Store, Ref, Node),
+	det_edt_node_from_id(Store, Ref, Node),
 	(
-		Node = fail(PrecId, _, _)
-	->
+		Node = fail(PrecId, CallId, _, _),
+		not_at_depth_limit(Store, CallId),
 		missing_answer_children(Store, PrecId, [], Children)
 	;
-		Node = exit(PrecId, _, _, _)
-	->
+		Node = exit(PrecId, CallId, _, _, _),
+		not_at_depth_limit(Store, CallId),
 		wrong_answer_children(Store, PrecId, [], Children)
-	;
-		error("trace_children: not an EXIT or FAIL node")
 	).
 
+:- pred not_at_depth_limit(S, R) <= annotated_trace(S, R).
+:- mode not_at_depth_limit(in, in) is semidet.
+
+not_at_depth_limit(Store, Ref) :-
+	call_node_from_id(Store, Ref, call(_, _, _, _, _, no)).
+
 :- pred wrong_answer_children(S, R, list(edt_node(R)), list(edt_node(R)))
 		<= annotated_trace(S, R).
 :- mode wrong_answer_children(in, in, in, out) is det.
@@ -362,21 +403,21 @@
 wrong_answer_children(Store, NodeId, Ns0, Ns) :-
 	det_trace_node_from_id(Store, NodeId, Node),
 	(
-		Node = call(_, _, _, _),
+		Node = call(_, _, _, _, _, _),
 		Ns = Ns0
 	;
 		Node = neg(_, _, _),
 		Ns = Ns0
 	;
-		Node = exit(_, Call, _, _),
-		call_node_from_id(Store, Call, call(Prec, _, _, _)),
+		Node = exit(_, Call, _, _, _),
+		call_node_from_id(Store, Call, call(Prec, _, _, _, _, _)),
 		wrong_answer_children(Store, Prec, [dynamic(NodeId) | Ns0], Ns)
 	;
 		Node = redo(_, _),
 		error("wrong_answer_children: unexpected REDO node")
 	;
-		Node = fail(_, Call, _),
-		call_node_from_id(Store, Call, call(Prec, _, _, _)),
+		Node = fail(_, Call, _, _),
+		call_node_from_id(Store, Call, call(Prec, _, _, _, _, _)),
 		wrong_answer_children(Store, Prec, [dynamic(NodeId) | Ns0], Ns)
 	;
 		Node = cond(Prec, _, Flag),
@@ -424,28 +465,29 @@
 missing_answer_children(Store, NodeId, Ns0, Ns) :-
 	det_trace_node_from_id(Store, NodeId, Node),
 	(
-		Node = call(_, _, _, _),
+		Node = call(_, _, _, _, _, _),
 		Ns = Ns0
 	;
 		Node = neg(_, _, _),
 		Ns = Ns0
 	;
-		Node = exit(_, Call, Redo, _),
+		Node = exit(_, Call, Redo, _, _),
 		(
 			maybe_redo_node_from_id(Store, Redo, redo(Prec0, _))
 		->
 			Prec = Prec0
 		;
-			call_node_from_id(Store, Call, call(Prec, _, _, _))
+			call_node_from_id(Store, Call, CallNode),
+			CallNode = call(Prec, _, _, _, _, _)
 		),
 		missing_answer_children(Store, Prec, [dynamic(NodeId) | Ns0],
 				Ns)
 	;
 		Node = redo(_, Exit),
-		exit_node_from_id(Store, Exit, exit(Prec, _, _, _)),
+		exit_node_from_id(Store, Exit, exit(Prec, _, _, _, _)),
 		missing_answer_children(Store, Prec, Ns0, Ns)
 	;
-		Node = fail(_, CallId, MaybeRedo),
+		Node = fail(_, CallId, MaybeRedo, _),
 		(
 			maybe_redo_node_from_id(Store, MaybeRedo, Redo)
 		->
@@ -453,7 +495,7 @@
 			Next = Prec
 		;
 			call_node_from_id(Store, CallId, Call),
-			Call = call(Back, _, _, _),
+			Call = call(Back, _, _, _, _, _),
 			Next = Back
 		),
 		missing_answer_children(Store, Next, [dynamic(NodeId) | Ns0],
@@ -495,3 +537,52 @@
 		neg_node_from_id(Store, Neg, neg(Back, _, _)),
 		missing_answer_children(Store, Back, Ns1, Ns)
 	).
+
+:- pred edt_subtree_details(S, edt_node(R), event_number, sequence_number)
+		<= annotated_trace(S, R).
+:- mode edt_subtree_details(in, in, out, out) is det.
+
+edt_subtree_details(Store, dynamic(Ref), Event, SeqNo) :-
+	det_edt_node_from_id(Store, Ref, Node),
+	(
+		Node = exit(_, Call, _, _, Event)
+	;
+		Node = fail(_, Call, _, Event)
+	),
+	call_node_from_id(Store, Call, call(_, _, _, SeqNo, _, _)).
+
+:- inst trace_node_edt_node =
+		bound(	exit(ground, ground, ground, ground, ground)
+		;	fail(ground, ground, ground, ground)).
+
+:- pred det_edt_node_from_id(S, R, trace_node(R)) <= annotated_trace(S, R).
+:- mode det_edt_node_from_id(in, in, out(trace_node_edt_node)) is det.
+
+det_edt_node_from_id(Store, Ref, Node) :-
+	(
+		trace_node_from_id(Store, Ref, Node0),
+		(
+			Node0 = exit(_, _, _, _, _)
+		;
+			Node0 = fail(_, _, _, _)
+		)
+	->
+		Node = Node0
+	;
+		error("det_edt_node_from_id: not an EXIT or FAIL node")
+	).
+
+%-----------------------------------------------------------------------------%
+
+:- pred decl_bug_get_event_number(decl_bug, event_number).
+:- mode decl_bug_get_event_number(in, out) is det.
+
+decl_bug_get_event_number(e_bug(EBug), Event) :-
+	(
+		EBug = incorrect_contour(_, _, Event)
+	;
+		EBug = partially_uncovered_atom(_, Event)
+	).
+decl_bug_get_event_number(i_bug(IBug), Event) :-
+	IBug = inadmissible_call(_, _, _, Event).
+
Index: browser/declarative_execution.m
===================================================================
RCS file: /home/mercury1/repository/mercury/browser/declarative_execution.m,v
retrieving revision 1.7
diff -u -r1.7 declarative_execution.m
--- browser/declarative_execution.m	2000/03/01 04:17:23	1.7
+++ browser/declarative_execution.m	2000/03/01 23:50:32
@@ -16,7 +16,7 @@
 
 :- module mdb__declarative_execution.
 :- interface.
-:- import_module list, std_util, string, io.
+:- import_module list, std_util, string, io, bool.
 :- import_module mdb__util.
 
 	% This type represents a port in the annotated trace.
@@ -32,13 +32,16 @@
 			R,			% Preceding event.
 			R,			% Last EXIT or REDO event.
 			trace_atom,		% Atom that was called.
-			sequence_number		% Call sequence number.
+			sequence_number,	% Call sequence number.
+			event_number,		% Trace event number.
+			bool			% At the maximum depth?
 		)
 	;	exit(
 			R,			% Preceding event.
 			R,			% CALL event.
 			R,			% Previous REDO event, if any.
-			trace_atom		% Atom in its final state.
+			trace_atom,		% Atom in its final state.
+			event_number		% Trace event number.
 		)
 	;	redo(
 			R,			% Preceding event.
@@ -47,7 +50,8 @@
 	;	fail(
 			R,			% Preceding event.
 			R,			% CALL event.
-			R			% Previous REDO event, if any.
+			R,			% Previous REDO event, if any.
+			event_number		% Trace event number.
 		)
 	;	switch(
 			R,			% Preceding event.
@@ -117,6 +121,7 @@
 :- type goal_path == goal_path_string.
 
 :- type sequence_number == int.
+:- type event_number == int.
 
 	% Members of this typeclass represent an entire annotated
 	% trace.  The second parameter is the type of identifiers
@@ -141,7 +146,8 @@
 :- pred det_trace_node_from_id(S, R, trace_node(R)) <= annotated_trace(S, R).
 :- mode det_trace_node_from_id(in, in, out) is det.
 
-:- inst trace_node_call = bound(call(ground, ground, ground, ground)).
+:- inst trace_node_call =
+		bound(call(ground, ground, ground, ground, ground, ground)).
 
 :- pred call_node_from_id(S, R, trace_node(R)) <= annotated_trace(S, R).
 :- mode call_node_from_id(in, in, out(trace_node_call)) is det.
@@ -154,7 +160,7 @@
 :- pred maybe_redo_node_from_id(S, R, trace_node(R)) <= annotated_trace(S, R).
 :- mode maybe_redo_node_from_id(in, in, out(trace_node_redo)) is semidet.
 
-:- inst trace_node_exit = bound(exit(ground, ground, ground, ground)).
+:- inst trace_node_exit = bound(exit(ground, ground, ground, ground, ground)).
 
 :- pred exit_node_from_id(S, R, trace_node(R)) <= annotated_trace(S, R).
 :- mode exit_node_from_id(in, in, out(trace_node_exit)) is det.
@@ -230,7 +236,7 @@
 call_node_from_id(Store, NodeId, Node) :-
 	(
 		trace_node_from_id(Store, NodeId, Node0),
-		Node0 = call(_, _, _, _)
+		Node0 = call(_, _, _, _, _, _)
 	->
 		Node = Node0
 	;
@@ -250,7 +256,7 @@
 exit_node_from_id(Store, NodeId, Node) :-
 	(
 		trace_node_from_id(Store, NodeId, Node0),
-		Node0 = exit(_, _, _, _)
+		Node0 = exit(_, _, _, _, _)
 	->
 		Node = Node0
 	;
@@ -344,7 +350,7 @@
 
 call_node_get_last_interface(Call) = Last :-
 	(
-		Call = call(_, Last0, _, _)
+		Call = call(_, Last0, _, _, _, _)
 	->
 		Last = Last0
 	;
@@ -359,7 +365,7 @@
 
 call_node_set_last_interface(Call0, Last) = Call :-
 	(
-		Call0 = call(_, _, _, _)
+		Call0 = call(_, _, _, _, _, _)
 	->
 		Call1 = Call0
 	;
@@ -423,10 +429,10 @@
 :- pragma export(trace_node_port(in) = out,
 		"MR_DD_trace_node_port").
 
-trace_node_port(call(_, _, _, _))	= call.
-trace_node_port(exit(_, _, _, _))	= exit.
+trace_node_port(call(_, _, _, _, _, _))	= call.
+trace_node_port(exit(_, _, _, _, _))	= exit.
 trace_node_port(redo(_, _))		= redo.
-trace_node_port(fail(_, _, _))		= fail.
+trace_node_port(fail(_, _, _, _))	= fail.
 trace_node_port(switch(_, _))		= switch.
 trace_node_port(first_disj(_, _))	= disj.
 trace_node_port(later_disj(_, _, _))	= disj.
@@ -442,10 +448,10 @@
 :- pragma export(trace_node_path(in, in) = out,
 		"MR_DD_trace_node_path").
 
-trace_node_path(_, call(_, _, _, _)) = "".
-trace_node_path(_, exit(_, _, _, _)) = "".
+trace_node_path(_, call(_, _, _, _, _, _)) = "".
+trace_node_path(_, exit(_, _, _, _, _)) = "".
 trace_node_path(_, redo(_, _)) = "".
-trace_node_path(_, fail(_, _, _)) = "".
+trace_node_path(_, fail(_, _, _, _)) = "".
 trace_node_path(_, switch(_, P)) = P.
 trace_node_path(_, first_disj(_, P)) = P.
 trace_node_path(_, later_disj(_, P, _)) = P.
@@ -468,12 +474,12 @@
 
 trace_node_seqno(S, Node, SeqNo) :-
 	(
-		Node = call(_, _, _, SeqNo0)
+		Node = call(_, _, _, SeqNo0, _, _)
 	->
 		SeqNo = SeqNo0
 	;
 		trace_node_call(S, Node, Call),
-		call_node_from_id(S, Call, call(_, _, _, SeqNo))
+		call_node_from_id(S, Call, call(_, _, _, SeqNo, _, _))
 	).
 
 :- pred trace_node_call(trace_node_store, trace_node(trace_node_id),
@@ -482,10 +488,10 @@
 
 :- pragma export(trace_node_call(in, in, out), "MR_DD_trace_node_call").
 
-trace_node_call(_, exit(_, Call, _, _), Call).
+trace_node_call(_, exit(_, Call, _, _, _), Call).
 trace_node_call(S, redo(_, Exit), Call) :-
-	exit_node_from_id(S, Exit, exit(_, Call, _, _)).
-trace_node_call(_, fail(_, Call, _), Call).
+	exit_node_from_id(S, Exit, exit(_, Call, _, _, _)).
+trace_node_call(_, fail(_, Call, _, _), Call).
 
 :- pred trace_node_first_disj(trace_node(trace_node_id), trace_node_id).
 :- mode trace_node_first_disj(in, out) is semidet.
@@ -509,7 +515,7 @@
 :- pragma export(step_left_in_context(in, in) = out,
 		"MR_DD_step_left_in_context").
 
-step_left_in_context(_, call(_, _, _, _)) = _ :-
+step_left_in_context(_, call(_, _, _, _, _, _)) = _ :-
 	error("step_left_in_context: unexpected CALL node").
 step_left_in_context(_, cond(Prec, _, Status)) = Node :-
 	(
@@ -521,10 +527,10 @@
 	).
 step_left_in_context(_, neg(_, _, _)) = _ :-
 	error("step_left_in_context: unexpected NEGE node").
-step_left_in_context(Store, exit(_, Call, _, _)) = Prec :-
-	call_node_from_id(Store, Call, call(Prec, _, _, _)).
-step_left_in_context(Store, fail(_, Call, _)) = Prec :-
-	call_node_from_id(Store, Call, call(Prec, _, _, _)).
+step_left_in_context(Store, exit(_, Call, _, _, _)) = Prec :-
+	call_node_from_id(Store, Call, call(Prec, _, _, _, _, _)).
+step_left_in_context(Store, fail(_, Call, _, _)) = Prec :-
+	call_node_from_id(Store, Call, call(Prec, _, _, _, _, _)).
 step_left_in_context(_, redo(_, _)) = _ :-
 	error("step_left_in_context: unexpected REDO node").
 step_left_in_context(_, switch(Prec, _)) = Prec.
@@ -555,13 +561,13 @@
 		trace_node(trace_node_id), trace_node_id).
 :- mode find_prev_contour_1(in, in, in, out) is det.
 
-find_prev_contour_1(_, _, call(_, _, _, _), _) :-
+find_prev_contour_1(_, _, call(_, _, _, _, _, _), _) :-
 	error("find_prev_contour: reached CALL node").
-find_prev_contour_1(_, Exit, exit(_, _, _, _), Exit).
+find_prev_contour_1(_, Exit, exit(_, _, _, _, _), Exit).
 find_prev_contour_1(Store, _, redo(_, Exit), OnContour) :-
-	exit_node_from_id(Store, Exit, exit(OnContour, _, _, _)).
-find_prev_contour_1(Store, _, fail(_, Call, _), OnContour) :-
-	call_node_from_id(Store, Call, call(OnContour, _, _, _)).
+	exit_node_from_id(Store, Exit, exit(OnContour, _, _, _, _)).
+find_prev_contour_1(Store, _, fail(_, Call, _, _), OnContour) :-
+	call_node_from_id(Store, Call, call(OnContour, _, _, _, _, _)).
 find_prev_contour_1(_, _, cond(_, _, _), _) :-
 	error("find_prev_contour: reached COND node").
 find_prev_contour_1(_, Then, then(_, _), Then).
@@ -595,23 +601,23 @@
 	% that the back end can build an execution tree.
 	%
 
-:- func construct_call_node(trace_node_id, trace_atom, sequence_number)
-		= trace_node(trace_node_id).
-:- pragma export(construct_call_node(in, in, in) = out,
+:- func construct_call_node(trace_node_id, trace_atom, sequence_number,
+		event_number, bool) = trace_node(trace_node_id).
+:- pragma export(construct_call_node(in, in, in, in, in) = out,
 		"MR_DD_construct_call_node").
 
-construct_call_node(Preceding, Atom, SeqNo) = Call :-
-	Call = call(Preceding, Answer, Atom, SeqNo),
+construct_call_node(Preceding, Atom, SeqNo, EventNo, MaxDepth) = Call :-
+	Call = call(Preceding, Answer, Atom, SeqNo, EventNo, MaxDepth),
 	null_trace_node_id(Answer).
 
 
 :- func construct_exit_node(trace_node_id, trace_node_id, trace_node_id,
-		trace_atom) = trace_node(trace_node_id).
-:- pragma export(construct_exit_node(in, in, in, in) = out,
+		trace_atom, event_number) = trace_node(trace_node_id).
+:- pragma export(construct_exit_node(in, in, in, in, in) = out,
 		"MR_DD_construct_exit_node").
 
-construct_exit_node(Preceding, Call, MaybeRedo, Atom)
-		= exit(Preceding, Call, MaybeRedo, Atom).
+construct_exit_node(Preceding, Call, MaybeRedo, Atom, EventNo)
+		= exit(Preceding, Call, MaybeRedo, Atom, EventNo).
 
 
 :- func construct_redo_node(trace_node_id, trace_node_id)
@@ -622,12 +628,13 @@
 construct_redo_node(Preceding, Exit) = redo(Preceding, Exit).
 
 
-:- func construct_fail_node(trace_node_id, trace_node_id, trace_node_id)
-		= trace_node(trace_node_id).
-:- pragma export(construct_fail_node(in, in, in) = out,
+:- func construct_fail_node(trace_node_id, trace_node_id, trace_node_id,
+		event_number) = trace_node(trace_node_id).
+:- pragma export(construct_fail_node(in, in, in, in) = out,
 		"MR_DD_construct_fail_node").
 
-construct_fail_node(Preceding, Call, Redo) = fail(Preceding, Call, Redo).
+construct_fail_node(Preceding, Call, Redo, EventNo) =
+		fail(Preceding, Call, Redo, EventNo).
 
 
 :- func construct_switch_node(trace_node_id, goal_path_string)
@@ -833,10 +840,10 @@
 	%
 :- func preceding_node(trace_node(T)) = T.
 
-preceding_node(call(P, _, _, _))	= P.
-preceding_node(exit(P, _, _, _))	= P.
+preceding_node(call(P, _, _, _, _, _))	= P.
+preceding_node(exit(P, _, _, _, _))	= P.
 preceding_node(redo(P, _))		= P.
-preceding_node(fail(P, _, _))		= P.
+preceding_node(fail(P, _, _, _))	= P.
 preceding_node(switch(P, _))		= P.
 preceding_node(first_disj(P, _))	= P.
 preceding_node(later_disj(P, _, _))	= P.
Index: browser/declarative_user.m
===================================================================
RCS file: /home/mercury1/repository/mercury/browser/declarative_user.m,v
retrieving revision 1.6
diff -u -r1.6 declarative_user.m
--- browser/declarative_user.m	2000/03/01 04:17:23	1.6
+++ browser/declarative_user.m	2000/03/01 23:50:35
@@ -279,18 +279,18 @@
 write_decl_bug(e_bug(EBug), User) -->
 	{ User = user(_, OutStr) },
 	(
-		{ EBug = incorrect_contour(Atom, _) },
+		{ EBug = incorrect_contour(Atom, _, _) },
 		io__write_string(OutStr, "Found incorrect contour:\n"),
 		write_decl_atom(OutStr, "", Atom)
 	;
-		{ EBug = partially_uncovered_atom(Atom) },
+		{ EBug = partially_uncovered_atom(Atom, _) },
 		io__write_string(OutStr, "Found partially uncovered atom:\n"),
 		write_decl_atom(OutStr, "", Atom)
 	).
 
 write_decl_bug(i_bug(IBug), User) -->
 	{ User = user(_, OutStr) },
-	{ IBug = inadmissible_call(Parent, _, Call) },
+	{ IBug = inadmissible_call(Parent, _, Call, _) },
 	io__write_string(OutStr, "Found inadmissible call:\n"),
 	write_decl_atom(OutStr, "Parent", Parent),
 	write_decl_atom(OutStr, "Call ", Call).
Index: tests/debugger/declarative/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/debugger/declarative/Mmakefile,v
retrieving revision 1.12
diff -u -r1.12 Mmakefile
--- tests/debugger/declarative/Mmakefile	2000/02/22 10:46:05	1.12
+++ tests/debugger/declarative/Mmakefile	2000/03/01 23:50:50
@@ -22,6 +22,7 @@
 	args			\
 	backtrack		\
 	big			\
+	filter			\
 	gcf			\
 	if_then_else		\
 	lpe_example		\
@@ -87,6 +88,9 @@
 
 family.out: family family.inp
 	$(MDB) ./family < family.inp > family.out 2>&1
+
+filter.out: filter filter.inp
+	$(MDB) ./filter < filter.inp > filter.out 2>&1
 
 gcf.out: gcf gcf.inp
 	$(MDB) ./gcf < gcf.inp > gcf.out 2>&1
Index: tests/debugger/declarative/aadebug.exp
===================================================================
RCS file: /home/mercury1/repository/tests/debugger/declarative/aadebug.exp,v
retrieving revision 1.4
diff -u -r1.4 aadebug.exp
--- tests/debugger/declarative/aadebug.exp	2000/03/01 04:17:24	1.4
+++ tests/debugger/declarative/aadebug.exp	2000/03/01 23:50:51
@@ -9,8 +9,6 @@
 mdb> finish
       15:      2  2 EXIT pred aadebug:p/2-0 (nondet) aadebug.m:24 (aadebug.m:9)
 mdb> dd
-p('a', 30)
-Valid? no
 q('a', 'a')
 Valid? yes
 r('a', 10)
@@ -26,8 +24,6 @@
 mdb> finish
       20:      2  2 EXIT pred aadebug:p/2-0 (nondet) aadebug.m:24 (aadebug.m:9)
 mdb> dd
-p('a', 31)
-Valid? no
 Found incorrect contour:
 p('a', 31)
 Is this a bug? yes
@@ -37,8 +33,6 @@
 mdb> finish
       35:      2  2 EXIT pred aadebug:p/2-0 (nondet) aadebug.m:24 (aadebug.m:9)
 mdb> dd
-p('a', 32)
-Valid? no
 q('a', 'b')
 Valid? yes
 Call r('b', _)
@@ -56,12 +50,6 @@
 mdb> finish
       41:      2  2 FAIL pred aadebug:p/2-0 (nondet) aadebug.m:24 (aadebug.m:9)
 mdb> dd
-Call p('a', _)
-Solutions:
-	p('a', 30)
-	p('a', 31)
-	p('a', 32)
-Complete? no
 Call q('a', _)
 Solutions:
 	q('a', 'a')
Index: tests/debugger/declarative/aadebug.exp2
===================================================================
RCS file: /home/mercury1/repository/tests/debugger/declarative/aadebug.exp2,v
retrieving revision 1.3
diff -u -r1.3 aadebug.exp2
--- tests/debugger/declarative/aadebug.exp2	2000/03/01 04:17:24	1.3
+++ tests/debugger/declarative/aadebug.exp2	2000/03/01 23:50:51
@@ -9,8 +9,6 @@
 mdb> finish
       15:      2  2 EXIT pred aadebug:p/2-0 (nondet) aadebug.m:24 (aadebug.m:9)
 mdb> dd
-p('a', 30)
-Valid? no
 q('a', 'a')
 Valid? yes
 r('a', 10)
@@ -26,8 +24,6 @@
 mdb> finish
       22:      2  2 EXIT pred aadebug:p/2-0 (nondet) aadebug.m:24 (aadebug.m:9)
 mdb> dd
-p('a', 31)
-Valid? no
 Found incorrect contour:
 p('a', 31)
 Is this a bug? yes
@@ -37,8 +33,6 @@
 mdb> finish
       39:      2  2 EXIT pred aadebug:p/2-0 (nondet) aadebug.m:24 (aadebug.m:9)
 mdb> dd
-p('a', 32)
-Valid? no
 q('a', 'b')
 Valid? yes
 Call r('b', _)
@@ -56,12 +50,6 @@
 mdb> finish
       47:      2  2 FAIL pred aadebug:p/2-0 (nondet) aadebug.m:24 (aadebug.m:9)
 mdb> dd
-Call p('a', _)
-Solutions:
-	p('a', 30)
-	p('a', 31)
-	p('a', 32)
-Complete? no
 Call q('a', _)
 Solutions:
 	q('a', 'a')
Index: tests/debugger/declarative/aadebug.inp
===================================================================
RCS file: /home/mercury1/repository/tests/debugger/declarative/aadebug.inp,v
retrieving revision 1.3
diff -u -r1.3 aadebug.inp
--- tests/debugger/declarative/aadebug.inp	2000/02/22 10:46:10	1.3
+++ tests/debugger/declarative/aadebug.inp	2000/03/01 23:50:51
@@ -4,7 +4,6 @@
 continue
 finish
 dd
-no
 yes
 yes
 yes
@@ -12,12 +11,10 @@
 continue
 finish
 dd
-no
 yes
 continue
 finish
 dd
-no
 yes
 yes
 yes
@@ -25,7 +22,6 @@
 continue
 finish
 dd
-no
 yes
 yes
 continue
Index: tests/debugger/declarative/app.exp
===================================================================
RCS file: /home/mercury1/repository/tests/debugger/declarative/app.exp,v
retrieving revision 1.6
diff -u -r1.6 app.exp
--- tests/debugger/declarative/app.exp	2000/03/01 04:17:25	1.6
+++ tests/debugger/declarative/app.exp	2000/03/01 23:50:53
@@ -15,8 +15,11 @@
 mdb> finish -n
       16:      5  5 EXIT pred app:app/3-0 (det) app.m:26 (app.m:28)
 mdb> dd
-app([4, 5], [6, 7, 8], [4, 5, 6, 7, 8])
+app([5], [6, 7, 8], [5, 6, 7, 8])
 Valid? yes
+Found incorrect contour:
+app([4, 5], [6, 7, 8], [4, 5, 6, 7, 8])
+Is this a bug? yes
       16:      5  5 EXIT pred app:app/3-0 (det) app.m:26 (app.m:28)
 mdb> continue
       17:      4  4 EXIT pred app:app/3-0 (det) app.m:26 (app.m:28)
@@ -25,15 +28,21 @@
 mdb> continue
       19:      2  2 EXIT pred app:app/3-0 (det) app.m:26 (app.m:13)
 mdb> dd
-app([1, 2, 3, 4, 5], [6, 7, 8], [1, 2, 3, 4, 5, 6, 7, 8])
-Valid? no
 app([2, 3, 4, 5], [6, 7, 8], [2, 3, 4, 5, 6, 7, 8])
 Valid? no
 app([3, 4, 5], [6, 7, 8], [3, 4, 5, 6, 7, 8])
 Valid? no
+app([4, 5], [6, 7, 8], [4, 5, 6, 7, 8])
+Valid? no
 Found incorrect contour:
-app([3, 4, 5], [6, 7, 8], [3, 4, 5, 6, 7, 8])
+app([4, 5], [6, 7, 8], [4, 5, 6, 7, 8])
 Is this a bug? yes
+      16:      5  5 EXIT pred app:app/3-0 (det) app.m:26 (app.m:28)
+mdb> continue
+      17:      4  4 EXIT pred app:app/3-0 (det) app.m:26 (app.m:28)
+mdb> continue
+      18:      3  3 EXIT pred app:app/3-0 (det) app.m:26 (app.m:28)
+mdb> continue
       19:      2  2 EXIT pred app:app/3-0 (det) app.m:26 (app.m:13)
 mdb> continue
 append([1, 2, 3, 4, 5], [6, 7, 8], [1, 2, 3, 4, 5, 6, 7, 8]).
@@ -41,8 +50,6 @@
 mdb> finish -n
       67:      8  2 EXIT pred app:app/3-0 (det) app.m:26 (app.m:18)
 mdb> dd
-app([1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5], [6, 7, 8], [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8])
-Valid? no
 app([2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5], [6, 7, 8], [2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8])
 Valid? no
 app([3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5], [6, 7, 8], [3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8])
@@ -61,9 +68,13 @@
 Valid? no
 app([0, 1, 2, 3, 4, 5], [6, 7, 8], [0, 1, 2, 3, 4, 5, 6, 7, 8])
 Valid? no
+app([1, 2, 3, 4, 5], [6, 7, 8], [1, 2, 3, 4, 5, 6, 7, 8])
+Valid? no
 Found incorrect contour:
-app([3, 4, 5], [6, 7, 8], [3, 4, 5, 6, 7, 8])
+app([4, 5], [6, 7, 8], [4, 5, 6, 7, 8])
 Is this a bug? yes
-      67:      8  2 EXIT pred app:app/3-0 (det) app.m:26 (app.m:18)
+      54:     21 15 EXIT pred app:app/3-0 (det) app.m:26 (app.m:28)
 mdb> continue
-append([1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5], [6, 7, 8], [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8]).
+      55:     20 14 EXIT pred app:app/3-0 (det) app.m:26 (app.m:28)
+mdb> quit
+mdb: are you sure you want to quit? y
Index: tests/debugger/declarative/app.exp2
===================================================================
RCS file: /home/mercury1/repository/tests/debugger/declarative/app.exp2,v
retrieving revision 1.6
diff -u -r1.6 app.exp2
--- tests/debugger/declarative/app.exp2	2000/03/01 04:17:25	1.6
+++ tests/debugger/declarative/app.exp2	2000/03/01 23:50:53
@@ -15,8 +15,11 @@
 mdb> finish -n
       16:      5  5 EXIT pred app:app/3-0 (det) app.m:26 (app.m:28)
 mdb> dd
-app([4, 5], [6, 7, 8], [4, 5, 6, 7, 8])
+app([5], [6, 7, 8], [5, 6, 7, 8])
 Valid? yes
+Found incorrect contour:
+app([4, 5], [6, 7, 8], [4, 5, 6, 7, 8])
+Is this a bug? yes
       16:      5  5 EXIT pred app:app/3-0 (det) app.m:26 (app.m:28)
 mdb> continue
       17:      4  4 EXIT pred app:app/3-0 (det) app.m:26 (app.m:28)
@@ -25,24 +28,28 @@
 mdb> continue
       19:      2  2 EXIT pred app:app/3-0 (det) app.m:26 (app.m:13)
 mdb> dd
-app([1, 2, 3, 4, 5], [6, 7, 8], [1, 2, 3, 4, 5, 6, 7, 8])
-Valid? no
 app([2, 3, 4, 5], [6, 7, 8], [2, 3, 4, 5, 6, 7, 8])
 Valid? no
 app([3, 4, 5], [6, 7, 8], [3, 4, 5, 6, 7, 8])
 Valid? no
+app([4, 5], [6, 7, 8], [4, 5, 6, 7, 8])
+Valid? no
 Found incorrect contour:
-app([3, 4, 5], [6, 7, 8], [3, 4, 5, 6, 7, 8])
+app([4, 5], [6, 7, 8], [4, 5, 6, 7, 8])
 Is this a bug? yes
+      16:      5  5 EXIT pred app:app/3-0 (det) app.m:26 (app.m:28)
+mdb> continue
+      17:      4  4 EXIT pred app:app/3-0 (det) app.m:26 (app.m:28)
+mdb> continue
+      18:      3  3 EXIT pred app:app/3-0 (det) app.m:26 (app.m:28)
+mdb> continue
       19:      2  2 EXIT pred app:app/3-0 (det) app.m:26 (app.m:13)
 mdb> continue
 append([1, 2, 3, 4, 5], [6, 7, 8], [1, 2, 3, 4, 5, 6, 7, 8]).
-      24:    608  2 CALL pred app:app/3-0 (det) app.m:26 (app.m:18)
+      24:     10  2 CALL pred app:app/3-0 (det) app.m:26 (app.m:18)
 mdb> finish -n
-      71:    608  2 EXIT pred app:app/3-0 (det) app.m:26 (app.m:18)
+      71:     10  2 EXIT pred app:app/3-0 (det) app.m:26 (app.m:18)
 mdb> dd
-app([1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5], [6, 7, 8], [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8])
-Valid? no
 app([2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5], [6, 7, 8], [2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8])
 Valid? no
 app([3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5], [6, 7, 8], [3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8])
@@ -61,9 +68,13 @@
 Valid? no
 app([0, 1, 2, 3, 4, 5], [6, 7, 8], [0, 1, 2, 3, 4, 5, 6, 7, 8])
 Valid? no
+app([1, 2, 3, 4, 5], [6, 7, 8], [1, 2, 3, 4, 5, 6, 7, 8])
+Valid? no
 Found incorrect contour:
-app([3, 4, 5], [6, 7, 8], [3, 4, 5, 6, 7, 8])
+app([4, 5], [6, 7, 8], [4, 5, 6, 7, 8])
 Is this a bug? yes
-      71:    608  2 EXIT pred app:app/3-0 (det) app.m:26 (app.m:18)
+      58:     23 15 EXIT pred app:app/3-0 (det) app.m:26 (app.m:28)
 mdb> continue
-append([1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5], [6, 7, 8], [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8]).
+      59:     22 14 EXIT pred app:app/3-0 (det) app.m:26 (app.m:28)
+mdb> quit
+mdb: are you sure you want to quit? y
Index: tests/debugger/declarative/app.inp
===================================================================
RCS file: /home/mercury1/repository/tests/debugger/declarative/app.inp,v
retrieving revision 1.4
diff -u -r1.4 app.inp
--- tests/debugger/declarative/app.inp	2000/02/22 10:46:11	1.4
+++ tests/debugger/declarative/app.inp	2000/03/01 23:50:53
@@ -8,6 +8,7 @@
 finish -n
 dd
 yes
+yes
 continue
 continue
 continue
@@ -17,6 +18,9 @@
 no
 yes
 continue
+continue
+continue
+continue
 finish -n
 dd
 no
@@ -31,4 +35,6 @@
 no
 yes
 continue
+quit
+y
 
Index: tests/debugger/declarative/args.exp
===================================================================
RCS file: /home/mercury1/repository/tests/debugger/declarative/args.exp,v
retrieving revision 1.2
diff -u -r1.2 args.exp
--- tests/debugger/declarative/args.exp	2000/03/01 04:17:25	1.2
+++ tests/debugger/declarative/args.exp	2000/03/01 23:50:53
@@ -9,8 +9,6 @@
 mdb> finish
        7:      2  2 EXIT pred args:p/5-0 (nondet) args.m:24 (args.m:10)
 mdb> dd
-p(1, 16, 3, 20, 5)
-Valid? no
 my_succeed
 Valid? yes
 Found incorrect contour:
@@ -22,8 +20,6 @@
 mdb> finish
       14:      2  2 EXIT pred args:p/5-0 (nondet) args.m:24 (args.m:10)
 mdb> dd
-p(1, -2, 3, 2, 5)
-Valid? no
 Found incorrect contour:
 p(1, -2, 3, 2, 5)
 Is this a bug? yes
@@ -33,11 +29,6 @@
 mdb> finish
       18:      2  2 FAIL pred args:p/5-0 (nondet) args.m:24 (args.m:10)
 mdb> dd
-Call p(1, _, 3, _, 5)
-Solutions:
-	p(1, 16, 3, 20, 5)
-	p(1, -2, 3, 2, 5)
-Complete? no
 Found partially uncovered atom:
 p(1, _, 3, _, 5)
 Is this a bug? yes
Index: tests/debugger/declarative/args.exp2
===================================================================
RCS file: /home/mercury1/repository/tests/debugger/declarative/args.exp2,v
retrieving revision 1.2
diff -u -r1.2 args.exp2
--- tests/debugger/declarative/args.exp2	2000/03/01 04:17:25	1.2
+++ tests/debugger/declarative/args.exp2	2000/03/01 23:50:54
@@ -9,8 +9,6 @@
 mdb> finish
        9:      2  2 EXIT pred args:p/5-0 (nondet) args.m:24 (args.m:10)
 mdb> dd
-p(1, 16, 3, 20, 5)
-Valid? no
 my_succeed
 Valid? yes
 Found incorrect contour:
@@ -22,8 +20,6 @@
 mdb> finish
       20:      2  2 EXIT pred args:p/5-0 (nondet) args.m:24 (args.m:10)
 mdb> dd
-p(1, -2, 3, 2, 5)
-Valid? no
 Found incorrect contour:
 p(1, -2, 3, 2, 5)
 Is this a bug? yes
@@ -33,11 +29,6 @@
 mdb> finish
       26:      2  2 FAIL pred args:p/5-0 (nondet) args.m:24 (args.m:10)
 mdb> dd
-Call p(1, _, 3, _, 5)
-Solutions:
-	p(1, 16, 3, 20, 5)
-	p(1, -2, 3, 2, 5)
-Complete? no
 Found partially uncovered atom:
 p(1, _, 3, _, 5)
 Is this a bug? yes
Index: tests/debugger/declarative/args.inp
===================================================================
RCS file: /home/mercury1/repository/tests/debugger/declarative/args.inp,v
retrieving revision 1.1
diff -u -r1.1 args.inp
--- tests/debugger/declarative/args.inp	2000/02/22 10:46:13	1.1
+++ tests/debugger/declarative/args.inp	2000/03/01 23:50:54
@@ -4,18 +4,15 @@
 continue
 finish
 dd
-no
 yes
 yes
 continue
 finish
 dd
-no
 yes
 continue
 finish
 dd
-no
 yes
 continue
 
Index: tests/debugger/declarative/backtrack.exp
===================================================================
RCS file: /home/mercury1/repository/tests/debugger/declarative/backtrack.exp,v
retrieving revision 1.3
diff -u -r1.3 backtrack.exp
--- tests/debugger/declarative/backtrack.exp	2000/03/01 04:17:25	1.3
+++ tests/debugger/declarative/backtrack.exp	2000/03/01 23:50:54
@@ -9,8 +9,6 @@
 mdb> finish
       17:      2  2 EXIT pred backtrack:p/2-0 (det) backtrack.m:23 (backtrack.m:9)
 mdb> dd
-p(1, no)
-Valid? no
 q(1, 1)
 Valid? yes
 q(1, 2)
Index: tests/debugger/declarative/backtrack.inp
===================================================================
RCS file: /home/mercury1/repository/tests/debugger/declarative/backtrack.inp,v
retrieving revision 1.2
diff -u -r1.2 backtrack.inp
--- tests/debugger/declarative/backtrack.inp	2000/02/22 10:46:15	1.2
+++ tests/debugger/declarative/backtrack.inp	2000/03/01 23:50:54
@@ -4,7 +4,6 @@
 continue
 finish
 dd
-no
 yes
 yes
 yes
Index: tests/debugger/declarative/big.exp
===================================================================
RCS file: /home/mercury1/repository/tests/debugger/declarative/big.exp,v
retrieving revision 1.4
diff -u -r1.4 big.exp
--- tests/debugger/declarative/big.exp	2000/03/01 04:17:25	1.4
+++ tests/debugger/declarative/big.exp	2000/03/01 23:50:55
@@ -9,8 +9,6 @@
 mdb> finish
       26:      2  2 EXIT pred big:p/1-0 (nondet) big.m:23 (big.m:11)
 mdb> dd
-p(-12)
-Valid? no
 a(0)
 Valid? yes
 b(0, 0)
@@ -33,8 +31,6 @@
 mdb> finish
       33:      2  2 EXIT pred big:p/1-0 (nondet) big.m:23 (big.m:11)
 mdb> dd
-p(-14)
-Valid? no
 c(2, 7)
 Valid? yes
 f(7, -14)
@@ -48,8 +44,6 @@
 mdb> finish
       65:      2  2 EXIT pred big:p/1-0 (nondet) big.m:23 (big.m:11)
 mdb> dd
-p(-20)
-Valid? no
 b(0, 1)
 Valid? yes
 c(1, 15)
@@ -73,8 +67,6 @@
 mdb> finish
       72:      2  2 EXIT pred big:p/1-0 (nondet) big.m:23 (big.m:11)
 mdb> dd
-p(-22)
-Valid? no
 e(1, 11)
 Valid? yes
 f(11, -22)
@@ -88,8 +80,6 @@
 mdb> finish
      109:      2  2 EXIT pred big:p/1-0 (nondet) big.m:23 (big.m:11)
 mdb> dd
-p(2)
-Valid? no
 f(0, 0)
 Valid? yes
 g(1, -1)
@@ -114,14 +104,6 @@
 mdb> finish
      137:      2  2 FAIL pred big:p/1-0 (nondet) big.m:23 (big.m:11)
 mdb> dd
-Call p(_)
-Solutions:
-	p(-12)
-	p(-14)
-	p(-20)
-	p(-22)
-	p(2)
-Complete? no
 c(0, 3)
 Valid? yes
 d(3, 9)
Index: tests/debugger/declarative/big.exp2
===================================================================
RCS file: /home/mercury1/repository/tests/debugger/declarative/big.exp2,v
retrieving revision 1.4
diff -u -r1.4 big.exp2
--- tests/debugger/declarative/big.exp2	2000/03/01 04:17:25	1.4
+++ tests/debugger/declarative/big.exp2	2000/03/01 23:50:56
@@ -9,8 +9,6 @@
 mdb> finish
       28:      2  2 EXIT pred big:p/1-0 (nondet) big.m:23 (big.m:11)
 mdb> dd
-p(-12)
-Valid? no
 a(0)
 Valid? yes
 b(0, 0)
@@ -33,8 +31,6 @@
 mdb> finish
       35:      2  2 EXIT pred big:p/1-0 (nondet) big.m:23 (big.m:11)
 mdb> dd
-p(-14)
-Valid? no
 c(2, 7)
 Valid? yes
 f(7, -14)
@@ -48,8 +44,6 @@
 mdb> finish
       71:      2  2 EXIT pred big:p/1-0 (nondet) big.m:23 (big.m:11)
 mdb> dd
-p(-20)
-Valid? no
 b(0, 1)
 Valid? yes
 c(1, 15)
@@ -73,8 +67,6 @@
 mdb> finish
       78:      2  2 EXIT pred big:p/1-0 (nondet) big.m:23 (big.m:11)
 mdb> dd
-p(-22)
-Valid? no
 e(1, 11)
 Valid? yes
 f(11, -22)
@@ -88,8 +80,6 @@
 mdb> finish
      115:      2  2 EXIT pred big:p/1-0 (nondet) big.m:23 (big.m:11)
 mdb> dd
-p(2)
-Valid? no
 f(0, 0)
 Valid? yes
 g(1, -1)
@@ -114,14 +104,6 @@
 mdb> finish
      143:      2  2 FAIL pred big:p/1-0 (nondet) big.m:23 (big.m:11)
 mdb> dd
-Call p(_)
-Solutions:
-	p(-12)
-	p(-14)
-	p(-20)
-	p(-22)
-	p(2)
-Complete? no
 c(0, 3)
 Valid? yes
 d(3, 9)
Index: tests/debugger/declarative/big.inp
===================================================================
RCS file: /home/mercury1/repository/tests/debugger/declarative/big.inp,v
retrieving revision 1.3
diff -u -r1.3 big.inp
--- tests/debugger/declarative/big.inp	2000/02/22 10:46:16	1.3
+++ tests/debugger/declarative/big.inp	2000/03/01 23:50:56
@@ -4,7 +4,6 @@
 continue
 finish
 dd
-no
 yes
 yes
 yes
@@ -15,14 +14,12 @@
 continue
 finish
 dd
-no
 yes
 yes
 yes
 continue
 finish
 dd
-no
 yes
 yes
 yes
@@ -33,14 +30,12 @@
 continue
 finish
 dd
-no
 yes
 yes
 yes
 continue
 finish
 dd
-no
 yes
 yes
 yes
@@ -51,7 +46,6 @@
 continue
 finish
 dd
-no
 yes
 yes
 yes
Index: tests/debugger/declarative/gcf.exp
===================================================================
RCS file: /home/mercury1/repository/tests/debugger/declarative/gcf.exp,v
retrieving revision 1.6
diff -u -r1.6 gcf.exp
--- tests/debugger/declarative/gcf.exp	2000/03/01 04:17:26	1.6
+++ tests/debugger/declarative/gcf.exp	2000/03/01 23:50:56
@@ -9,8 +9,6 @@
 mdb> finish
       23:      2  2 EXIT pred gcf:a/1-0 (nondet) gcf.m:26 (gcf.m:10)
 mdb> dd
-a(11)
-Valid? no
 g(2)
 Valid? yes
 c(2, 11)
@@ -26,8 +24,6 @@
 mdb> finish
       30:      2  2 EXIT pred gcf:a/1-0 (nondet) gcf.m:26 (gcf.m:10)
 mdb> dd
-a(12)
-Valid? no
 c(2, 12)
 Valid? yes
 f(12)
@@ -41,8 +37,6 @@
 mdb> finish
       42:      2  2 EXIT pred gcf:a/1-0 (nondet) gcf.m:26 (gcf.m:10)
 mdb> dd
-a(20)
-Valid? no
 g(3)
 Valid? yes
 c(3, 20)
Index: tests/debugger/declarative/gcf.inp
===================================================================
RCS file: /home/mercury1/repository/tests/debugger/declarative/gcf.inp,v
retrieving revision 1.4
diff -u -r1.4 gcf.inp
--- tests/debugger/declarative/gcf.inp	2000/02/22 10:46:17	1.4
+++ tests/debugger/declarative/gcf.inp	2000/03/01 23:50:56
@@ -4,7 +4,6 @@
 continue
 finish
 dd
-no
 yes
 yes
 yes
@@ -12,14 +11,12 @@
 continue
 finish
 dd
-no
 yes
 yes
 yes
 continue
 finish
 dd
-no
 yes
 yes
 yes
Index: tests/debugger/declarative/if_then_else.exp
===================================================================
RCS file: /home/mercury1/repository/tests/debugger/declarative/if_then_else.exp,v
retrieving revision 1.6
diff -u -r1.6 if_then_else.exp
--- tests/debugger/declarative/if_then_else.exp	2000/03/01 04:17:26	1.6
+++ tests/debugger/declarative/if_then_else.exp	2000/03/01 23:50:57
@@ -9,8 +9,6 @@
 mdb> finish
        9:      2  2 EXIT pred if_then_else:ite/2-0 (det) if_then_else.m:22 (if_then_else.m:8)
 mdb> dd
-ite(0, 1)
-Valid? no
 a(0)
 Valid? yes
 b(1)
@@ -25,8 +23,6 @@
 mdb> finish
       17:      5  2 EXIT pred if_then_else:ite/2-0 (det) if_then_else.m:22 (if_then_else.m:12)
 mdb> dd
-ite(1, 0)
-Valid? no
 Call a(1)
 No solutions.
 Complete? yes
Index: tests/debugger/declarative/if_then_else.exp2
===================================================================
RCS file: /home/mercury1/repository/tests/debugger/declarative/if_then_else.exp2,v
retrieving revision 1.6
diff -u -r1.6 if_then_else.exp2
--- tests/debugger/declarative/if_then_else.exp2	2000/03/01 04:17:26	1.6
+++ tests/debugger/declarative/if_then_else.exp2	2000/03/01 23:50:57
@@ -9,8 +9,6 @@
 mdb> finish
        9:      2  2 EXIT pred if_then_else:ite/2-0 (det) if_then_else.m:22 (if_then_else.m:8)
 mdb> dd
-ite(0, 1)
-Valid? no
 a(0)
 Valid? yes
 b(1)
@@ -21,18 +19,16 @@
        9:      2  2 EXIT pred if_then_else:ite/2-0 (det) if_then_else.m:22 (if_then_else.m:8)
 mdb> continue
 ite(0, 1).
-      16:    387  2 CALL pred if_then_else:ite/2-0 (det) if_then_else.m:22 (if_then_else.m:12)
+      16:      8  2 CALL pred if_then_else:ite/2-0 (det) if_then_else.m:22 (if_then_else.m:12)
 mdb> finish
-      23:    387  2 EXIT pred if_then_else:ite/2-0 (det) if_then_else.m:22 (if_then_else.m:12)
+      23:      8  2 EXIT pred if_then_else:ite/2-0 (det) if_then_else.m:22 (if_then_else.m:12)
 mdb> dd
-ite(1, 0)
-Valid? no
 Call a(1)
 No solutions.
 Complete? yes
 Found incorrect contour:
 ite(1, 0)
 Is this a bug? yes
-      23:    387  2 EXIT pred if_then_else:ite/2-0 (det) if_then_else.m:22 (if_then_else.m:12)
+      23:      8  2 EXIT pred if_then_else:ite/2-0 (det) if_then_else.m:22 (if_then_else.m:12)
 mdb> continue
 ite(1, 0).
Index: tests/debugger/declarative/if_then_else.inp
===================================================================
RCS file: /home/mercury1/repository/tests/debugger/declarative/if_then_else.inp,v
retrieving revision 1.4
diff -u -r1.4 if_then_else.inp
--- tests/debugger/declarative/if_then_else.inp	2000/02/22 10:46:19	1.4
+++ tests/debugger/declarative/if_then_else.inp	2000/03/01 23:50:57
@@ -4,14 +4,12 @@
 continue
 finish
 dd
-no
 yes
 yes
 yes
 continue
 finish
 dd
-no
 yes
 yes
 continue
Index: tests/debugger/declarative/lpe_example.exp
===================================================================
RCS file: /home/mercury1/repository/tests/debugger/declarative/lpe_example.exp,v
retrieving revision 1.5
diff -u -r1.5 lpe_example.exp
--- tests/debugger/declarative/lpe_example.exp	2000/03/01 07:53:58	1.5
+++ tests/debugger/declarative/lpe_example.exp	2000/03/01 23:50:57
@@ -11,8 +11,6 @@
 mdb> finish
       10:      2  2 EXIT pred lpe_example:p/2-0 (nondet)
 mdb> dd
-p(1, 13)
-Valid? no
 q(3)
 Valid? yes
 r(3, 13)
@@ -26,8 +24,6 @@
 mdb> finish
       15:      2  2 EXIT pred lpe_example:p/2-0 (nondet)
 mdb> dd
-p(1, 23)
-Valid? no
 r(3, 23)
 Valid? yes
 Found incorrect contour:
@@ -39,8 +35,6 @@
 mdb> finish
       20:      2  2 EXIT pred lpe_example:p/2-0 (nondet)
 mdb> dd
-p(1, 3)
-Valid? no
 Found incorrect contour:
 p(1, 3)
 Is this a bug? yes
@@ -50,12 +44,6 @@
 mdb> finish
       22:      2  2 FAIL pred lpe_example:p/2-0 (nondet)
 mdb> dd
-Call p(1, _)
-Solutions:
-	p(1, 13)
-	p(1, 23)
-	p(1, 3)
-Complete? no
 Call r(3, _)
 Solutions:
 	r(3, 13)
Index: tests/debugger/declarative/lpe_example.exp2
===================================================================
RCS file: /home/mercury1/repository/tests/debugger/declarative/lpe_example.exp2,v
retrieving revision 1.5
diff -u -r1.5 lpe_example.exp2
--- tests/debugger/declarative/lpe_example.exp2	2000/03/01 07:53:58	1.5
+++ tests/debugger/declarative/lpe_example.exp2	2000/03/01 23:50:58
@@ -11,8 +11,6 @@
 mdb> finish
       11:      3  3 EXIT pred lpe_example:p/2-0 (nondet)
 mdb> dd
-p(1, 13)
-Valid? no
 q(3)
 Valid? yes
 r(3, 13)
@@ -26,8 +24,6 @@
 mdb> finish
       16:      3  3 EXIT pred lpe_example:p/2-0 (nondet)
 mdb> dd
-p(1, 23)
-Valid? no
 r(3, 23)
 Valid? yes
 Found incorrect contour:
@@ -39,8 +35,6 @@
 mdb> finish
       21:      3  3 EXIT pred lpe_example:p/2-0 (nondet)
 mdb> dd
-p(1, 3)
-Valid? no
 Found incorrect contour:
 p(1, 3)
 Is this a bug? yes
@@ -50,12 +44,6 @@
 mdb> finish
       23:      3  3 FAIL pred lpe_example:p/2-0 (nondet)
 mdb> dd
-Call p(1, _)
-Solutions:
-	p(1, 13)
-	p(1, 23)
-	p(1, 3)
-Complete? no
 Call r(3, _)
 Solutions:
 	r(3, 13)
Index: tests/debugger/declarative/lpe_example.inp
===================================================================
RCS file: /home/mercury1/repository/tests/debugger/declarative/lpe_example.inp,v
retrieving revision 1.4
diff -u -r1.4 lpe_example.inp
--- tests/debugger/declarative/lpe_example.inp	2000/03/01 07:53:59	1.4
+++ tests/debugger/declarative/lpe_example.inp	2000/03/01 23:50:58
@@ -5,25 +5,21 @@
 continue
 finish
 dd
-no
 yes
 yes
 yes
 continue
 finish
 dd
-no
 yes
 yes
 continue
 finish
 dd
-no
 yes
 continue
 finish
 dd
-no
 yes
 yes
 continue
Index: tests/debugger/declarative/neg_conj.exp
===================================================================
RCS file: /home/mercury1/repository/tests/debugger/declarative/neg_conj.exp,v
retrieving revision 1.4
diff -u -r1.4 neg_conj.exp
--- tests/debugger/declarative/neg_conj.exp	2000/03/01 04:17:27	1.4
+++ tests/debugger/declarative/neg_conj.exp	2000/03/01 23:50:58
@@ -9,8 +9,6 @@
 mdb> finish
       18:      2  2 EXIT pred neg_conj:p/1-0 (semidet) neg_conj.m:19 (neg_conj.m:9)
 mdb> dd
-p(0)
-Valid? no
 q(0, 0)
 Valid? yes
 Call r(0)
Index: tests/debugger/declarative/neg_conj.inp
===================================================================
RCS file: /home/mercury1/repository/tests/debugger/declarative/neg_conj.inp,v
retrieving revision 1.3
diff -u -r1.3 neg_conj.inp
--- tests/debugger/declarative/neg_conj.inp	2000/02/22 10:46:22	1.3
+++ tests/debugger/declarative/neg_conj.inp	2000/03/01 23:50:58
@@ -4,7 +4,6 @@
 continue
 finish
 dd
-no
 yes
 yes
 yes
Index: tests/debugger/declarative/negation.exp
===================================================================
RCS file: /home/mercury1/repository/tests/debugger/declarative/negation.exp,v
retrieving revision 1.4
diff -u -r1.4 negation.exp
--- tests/debugger/declarative/negation.exp	2000/03/01 04:17:27	1.4
+++ tests/debugger/declarative/negation.exp	2000/03/01 23:50:58
@@ -9,8 +9,6 @@
 mdb> finish
       23:      2  2 EXIT pred negation:p/2-0 (det) negation.m:29 (negation.m:14)
 mdb> dd
-p(1, 42)
-Valid? no
 r(1, 11)
 Valid? yes
 q(11)
Index: tests/debugger/declarative/negation.inp
===================================================================
RCS file: /home/mercury1/repository/tests/debugger/declarative/negation.inp,v
retrieving revision 1.3
diff -u -r1.3 negation.inp
--- tests/debugger/declarative/negation.inp	2000/02/22 10:46:23	1.3
+++ tests/debugger/declarative/negation.inp	2000/03/01 23:50:58
@@ -4,7 +4,6 @@
 continue
 finish
 dd
-no
 yes
 yes
 yes
Index: tests/debugger/declarative/oracle_db.exp
===================================================================
RCS file: /home/mercury1/repository/tests/debugger/declarative/oracle_db.exp,v
retrieving revision 1.6
diff -u -r1.6 oracle_db.exp
--- tests/debugger/declarative/oracle_db.exp	2000/03/01 04:17:27	1.6
+++ tests/debugger/declarative/oracle_db.exp	2000/03/01 23:50:58
@@ -9,8 +9,6 @@
 mdb> finish
       10:      2  2 EXIT pred oracle_db:a/3-0 (semidet) oracle_db.m:19 (oracle_db.m:9)
 mdb> dd
-a(99, 99, 99)
-Valid? no
 b(99)
 Valid? yes
 Found incorrect contour:
Index: tests/debugger/declarative/oracle_db.inp
===================================================================
RCS file: /home/mercury1/repository/tests/debugger/declarative/oracle_db.inp,v
retrieving revision 1.4
diff -u -r1.4 oracle_db.inp
--- tests/debugger/declarative/oracle_db.inp	2000/02/22 10:46:24	1.4
+++ tests/debugger/declarative/oracle_db.inp	2000/03/01 23:50:58
@@ -4,7 +4,6 @@
 continue
 finish
 dd
-no
 yes
 yes
 continue
Index: tests/debugger/declarative/propositional.exp
===================================================================
RCS file: /home/mercury1/repository/tests/debugger/declarative/propositional.exp,v
retrieving revision 1.7
diff -u -r1.7 propositional.exp
--- tests/debugger/declarative/propositional.exp	2000/03/01 04:17:27	1.7
+++ tests/debugger/declarative/propositional.exp	2000/03/01 23:50:59
@@ -11,8 +11,6 @@
 mdb> finish
       11:      2  2 EXIT pred propositional:a/0-0 (semidet) propositional.m:27 (propositional.m:10)
 mdb> dd
-a
-Valid? no
 c
 Valid? yes
 Found incorrect contour:
@@ -24,8 +22,6 @@
 mdb> finish
       22:      5  2 EXIT pred propositional:b/0-0 (semidet) propositional.m:29 (propositional.m:10)
 mdb> dd
-b
-Valid? no
 f
 Valid? no
 i
@@ -33,6 +29,8 @@
 Found incorrect contour:
 f
 Is this a bug? yes
+      21:      6  3 EXIT pred propositional:f/0-0 (semidet) propositional.m:35 (propositional.m:29)
+mdb> continue
       22:      5  2 EXIT pred propositional:b/0-0 (semidet) propositional.m:29 (propositional.m:10)
 mdb> continue
 yes
Index: tests/debugger/declarative/propositional.exp2
===================================================================
RCS file: /home/mercury1/repository/tests/debugger/declarative/propositional.exp2,v
retrieving revision 1.6
diff -u -r1.6 propositional.exp2
--- tests/debugger/declarative/propositional.exp2	2000/03/01 04:17:27	1.6
+++ tests/debugger/declarative/propositional.exp2	2000/03/01 23:50:59
@@ -11,8 +11,6 @@
 mdb> finish
       15:      2  2 EXIT pred propositional:a/0-0 (semidet) propositional.m:27 (propositional.m:10)
 mdb> dd
-a
-Valid? no
 c
 Valid? yes
 Found incorrect contour:
@@ -20,12 +18,10 @@
 Is this a bug? yes
       15:      2  2 EXIT pred propositional:a/0-0 (semidet) propositional.m:27 (propositional.m:10)
 mdb> continue
-      16:    315  2 CALL pred propositional:b/0-0 (semidet) propositional.m:29 (propositional.m:10)
+      16:      7  2 CALL pred propositional:b/0-0 (semidet) propositional.m:29 (propositional.m:10)
 mdb> finish
-      30:    315  2 EXIT pred propositional:b/0-0 (semidet) propositional.m:29 (propositional.m:10)
+      30:      7  2 EXIT pred propositional:b/0-0 (semidet) propositional.m:29 (propositional.m:10)
 mdb> dd
-b
-Valid? no
 f
 Valid? no
 i
@@ -33,6 +29,8 @@
 Found incorrect contour:
 f
 Is this a bug? yes
-      30:    315  2 EXIT pred propositional:b/0-0 (semidet) propositional.m:29 (propositional.m:10)
+      29:      8  3 EXIT pred propositional:f/0-0 (semidet) propositional.m:35 (propositional.m:29)
+mdb> continue
+      30:      7  2 EXIT pred propositional:b/0-0 (semidet) propositional.m:29 (propositional.m:10)
 mdb> continue
 yes
Index: tests/debugger/declarative/propositional.inp
===================================================================
RCS file: /home/mercury1/repository/tests/debugger/declarative/propositional.inp,v
retrieving revision 1.5
diff -u -r1.5 propositional.inp
--- tests/debugger/declarative/propositional.inp	2000/02/22 10:46:26	1.5
+++ tests/debugger/declarative/propositional.inp	2000/03/01 23:50:59
@@ -5,14 +5,13 @@
 continue
 finish
 dd
-no
 yes
 yes
 continue
 finish
 dd
 no
-no
 yes
 yes
+continue
 continue
Index: tests/debugger/declarative/queens.exp
===================================================================
RCS file: /home/mercury1/repository/tests/debugger/declarative/queens.exp,v
retrieving revision 1.6
diff -u -r1.6 queens.exp
--- tests/debugger/declarative/queens.exp	2000/03/01 04:17:27	1.6
+++ tests/debugger/declarative/queens.exp	2000/03/01 23:51:00
@@ -11,9 +11,6 @@
 mdb> finish
      161:      3  2 FAIL pred queens:queen/2-0 (nondet) queens.m:41 (queens.m:15)
 mdb> dd
-Call queen([1, 2, 3, 4, 5], _)
-No solutions.
-Complete? no
 Call qperm([1, 2, 3, 4, 5], _)
 No solutions.
 Complete? no
@@ -54,6 +51,8 @@
 Found partially uncovered atom:
 qperm([1], _)
 Is this a bug? yes
+      60:     16  7 FAIL pred queens:qperm/2-0 (nondet) queens.m:45 (queens.m:49)
+mdb> continue
      161:      3  2 FAIL pred queens:queen/2-0 (nondet) queens.m:41 (queens.m:15)
 mdb> continue
 No solution
Index: tests/debugger/declarative/queens.inp
===================================================================
RCS file: /home/mercury1/repository/tests/debugger/declarative/queens.inp,v
retrieving revision 1.4
diff -u -r1.4 queens.inp
--- tests/debugger/declarative/queens.inp	2000/02/22 10:46:27	1.4
+++ tests/debugger/declarative/queens.inp	2000/03/01 23:51:00
@@ -6,7 +6,6 @@
 finish
 dd
 no
-no
 yes
 yes
 no
@@ -22,4 +21,5 @@
 yes
 yes
 yes
+continue
 continue
Index: tests/debugger/declarative/small.exp
===================================================================
RCS file: /home/mercury1/repository/tests/debugger/declarative/small.exp,v
retrieving revision 1.4
diff -u -r1.4 small.exp
--- tests/debugger/declarative/small.exp	2000/03/01 04:17:27	1.4
+++ tests/debugger/declarative/small.exp	2000/03/01 23:51:00
@@ -9,8 +9,6 @@
 mdb> finish
        3:      2  2 EXIT pred small:p/1-0 (det) small.m:14 (small.m:8)
 mdb> dd
-p(42)
-Valid? no
 Found incorrect contour:
 p(42)
 Is this a bug? yes
Index: tests/debugger/declarative/small.inp
===================================================================
RCS file: /home/mercury1/repository/tests/debugger/declarative/small.inp,v
retrieving revision 1.3
diff -u -r1.3 small.inp
--- tests/debugger/declarative/small.inp	2000/02/22 10:46:28	1.3
+++ tests/debugger/declarative/small.inp	2000/03/01 23:51:00
@@ -4,7 +4,6 @@
 continue
 finish
 dd
-no
 yes
 continue
 
Index: trace/mercury_trace_declarative.c
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_declarative.c,v
retrieving revision 1.18
diff -u -r1.18 mercury_trace_declarative.c
--- trace/mercury_trace_declarative.c	2000/02/22 10:46:53	1.18
+++ trace/mercury_trace_declarative.c	2000/03/01 23:51:25
@@ -15,7 +15,7 @@
 ** browse/declarative_debugger.m.
 **
 ** The interface between the front and back ends is via the
-** execution_tree/2 typeclass, which is documented in
+** annotated_trace/2 typeclass, which is documented in
 ** browse/declarative_debugger.m.  It would be possible to replace
 ** the front end or the back end with an alternative implementation
 ** which also conforms to the typeclass constraints.  For example:
@@ -56,7 +56,7 @@
 ** adjust this factor based on profiling information.
 */
 
-#define MR_EDT_DEPTH_STEP_SIZE		128
+#define MR_EDT_DEPTH_STEP_SIZE		6
 
 /*
 ** These macros are to aid debugging of the code which constructs
@@ -66,8 +66,11 @@
 #ifdef MR_DEBUG_DD_BACK_END
 
 #define MR_decl_checkpoint_event(event_info)				\
-		MR_decl_checkpoint_event_imp(event_info)
+		MR_decl_checkpoint_event_imp("EVENT", event_info)
 
+#define MR_decl_checkpoint_filter(event_info)				\
+		MR_decl_checkpoint_event_imp("FILTER", event_info)
+
 #define MR_decl_checkpoint_find(location)				\
 		MR_decl_checkpoint_loc("FIND", location)
 
@@ -83,6 +86,7 @@
 #else /* !MR_DEBUG_DD_BACK_END */
 
 #define MR_decl_checkpoint_event(event_info)
+#define MR_decl_checkpoint_filter(event_info)
 #define MR_decl_checkpoint_find(location)
 #define MR_decl_checkpoint_step(location)
 #define MR_decl_checkpoint_match(location)
@@ -95,15 +99,18 @@
 ** settings of the following variables.  They are set in
 ** MR_trace_start_decl_debug when the back end is started.  They
 ** are used by MR_trace_decl_debug to decide what action to
-** take for a particular trace event.  Events that are outside
-** the given depth range are ignored.  Events that are beyond the
-** given last event cause the internal debugger to be switched
-** back into interactive mode.
+** take for a particular trace event.
+**
+** Events that are deeper than the maximum depth, or which are
+** outside the top call being debugged, are ignored.  Events which
+** are beyond the given last event cause the internal debugger to
+** be switched back into interactive mode.
 */
 
-static	Unsigned	MR_edt_min_depth;
 static	Unsigned	MR_edt_max_depth;
 static	Unsigned	MR_edt_last_event;
+static	bool		MR_edt_inside;
+static	Unsigned	MR_edt_start_seqno;
 
 /*
 ** This is used as the abstract map from node identifiers to nodes
@@ -133,7 +140,9 @@
 
 /*
 ** When in test mode, MR_trace_store_file points to an open file to
-** which the store should be written when built.
+** which the store should be written when built.  This global is
+** set in MR_trace_start_decl_debug, and keeps the same value
+** throughout the declarative debugging session.
 */
 
 static	FILE		*MR_trace_store_file;
@@ -212,12 +221,27 @@
 static	Word
 MR_decl_atom_args(const MR_Stack_Layout_Label *layout, Word *saved_regs);
 
-static	void
-MR_decl_diagnosis(MR_Trace_Node root);
+static	const char *
+MR_trace_start_collecting(Unsigned event, Unsigned seqno, Unsigned maxdepth,
+		MR_Trace_Cmd_Info *cmd, MR_Event_Info *event_info,
+		MR_Event_Details *event_details, Code **jumpaddr);
+
+static	Code *
+MR_trace_restart_decl_debug(Unsigned event, Unsigned seqno,
+		MR_Trace_Cmd_Info *cmd, MR_Event_Info *event_info,
+		MR_Event_Details *event_details);
+
+static	Code *
+MR_decl_diagnosis(MR_Trace_Node root, MR_Trace_Cmd_Info *cmd,
+		MR_Event_Info *event_info, MR_Event_Details *event_details);
 
 static	void
 MR_decl_diagnosis_test(MR_Trace_Node root);
 
+static	Code *
+MR_decl_handle_bug_found(Unsigned event, MR_Trace_Cmd_Info *cmd,
+		MR_Event_Info *event_info, MR_Event_Details *event_details);
+
 static	String
 MR_trace_node_path(MR_Trace_Node node);
 
@@ -237,7 +261,7 @@
 MR_trace_find_prev_contour(MR_Trace_Node node);
 
 static	void
-MR_decl_checkpoint_event_imp(MR_Event_Info *event_info);
+MR_decl_checkpoint_event_imp(const char *str, MR_Event_Info *event_info);
 
 static	void
 MR_decl_checkpoint_loc(const char *str, MR_Trace_Node node);
@@ -248,6 +272,7 @@
 	MR_Stack_Layout_Entry 	*entry;
 	Unsigned		depth;
 	MR_Trace_Node		trace;
+	MR_Event_Details	event_details;
 
 	entry = event_info->MR_event_sll->MR_sll_entry;
 	depth = event_info->MR_call_depth;
@@ -267,17 +292,47 @@
 		fatal_error("layout has no execution tracing");
 	}
 
-	if (depth > MR_edt_max_depth || depth < MR_edt_min_depth) {
+	if (depth > MR_edt_max_depth) {
 		/*
-		** We filter out events with a depth outside the range
-		** given by MR_edt_{min,max}_depth.  These events are
-		** either irrelevant, or else implicitly represented in
-		** the structure being built.  See comment in
-		** trace/mercury_trace_declarative.h.
+		** We filter out events which are deeper than a certain
+		** limit given by MR_edt_max_depth.  These events are
+		** implicitly represented in the structure being built.
 		*/
 		return NULL;
 	}
 
+	if (MR_edt_inside)
+	{
+		if (event_info->MR_call_seqno == MR_edt_start_seqno &&
+			MR_port_is_final(event_info->MR_trace_port))
+		{
+			/*
+			** We are leaving the topmost call.
+			*/
+			MR_edt_inside = FALSE;
+		}
+	}
+	else
+	{
+		if (event_info->MR_call_seqno == MR_edt_start_seqno)
+		{
+			/*
+			** The port must be either CALL or REDO;
+			** we are (re)entering the topmost call.
+			*/
+			MR_edt_inside = TRUE;
+		}
+		else
+		{
+			/*
+			** Ignore this event---it is outside the
+			** topmost call.
+			*/
+			MR_decl_checkpoint_filter(event_info);
+			return NULL;
+		}
+	}
+
 #ifdef MR_USE_DECL_STACK_SLOT
 	if (entry->MR_sle_maybe_decl_debug < 1) {
 		/*
@@ -289,6 +344,10 @@
 	}
 #endif /* MR_USE_DECL_STACK_SLOT */
 
+	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;
+
 	MR_trace_enabled = FALSE;
 	MR_decl_checkpoint_event(event_info);
 	trace = MR_trace_current_node;
@@ -342,12 +401,22 @@
 	MR_decl_checkpoint_alloc(trace);
 	MR_trace_current_node = trace;
 	
+	/*
+	** Restore globals from the saved copies.
+	*/
+        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;
+
 	if (MR_trace_event_number == MR_edt_last_event) {
+		/*
+		** Call the front end.
+		*/
 		switch (MR_trace_decl_mode) {
 			case MR_TRACE_DECL_DEBUG:
-				/* Call the front end */
-				MR_decl_diagnosis(MR_trace_current_node);
-				break;
+				return MR_decl_diagnosis(
+						MR_trace_current_node, cmd,
+						event_info, &event_details);
 
 			case MR_TRACE_DECL_DEBUG_TEST:
 				MR_decl_diagnosis_test(MR_trace_current_node);
@@ -357,17 +426,11 @@
 				fatal_error("MR_trace_decl_debug: "
 						"unexpected mode");
 		}
-
-		/*
-		** XXX we should return to the CALL event of the buggy
-		** node, if one was found.
-		*/
 		MR_trace_decl_mode = MR_TRACE_INTERACTIVE;
 		return MR_trace_event_internal(cmd, TRUE, event_info);
 	}
 
 	MR_trace_enabled = TRUE;
-
 	return NULL;
 }
 
@@ -376,14 +439,23 @@
 {
 	MR_Trace_Node			node;
 	Word				atom;
+	bool				at_depth_limit;
 	const MR_Stack_Layout_Label	*layout = event_info->MR_event_sll;
 
+	if (event_info->MR_call_depth == MR_edt_max_depth) {
+		at_depth_limit = TRUE;
+	} else {
+		at_depth_limit = FALSE;
+	}
+
 	atom = MR_decl_make_atom(layout, event_info->MR_saved_regs,
 			MR_PORT_CALL);
 	MR_TRACE_CALL_MERCURY(
 		node = (MR_Trace_Node) MR_DD_construct_call_node(
 					(Word) prev, atom,
-					(Word) event_info->MR_call_seqno);
+					(Word) event_info->MR_call_seqno,
+					(Word) event_info->MR_event_number,
+					(Word) at_depth_limit);
 	);
 
 #ifdef MR_USE_DECL_STACK_SLOT
@@ -418,8 +490,8 @@
 		last_interface = MR_DD_call_node_get_last_interface(
 				(Word) call);
 		node = (MR_Trace_Node) MR_DD_construct_exit_node(
-				(Word) prev, (Word) call,
-				last_interface, atom);
+				(Word) prev, (Word) call, last_interface,
+				atom, (Word) event_info->MR_event_number);
 		MR_DD_call_node_set_last_interface((Word) call, (Word) node);
 	);
 
@@ -502,9 +574,8 @@
 	MR_TRACE_CALL_MERCURY(
 		redo = MR_DD_call_node_get_last_interface( (Word) call);
 		node = (MR_Trace_Node) MR_DD_construct_fail_node(
-						(Word) prev,
-						(Word) call,
-						(Word) redo);
+					(Word) prev, (Word) call, (Word) redo,
+					(Word) event_info->MR_event_number);
 		MR_DD_call_node_set_last_interface((Word) call, (Word) node);
 	);
 	return node;
@@ -992,8 +1063,8 @@
 MR_trace_decl_ensure_init(void)
 {
 	static bool		done = FALSE;
-	static MercuryFile		mdb_in;
-	static MercuryFile		mdb_out;
+	static MercuryFile	mdb_in;
+	static MercuryFile	mdb_out;
 
 	mdb_in.file = MR_mdb_in;
 	mdb_in.line_number = 1;
@@ -1002,6 +1073,7 @@
 
 	if (! done) {
 		MR_TRACE_CALL_MERCURY(
+			MR_trace_node_store = 0;
 			MR_DD_decl_diagnosis_state_init(
 					(Word) &mdb_in,
 					(Word) &mdb_out,
@@ -1017,26 +1089,30 @@
 		Code **jumpaddr)
 {
 	MR_Stack_Layout_Entry 	*entry;
-	const char		*message;
 	FILE			*out;
+	Unsigned		depth_limit;
+	const char		*message;
 
 	entry = event_info->MR_event_sll->MR_sll_entry;
 	if (!MR_ENTRY_LAYOUT_HAS_EXEC_TRACE(entry)) {
+		fflush(MR_mdb_out);
+		fprintf(MR_mdb_err, "mdb: cannot start declarative debugging, "
+				"because this procedure was not\n"
+				"compiled with execution tracing enabled.\n");
 		return FALSE;
 	}
 
 #ifdef MR_USE_DECL_STACK_SLOT
 	if (entry->MR_sle_maybe_decl_debug < 1) {
 		/* No slots are reserved for declarative debugging */
+		fflush(MR_mdb_out);
+		fprintf(MR_mdb_err, "mdb: cannot start declarative debugging, "
+				"because this procedure was not\n"
+				"compiled with stack slots reserved.\n");
 		return FALSE;
 	}
 #endif /* MR_USE_DECL_STACK_SLOT */
 
-	message = MR_trace_retry(event_info, event_details, jumpaddr);
-	if (message != NULL) {
-		return FALSE;
-	}
-
 	if (outfile == (const char *) NULL) {
 		/* Normal debugging mode */
 		MR_trace_decl_mode = MR_TRACE_DECL_DEBUG;
@@ -1056,25 +1132,102 @@
 	}
 
 	MR_trace_decl_ensure_init();
+	depth_limit = event_info->MR_call_depth + MR_EDT_DEPTH_STEP_SIZE;
+	message = MR_trace_start_collecting(event_info->MR_event_number,
+			event_info->MR_call_seqno, depth_limit, cmd,
+			event_info, event_details, jumpaddr);
+
+	if (message == NULL) {
+		return TRUE;
+	} else {
+		fflush(MR_mdb_out);
+		fprintf(MR_mdb_err,
+			"mdb: failed to start collecting events:\n%s\n",
+			message);
+
+		return FALSE;
+	}
+}
+
+static	Code *
+MR_trace_restart_decl_debug(Unsigned event, Unsigned seqno,
+		MR_Trace_Cmd_Info *cmd, MR_Event_Info *event_info,
+		MR_Event_Details *event_details)
+{
+	Unsigned		depth_limit;
+	const char		*message;
+	Code			*jumpaddr;
+
+	depth_limit = MR_edt_max_depth + MR_EDT_DEPTH_STEP_SIZE;
+	message = MR_trace_start_collecting(event, seqno, depth_limit,
+			cmd, event_info, event_details, &jumpaddr);
 
-	MR_edt_last_event = event_info->MR_event_number;
-	MR_edt_min_depth = event_info->MR_call_depth;
-	MR_edt_max_depth = event_info->MR_call_depth + MR_EDT_DEPTH_STEP_SIZE;
-	MR_trace_node_store = 0;
+	if (message != NULL) {
+		fflush(MR_mdb_out);
+		fprintf(MR_mdb_err, "mdb: diagnosis aborted:\n%s\n", message);
+		MR_trace_decl_mode = MR_TRACE_INTERACTIVE;
+		MR_trace_enabled = TRUE;
+		return MR_trace_event_internal(cmd, TRUE, event_info);
+	}
+
+	return jumpaddr;
+}
+
+static	const char *
+MR_trace_start_collecting(Unsigned event, Unsigned seqno, Unsigned maxdepth,
+		MR_Trace_Cmd_Info *cmd, MR_Event_Info *event_info,
+		MR_Event_Details *event_details, Code **jumpaddr)
+{
+	const char		*message;
+
+	/*
+	** Go back to an event before the topmost call.
+	*/
+	message = MR_trace_retry(event_info, event_details, jumpaddr);
+	if (message != NULL) {
+		return message;
+	}
+
+	/*
+	** Start collecting the trace from the desired call, with the
+	** desired depth bound.
+	*/
+	MR_edt_last_event = event;
+	MR_edt_inside = FALSE;
+	MR_edt_start_seqno = seqno;
+	MR_edt_max_depth = maxdepth;
 	MR_trace_current_node = (MR_Trace_Node) NULL;
 
+	/*
+	** Restore globals from the saved copies.
+	*/
+       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;
+
+	/*
+	** Single step through every event.
+	*/
 	cmd->MR_trace_cmd = MR_CMD_GOTO;
-	cmd->MR_trace_stop_event = MR_trace_event_number + 1;
-	cmd->MR_trace_strict = FALSE;
-	cmd->MR_trace_print_level = MR_PRINT_LEVEL_ALL;
+	cmd->MR_trace_stop_event = 0;
+	cmd->MR_trace_strict = TRUE;
+	cmd->MR_trace_print_level = MR_PRINT_LEVEL_NONE;
+	cmd->MR_trace_must_check = FALSE;
 
-	return TRUE;
+	MR_trace_enabled = TRUE;
+	return NULL;
 }
 
-static	void
-MR_decl_diagnosis(MR_Trace_Node root)
+static	Code *
+MR_decl_diagnosis(MR_Trace_Node root, MR_Trace_Cmd_Info *cmd,
+		MR_Event_Info *event_info, MR_Event_Details *event_details)
 {
 	Word			response;
+	bool			bug_found;
+	bool			require_subtree;
+	Unsigned		bug_event;
+	Unsigned		final_event;
+	Unsigned		topmost_seqno;
 
 #if 0
 	/*
@@ -1088,13 +1241,66 @@
 				MR_trace_front_end_state,
 				&MR_trace_front_end_state
 			);
+		bug_found = MR_DD_diagnoser_bug_found(response,
+				(Word *) &bug_event);
+		require_subtree = MR_DD_diagnoser_require_subtree(response,
+				(Word *) &final_event,
+				(Word *) &topmost_seqno);
 	);
 
+	if (bug_found) {
+		return MR_decl_handle_bug_found(bug_event, cmd,
+				event_info, event_details);
+	}
+
+	if (require_subtree) {
+		/*
+		** Front end requires a subtree to be made explicit.
+		** Restart the declarative debugger with deeper
+		** depth limit.
+		*/
+		return MR_trace_restart_decl_debug(final_event, topmost_seqno,
+				cmd, event_info, event_details);
+	}
+
 	/*
-	** XXX We don't do anything with the response yet.
-	** We should set the current event to the call of the buggy node
-	** (if there is one), or we should handle requests for subtrees.
+	** No bug found.  Return to the procedural debugger at the
+	** current event, which was the event it was left from.
 	*/
+	MR_trace_decl_mode = MR_TRACE_INTERACTIVE;
+	MR_trace_enabled = TRUE;
+	return MR_trace_event_internal(cmd, TRUE, event_info);
+}
+
+static	Code *
+MR_decl_handle_bug_found(Unsigned bug_event, MR_Trace_Cmd_Info *cmd,
+		MR_Event_Info *event_info, MR_Event_Details *event_details)
+{
+	const char		*message;
+	Code			*jumpaddr;
+
+	/*
+	** Perform a retry to get to somewhere before the
+	** bug event.  Then set the command to go to the bug
+	** event and return to interactive mode.
+	*/
+	message = MR_trace_retry(event_info, event_details, &jumpaddr);
+	if (message != NULL) {
+		fflush(MR_mdb_out);
+		fprintf(MR_mdb_err, "mdb: diagnosis aborted:\n%s\n", message);
+		MR_trace_decl_mode = MR_TRACE_INTERACTIVE;
+		MR_trace_enabled = TRUE;
+		return MR_trace_event_internal(cmd, TRUE, event_info);
+	}
+
+	cmd->MR_trace_cmd = MR_CMD_GOTO;
+	cmd->MR_trace_stop_event = bug_event;
+	cmd->MR_trace_print_level = MR_PRINT_LEVEL_NONE;
+	cmd->MR_trace_strict = TRUE;
+	cmd->MR_trace_must_check = FALSE;
+	MR_trace_decl_mode = MR_TRACE_INTERACTIVE;
+	MR_trace_enabled = TRUE;
+	return jumpaddr;
 }
 
 static	void
@@ -1201,9 +1407,10 @@
 #ifdef MR_DEBUG_DD_BACK_END
 
 static	void
-MR_decl_checkpoint_event_imp(MR_Event_Info *event_info)
+MR_decl_checkpoint_event_imp(const char *str, MR_Event_Info *event_info)
 {
-	fprintf(MR_mdb_out, "DD EVENT %ld: #%ld %ld %s ",
+	fprintf(MR_mdb_out, "DD %s %ld: #%ld %ld %s ",
+			str,
 			(long) event_info->MR_event_number,
 			(long) event_info->MR_call_seqno,
 			(long) event_info->MR_call_depth,
Index: trace/mercury_trace_internal.c
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_internal.c,v
retrieving revision 1.63
diff -u -r1.63 mercury_trace_internal.c
--- trace/mercury_trace_internal.c	2000/02/04 03:45:43	1.63
+++ trace/mercury_trace_internal.c	2000/03/01 23:51:46
@@ -210,8 +210,7 @@
 	}
 
 #ifdef	MR_USE_DECLARATIVE_DEBUGGER
-	if (MR_trace_decl_mode == MR_TRACE_DECL_DEBUG
-		|| MR_trace_decl_mode == MR_TRACE_DECL_DEBUG_TEST)
+	if (MR_trace_decl_mode != MR_TRACE_INTERACTIVE)
 	{
 		return MR_trace_decl_debug(cmd, event_info);
 	}
@@ -1609,12 +1608,6 @@
 			{
 				return STOP_INTERACTING;
 			}
-			else
-			{
-				fflush(MR_mdb_out);
-				fprintf(MR_mdb_err, "mdb: unable to start "
-						"declarative debugging.\n");
-			}
 		} else {
 			fflush(MR_mdb_out);
 			fprintf(MR_mdb_err,
@@ -1634,12 +1627,6 @@
 						jumpaddr))
 			{
 				return STOP_INTERACTING;
-			}
-			else
-			{
-				fflush(MR_mdb_out);
-				fprintf(MR_mdb_err, "mdb: unable to start "
-						"declarative debugging.\n");
 			}
 		} else {
 			fflush(MR_mdb_out);


New file tests/debugger/declarative/filter.m:

:- module filter.
:- interface.
:- import_module io.
:- pred main(io__state::di, io__state::uo) is det.
:- implementation.
:- import_module list, int.

main -->
	(
		{ p(X), q(X) }
	->
		io__write_string("yes\n")
	;
		io__write_string("no\n")
	).

:- pred p(list(int)).
:- mode p(out) is multi.

p(X) :-
	s1(A),
	s2(B),
	my_append(A, B, X).

:- pred s1(list(int)).
:- mode s1(out) is multi.

s1([1, 2]).
s1([1, 2, 3]).

:- pred s2(list(int)).
:- mode s2(out) is multi.

s2([9]).
s2([7, 8, 9]).

:- pred q(list(T)).
:- mode q(in) is semidet.

q(X) :-
	my_length(X, L),
	L > 6.

:- pred my_append(list(T), list(T), list(T)).
:- mode my_append(in, in, out) is det.

my_append(A, B, C) :-
	list__append(A, B, C).

:- pred my_length(list(T), int).
:- mode my_length(in, out) is det.

my_length(A, L) :-
	list__length(A, L).


New file tests/debugger/declarative/filter.inp:

echo on
register --quiet
break p
continue
finish
dd
yes
yes
yes
yes
continue
finish
dd
yes
yes
yes
continue
finish
dd
yes
yes
yes
continue
finish
dd
yes
yes
continue
finish
dd
yes
yes
yes
continue


New file tests/debugger/declarative/filter.exp:

       1:      1  1 CALL pred filter:main/2-0 (det) filter.m:13
mdb> echo on
Command echo enabled.
mdb> register --quiet
mdb> break p
 0: + stop  interface pred filter:p/1-0 (multi)
mdb> continue
       3:      2  2 CALL pred filter:p/1-0 (multi) filter.m:20 (filter.m:10)
mdb> finish
      12:      2  2 EXIT pred filter:p/1-0 (multi) filter.m:20 (filter.m:10)
mdb> dd
s1([1, 2])
Valid? yes
s2([9])
Valid? yes
my_append([1, 2], [9], [1, 2, 9])
Valid? yes
Found incorrect contour:
p([1, 2, 9])
Is this a bug? yes
      12:      2  2 EXIT pred filter:p/1-0 (multi) filter.m:20 (filter.m:10)
mdb> continue
      17:      2  2 REDO pred filter:p/1-0 (multi) filter.m:20 (filter.m:10)
mdb> finish
      23:      2  2 EXIT pred filter:p/1-0 (multi) filter.m:20 (filter.m:10)
mdb> dd
s2([7, 8, 9])
Valid? yes
my_append([1, 2], [7, 8, 9], [1, 2, 7, 8, 9])
Valid? yes
Found incorrect contour:
p([1, 2, 7, 8, 9])
Is this a bug? yes
      23:      2  2 EXIT pred filter:p/1-0 (multi) filter.m:20 (filter.m:10)
mdb> continue
      28:      2  2 REDO pred filter:p/1-0 (multi) filter.m:20 (filter.m:10)
mdb> finish
      39:      2  2 EXIT pred filter:p/1-0 (multi) filter.m:20 (filter.m:10)
mdb> dd
s1([1, 2, 3])
Valid? yes
my_append([1, 2, 3], [9], [1, 2, 3, 9])
Valid? yes
Found incorrect contour:
p([1, 2, 3, 9])
Is this a bug? yes
      39:      2  2 EXIT pred filter:p/1-0 (multi) filter.m:20 (filter.m:10)
mdb> continue
      44:      2  2 REDO pred filter:p/1-0 (multi) filter.m:20 (filter.m:10)
mdb> finish
      50:      2  2 EXIT pred filter:p/1-0 (multi) filter.m:20 (filter.m:10)
mdb> dd
my_append([1, 2, 3], [7, 8, 9], [1, 2, 3, 7, 8, 9])
Valid? yes
Found incorrect contour:
p([1, 2, 3, 7, 8, 9])
Is this a bug? yes
      50:      2  2 EXIT pred filter:p/1-0 (multi) filter.m:20 (filter.m:10)
mdb> continue
      55:      2  2 REDO pred filter:p/1-0 (multi) filter.m:20 (filter.m:10)
mdb> finish
      60:      2  2 FAIL pred filter:p/1-0 (multi) filter.m:20 (filter.m:10)
mdb> dd
Call s2(_)
Solutions:
	s2([9])
	s2([7, 8, 9])
Complete? yes
Call s1(_)
Solutions:
	s1([1, 2])
	s1([1, 2, 3])
Complete? yes
Found partially uncovered atom:
p(_)
Is this a bug? yes
      60:      2  2 FAIL pred filter:p/1-0 (multi) filter.m:20 (filter.m:10)
mdb> continue
no


New file tests/debugger/declarative/filter.exp2:

       1:      1  1 CALL pred filter:main/2-0 (det) filter.m:13
mdb> echo on
Command echo enabled.
mdb> register --quiet
mdb> break p
 0: + stop  interface pred filter:p/1-0 (multi)
mdb> continue
       3:      2  2 CALL pred filter:p/1-0 (multi) filter.m:20 (filter.m:10)
mdb> finish
      14:      2  2 EXIT pred filter:p/1-0 (multi) filter.m:20 (filter.m:10)
mdb> dd
s1([1, 2])
Valid? yes
s2([9])
Valid? yes
my_append([1, 2], [9], [1, 2, 9])
Valid? yes
Found incorrect contour:
p([1, 2, 9])
Is this a bug? yes
      14:      2  2 EXIT pred filter:p/1-0 (multi) filter.m:20 (filter.m:10)
mdb> continue
      21:      2  2 REDO pred filter:p/1-0 (multi) filter.m:20 (filter.m:10)
mdb> finish
      29:      2  2 EXIT pred filter:p/1-0 (multi) filter.m:20 (filter.m:10)
mdb> dd
s2([7, 8, 9])
Valid? yes
my_append([1, 2], [7, 8, 9], [1, 2, 7, 8, 9])
Valid? yes
Found incorrect contour:
p([1, 2, 7, 8, 9])
Is this a bug? yes
      29:      2  2 EXIT pred filter:p/1-0 (multi) filter.m:20 (filter.m:10)
mdb> continue
      36:      2  2 REDO pred filter:p/1-0 (multi) filter.m:20 (filter.m:10)
mdb> finish
      49:      2  2 EXIT pred filter:p/1-0 (multi) filter.m:20 (filter.m:10)
mdb> dd
s1([1, 2, 3])
Valid? yes
my_append([1, 2, 3], [9], [1, 2, 3, 9])
Valid? yes
Found incorrect contour:
p([1, 2, 3, 9])
Is this a bug? yes
      49:      2  2 EXIT pred filter:p/1-0 (multi) filter.m:20 (filter.m:10)
mdb> continue
      56:      2  2 REDO pred filter:p/1-0 (multi) filter.m:20 (filter.m:10)
mdb> finish
      64:      2  2 EXIT pred filter:p/1-0 (multi) filter.m:20 (filter.m:10)
mdb> dd
my_append([1, 2, 3], [7, 8, 9], [1, 2, 3, 7, 8, 9])
Valid? yes
Found incorrect contour:
p([1, 2, 3, 7, 8, 9])
Is this a bug? yes
      64:      2  2 EXIT pred filter:p/1-0 (multi) filter.m:20 (filter.m:10)
mdb> continue
      71:      2  2 REDO pred filter:p/1-0 (multi) filter.m:20 (filter.m:10)
mdb> finish
      76:      2  2 FAIL pred filter:p/1-0 (multi) filter.m:20 (filter.m:10)
mdb> dd
Call s2(_)
Solutions:
	s2([9])
	s2([7, 8, 9])
Complete? yes
Call s1(_)
Solutions:
	s1([1, 2])
	s1([1, 2, 3])
Complete? yes
Found partially uncovered atom:
p(_)
Is this a bug? yes
      76:      2  2 FAIL pred filter:p/1-0 (multi) filter.m:20 (filter.m:10)
mdb> continue
no
-- 
Mark Brown, PhD student            )O+  |  "Another of Fortran's breakthroughs
(m.brown at cs.mu.oz.au)                   |  was the GOTO statement, which was...
Dept. of Computer Science and Software  |  uniquely simple and understandable"
Engineering, University of Melbourne    |              -- IEEE, 1994
--------------------------------------------------------------------------
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