[m-dev.] for review: redo events in shallow traced procedures
Zoltan Somogyi
zs at cs.mu.OZ.AU
Tue Aug 24 13:56:02 AEST 1999
Shallow traced procedures do not fill in most of their stack slots holding
debugging information unless they are called from deep traced code, yet the
code in the runtime that handles redo events for such procedures was using
the values in those slots. This changes fixes that problem, by adding another
piece of code in the runtime for handling redo events for shallow traced
procedures.
compiler/llds.m:
Rename do_trace_redo_fail as do_trace_redo_fail_deep and add a new
label, do_trace_redo_fail_shallow.
compiler/trace.m:
Select which label gets included as the redoip in the temporary frame
that generates redo events, and document the assumptions about stack
slots used by the new label.
compiler/dupelim.m:
compiler/exprn_aux.m:
compiler/livemap.m:
compiler/llds_out.m:
compiler/opt_debug.m:
compiler/opt_util.m:
Conform to the changes in llds.m.
runtime/mercury_trace_base.c:
Add the label and code for handling redo events in shallow traced
procedures.
runtime/mercury_stack_layout.h:
Add a macro used by mercury_trace_base.c.
tests/debugger/shallow.{m,inp,exp}:
New test case. It is the same code as queens.m, but compiled with
shallow tracing. It segfaults before but not after this change.
tests/debugger/Mmakefile:
Enable the new test case.
Comment out a rule for a disabled test case, to avoid make errors.
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/dupelim.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/dupelim.m,v
retrieving revision 1.41
diff -u -b -r1.41 dupelim.m
--- dupelim.m 1999/07/13 08:52:51 1.41
+++ dupelim.m 1999/08/23 05:27:30
@@ -947,7 +947,10 @@
dupelim__replace_labels_code_addr(do_succeed(Last), _, do_succeed(Last)).
dupelim__replace_labels_code_addr(do_redo, _, do_redo).
dupelim__replace_labels_code_addr(do_fail, _, do_fail).
-dupelim__replace_labels_code_addr(do_trace_redo_fail, _, do_trace_redo_fail).
+dupelim__replace_labels_code_addr(do_trace_redo_fail_shallow, _,
+ do_trace_redo_fail_shallow).
+dupelim__replace_labels_code_addr(do_trace_redo_fail_deep, _,
+ do_trace_redo_fail_deep).
dupelim__replace_labels_code_addr(do_call_closure, _, do_call_closure).
dupelim__replace_labels_code_addr(do_call_class_method, _,
do_call_class_method).
Index: compiler/exprn_aux.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/exprn_aux.m,v
retrieving revision 1.36
diff -u -b -r1.36 exprn_aux.m
--- exprn_aux.m 1999/07/13 08:52:52 1.36
+++ exprn_aux.m 1999/08/23 05:26:28
@@ -149,7 +149,8 @@
exprn_aux__addr_is_constant(do_succeed(_), _, no).
exprn_aux__addr_is_constant(do_redo, _, no).
exprn_aux__addr_is_constant(do_fail, _, no).
-exprn_aux__addr_is_constant(do_trace_redo_fail, _, no).
+exprn_aux__addr_is_constant(do_trace_redo_fail_shallow, _, no).
+exprn_aux__addr_is_constant(do_trace_redo_fail_deep, _, no).
exprn_aux__addr_is_constant(do_call_closure, _, no).
exprn_aux__addr_is_constant(do_call_class_method, _, no).
exprn_aux__addr_is_constant(do_det_aditi_call, _, no).
Index: compiler/livemap.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/livemap.m,v
retrieving revision 1.42
diff -u -b -r1.42 livemap.m
--- livemap.m 1999/07/13 08:53:04 1.42
+++ livemap.m 1999/08/23 05:25:37
@@ -393,7 +393,8 @@
livemap__special_code_addr(succip, yes(succip)).
livemap__special_code_addr(do_succeed(_), yes(succip(lval(curfr)))).
livemap__special_code_addr(do_redo, yes(redoip(lval(maxfr)))).
-livemap__special_code_addr(do_trace_redo_fail, no).
+livemap__special_code_addr(do_trace_redo_fail_shallow, no).
+livemap__special_code_addr(do_trace_redo_fail_deep, no).
livemap__special_code_addr(do_fail, no).
livemap__special_code_addr(do_call_closure, no).
livemap__special_code_addr(do_call_class_method, no).
Index: compiler/llds.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/llds.m,v
retrieving revision 1.247
diff -u -b -r1.247 llds.m
--- llds.m 1999/08/23 05:20:50 1.247
+++ llds.m 1999/08/23 05:23:41
@@ -852,10 +852,15 @@
% rather than a succeed().
; do_redo
; do_fail
- ; do_trace_redo_fail
- % A label in the runtime, the code
+
+ ; do_trace_redo_fail_shallow
+ ; do_trace_redo_fail_deep
+ % Labels in the runtime, the code
% at which calls MR_trace with a
- % REDO event and then fails.
+ % REDO event and then fails. The
+ % shallow variety only does this
+ % if the from_full flag was set
+ % on entry to the given procedure.
; do_call_closure
; do_call_class_method
; do_det_aditi_call
Index: compiler/llds_out.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/llds_out.m,v
retrieving revision 1.119
diff -u -b -r1.119 llds_out.m
--- llds_out.m 1999/08/24 01:34:48 1.119
+++ llds_out.m 1999/08/24 01:46:53
@@ -2597,7 +2597,8 @@
{ UseMacro = no },
{ NeedDecl = yes }
).
-need_code_addr_decls(do_trace_redo_fail, yes) --> [].
+need_code_addr_decls(do_trace_redo_fail_shallow, yes) --> [].
+need_code_addr_decls(do_trace_redo_fail_deep, yes) --> [].
need_code_addr_decls(do_call_closure, yes) --> [].
need_code_addr_decls(do_call_class_method, yes) --> [].
need_code_addr_decls(do_det_aditi_call, yes) --> [].
@@ -2641,8 +2642,10 @@
io__write_string("do_fail"),
io__write_string(");\n")
).
-output_code_addr_decls(do_trace_redo_fail) -->
- io__write_string("Declare_entry(MR_do_trace_redo_fail);\n").
+output_code_addr_decls(do_trace_redo_fail_shallow) -->
+ io__write_string("Declare_entry(MR_do_trace_redo_fail_shallow);\n").
+output_code_addr_decls(do_trace_redo_fail_deep) -->
+ io__write_string("Declare_entry(MR_do_trace_redo_fail_deep);\n").
output_code_addr_decls(do_call_closure) -->
io__write_string("Declare_entry(mercury__do_call_closure);\n").
output_code_addr_decls(do_call_class_method) -->
@@ -2866,8 +2869,10 @@
{ UseMacro = no },
io__write_string("GOTO(ENTRY(do_fail));\n")
).
-output_goto(do_trace_redo_fail, _) -->
- io__write_string("GOTO(ENTRY(MR_do_trace_redo_fail));\n").
+output_goto(do_trace_redo_fail_shallow, _) -->
+ io__write_string("GOTO(ENTRY(MR_do_trace_redo_fail_shallow));\n").
+output_goto(do_trace_redo_fail_deep, _) -->
+ io__write_string("GOTO(ENTRY(MR_do_trace_redo_fail_deep));\n").
output_goto(do_call_closure, CallerLabel) -->
io__write_string("tailcall(ENTRY(mercury__do_call_closure),\n\t\t"),
output_label_as_code_addr(CallerLabel),
@@ -2972,8 +2977,10 @@
io__write_string("ENTRY(do_redo)").
output_code_addr(do_fail) -->
io__write_string("ENTRY(do_fail)").
-output_code_addr(do_trace_redo_fail) -->
- io__write_string("ENTRY(MR_do_trace_redo_fail)").
+output_code_addr(do_trace_redo_fail_shallow) -->
+ io__write_string("ENTRY(MR_do_trace_redo_fail_shallow)").
+output_code_addr(do_trace_redo_fail_deep) -->
+ io__write_string("ENTRY(MR_do_trace_redo_fail_deep)").
output_code_addr(do_call_closure) -->
io__write_string("ENTRY(mercury__do_call_closure)").
output_code_addr(do_call_class_method) -->
Index: compiler/opt_debug.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/opt_debug.m,v
retrieving revision 1.94
diff -u -b -r1.94 opt_debug.m
--- opt_debug.m 1999/07/13 08:53:17 1.94
+++ opt_debug.m 1999/08/23 05:24:49
@@ -767,7 +767,9 @@
).
opt_debug__dump_code_addr(do_redo, "do_redo").
opt_debug__dump_code_addr(do_fail, "do_fail").
-opt_debug__dump_code_addr(do_trace_redo_fail, "do_trace_redo_fail").
+opt_debug__dump_code_addr(do_trace_redo_fail_shallow,
+ "do_trace_redo_fail_shallow").
+opt_debug__dump_code_addr(do_trace_redo_fail_deep, "do_trace_redo_fail_deep").
opt_debug__dump_code_addr(do_call_closure, "do_nondet_closure").
opt_debug__dump_code_addr(do_call_class_method, "do_nondet_class_method").
opt_debug__dump_code_addr(do_det_aditi_call, "do_det_aditi_call").
Index: compiler/opt_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/opt_util.m,v
retrieving revision 1.101
diff -u -b -r1.101 opt_util.m
--- opt_util.m 1999/07/13 08:53:18 1.101
+++ opt_util.m 1999/08/23 05:25:20
@@ -1281,7 +1281,8 @@
opt_util__livevals_addr(do_succeed(_), yes).
opt_util__livevals_addr(do_redo, no).
opt_util__livevals_addr(do_fail, no).
-opt_util__livevals_addr(do_trace_redo_fail, no).
+opt_util__livevals_addr(do_trace_redo_fail_shallow, no).
+opt_util__livevals_addr(do_trace_redo_fail_deep, no).
opt_util__livevals_addr(do_call_closure, yes).
opt_util__livevals_addr(do_call_class_method, yes).
opt_util__livevals_addr(do_det_aditi_call, yes).
Index: compiler/trace.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/trace.m,v
retrieving revision 1.21
diff -u -b -r1.21 trace.m
--- trace.m 1999/08/16 05:48:12 1.21
+++ trace.m 1999/08/23 05:27:57
@@ -229,6 +229,15 @@
% trace events, the runtime will know that this slot exists and
% what its number must be; if we do not, the runtime will never
% refer to such a slot.
+ %
+ % We need two redo labels in the runtime. Deep traced procedures
+ % do not have a from-full slot, but their slots 1 through 4 are always
+ % valid; the label handling their redos accesses those slots directly.
+ % Shallow traced procedures do have a from-full slot, and their slots
+ % 1-4 are valid only if the from-full slot is TRUE; the label handling
+ % their redos thus checks this slot to see whether it can (or should)
+ % access the other slots. In shallow-traced model_non procedures
+ % that generate redo events, the from-full flag is always in slot 5.
trace__reserved_slots(ProcInfo, Globals, ReservedSlots) :-
globals__get_trace_level(Globals, TraceLevel),
@@ -544,13 +553,28 @@
}.
trace__maybe_setup_redo_event(TraceInfo, Code) :-
- TraceInfo = trace_info(_, _, _, TraceRedo),
+ TraceInfo = trace_info(TraceType, _, _, TraceRedo),
( TraceRedo = yes(_) ->
+ (
+ TraceType = shallow_trace(Lval),
+ % The code in the runtime looks for the from-full
+ % flag in framevar 5; see the comment before
+ % trace__reserved_slots.
+ require(unify(Lval, framevar(5)),
+ "from-full flag not stored in expected slot"),
Code = node([
mkframe(temp_frame(nondet_stack_proc),
- do_trace_redo_fail)
+ do_trace_redo_fail_shallow)
+ - "set up shallow redo event"
+ ])
+ ;
+ TraceType = deep_trace,
+ Code = node([
+ mkframe(temp_frame(nondet_stack_proc),
+ do_trace_redo_fail_deep)
- "set up deep redo event"
])
+ )
;
Code = empty
).
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/dynamic_linking
cvs diff: Diffing extras/exceptions
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/odbc
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 runtime
Index: runtime/mercury_stack_layout.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_stack_layout.h,v
retrieving revision 1.26
diff -u -b -r1.26 mercury_stack_layout.h
--- mercury_stack_layout.h 1999/08/24 01:35:47 1.26
+++ mercury_stack_layout.h 1999/08/24 01:47:37
@@ -471,18 +471,20 @@
/*
** In model_non procedures compiled with an execution trace options that
-** require REDO events, one other item is stored in a fixed stack slot.
+** require REDO events, one or two other items are stored in fixed stack slots.
** This is
**
** the address of the layout structure for the redo event
+** the saved copy of the from-full flag (only if trace level is shallow)
**
-** The following macro will access it. This macro should be used only from
+** The following macros will access these slots. They should be used only from
** within the code that calls MR_trace for the REDO event.
**
** This macros have to be kept in sync with compiler/trace.m.
*/
#define MR_redo_layout_framevar(base_curfr) MR_based_framevar(base_curfr, 4)
+#define MR_redo_fromfull_framevar(base_curfr) MR_based_framevar(base_curfr, 5)
/*-------------------------------------------------------------------------*/
/*
Index: runtime/mercury_trace_base.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_trace_base.c,v
retrieving revision 1.16
diff -u -b -r1.16 mercury_trace_base.c
--- mercury_trace_base.c 1999/05/14 02:25:06 1.16
+++ mercury_trace_base.c 1999/08/23 05:31:33
@@ -375,13 +375,35 @@
MR_PORT_REDO
};
-Define_extern_entry(MR_do_trace_redo_fail);
+Define_extern_entry(MR_do_trace_redo_fail_shallow);
+Define_extern_entry(MR_do_trace_redo_fail_deep);
BEGIN_MODULE(MR_trace_labels_module)
- init_entry_ai(MR_do_trace_redo_fail);
+ init_entry_ai(MR_do_trace_redo_fail_shallow);
+ init_entry_ai(MR_do_trace_redo_fail_deep);
BEGIN_CODE
-Define_entry(MR_do_trace_redo_fail);
+Define_entry(MR_do_trace_redo_fail_shallow);
+ /*
+ ** If this code ever needs changing, you may also need to change
+ ** the code in extras/exceptions/exception.m similarly.
+ */
+ if (MR_redo_fromfull_framevar(MR_redofr_slot(MR_curfr)))
+ {
+ Code *MR_jumpaddr;
+ MR_retry_trace_call_info.MR_trace_sll =
+ (const MR_Stack_Layout_Label *)
+ MR_redo_layout_framevar(MR_redofr_slot(MR_curfr));
+ save_transient_registers();
+ MR_jumpaddr = MR_trace_struct(&MR_retry_trace_call_info);
+ restore_transient_registers();
+ if (MR_jumpaddr != NULL) {
+ GOTO(MR_jumpaddr);
+ }
+ }
+ fail();
+
+Define_entry(MR_do_trace_redo_fail_deep);
#if 0
/* For use in case this ever needs to be debugged again. */
printf("MR_curfr = %p\n", MR_curfr);
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 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.26
diff -u -b -r1.26 Mmakefile
--- Mmakefile 1999/07/12 06:25:15 1.26
+++ Mmakefile 1999/08/24 01:54:13
@@ -24,12 +24,15 @@
interpreter \
mdb_command_test \
multi_parameter \
- queens
+ queens \
+ shallow
# The following tests are disabled, since currently they get some spurious
# failures if readline support is enabled:
# interactive
+# Note that some of the make rules for interactive are disabled too.
+MCFLAGS-shallow = --trace shallow
MCFLAGS = --trace deep
MLFLAGS = --trace
C2INITFLAGS = --trace
@@ -87,8 +90,12 @@
# Note that interactive.out.orig depends on $(interactive.ints) because
# interactive.inp contains interactive queries that require interactive.ints
# to have been built.
-interactive.out.orig: interactive interactive.inp $(interactive.ints)
- $(MDB) ./interactive < interactive.inp > interactive.out.orig 2>&1
+
+# This rule is commented out while the interactive test case is disabled,
+# because otherwise we get an undefined variable error from make.
+
+# interactive.out.orig: interactive interactive.inp $(interactive.ints)
+# $(MDB) ./interactive < interactive.inp > interactive.out.orig 2>&1
# We pipe the output through sed to remove some spurious warnings that
# `ld' issues.
Index: tests/debugger/shallow.exp
===================================================================
RCS file: shallow.exp
diff -N shallow.exp
--- /dev/null Tue Aug 24 12:32:12 1999
+++ shallow.exp Tue Aug 24 12:01:45 1999
@@ -0,0 +1,4 @@
+ 1: 1 1 CALL pred shallow:main/2-0 (cc_multi)
+mdb> c -a
+[1, 3, 5, 2, 4]
+ 2: 1 1 EXIT pred shallow:main/2-0 (cc_multi)
Index: tests/debugger/shallow.inp
===================================================================
RCS file: shallow.inp
diff -N shallow.inp
--- /dev/null Tue Aug 24 12:32:12 1999
+++ shallow.inp Tue Aug 24 11:42:28 1999
@@ -0,0 +1 @@
+c -a
Index: tests/debugger/shallow.m
===================================================================
RCS file: shallow.m
diff -N shallow.m
--- /dev/null Tue Aug 24 12:32:12 1999
+++ shallow.m Tue Aug 24 11:42:57 1999
@@ -0,0 +1,101 @@
+:- module shallow.
+
+:- interface.
+
+:- import_module io.
+
+:- pred main(io__state, io__state).
+:- mode main(di, uo) is cc_multi.
+
+:- implementation.
+
+:- import_module list, int.
+
+main -->
+ ( { data(Data), queen(Data, Out) } ->
+ print_list(Out)
+ ;
+ io__write_string("No solution\n")
+ ).
+
+:- pred data(list(int)).
+:- mode data(out) is det.
+
+:- pred queen(list(int), list(int)).
+:- mode queen(in, out) is nondet.
+
+:- pred qperm(list(T), list(T)).
+:- mode qperm(in, out) is nondet.
+
+:- pred qdelete(T, list(T), list(T)).
+:- mode qdelete(out, in, out) is nondet.
+
+:- pred safe(list(int)).
+:- mode safe(in) is semidet.
+
+:- pred nodiag(int, int, list(int)).
+:- mode nodiag(in, in, in) is semidet.
+
+data([1,2,3,4,5]).
+
+queen(Data, Out) :-
+ qperm(Data, Out),
+ safe(Out).
+
+qperm([], []).
+qperm([X|Y], K) :-
+ qdelete(U, [X|Y], Z),
+ K = [U|V],
+ qperm(Z, V).
+
+qdelete(A, [A|L], L).
+qdelete(X, [A|Z], [A|R]) :-
+ qdelete(X, Z, R).
+
+safe([]).
+safe([N|L]) :-
+ nodiag(N, 1, L),
+ safe(L).
+
+nodiag(_, _, []).
+nodiag(B, D, [N|L]) :-
+ NmB is N - B,
+ BmN is B - N,
+ ( D = NmB ->
+ fail
+ ; D = BmN ->
+ fail
+ ;
+ true
+ ),
+ D1 is D + 1,
+ nodiag(B, D1, L).
+
+:- pred print_list(list(int), io__state, io__state).
+:- mode print_list(in, di, uo) is det.
+
+print_list(Xs) -->
+ (
+ { Xs = [] }
+ ->
+ io__write_string("[]\n")
+ ;
+ io__write_string("["),
+ print_list_2(Xs),
+ io__write_string("]\n")
+ ).
+
+:- pred print_list_2(list(int), io__state, io__state).
+:- mode print_list_2(in, di, uo) is det.
+
+print_list_2([]) --> [].
+print_list_2([X|Xs]) -->
+ io__write_int(X),
+ (
+ { Xs = [] }
+ ->
+ []
+ ;
+ io__write_string(", "),
+ print_list_2(Xs)
+ ).
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/sub-modules
cvs diff: Diffing tests/hard_coded/typeclasses
cvs diff: Diffing tests/invalid
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
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