[m-rev.] For review: Changes to trust command.

Ian MacLarty maclarty at cs.mu.OZ.AU
Tue Aug 10 13:29:54 AEST 2004


For review by anyone.

Estimated hours taken: 10
Branches: main

Added `trusted' and `untrust' commands.  Also allowed individual predicates to
be trusted.

browser/declarative_debugger.m
	Exported predicates to add a trusted predicate or function, remove
	a trusted object and return a list of the trusted objects.
	
browser/declarative_oracle.m
	Changed trusted set so it can also contains individual predicates and
	functions.  Added predicates to add a trusted predicate or function
	to the set, remove a trusted object from the set and return a list
	of the trusted objects.
	
doc/mdb_categories
	Added dd category.
	
doc/user_guide.texi
	Documented `untrust' and `trusted' commands.
	
runtime/mercury_stack_trace.c
runtime/mercury_stack_trace.h
	Added a print_mode argument to MR_print_proc_id_internal, so that 
	printing of mode information can be turned on or off.  When a list
	of matching predicates for the trust command is shown then mode
	information is superfluous, since a predicate/function is trusted, not
	a procedure.
	Added MR_print_pred_id to print predicate id - i.e. proc id without
	the mode info.

tests/debugger/completion.exp
	New commands shown in completion list.
	
tests/debugger/completion.inp
	Added a space, since a --More-- prompt is now displayed when showing
	all the commands.

tests/debugger/mdb_command_test.inp
	untrust and trusted added.

tests/debugger/declarative/trust.exp
tests/debugger/declarative/trust.inp
	Testing of new commands.

trace/mercury_trace_declarative.c
trace/mercury_trace_declarative.h
	Added functions to add a trusted predicate and remove a trusted
	object.  Also added a function to print a list of the trusted objects.
	These all call the predicates exported from declarative_debugger.m.
	
trace/mercury_trace_internal.c
	Added handlers for `trusted' and `untrust' commands.
	
trace/mercury_trace_tables.c
trace/mercury_trace_tables.h
	Added a function to filter out only the user predicates and functions
	from a list of procedures.  This filters out uci procs and also 
	filters out all procs with a mode number > 0 (thus leaving one proc
	for each predicate/function).  This is used when displaying the
	predicates matching an ambiguous proc-spec with a trust command.

Index: browser/declarative_debugger.m
===================================================================
RCS file: /home/mercury1/repository/mercury/browser/declarative_debugger.m,v
retrieving revision 1.38
diff -u -r1.38 declarative_debugger.m
--- browser/declarative_debugger.m	7 Jul 2004 05:26:15 -0000	1.38
+++ browser/declarative_debugger.m	9 Aug 2004 14:28:56 -0000
@@ -252,6 +252,7 @@
 :- import_module mdb__declarative_analyser.
 :- import_module mdb__declarative_oracle.
 :- import_module mdb__declarative_tree.
+:- import_module mdb__util.
 
 :- import_module exception, int, map.
 
@@ -519,14 +520,51 @@
 :- pred add_trusted_module(string::in, diagnoser_state(trace_node_id)::in, 
 		diagnoser_state(trace_node_id)::out) is det.
 
-:- pragma export(add_trusted_module(in, in, out),
+:- pragma export(mdb.declarative_debugger.add_trusted_module(in, in, out),
 		"MR_DD_decl_add_trusted_module").
 		
-add_trusted_module(ModuleName, OldDiagnoserState,
-	OldDiagnoserState ^ oracle_state := 
-		mdb.declarative_oracle.add_trusted_module(ModuleName, 
-			OldDiagnoserState ^ oracle_state)
-).
+add_trusted_module(ModuleName, Diagnoser0, Diagnoser) :-
+	add_trusted_module(ModuleName, Diagnoser0 ^ oracle_state, Oracle),
+	Diagnoser = Diagnoser0 ^ oracle_state := Oracle.
+
+	% Adds a trusted predicate/function to the given diagnoser.
+	%  
+:- pred add_trusted_pred_or_func(proc_layout::in, 
+	diagnoser_state(trace_node_id)::in,
+	diagnoser_state(trace_node_id)::out) is det.
+
+:- pragma export(mdb.declarative_debugger.add_trusted_pred_or_func(in, in, 
+	out), "MR_DD_decl_add_trusted_pred_or_func").
+		
+add_trusted_pred_or_func(ProcLayout, !Diagnoser) :-
+	add_trusted_pred_or_func(ProcLayout, !.Diagnoser ^ oracle_state, 
+		Oracle),
+	!:Diagnoser = !.Diagnoser ^ oracle_state := Oracle.
+
+:- pred remove_trusted(int::in, diagnoser_state(trace_node_id)::in,
+	diagnoser_state(trace_node_id)::out) is semidet.
+	
+:- pragma export(mdb.declarative_debugger.remove_trusted(in, in, out),
+	"MR_DD_decl_remove_trusted").
+
+remove_trusted(N, !Diagnoser) :-
+	remove_trusted(N, !.Diagnoser ^ oracle_state, Oracle),
+	!:Diagnoser = !.Diagnoser ^ oracle_state := Oracle.
+
+	% get_trusted_list(Diagnoser, MDBCommandFormat, String).
+	% Return a string listing the trusted objects for Diagnoser.
+	% If MDBCommandFormat is true then returns the list so that it can be
+	% run as a series of mdb `trust' commands.  Otherwise returns them
+	% in a format suitable for display only.
+	%
+:- pred get_trusted_list(diagnoser_state(trace_node_id)::in, bool::in,
+	string::out) is det.
+
+:- pragma export(mdb.declarative_debugger.get_trusted_list(in, in, out),
+	"MR_DD_decl_get_trusted_list").
+
+get_trusted_list(Diagnoser, MDBCommandFormat, List) :-
+	get_trusted_list(Diagnoser ^ oracle_state, MDBCommandFormat, List).
 
 %-----------------------------------------------------------------------------%
 
Index: browser/declarative_oracle.m
===================================================================
RCS file: /home/mercury1/repository/mercury/browser/declarative_oracle.m,v
retrieving revision 1.24
diff -u -r1.24 declarative_oracle.m
--- browser/declarative_oracle.m	16 Jul 2004 04:43:02 -0000	1.24
+++ browser/declarative_oracle.m	9 Aug 2004 06:26:05 -0000
@@ -27,8 +27,9 @@
 :- interface.
 
 :- import_module mdb__declarative_debugger.
+:- import_module mdb__declarative_execution.
 
-:- import_module list, io.
+:- import_module list, io, bool, string.
 
 	% A response that the oracle gives to a query about the
 	% truth of an EDT node.
@@ -51,7 +52,31 @@
 
 	% Add a module to the set of modules trusted by the oracle
 	%
-:- func add_trusted_module(string, oracle_state) = oracle_state. 
+:- pred add_trusted_module(string::in, oracle_state::in, oracle_state::out) 
+	is det. 
+
+	% Add a predicate/function to the set of predicates/functions trusted 
+	% by the oracle.
+	%
+:- pred add_trusted_pred_or_func(proc_layout::in, oracle_state::in, 
+	oracle_state::out) is det. 
+
+	% remove_trusted(N, !Oracle).
+	% Removes the (N-1)th trusted object from the set of trusted objects.
+	% Fails if there are fewer than N-1 trusted modules (or N < 0).
+	% The trusted set is turned into a sorted list before finding the
+	% (N-1)th element.
+	%
+:- pred remove_trusted(int::in, oracle_state::in, oracle_state::out)
+	is semidet.
+
+	% get_trusted_list(Oracle, MDBCommandFormat, String).
+	% Return a string listing the trusted objects.
+	% If MDBCommandFormat is true then returns the list so that it can be
+	% run as a series of mdb `trust' commands.  Otherwise returns them
+	% in a format suitable for display only.
+	%
+:- pred get_trusted_list(oracle_state::in, bool::in, string::out) is det.
 
 	% Query the oracle about the program being debugged.  The first
 	% argument is a queue of nodes in the evaluation tree, the second
@@ -75,13 +100,12 @@
 
 :- implementation.
 
-:- import_module mdb__declarative_execution.
 :- import_module mdb__declarative_user.
 :- import_module mdb__tree234_cc.
 :- import_module mdb__set_cc.
 :- import_module mdb__util.
 
-:- import_module bool, std_util, set.
+:- import_module bool, std_util, set, int.
 
 query_oracle(Questions, Response, Oracle0, Oracle) -->
 	{ query_oracle_list(Oracle0, Questions, Answers) },
@@ -190,11 +214,9 @@
 			user_state	:: user_state,
 				% User interface.
 				
-			trusted_modules :: set(string)
-				% If a module name is in this set then the 
-				% oracle will report any calls to predicates 
-				% or functions in that module as valid.
-		
+			trusted :: set(trusted_module_or_predicate)
+				% Modules and predicates/functions trusted
+				% by the oracle.
 		).
 
 oracle_state_init(InStr, OutStr, Oracle) :-
@@ -204,10 +226,95 @@
 	set.init(TrustedModules),
 	Oracle = oracle(Current, Old, User, TrustedModules).
 	
-add_trusted_module(ModuleName, OracleState) = 
-	OracleState ^ trusted_modules := 
-		insert(OracleState ^ trusted_modules, ModuleName). 
+%-----------------------------------------------------------------------------%
 
+:- type trusted_module_or_predicate
+	--->	all(string) % all predicates/functions in a module
+	;	specific(
+			pred_or_func,	
+			string,		% module name
+			string,		% pred or func name
+			int		% arity
+		).
+
+add_trusted_module(ModuleName, !Oracle) :-
+	insert(!.Oracle ^ trusted, all(ModuleName), Trusted),
+	!:Oracle = !.Oracle ^ trusted := Trusted.
+
+add_trusted_pred_or_func(ProcLayout, !Oracle) :-
+	ProcId = get_proc_id_from_layout(ProcLayout),
+	(
+		ProcId = proc(ModuleName, PredOrFunc, _, Name, Arity, _)
+	;
+		ProcId = uci_proc(ModuleName, _, _, Name, Arity, _),
+		PredOrFunc = predicate
+	),
+	insert(!.Oracle ^ trusted, specific(PredOrFunc, ModuleName, Name, 
+		Arity), Trusted),
+	!:Oracle = !.Oracle ^ trusted := Trusted.
+
+remove_trusted(N, !Oracle) :-
+	TrustedList = to_sorted_list(!.Oracle ^ trusted),
+	index0(TrustedList, N, ObjectToDelete),
+	delete_all(TrustedList, ObjectToDelete, NewTrustedList),
+	!:Oracle = !.Oracle ^ trusted := sorted_list_to_set(NewTrustedList). 
+
+get_trusted_list(Oracle, CommandFormat, List) :-
+	Trusted = to_sorted_list(Oracle ^ trusted),
+	(
+		CommandFormat = yes,
+		foldl(format_trust_command, Trusted, "", List)
+	;
+		CommandFormat = no,
+		foldl(format_trust_display, Trusted, {0, "Trusted Objects:\n"}, 
+			{I, List0}),
+		(
+			I = 0
+		->
+			List = "There are no trusted modules, predicates "++
+				"or functions.\n"
+		;
+			List = List0
+		)
+	).
+
+:- pred format_trust_command(trusted_module_or_predicate::in, string::in,
+	string::out) is det.
+
+format_trust_command(all(ModuleName), S, S++"trust "++ModuleName++"\n").
+format_trust_command(specific(PredOrFunc, ModuleName, Name, Arity), S, 
+		S++Command) :-
+	(
+		PredOrFunc = predicate,
+		PredOrFuncStr = "pred*",
+		ArityStr = int_to_string(Arity)
+	;
+		PredOrFunc = function,
+		PredOrFuncStr = "func*",
+		ArityStr = int_to_string(Arity - 1)
+	),
+	Command = "trust "++PredOrFuncStr++ModuleName++"."++Name++"/"++
+		ArityStr++ "\n".
+		
+:- pred format_trust_display(trusted_module_or_predicate::in, {int,string}::in,
+	{int,string}::out) is det.
+
+format_trust_display(all(ModuleName), {I, S}, 
+	{I + 1, S++int_to_string(I)++": module "++ModuleName++"\n"}).
+format_trust_display(specific(PredOrFunc, ModuleName, Name, Arity), {I, S}, 
+		{I + 1, S++Display}) :-
+	(
+		PredOrFunc = predicate,
+		PredOrFuncStr = "pred",
+		ArityStr = int_to_string(Arity)
+	;
+		PredOrFunc = function,
+		PredOrFuncStr = "func",
+		ArityStr = int_to_string(Arity - 1)
+	),
+	Display = int_to_string(I)++": "++PredOrFuncStr++" "++ModuleName++"."++
+		Name++"/"++ArityStr++"\n".
+		
 %-----------------------------------------------------------------------------%
 
 	%
@@ -306,10 +413,7 @@
 	query_oracle_list(OS, Qs0, As0),
 	Atom = get_decl_question_atom(Q),
 	(
-		% do we trust the correctness of the procedure?
-		ProcId = get_proc_id_from_layout(Atom ^ proc_layout),
-		ProcId = proc(Module, _, _, _, _, _),
-		set__member(Module, OS ^ trusted_modules)
+		trusted(Atom ^ proc_layout, OS)
 	->
 		As = [truth_value(get_decl_question_node(Q), yes) | As0]
 	;
@@ -322,6 +426,22 @@
 			As = As0
 		)
 	).	
+
+:- pred trusted(proc_layout::in, oracle_state::in) is semidet.
+
+trusted(ProcLayout, Oracle) :-
+	ProcId = get_proc_id_from_layout(ProcLayout),
+	(
+		ProcId = proc(Module, PredOrFunc, _, Name, Arity, _),
+		(
+			member(all(Module), Oracle ^ trusted)
+		;
+			member(specific(PredOrFunc, Module, Name, Arity),
+				Oracle ^ trusted)
+		)
+	;
+		ProcId = uci_proc(_, _, _, _, _, _)
+	).
 
 :- pred query_oracle_kb(oracle_kb::in, decl_question(T)::in,
 	maybe(decl_answer(T))::out) is cc_multi.
Index: doc/mdb_categories
===================================================================
RCS file: /home/mercury1/repository/mercury/doc/mdb_categories,v
retrieving revision 1.23
diff -u -r1.23 mdb_categories
--- doc/mdb_categories	15 Jun 2004 05:35:09 -0000	1.23
+++ doc/mdb_categories	9 Aug 2004 11:15:37 -0000
@@ -54,10 +54,15 @@
              For help on the `help' command, type `help help help'.
 
 end
+document_category 850 dd
+dd         - Commands related to declarative debugging.  These are `dd', 
+             `trust', `trusted' and `untrust'.
+
+end
 document_category 900 misc
 misc       - Commands that are of interest to most users but do not fit into
-             other categories. The misc commands are `source', `save', `dd',
-             `trust' and `quit'.
+             other categories. The misc commands are `source', `save' and 
+	     `quit'.
 
 end
 document_category 1000 exp
Index: doc/user_guide.texi
===================================================================
RCS file: /home/mercury1/repository/mercury/doc/user_guide.texi,v
retrieving revision 1.390
diff -u -r1.390 user_guide.texi
--- doc/user_guide.texi	19 Jul 2004 03:37:49 -0000	1.390
+++ doc/user_guide.texi	9 Aug 2004 07:21:57 -0000
@@ -3256,12 +3256,24 @@
 using the current event as the initial symptom.
 For details, see @ref{Declarative debugging}.
 @sp 1
- at item trust @var{module-name}
+ at item trust [@var{module-name}|@var{proc-spec}]
 @kindex trust (mdb command)
-The declarative debugger will assume that all predicates and functions in the
-given module are correct.  Use this command with modules you are confident do
-not contain any bugs to reduce the number of questions the declarative
-debugger needs to ask to find a bug.
+Tells the declarative debugger to trust the given module, predicate or 
+function.  Individual predicates or functions can be trusted by just giving
+the predicate or function name.  If there is more than one predicate or 
+function with the given name then a list of alternatives will be shown.
+See also `trusted' and `untrust'.
+ at sp 1
+ at item trusted
+ at kindex trusted (mdb command)
+Lists all the trusted modules, predicates and functions.  See also `trust'
+and `untrust'.
+ at sp 1
+ at item untrust @var{num}
+ at kindex untrust (mdb command)
+Removes the object from the list of trusted objects.  @var{num} should 
+correspond with the number shown the the list produced by issuing a `trusted'
+command.  See also `trust' and `trusted'.
 @sp 1
 @item quit [-y]
 @kindex quit (mdb command)
Index: runtime/mercury_stack_trace.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_stack_trace.c,v
retrieving revision 1.67
diff -u -r1.67 mercury_stack_trace.c
--- runtime/mercury_stack_trace.c	20 Jul 2004 04:41:23 -0000	1.67
+++ runtime/mercury_stack_trace.c	9 Aug 2004 05:50:16 -0000
@@ -76,7 +76,8 @@
                         MR_Print_Stack_Record print_stack_record);
 
 static  void        MR_print_proc_id_internal(FILE *fp,
-                        const MR_Proc_Layout *entry, MR_bool spec);
+                        const MR_Proc_Layout *entry, MR_bool spec, 
+                        MR_bool print_mode);
 
 static  void        MR_maybe_print_context(FILE *fp,
                         const char *filename, int lineno);
@@ -1255,17 +1256,24 @@
 void
 MR_print_proc_id(FILE *fp, const MR_Proc_Layout *entry)
 {
-    MR_print_proc_id_internal(fp, entry, MR_FALSE);
+    MR_print_proc_id_internal(fp, entry, MR_FALSE, MR_TRUE);
+}
+
+void
+MR_print_pred_id(FILE *fp, const MR_Proc_Layout *entry)
+{
+    MR_print_proc_id_internal(fp, entry, MR_FALSE, MR_FALSE);
 }
 
 void
 MR_print_proc_spec(FILE *fp, const MR_Proc_Layout *entry)
 {
-    MR_print_proc_id_internal(fp, entry, MR_TRUE);
+    MR_print_proc_id_internal(fp, entry, MR_TRUE, MR_TRUE);
 }
 
 static void
-MR_print_proc_id_internal(FILE *fp, const MR_Proc_Layout *entry, MR_bool spec)
+MR_print_proc_id_internal(FILE *fp, const MR_Proc_Layout *entry, MR_bool spec,
+    MR_bool print_mode)
 {
     const MR_User_Proc_Id *user;
     const MR_UCI_Proc_Id  *uci;
@@ -1288,18 +1296,21 @@
                 MR_fatal_error("uci procedure is not unify, compare or index");
             }
 
-            fprintf(fp, "%s.%s/%ld-%ld",
+            fprintf(fp, "%s.%s/%ld",
                 uci->MR_uci_type_module,
                 uci->MR_uci_type_name,
-                (long) uci->MR_uci_type_arity,
-                (long) uci->MR_uci_mode);
+                (long) uci->MR_uci_type_arity);
+
         } else {
-            fprintf(fp, "%s for %s.%s/%ld-%ld",
+            fprintf(fp, "%s for %s.%s/%ld",
                 uci->MR_uci_pred_name,
                 uci->MR_uci_type_module,
                 uci->MR_uci_type_name,
-                (long) uci->MR_uci_type_arity,
-                (long) uci->MR_uci_mode);
+                (long) uci->MR_uci_type_arity);
+        }
+
+        if (print_mode) {
+            fprintf(fp, "-%ld", (long) uci->MR_uci_mode);
         }
 
         if (strcmp(uci->MR_uci_type_module,
@@ -1324,11 +1335,14 @@
             fprintf(fp, " ");
         }
 
-        fprintf(fp, "%s.%s/%ld-%ld",
+        fprintf(fp, "%s.%s/%ld",
             user->MR_user_decl_module,
             user->MR_user_name,
-            (long) MR_sle_user_adjusted_arity(entry),
-            (long) user->MR_user_mode);
+            (long) MR_sle_user_adjusted_arity(entry));
+
+        if (print_mode) {
+            fprintf(fp, "-%ld", (long) user->MR_user_mode);
+        }
 
         if (!spec && strcmp(user->MR_user_decl_module,
             user->MR_user_def_module) != 0)
@@ -1337,7 +1351,7 @@
         }
     }
 
-    if (! spec) {
+    if (! spec && print_mode) {
         fprintf(fp, " (%s)", MR_detism_names[entry->MR_sle_detism]);
     }
 }
Index: runtime/mercury_stack_trace.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_stack_trace.h,v
retrieving revision 1.33
diff -u -r1.33 mercury_stack_trace.h
--- runtime/mercury_stack_trace.h	24 May 2004 04:32:48 -0000	1.33
+++ runtime/mercury_stack_trace.h	9 Aug 2004 05:50:16 -0000
@@ -242,6 +242,13 @@
 extern	void	MR_print_proc_id(FILE *fp, const MR_Proc_Layout *entry);
 
 /*
+** MR_print_pred_id prints everything that MR_print_proc_id does, except
+** the mode number and determinism.
+*/
+
+extern	void	MR_print_pred_id(FILE *fp, const MR_Proc_Layout *entry);
+
+/*
 ** MR_print_proc_spec prints a string that uniquely specifies the given
 ** procedure to the debugger.
 */
Index: tests/debugger/completion.exp
===================================================================
RCS file: /home/mercury1/repository/tests/debugger/completion.exp,v
retrieving revision 1.19
diff -u -r1.19 completion.exp
--- tests/debugger/completion.exp	19 Jul 2004 03:37:51 -0000	1.19
+++ tests/debugger/completion.exp	10 Aug 2004 02:45:17 -0000
@@ -3,29 +3,30 @@
 Command echo enabled.
 mdb> register --quiet
 mdb> 
-?                  disable            label_stats        save
-P                  document           level              save_to_file
-alias              document_category  maxdepth           scope
-all_class_decls    down               mindepth           scroll
-all_regs           e                  mm_stacks          set
-all_type_ctors     echo               mmc_options        source
-b                  enable             modules            stack
-break              exception          next               stack_regs
-browse             excp               nondet_stack       step
-c                  f                  p                  subgoal
-cc_query           finish             pneg_stack         table
-class_decl         flag               print              table_io
-clear_histogram    forward            print_optionals    term_size
-consumer           g                  printlevel         trust
-context            gen_stack          proc_stats         type_ctor
-continue           goal_paths         procedures         unalias
-current            goto               query              unhide_events
-cut_stack          h                  quit               up
-d                  help               r                  v
-dd                 histogram_all      register           var_details
-dd_dd              histogram_exp      retry              var_name_stats
-debug_vars         ignore             return             vars
-delete             io_query           s                  view
+?                  document           maxdepth           scroll
+P                  document_category  mindepth           set
+alias              down               mm_stacks          source
+all_class_decls    e                  mmc_options        stack
+all_regs           echo               modules            stack_regs
+all_type_ctors     enable             next               step
+b                  exception          nondet_stack       subgoal
+break              excp               p                  table
+browse             f                  pneg_stack         table_io
+c                  finish             print              term_size
+cc_query           flag               print_optionals    trust
+class_decl         forward            printlevel         trusted
+clear_histogram    g                  proc_stats         type_ctor
+consumer           gen_stack          procedures         unalias
+context            goal_paths         query              unhide_events
+continue           goto               quit               untrust
+current            h                  r                  up
+cut_stack          help               register           v
+d                  histogram_all      retry              var_details
+dd                 histogram_exp      return             var_name_stats
+dd_dd              ignore             s                  vars
+debug_vars         io_query           save               view
+delete             label_stats        save_to_file       
+--More--

disable            level              scope              
 h              help           histogram_all  histogram_exp  
 var_details     var_name_stats  vars            view
 var_details     var_name_stats  vars            
Index: tests/debugger/completion.inp
===================================================================
RCS file: /home/mercury1/repository/tests/debugger/completion.inp,v
retrieving revision 1.8
diff -u -r1.8 completion.inp
--- tests/debugger/completion.inp	4 May 2004 07:23:23 -0000	1.8
+++ tests/debugger/completion.inp	10 Aug 2004 02:38:09 -0000
@@ -1,6 +1,6 @@
 echo on
 register --quiet
- at h@e at v@a at s@
+@ h at e@v at a@s@
 p --f@@D@
 sta@ @
 proc at e@complet at .@1
Index: tests/debugger/mdb_command_test.inp
===================================================================
RCS file: /home/mercury1/repository/tests/debugger/mdb_command_test.inp,v
retrieving revision 1.31
diff -u -r1.31 mdb_command_test.inp
--- tests/debugger/mdb_command_test.inp	19 Jul 2004 03:37:52 -0000	1.31
+++ tests/debugger/mdb_command_test.inp	10 Aug 2004 02:47:38 -0000
@@ -44,6 +44,8 @@
 save                 xyzzy xyzzy xyzzy xyzzy xyzzy
 dd                   xyzzy xyzzy xyzzy xyzzy xyzzy
 trust                xyzzy xyzzy xyzzy xyzzy xyzzy
+trusted              xyzzy xyzzy xyzzy xyzzy xyzzy
+untrust              xyzzy xyzzy xyzzy xyzzy xyzzy
 quit                 xyzzy xyzzy xyzzy xyzzy xyzzy
 histogram_all        xyzzy xyzzy xyzzy xyzzy xyzzy
 histogram_exp        xyzzy xyzzy xyzzy xyzzy xyzzy
Index: tests/debugger/declarative/trust.exp
===================================================================
RCS file: /home/mercury1/repository/tests/debugger/declarative/trust.exp,v
retrieving revision 1.2
diff -u -r1.2 trust.exp
--- tests/debugger/declarative/trust.exp	24 Jun 2004 05:57:01 -0000	1.2
+++ tests/debugger/declarative/trust.exp	10 Aug 2004 02:47:09 -0000
@@ -1,9 +1,64 @@
       E1:     C1  1 CALL pred trust.main/2-0 (cc_multi) trust.m:13
-mdb> Contexts will not be printed.
+mdb> mdb> Contexts will not be printed.
 mdb> echo on
 Command echo enabled.
-mdb> trust trust_1
+mdb> trust trust_1.
+Ambiguous predicate or function specification. The matches are:
+0: pred trust_1.IntroducedFrom__pred__w_cmp__15__1/3
+1: pred trust_1.w_cmp/3
+
+Which predicate or function do you want to trust (0-1 or *)? *
+Trusting pred trust_1.IntroducedFrom__pred__w_cmp__15__1/3
+Trusting pred trust_1.w_cmp/3
+mdb> trusted
+Trusted Objects:
+0: pred trust_1.IntroducedFrom__pred__w_cmp__15__1/3
+1: pred trust_1.w_cmp/3
+mdb> untrust 1
+mdb> trusted
+Trusted Objects:
+0: pred trust_1.IntroducedFrom__pred__w_cmp__15__1/3
+mdb> untrust 0
+mdb> trusted
+There are no trusted modules, predicates or functions.
+mdb> trust trust_2
+Trusting module trust_2
+mdb> trust trust.
+Ambiguous predicate or function specification. The matches are:
+0: pred trust.dostuff/2
+1: pred trust.main/2
+
+Which predicate or function do you want to trust (0-1 or *)? 1
+Trusting pred trust.main/2
+mdb> trusted
+Trusted Objects:
+0: module trust_2
+1: pred trust.main/2
 mdb> trust trust_2
+Trusting module trust_2
+mdb> trusted
+Trusted Objects:
+0: module trust_2
+1: pred trust.main/2
+mdb> untrust 0
+mdb> trust trust_1
+Trusting module trust_1
+mdb> trust no_such_module
+mdb: there is no such module, predicate or function.
+mdb> trust trust_2.
+Trusting pred trust_2.concat/3
+mdb> trusted
+Trusted Objects:
+0: module trust_1
+1: pred trust.main/2
+2: pred trust_2.concat/3
+mdb> untrust 1
+mdb> trusted
+Trusted Objects:
+0: module trust_1
+1: pred trust_2.concat/3
+mdb> untrust 99
+mdb: no such trusted object
 mdb> step
       E2:     C2  2 CALL pred trust.dostuff/2-0 (cc_multi)
 mdb> finish
Index: tests/debugger/declarative/trust.inp
===================================================================
RCS file: /home/mercury1/repository/tests/debugger/declarative/trust.inp,v
retrieving revision 1.1
diff -u -r1.1 trust.inp
--- tests/debugger/declarative/trust.inp	15 Jun 2004 05:35:12 -0000	1.1
+++ tests/debugger/declarative/trust.inp	9 Aug 2004 14:19:40 -0000
@@ -1,7 +1,27 @@
+register --quiet
 context none
 echo on
-trust trust_1
+trust trust_1.
+*
+trusted
+untrust 1
+trusted
+untrust 0
+trusted
+trust trust_2
+trust trust.
+1
+trusted
 trust trust_2
+trusted
+untrust 0
+trust trust_1
+trust no_such_module
+trust trust_2.
+trusted
+untrust 1
+trusted
+untrust 99
 step
 finish
 dd
Index: trace/mercury_trace_declarative.c
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_declarative.c,v
retrieving revision 1.69
diff -u -r1.69 mercury_trace_declarative.c
--- trace/mercury_trace_declarative.c	7 Jul 2004 07:11:22 -0000	1.69
+++ trace/mercury_trace_declarative.c	9 Aug 2004 05:50:16 -0000
@@ -1030,6 +1030,48 @@
 	);
 }
 
+void
+MR_decl_add_trusted_pred_or_func(const MR_Proc_Layout *entry)
+{
+	MR_trace_decl_ensure_init();
+	MR_TRACE_CALL_MERCURY(
+		MR_DD_decl_add_trusted_pred_or_func(entry,
+			MR_trace_front_end_state,
+			&MR_trace_front_end_state);
+	);
+}
+
+MR_bool
+MR_decl_remove_trusted(int n)
+{
+	MR_bool success;
+	MR_Word new_diagnoser;
+	
+	MR_trace_decl_ensure_init();
+	MR_TRACE_CALL_MERCURY(
+		success = MR_DD_decl_remove_trusted(n,
+			MR_trace_front_end_state,
+			&new_diagnoser);
+	);
+	if (success) {
+		MR_trace_front_end_state = new_diagnoser;
+	}
+	return success;
+}
+
+void 
+MR_decl_print_all_trusted(FILE *fp, MR_bool mdb_command_format)
+{
+	MR_String	trusted_list;
+	
+	MR_trace_decl_ensure_init();
+	MR_TRACE_CALL_MERCURY(
+		MR_DD_decl_get_trusted_list(MR_trace_front_end_state, 
+			mdb_command_format, &trusted_list);
+	);
+	fprintf(fp, trusted_list);
+}
+
 MR_bool
 MR_trace_start_decl_debug(MR_Trace_Mode trace_mode, const char *outfile,
 	MR_Trace_Cmd_Info *cmd, MR_Event_Info *event_info,
Index: trace/mercury_trace_declarative.h
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_declarative.h,v
retrieving revision 1.17
diff -u -r1.17 mercury_trace_declarative.h
--- trace/mercury_trace_declarative.h	15 Jun 2004 05:35:13 -0000	1.17
+++ trace/mercury_trace_declarative.h	9 Aug 2004 05:50:16 -0000
@@ -50,14 +50,24 @@
 extern	MR_bool	MR_trace_decl_assume_all_io_is_tabled;
 
 /*
-** This function adds a module to the set of trusted modules in the 
-** oracle_state inside the current diagnoser_state.  It will call 
-** MR_trace_decl_ensure_init to ensure the diagnoser_state is initialised 
-** first.
+** These functions add(or remove) a module, pred or func to(or from) the set of 
+** trusted objects in the oracle_state inside the current diagnoser_state.
+** They will call MR_trace_decl_ensure_init to ensure the diagnoser_state is
+** initialised first.
 */
 
 extern	void	MR_decl_add_trusted_module(const char *module_name);
+extern	void	MR_decl_add_trusted_pred_or_func(const MR_Proc_Layout *entry);
+extern	MR_bool	MR_decl_remove_trusted(int n);
 
+/*
+** Prints a list of the trusted objects.  If mdb_command_format is true it
+** prints the list as a series of mdb `trust' commands.  Otherwise it 
+** prints the list in a format suitable for display.
+*/
+
+extern	void	MR_decl_print_all_trusted(FILE *fp, 
+			MR_bool mdb_command_format);
 /*
 ** The following macros are provided to help C code manipulate the
 ** Mercury data structure.  The values here must match the corresponding
Index: trace/mercury_trace_internal.c
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_internal.c,v
retrieving revision 1.177
diff -u -r1.177 mercury_trace_internal.c
--- trace/mercury_trace_internal.c	20 Jul 2004 04:41:54 -0000	1.177
+++ trace/mercury_trace_internal.c	9 Aug 2004 07:26:28 -0000
@@ -471,6 +471,8 @@
 static	MR_TraceCmdFunc	MR_trace_cmd_dd;
 static	MR_TraceCmdFunc	MR_trace_cmd_dd_dd;
 static	MR_TraceCmdFunc	MR_trace_cmd_trust;
+static	MR_TraceCmdFunc	MR_trace_cmd_untrust;
+static	MR_TraceCmdFunc	MR_trace_cmd_trusted;
 
 static	void	MR_maybe_print_spy_point(int slot, const char *problem);
 static	void	MR_print_unsigned_var(FILE *fp, const char *var,
@@ -5252,6 +5254,8 @@
 					"invalid default scope");
 		}
 
+		MR_decl_print_all_trusted(fp, MR_TRUE);
+
 		if (found_error) {
 			fflush(MR_mdb_out);
 			fprintf(MR_mdb_err, "mdb: could not save "
@@ -5369,6 +5373,9 @@
 		&words, &word_count, "dd", "dd_dd"))
 	{
 		; /* the usage message has already been printed */
+	MR_Proc_Spec		spec;
+	MR_Matches_Info		matches;
+
 	} else if (word_count <= 2) {
 		if (word_count == 2) {
 			trace_mode = MR_TRACE_DECL_DEBUG_DUMP;
@@ -5395,14 +5402,134 @@
 	MR_Event_Info *event_info, MR_Event_Details *event_details,
 	MR_Code **jumpaddr)
 {	
+	MR_Proc_Spec		spec;
+	MR_Matches_Info		matches;
+
 	if (word_count == 2) {
-		MR_decl_add_trusted_module(words[1]);
+		spec.MR_proc_module = NULL;
+		spec.MR_proc_name   = NULL;
+		spec.MR_proc_arity  = -1;
+		spec.MR_proc_mode   = -1;
+		spec.MR_proc_prefix = (MR_Proc_Prefix) -1;
+
+		MR_register_all_modules_and_procs(MR_mdb_out, MR_TRUE);
+		
+		/* First see if the argument is a module name */
+		spec.MR_proc_module = words[1];
+		matches = MR_search_for_matching_procedures(&spec);
+		if (matches.match_proc_next > 0) {
+			MR_decl_add_trusted_module(words[1]);
+			fprintf(MR_mdb_out, "Trusting module %s\n", words[1]);
+		} else if (MR_parse_proc_spec(words[1], &spec)){
+			/* Check to see if the argument is a pred/func */
+			matches = MR_search_for_matching_procedures(&spec);
+			MR_filter_user_preds(&matches);
+			if (matches.match_proc_next == 0) {
+				fprintf(MR_mdb_err, "mdb: there is no such "
+					"module, predicate or function.\n");
+			} else if (matches.match_proc_next == 1) {
+				MR_decl_add_trusted_pred_or_func(
+					matches.match_procs[0]);
+				fprintf(MR_mdb_out, "Trusting ");
+				MR_print_pred_id_and_nl(MR_mdb_out,
+					matches.match_procs[0]);
+			} else {
+				int i;
+				char buf[80];
+				char *line2;
+
+				fprintf(MR_mdb_out, "Ambiguous predicate or "
+					"function specification. The matches "
+					"are:\n");
+				for (i = 0; i < matches.match_proc_next; i++)
+				{
+					fprintf(MR_mdb_out, "%d: ", i);
+					MR_print_pred_id_and_nl(MR_mdb_out,
+						matches.match_procs[i]);
+				}
+				sprintf(buf, "\nWhich predicate or function "
+					"do you want to trust (0-%d or *)? ",
+					matches.match_proc_next - 1);
+				line2 = MR_trace_getline(buf,
+					MR_mdb_in, MR_mdb_out);
+				if (line2 == NULL) {
+					/* This means the user input EOF. */
+					fprintf(MR_mdb_out, "none of them\n");
+				} else if (MR_streq(line2, "*")) {
+					for (i = 0;
+						i < matches.match_proc_next;
+						i++)
+					{
+					    MR_decl_add_trusted_pred_or_func(
+						matches.match_procs[i]);
+					    
+					    fprintf(MR_mdb_out, "Trusting ");
+					    MR_print_pred_id_and_nl(MR_mdb_out,
+						matches.match_procs[i]);
+					}
+					MR_free(line2);
+				}else if(MR_trace_is_natural_number(line2, &i))
+					{
+					if (0 <= i &&
+						i < matches.match_proc_next)
+					{
+					    MR_decl_add_trusted_pred_or_func(
+						matches.match_procs[i]);
+					    
+					    fprintf(MR_mdb_out, "Trusting ");
+					    MR_print_pred_id_and_nl(MR_mdb_out,
+						matches.match_procs[i]);
+					} else {
+						fprintf(MR_mdb_out,
+							"no such match\n");
+					}
+					MR_free(line2);
+				} else {
+					fprintf(MR_mdb_out, "none of them\n");
+					MR_free(line2);
+				}
+			}
+		}
 	} else {
 		MR_trace_usage("dd", "trust");
 	}
 	return KEEP_INTERACTING;
 }
 
+static MR_Next
+MR_trace_cmd_untrust(char **words, int word_count, MR_Trace_Cmd_Info *cmd,
+	MR_Event_Info *event_info, MR_Event_Details *event_details,
+	MR_Code **jumpaddr)
+{
+	int i;
+	
+	if (word_count == 2) {
+		if (MR_trace_is_natural_number(words[1], &i)) {
+			if (!MR_decl_remove_trusted(i)) {
+				fprintf(MR_mdb_err, "mdb: no such trusted "
+					"object\n");
+			}
+		} else {
+			MR_trace_usage("dd", "untrust");
+		}
+	} else {
+		MR_trace_usage("dd", "untrust");
+	}
+	return KEEP_INTERACTING;
+}
+
+static MR_Next
+MR_trace_cmd_trusted(char **words, int word_count, MR_Trace_Cmd_Info *cmd,
+	MR_Event_Info *event_info, MR_Event_Details *event_details,
+	MR_Code **jumpaddr)
+{
+	if (word_count == 1) {
+		MR_decl_print_all_trusted(MR_mdb_out, MR_FALSE);
+	} else {
+		MR_trace_usage("dd", "trusted");
+	}
+	return KEEP_INTERACTING;
+}
 
 static void
 MR_maybe_print_spy_point(int slot, const char *problem)
@@ -7181,17 +7308,22 @@
 	{ "help", "help", MR_trace_cmd_help,
 		NULL, MR_trace_help_completer },
 
+	{ "dd", "dd", MR_trace_cmd_dd,
+		NULL, MR_trace_null_completer },
+	{ "dd", "trust", MR_trace_cmd_trust, NULL, 
+		MR_trace_null_completer },
+	{ "dd", "untrust", MR_trace_cmd_untrust, NULL,
+		MR_trace_null_completer },
+	{ "dd", "trusted", MR_trace_cmd_trusted, NULL,
+		MR_trace_null_completer },
+
 	{ "misc", "source", MR_trace_cmd_source,
 		MR_trace_source_cmd_args, MR_trace_filename_completer },
 	{ "misc", "save", MR_trace_cmd_save,
 		NULL, MR_trace_filename_completer },
-	{ "misc", "dd", MR_trace_cmd_dd,
-		NULL, MR_trace_null_completer },
 	{ "misc", "quit", MR_trace_cmd_quit,
 		MR_trace_quit_cmd_args, NULL },
-	{ "misc", "trust", MR_trace_cmd_trust, NULL, 
-		MR_trace_null_completer },
-
+	
 	{ "exp", "histogram_all", MR_trace_cmd_histogram_all,
 		NULL, MR_trace_filename_completer },
 	{ "exp", "histogram_exp", MR_trace_cmd_histogram_exp,
Index: trace/mercury_trace_tables.c
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_tables.c,v
retrieving revision 1.28
diff -u -r1.28 mercury_trace_tables.c
--- trace/mercury_trace_tables.c	23 May 2004 22:16:56 -0000	1.28
+++ trace/mercury_trace_tables.c	9 Aug 2004 05:50:16 -0000
@@ -680,6 +680,25 @@
 	}
 }
 
+void
+MR_filter_user_preds(MR_Matches_Info *matches)
+{
+	int filter_pos = 0;
+	int i;
+	const MR_Proc_Layout *entry;
+
+	for(i = 0; i < matches->match_proc_next; i++) {
+		entry = matches->match_procs[i];
+    		if (!MR_PROC_LAYOUT_IS_UCI(entry) && 
+			(entry->MR_sle_user).MR_user_mode == 0) 
+		{
+			matches->match_procs[filter_pos] = entry;
+			filter_pos++;
+		}
+	}
+	matches->match_proc_next = filter_pos;
+}
+
 MR_Completer_List *
 MR_trace_module_completer(const char *word, size_t word_len)
 {
@@ -1012,6 +1031,13 @@
 MR_print_proc_id_and_nl(FILE *fp, const MR_Proc_Layout *entry_layout)
 {
 	MR_print_proc_id(fp, entry_layout);
+	fprintf(fp, "\n");
+}
+
+void
+MR_print_pred_id_and_nl(FILE *fp, const MR_Proc_Layout *entry_layout)
+{
+	MR_print_pred_id(fp, entry_layout);
 	fprintf(fp, "\n");
 }
 
Index: trace/mercury_trace_tables.h
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_tables.h,v
retrieving revision 1.15
diff -u -r1.15 mercury_trace_tables.h
--- trace/mercury_trace_tables.h	23 May 2004 22:16:57 -0000	1.15
+++ trace/mercury_trace_tables.h	9 Aug 2004 05:50:16 -0000
@@ -146,6 +146,9 @@
 
 extern	MR_Matches_Info	MR_search_for_matching_procedures(MR_Proc_Spec *spec);
 
+/* filter out UCI procs and keep only mode number 0 */
+extern	void MR_filter_user_preds(MR_Matches_Info *matches);
+
 /*
 ** MR_process_matching_procedures(spec, f, data):
 **	For each procedure that matches the specification given by `spec',
@@ -164,6 +167,14 @@
 */
 
 extern	void	MR_print_proc_id_and_nl(FILE *fp, const MR_Proc_Layout *proc);
+
+/*
+** MR_print_pred_id_and_nl(fp, proc):
+** 	Print the id of the predicate/function identified by proc, 
+**	followed by a newline.
+*/
+
+extern	void	MR_print_pred_id_and_nl(FILE *fp, const MR_Proc_Layout *proc);
 
 /*
 ** MR_proc_layout_stats(fp):

--------------------------------------------------------------------------
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