[m-dev.] for review: resolving ambiguity in the mdb "break" command

Zoltan Somogyi zs at cs.mu.OZ.AU
Fri Aug 25 16:15:18 AEST 2000


For review by anyone.

Handle ambiguous procedure specifications in the debugger's "break" command
more usefully.

trace/mercury_trace_tables.[ch]:
	Add a function for returning all the procedures that match a
	specification.

trace/mercury_trace_internal.c:
	Use this function to present the user all the matches for the procedure
	specification if their specification matches more than one procedure,
	and let them choose whether they want to put a breakpoint on them all,
	and if not, which one to put the breakpoint on.

doc/user_guide.texi:
	Document the new functionality.

tests/debugger/breakpoints.{m,in,exp}:
	Introduce a function named "data" to go with the predicate, and check
	that the "break" command handles the ambiguity properly.

Zoltan.

cvs diff: Diffing .
cvs diff: Diffing bindist
cvs diff: Diffing boehm_gc
cvs diff: Diffing boehm_gc/Mac_files
cvs diff: Diffing boehm_gc/cord
cvs diff: Diffing boehm_gc/cord/private
cvs diff: Diffing boehm_gc/include
cvs diff: Diffing boehm_gc/include/private
cvs diff: Diffing browser
cvs diff: Diffing bytecode
cvs diff: Diffing compiler
cvs diff: Diffing compiler/notes
cvs diff: Diffing debian
cvs diff: Diffing doc
Index: doc/user_guide.texi
===================================================================
RCS file: /home/mercury1/repository/mercury/doc/user_guide.texi,v
retrieving revision 1.215
diff -u -r1.215 user_guide.texi
--- doc/user_guide.texi	2000/08/23 16:42:54	1.215
+++ doc/user_guide.texi	2000/08/25 02:17:20
@@ -2125,6 +2125,9 @@
 @item break [-PSaei] @var{proc-spec}
 @c <module name> <predicate name> [<arity> [<mode> [<predfunc>]]]
 Puts a break point on the specified procedure.
+If the specification matches more than one procedure,
+you will be asked whether you want to put a breakpoint on all of them,
+or just one (and if so, which one).
 @sp 1
 The options @samp{-P} or @samp{--print}, and @samp{-S} or @samp{--stop}
 specify the action to be taken at the break point,
cvs diff: Diffing extras
cvs diff: Diffing extras/aditi
cvs diff: Diffing extras/cgi
cvs diff: Diffing extras/complex_numbers
cvs diff: Diffing extras/complex_numbers/samples
cvs diff: Diffing extras/complex_numbers/tests
cvs diff: Diffing extras/concurrency
cvs diff: Diffing extras/curses
cvs diff: Diffing extras/curses/sample
cvs diff: Diffing extras/dynamic_linking
cvs diff: Diffing extras/graphics
cvs diff: Diffing extras/graphics/mercury_opengl
cvs diff: Diffing extras/graphics/mercury_tcltk
cvs diff: Diffing extras/graphics/samples
cvs diff: Diffing extras/graphics/samples/calc
cvs diff: Diffing extras/graphics/samples/maze
cvs diff: Diffing extras/graphics/samples/pent
cvs diff: Diffing extras/lazy_evaluation
cvs diff: Diffing extras/logged_output
cvs diff: Diffing extras/moose
cvs diff: Diffing extras/moose/samples
cvs diff: Diffing extras/morphine
cvs diff: Diffing extras/morphine/non-regression-tests
cvs diff: Diffing extras/morphine/scripts
cvs diff: Diffing extras/morphine/source
cvs diff: Diffing extras/odbc
cvs diff: Diffing extras/posix
cvs diff: Diffing extras/references
cvs diff: Diffing extras/references/samples
cvs diff: Diffing extras/references/tests
cvs diff: Diffing extras/trailed_update
cvs diff: Diffing extras/trailed_update/samples
cvs diff: Diffing extras/trailed_update/tests
cvs diff: Diffing library
cvs diff: Diffing profiler
cvs diff: Diffing robdd
cvs diff: Diffing runtime
cvs diff: Diffing runtime/GETOPT
cvs diff: Diffing runtime/machdeps
cvs diff: Diffing samples
cvs diff: Diffing samples/c_interface
cvs diff: Diffing samples/c_interface/c_calls_mercury
cvs diff: Diffing samples/c_interface/cplusplus_calls_mercury
cvs diff: Diffing samples/c_interface/mercury_calls_c
cvs diff: Diffing samples/c_interface/mercury_calls_cplusplus
cvs diff: Diffing samples/c_interface/mercury_calls_fortran
cvs diff: Diffing samples/c_interface/simpler_c_calls_mercury
cvs diff: Diffing samples/c_interface/simpler_cplusplus_calls_mercury
cvs diff: Diffing samples/diff
cvs diff: Diffing samples/muz
cvs diff: Diffing samples/rot13
cvs diff: Diffing samples/solutions
cvs diff: Diffing samples/tests
cvs diff: Diffing samples/tests/c_interface
cvs diff: Diffing samples/tests/c_interface/c_calls_mercury
cvs diff: Diffing samples/tests/c_interface/cplusplus_calls_mercury
cvs diff: Diffing samples/tests/c_interface/mercury_calls_c
cvs diff: Diffing samples/tests/c_interface/mercury_calls_cplusplus
cvs diff: Diffing samples/tests/c_interface/mercury_calls_fortran
cvs diff: Diffing samples/tests/c_interface/simpler_c_calls_mercury
cvs diff: Diffing samples/tests/c_interface/simpler_cplusplus_calls_mercury
cvs diff: Diffing samples/tests/diff
cvs diff: Diffing samples/tests/muz
cvs diff: Diffing samples/tests/rot13
cvs diff: Diffing samples/tests/solutions
cvs diff: Diffing samples/tests/toplevel
cvs diff: Diffing scripts
cvs diff: Diffing tests
cvs diff: Diffing tests/benchmarks
cvs diff: Diffing tests/debugger
Index: tests/debugger/breakpoints.exp
===================================================================
RCS file: /home/mercury1/repository/tests/debugger/breakpoints.exp,v
retrieving revision 1.3
diff -u -r1.3 breakpoints.exp
--- tests/debugger/breakpoints.exp	1999/11/20 01:03:25	1.3
+++ tests/debugger/breakpoints.exp	2000/08/25 05:39:29
@@ -3,9 +3,26 @@
 Command echo enabled.
 mdb> register --quiet
 mdb> break data
+Ambiguous procedure specification. The matches are:
+0: pred breakpoints:data/1-0 (det)
+1: func breakpoints:data/1-0 (det)
+
+Which do you want to put a breakpoint on (0-1 or *)? *
  0: + stop  interface pred breakpoints:data/1-0 (det)
+ 1: + stop  interface func breakpoints:data/1-0 (det)
+mdb> delete 0
+ 0: E stop  interface pred breakpoints:data/1-0 (det)
+mdb> delete 1
+ 1: E stop  interface func breakpoints:data/1-0 (det)
+mdb> break data
+Ambiguous procedure specification. The matches are:
+0: pred breakpoints:data/1-0 (det)
+1: func breakpoints:data/1-0 (det)
+
+Which do you want to put a breakpoint on (0-1 or *)? 0
+ 0: + stop  interface pred breakpoints:data/1-0 (det)
 mdb> continue
-       2:      2  2 CALL pred breakpoints:data/1-0 (det) breakpoints.m:39 (breakpoints.m:15)
+       3:      3  3 CALL pred breakpoints:data/1-0 (det) breakpoints.m:44 (breakpoints.m:42)
 mdb> disable 0
  0: - stop  interface pred breakpoints:data/1-0 (det)
 mdb> break info
@@ -36,21 +53,21 @@
 mdb> break nodiag
  0: + stop  interface pred breakpoints:nodiag/3-0 (semidet)
 mdb> continue
-       5:      4  3 CALL pred breakpoints:qperm/2-0 (nondet) breakpoints.m:45 (breakpoints.m:42)
+       7:      5  3 CALL pred breakpoints:qperm/2-0 (nondet) breakpoints.m:50 (breakpoints.m:47)
 mdb> continue
-       6:      4  3 SWTC pred breakpoints:qperm/2-0 (nondet) s1; breakpoints.m:46
+       8:      5  3 SWTC pred breakpoints:qperm/2-0 (nondet) s1; breakpoints.m:51
 mdb> finish -N
-      10:      6  4 CALL pred breakpoints:qperm/2-0 (nondet) breakpoints.m:45 (breakpoints.m:49)
+      12:      7  4 CALL pred breakpoints:qperm/2-0 (nondet) breakpoints.m:50 (breakpoints.m:54)
 mdb> finish -n
-      36:      6  4 EXIT pred breakpoints:qperm/2-0 (nondet) breakpoints.m:45 (breakpoints.m:49)
+      38:      7  4 EXIT pred breakpoints:qperm/2-0 (nondet) breakpoints.m:50 (breakpoints.m:54)
 mdb> continue
-      37:      4  3 EXIT pred breakpoints:qperm/2-0 (nondet) breakpoints.m:45 (breakpoints.m:42)
+      39:      5  3 EXIT pred breakpoints:qperm/2-0 (nondet) breakpoints.m:50 (breakpoints.m:47)
 mdb> continue
-      38:     15  3 CALL pred breakpoints:safe/1-0 (semidet) breakpoints.m:55 (breakpoints.m:43)
+      40:     16  3 CALL pred breakpoints:safe/1-0 (semidet) breakpoints.m:60 (breakpoints.m:48)
 mdb> finish
-      40:     16  4 CALL pred breakpoints:nodiag/3-0 (semidet) breakpoints.m:60 (breakpoints.m:57)
-      43:     16  4 FAIL pred breakpoints:nodiag/3-0 (semidet) breakpoints.m:60 (breakpoints.m:57)
-      44:     15  3 FAIL pred breakpoints:safe/1-0 (semidet) breakpoints.m:55 (breakpoints.m:43)
+      42:     17  4 CALL pred breakpoints:nodiag/3-0 (semidet) breakpoints.m:65 (breakpoints.m:62)
+      45:     17  4 FAIL pred breakpoints:nodiag/3-0 (semidet) breakpoints.m:65 (breakpoints.m:62)
+      46:     16  3 FAIL pred breakpoints:safe/1-0 (semidet) breakpoints.m:60 (breakpoints.m:48)
 mdb> delete *
  0: E stop  interface pred breakpoints:nodiag/3-0 (semidet)
  1: E stop  interface pred breakpoints:qperm/2-0 (nondet)
Index: tests/debugger/breakpoints.inp
===================================================================
RCS file: /home/mercury1/repository/tests/debugger/breakpoints.inp,v
retrieving revision 1.1
diff -u -r1.1 breakpoints.inp
--- tests/debugger/breakpoints.inp	1999/10/07 09:31:29	1.1
+++ tests/debugger/breakpoints.inp	2000/08/25 05:39:12
@@ -1,6 +1,11 @@
 echo on
 register --quiet
 break data
+*
+delete 0
+delete 1
+break data
+0
 continue
 disable 0
 break info
Index: tests/debugger/breakpoints.m
===================================================================
RCS file: /home/mercury1/repository/tests/debugger/breakpoints.m,v
retrieving revision 1.1
diff -u -r1.1 breakpoints.m
--- tests/debugger/breakpoints.m	1999/10/07 09:31:30	1.1
+++ tests/debugger/breakpoints.m	2000/08/25 05:32:18
@@ -12,12 +12,14 @@
 :- import_module list, int.
 
 main -->
-	( { data(Data), queen(Data, Out) } ->
+	( { queen(data, Out) } ->
 		print_list(Out)
 	;
 		io__write_string("No solution\n")
 	).
 
+:- func data = list(int).
+
 :- pred data(list(int)).
 :- mode data(out) is det.
 
@@ -35,6 +37,9 @@
 
 :- pred nodiag(int, int, list(int)).
 :- mode nodiag(in, in, in) is semidet.
+
+data = D :-
+	data(D).
 
 data([1,2,3,4,5]).
 
cvs diff: Diffing tests/debugger/declarative
cvs diff: Diffing tests/dppd
cvs diff: Diffing tests/general
cvs diff: Diffing tests/general/accumulator
cvs diff: Diffing tests/hard_coded
cvs diff: Diffing tests/hard_coded/exceptions
cvs diff: Diffing tests/hard_coded/purity
cvs diff: Diffing tests/hard_coded/sub-modules
cvs diff: Diffing tests/hard_coded/typeclasses
cvs diff: Diffing tests/invalid
cvs diff: Diffing tests/invalid/purity
cvs diff: Diffing tests/misc_tests
cvs diff: Diffing tests/tabling
cvs diff: Diffing tests/term
cvs diff: Diffing tests/valid
cvs diff: Diffing tests/warnings
cvs diff: Diffing tools
cvs diff: Diffing trace
Index: trace/mercury_trace_internal.c
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_internal.c,v
retrieving revision 1.74
diff -u -r1.74 mercury_trace_internal.c
--- trace/mercury_trace_internal.c	2000/08/10 05:51:29	1.74
+++ trace/mercury_trace_internal.c	2000/08/25 05:32:07
@@ -1016,32 +1016,75 @@
 		} else if (word_count == 2 &&
 				MR_parse_proc_spec(words[1], &spec))
 		{
-			const MR_Stack_Layout_Entry	*spy_proc;
-			bool				unique;
-			int				slot;
+			MR_Matches_Info	matches;
+			int		slot;
 
 			MR_register_all_modules_and_procs(MR_mdb_out, TRUE);
-			spy_proc = MR_search_for_matching_procedure(&spec,
-					&unique);
-			if (spy_proc != NULL) {
-				if (unique) {
-					slot = MR_add_proc_spy_point(when,
-						action, spy_proc, NULL);
-					MR_print_spy_point(slot);
-				} else {
-					fflush(MR_mdb_out);
-					fprintf(MR_mdb_err,
-						"Ambiguous procedure "
-						"specification. "
-						"The matches are:\n");
-					MR_process_matching_procedures(&spec,
-						MR_mdb_print_proc_id,
-						MR_mdb_err);
-				}
-			} else {
+			matches = MR_search_for_matching_procedures(&spec);
+			if (matches.match_proc_next == 0) {
 				fflush(MR_mdb_out);
 				fprintf(MR_mdb_err,
 					"There is no such procedure.\n");
+			} else if (matches.match_proc_next == 1) {
+				slot = MR_add_proc_spy_point(when, action,
+					matches.match_procs[0], NULL);
+				MR_print_spy_point(slot);
+			} else {
+				char	buf[80];
+				int	i;
+				char	*line2;
+
+				fflush(MR_mdb_out);
+				fprintf(MR_mdb_err,
+					"Ambiguous procedure specification. "
+					"The matches are:\n");
+				for (i = 0; i < matches.match_proc_next; i++)
+				{
+					fprintf(MR_mdb_out, "%d: ", i);
+					MR_print_proc_id_for_debugger(
+						MR_mdb_out,
+						matches.match_procs[i]);
+				}
+
+				sprintf(buf, "\nWhich do you want to put "
+					"a breakpoint on (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 (streq(line2, "*")) {
+					for (i = 0;
+						i < matches.match_proc_next;
+						i++)
+					{
+						slot = MR_add_proc_spy_point(
+							when, action,
+							matches.match_procs[i],
+							NULL);
+						MR_print_spy_point(slot);
+					}
+
+					MR_free(line2);
+				} else if (MR_trace_is_number(line2, &i)) {
+					if (0 <= i &&
+						i < matches.match_proc_next)
+					{
+						slot = MR_add_proc_spy_point(
+							when, action,
+							matches.match_procs[i],
+							NULL);
+						MR_print_spy_point(slot);
+					} 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 if (word_count == 2 &&
 				MR_parse_source_locn(words[1], &file, &line))
Index: trace/mercury_trace_tables.c
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_tables.c,v
retrieving revision 1.10
diff -u -r1.10 mercury_trace_tables.c
--- trace/mercury_trace_tables.c	2000/05/15 16:37:47	1.10
+++ trace/mercury_trace_tables.c	2000/08/24 15:53:22
@@ -309,19 +309,48 @@
 	return TRUE;
 }
 
+#define	MR_INIT_MATCH_PROC_SIZE		8
+
+static void
+MR_register_matches(void *data, const MR_Stack_Layout_Entry *entry)
+{
+	MR_Matches_Info	*m;
+
+	m = (MR_Matches_Info *) data;
+	MR_ensure_room_for_next(m->match_proc, const MR_Stack_Layout_Entry *,
+		MR_INIT_MATCH_PROC_SIZE);
+	m->match_procs[m->match_proc_next] = entry;
+	m->match_proc_next++;
+}
+
+MR_Matches_Info
+MR_search_for_matching_procedures(MR_Proc_Spec *spec)
+{
+	MR_Matches_Info	m;
+
+	m.match_procs = NULL;
+	m.match_proc_max = 0;
+	m.match_proc_next = 0;
+	MR_process_matching_procedures(spec, MR_register_matches, &m);
+	return m;
+}
+
 /*
 ** This struct is for communication between
 ** MR_register_match and MR_search_for_matching_procedure.
 */
+
 typedef struct {
 	const MR_Stack_Layout_Entry	*matching_entry;
 	bool	 			match_unique;
-} MR_match_info;
+} MR_Match_Info;
 
 static void
 MR_register_match(void *data, const MR_Stack_Layout_Entry *entry)
 {
-	MR_match_info *m = data;
+	MR_Match_Info	*m;
+
+	m = (MR_Match_Info *) data;
 	if (m->matching_entry == NULL) {
 		m->matching_entry = entry;
 	} else {
@@ -332,7 +361,8 @@
 const MR_Stack_Layout_Entry *
 MR_search_for_matching_procedure(MR_Proc_Spec *spec, bool *unique)
 {
-	MR_match_info m;
+	MR_Match_Info	m;
+
 	m.matching_entry = NULL;
 	m.match_unique = TRUE;
 	MR_process_matching_procedures(spec, MR_register_match, &m);
Index: trace/mercury_trace_tables.h
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_tables.h,v
retrieving revision 1.6
diff -u -r1.6 mercury_trace_tables.h
--- trace/mercury_trace_tables.h	1999/11/15 00:43:58	1.6
+++ trace/mercury_trace_tables.h	2000/08/24 15:53:38
@@ -116,6 +116,22 @@
 					MR_Proc_Spec *spec, bool *unique);
 
 /*
+** Search the tables for procedures that matches the given specification.
+** Return their layout structures in the array in the match_procs field
+** of the structure. The match_proc_next field says how many matches there are,
+** and the match_proc_max field says how many entries the array has allocated
+** for it.
+*/
+
+typedef struct {
+	const MR_Stack_Layout_Entry	**match_procs;
+	int	 			match_proc_max;
+	int	 			match_proc_next;
+} MR_Matches_Info;
+
+extern	MR_Matches_Info	MR_search_for_matching_procedures(MR_Proc_Spec *spec);
+
+/*
 ** MR_process_matching_procedures(spec, f, data):
 **	For each procedure that matches the specification given by `spec',
 **	call `f(data, entry)', where `entry' is the entry layout for that
cvs diff: Diffing trax
cvs diff: Diffing trial
cvs diff: Diffing util
--------------------------------------------------------------------------
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