[m-dev.] for review: fix retry bugs

Zoltan Somogyi zs at cs.mu.OZ.AU
Fri Dec 15 14:54:57 AEDT 2000


For review by Fergus or Mark. The diff doesn't contain the updates of the .exp*
files; I will decide on them after I finish two bootchecks (one in a normal
grade, and one in a debug grade).

---------------------------------

Fix several bugs in retry.

trace/mercury_trace.c:
	Fix three bugs reported by Fergus in the behavior of the mdb retry
	command.

	Catch the case where the retry command tries to retry a call that
	would be an ancestor of main.

	Catch the case where the retry command tries to retry a call that
	is in shallow traced region of the computation tree.

	Don't abort if the retried call is missing an I/O state argument
	and relevant procedure was compiled without --trace-table-io; just
	ask the user whether they want to proceed with the retry.

	Add some conditionally compiled debugging code.

compiler/trace.m:
	Fix a bug that caused the debugger to core dump when given a retry
	command that went across a shallow traced region of the program.
	(This bug was exposed when I fixed the second bug reported by Fergus.)
	A procedure that lives on the det stack that nevertheless pushes
	temporary frames onto the nondet stack should save the original value
	of maxfr on procedure entry even if it is shallow traced and from_full
	is false, since the debugger will need to restore the value of maxfr
	during retry.

tests/debugger/queens.{inp,exp,exp2}:
	Test how mdb handles trying to retry an ancestor of main.

	Test how mdb handles a retry with a missing I/O state argument.

tests/debugger/all_solutions.{m,inp,exp,exp2}:
	New test case. The code is a copy of samples/solutions/all_solutions.m.
	Its input script tests retry into and across a shallow traced region
	(inside std_util:solutions).

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
Index: compiler/trace.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/trace.m,v
retrieving revision 1.42
diff -u -b -r1.42 trace.m
--- compiler/trace.m	2000/12/06 06:05:21	1.42
+++ compiler/trace.m	2000/12/15 02:40:51
@@ -575,35 +575,20 @@
 		FillSlotsUptoTrail = FillSlotsUptoRedo
 	),
 	(
-		% This could be done by generating proper LLDS instead of C.
-		% However, in shallow traced code we want to execute this
-		% only when the caller is deep traced, and everything inside
-		% that test must be in C code.
-		MaybeMaxfrLval = yes(MaxfrLval),
-		trace__stackref_to_string(MaxfrLval, MaxfrLvalStr),
-		string__append_list([
-			FillSlotsUptoTrail,
-			"\n\t\t", MaxfrLvalStr, " = (MR_Word) MR_maxfr;"
-		], FillSlotsUptoMaxfr)
-	;
-		MaybeMaxfrLval = no,
-		FillSlotsUptoMaxfr = FillSlotsUptoTrail
-	),
-	(
 		MaybeFromFullSlot = yes(CallFromFullSlot),
 		trace__stackref_to_string(CallFromFullSlot,
 			CallFromFullSlotStr),
 		string__append_list([
 			"\t\t", CallFromFullSlotStr, " = MR_trace_from_full;\n",
 			"\t\tif (MR_trace_from_full) {\n",
-			FillSlotsUptoMaxfr, "\n",
+			FillSlotsUptoTrail, "\n",
 			"\t\t} else {\n",
 			"\t\t\t", CallDepthStr, " = MR_trace_call_depth;\n",
 			"\t\t}"
 		], TraceStmt1)
 	;
 		MaybeFromFullSlot = no,
-		TraceStmt1 = FillSlotsUptoMaxfr
+		TraceStmt1 = FillSlotsUptoTrail
 	),
 	TraceCode1 = node([
 		pragma_c([], [pragma_c_raw_code(TraceStmt1)],
@@ -611,20 +596,29 @@
 			- ""
 	]),
 	(
+		MaybeMaxfrLval = yes(MaxfrLval),
+		TraceCode2 = node([
+			assign(MaxfrLval, lval(maxfr)) - "save initial maxfr"
+		])
+	;
+		MaybeMaxfrLval = no,
+		TraceCode2 = empty
+	),
+	(
 		MaybeCallTableLval = yes(CallTableLval),
 		trace__stackref_to_string(CallTableLval, CallTableLvalStr),
 		string__append_list([
 			"\t\t", CallTableLvalStr, " = 0;"
-		], TraceStmt2),
-		TraceCode2 = node([
-			pragma_c([], [pragma_c_raw_code(TraceStmt2)],
+		], TraceStmt3),
+		TraceCode3 = node([
+			pragma_c([], [pragma_c_raw_code(TraceStmt3)],
 				will_not_call_mercury, no, no, no, yes) - ""
 		])
 	;
 		MaybeCallTableLval = no,
-		TraceCode2 = empty
+		TraceCode3 = empty
 	),
-	TraceCode = tree(TraceCode1, TraceCode2)
+	TraceCode = tree(TraceCode1, tree(TraceCode2, TraceCode3))
 	}.
 
 trace__prepare_for_call(TraceCode) -->
cvs diff: Diffing compiler/notes
cvs diff: Diffing debian
cvs diff: Diffing doc
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/stream
cvs diff: Diffing extras/trailed_update
cvs diff: Diffing extras/trailed_update/samples
cvs diff: Diffing extras/trailed_update/tests
cvs diff: Diffing extras/xml
cvs diff: Diffing extras/xml/samples
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/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/debugger/Mmakefile,v
retrieving revision 1.46
diff -u -b -r1.46 Mmakefile
--- tests/debugger/Mmakefile	2000/12/06 06:05:52	1.46
+++ tests/debugger/Mmakefile	2000/12/15 03:47:19
@@ -18,6 +18,7 @@
 #-----------------------------------------------------------------------------#
 
 DEBUGGER_PROGS=	\
+	all_solutions			\
 	breakpoints			\
 	browse_pretty			\
 	browser_test			\
Index: tests/debugger/all_solutions.exp
===================================================================
RCS file: all_solutions.exp
diff -N all_solutions.exp
Index: tests/debugger/all_solutions.exp2
===================================================================
RCS file: all_solutions.exp2
diff -N all_solutions.exp2
Index: tests/debugger/all_solutions.inp
===================================================================
RCS file: all_solutions.inp
diff -N all_solutions.inp
--- /dev/null	Thu Sep  2 15:00:04 1999
+++ all_solutions.inp	Fri Dec 15 14:38:10 2000
@@ -0,0 +1,8 @@
+echo on
+context none
+break hello
+continue
+retry 1
+retry 2
+retry 3
+continue -a
Index: tests/debugger/all_solutions.m
===================================================================
RCS file: all_solutions.m
diff -N all_solutions.m
--- /dev/null	Thu Sep  2 15:00:04 1999
+++ all_solutions.m	Fri Dec 15 14:36:59 2000
@@ -0,0 +1,24 @@
+% An example program to illustrate the use of all-solutions predicates
+% in Mercury.  This program just prints out all solutions to the
+% predicate hello/1.
+
+% This source file is hereby placed in the public domain.  -fjh (the author).
+
+:- module all_solutions.
+:- interface.
+:- import_module io.
+
+:- pred main(io__state::di, io__state::uo) is det.
+
+:- implementation.
+:- import_module std_util.
+
+main --> 
+	{ solutions(hello, List) },
+	io__write_strings(List).
+
+:- pred hello(string::out) is multidet.
+
+hello("Hello, world\n").
+hello("Hello again, world\n").
+
Index: tests/debugger/queens.inp
===================================================================
RCS file: /home/mercury1/repository/tests/debugger/queens.inp,v
retrieving revision 1.9
diff -u -b -r1.9 queens.inp
--- tests/debugger/queens.inp	1999/11/15 00:43:48	1.9
+++ tests/debugger/queens.inp	2000/12/15 03:39:17
@@ -1,4 +1,5 @@
 echo on
+retry 1
 print *
 
 print *
@@ -71,4 +72,9 @@
 forward
 continue -n
 continue -n
+delete *
+break main
+continue -n
+retry
+yes
 continue -n -S
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.c
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace.c,v
retrieving revision 1.33
diff -u -b -r1.33 mercury_trace.c
--- trace/mercury_trace.c	2000/12/08 06:37:06	1.33
+++ trace/mercury_trace.c	2000/12/15 03:24:42
@@ -66,10 +66,14 @@
 				const MR_Stack_Layout_Label *layout,
 				MR_Trace_Port port, MR_Unsigned seqno,
 				MR_Unsigned depth);
+static	bool		MR_in_traced_region(
+				const MR_Stack_Layout_Entry *proc_layout,
+				MR_Word *base_sp, MR_Word *base_curfr);
 static	bool		MR_is_io_state(MR_PseudoTypeInfo pti);
-static	MR_Unsigned	MR_find_saved_io_counter(
+static	bool		MR_find_saved_io_counter(
 				const MR_Stack_Layout_Label *call_label,
-				MR_Word *base_sp, MR_Word *base_curfr);
+				MR_Word *base_sp, MR_Word *base_curfr,
+				MR_Unsigned *saved_io_counter_ptr);
 static	const MR_Stack_Layout_Label *MR_unwind_stacks_for_retry(
 				const MR_Stack_Layout_Label *top_layout,
 				int ancestor_level, MR_Word **base_sp_ptr,
@@ -467,7 +471,8 @@
 	bool				succeeded;
 	MR_Word 			*saved_regs;
 	bool				has_io_state;
-	MR_Unsigned			saved_io_state_counter;
+	bool				found_io_action_counter;
+	MR_Unsigned			saved_io_action_counter;
 #ifdef	MR_USE_MINIMAL_MODEL
 	MR_Retry_Result			result;
 #endif
@@ -507,6 +512,11 @@
 		goto report_problem;
 	}
 
+	if (! MR_in_traced_region(level_layout, base_sp, base_curfr)) {
+		*problem = "that call is not in a deep traced region";
+		goto report_problem;
+	}
+
 	call_label = level_layout->MR_sle_call_label;
 	input_args = &call_label->MR_sll_var_info;
 	if (input_args->MR_slvs_var_count < 0) {
@@ -526,8 +536,9 @@
 	arg_max = 0;
 
 	has_io_state = FALSE;
+	found_io_action_counter = FALSE;
 		/* just to prevent uninitialized variable warnings */
-	saved_io_state_counter = 0;
+	saved_io_action_counter = 0;
 
 	for (i = 0; i < MR_all_desc_var_count(input_args); i++) {
 		arg_value = MR_trace_find_input_arg(return_label_layout,
@@ -537,10 +548,17 @@
 
 		if (! succeeded) {
 			if (MR_is_io_state(MR_var_pti(input_args, i))) {
+				/*
+				** Since I/O state input arguments are not
+				** used, we can leave arg_value containing
+				** garbage.
+				*/
+
 				has_io_state = TRUE;
-				saved_io_state_counter =
+				found_io_action_counter =
 					MR_find_saved_io_counter(call_label,
-						base_sp, base_curfr);
+						base_sp, base_curfr,
+						&saved_io_action_counter);
 			} else {
 				*problem = "Cannot perform retry because the "
 					"values of some input arguments "
@@ -571,11 +589,22 @@
 			bool	allow_retry;
 			char	*answer;
 
+			if (found_io_action_counter
+			|| MR_io_tabling_counter == 0)
+			{
 			answer = MR_trace_getline(
 				"Retry across I/O operations "
 				"is not always safe.\n"
 				"Are you sure you want to do it? ",
 				in_fp, out_fp);
+			} else {
+				answer = MR_trace_getline(
+					"Retry across I/O operations "
+					"without saved I/O action numbers "
+					"is not safe.\n"
+					"Are you sure you want to do it? ",
+					in_fp, out_fp);
+			}
 
 			allow_retry = (answer[0] == 'y' || answer[0] == 'Y');
 			MR_free(answer);
@@ -710,8 +739,8 @@
 		MR_saved_reg(saved_regs, i) = args[i];
 	}
 
-	if (has_io_state) {
-		MR_io_tabling_counter = saved_io_state_counter;
+	if (has_io_state && found_io_action_counter) {
+		MR_io_tabling_counter = saved_io_action_counter;
 	}
 
 	event_info->MR_max_mr_num = max(event_info->MR_max_mr_num, arg_max);
@@ -747,6 +776,29 @@
 }
 
 static bool
+MR_in_traced_region(const MR_Stack_Layout_Entry *proc_layout,
+	MR_Word *base_sp, MR_Word *base_curfr)
+{
+	if (proc_layout->MR_sle_maybe_from_full <= 0) {
+		/* the procedure was deep traced */
+		return TRUE;
+	} else {
+		/* the procedure was shallow traced */
+		MR_Word	from_full;
+
+		if (MR_DETISM_DET_STACK(proc_layout->MR_sle_detism)) {
+			from_full = MR_based_stackvar(base_sp, 
+				proc_layout->MR_sle_maybe_from_full);
+		} else {
+			from_full = MR_based_framevar(base_curfr, 
+				proc_layout->MR_sle_maybe_from_full);
+		}
+
+		return from_full;
+	}
+}
+
+static bool
 MR_is_io_state(MR_PseudoTypeInfo pti)
 {
 	MR_TypeCtorInfo	type_ctor_info;
@@ -761,28 +813,32 @@
 		&& streq(type_ctor_info->type_ctor_name, "state"));
 }
 
-static MR_Unsigned
+static bool
 MR_find_saved_io_counter(const MR_Stack_Layout_Label *call_label,
-	MR_Word *base_sp, MR_Word *base_curfr)
+	MR_Word *base_sp, MR_Word *base_curfr,
+	MR_Unsigned *saved_io_counter_ptr)
 {
 	const MR_Stack_Layout_Entry	*level_layout;
 	MR_Unsigned			saved_io_counter;
 
 	level_layout = call_label->MR_sll_entry;
 	if (level_layout->MR_sle_maybe_io_seq <= 0) {
-		MR_fatal_error("MR_trace_retry: "
-			"missing io seq number slot");
+		return FALSE;
 	}
 
+	if (! MR_in_traced_region(level_layout, base_sp, base_curfr)) {
+		return FALSE;
+	}
+
 	if (MR_DETISM_DET_STACK(level_layout->MR_sle_detism)) {
-		saved_io_counter = MR_based_stackvar(base_sp,
+		*saved_io_counter_ptr = MR_based_stackvar(base_sp,
 			level_layout->MR_sle_maybe_io_seq);
 	} else {
-		saved_io_counter = MR_based_framevar(base_curfr,
+		*saved_io_counter_ptr = MR_based_framevar(base_curfr,
 			level_layout->MR_sle_maybe_io_seq);
 	}
 
-	return saved_io_counter;
+	return TRUE;
 }
 
 /*
@@ -811,6 +867,15 @@
 		return NULL;
 	}
 
+#ifdef	MR_DEBUG_RETRY_STACKS
+	MR_print_detstackptr(MR_mdb_out, *sp_ptr);
+	fprintf(MR_mdb_out, "\n");
+	MR_print_nondstackptr(MR_mdb_out, *curfr_ptr);
+	fprintf(MR_mdb_out, "\n");
+	MR_print_nondstackptr(MR_mdb_out, *maxfr_ptr);
+	fprintf(MR_mdb_out, "\n");
+#endif
+
 	return_label_layout = top_layout;
 	level_layout = top_layout->MR_sll_entry;
 	*problem = MR_undo_updates_of_maxfr(level_layout,
@@ -822,10 +887,19 @@
 
 	MR_maybe_record_call_table(level_layout, *sp_ptr, *curfr_ptr);
 
+#ifdef	MR_DEBUG_RETRY_STACKS
+	MR_print_detstackptr(MR_mdb_out, *sp_ptr);
+	fprintf(MR_mdb_out, "\n");
+	MR_print_nondstackptr(MR_mdb_out, *curfr_ptr);
+	fprintf(MR_mdb_out, "\n");
+	MR_print_nondstackptr(MR_mdb_out, *maxfr_ptr);
+	fprintf(MR_mdb_out, "\n");
+#endif
+
 	for (i = 0; i < ancestor_level; i++) {
 		result = MR_stack_walk_step(level_layout, &return_label_layout,
 				sp_ptr, curfr_ptr, problem);
-		if (result != STEP_OK) {
+		if (result != STEP_OK || return_label_layout == NULL) {
 			if (*problem == NULL) {
 				*problem = "not that many ancestors";
 			}
@@ -833,6 +907,15 @@
 			return NULL;
 		}
 
+#ifdef	MR_DEBUG_RETRY_STACKS
+		MR_print_detstackptr(MR_mdb_out, *sp_ptr);
+		fprintf(MR_mdb_out, "\n");
+		MR_print_nondstackptr(MR_mdb_out, *curfr_ptr);
+		fprintf(MR_mdb_out, "\n");
+		MR_print_nondstackptr(MR_mdb_out, *maxfr_ptr);
+		fprintf(MR_mdb_out, "\n");
+#endif
+
 		level_layout = return_label_layout->MR_sll_entry;
 		*problem = MR_undo_updates_of_maxfr(level_layout,
 				*sp_ptr, *curfr_ptr, maxfr_ptr);
@@ -843,6 +926,15 @@
 
 		MR_maybe_record_call_table(level_layout, *sp_ptr, *curfr_ptr);
 	}
+
+#ifdef	MR_DEBUG_RETRY_STACKS
+	MR_print_detstackptr(MR_mdb_out, *sp_ptr);
+	fprintf(MR_mdb_out, "\n");
+	MR_print_nondstackptr(MR_mdb_out, *curfr_ptr);
+	fprintf(MR_mdb_out, "\n");
+	MR_print_nondstackptr(MR_mdb_out, *maxfr_ptr);
+	fprintf(MR_mdb_out, "\n");
+#endif
 
 	return return_label_layout;
 }
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