Files
mercury/trace
Zoltan Somogyi fbfd4970df Make the debugging of minimal model tabling easier by providing a mechanism
Estimated hours taken: 32
Branches: main

Make the debugging of minimal model tabling easier by providing a mechanism
to print the contents of the nondet stack, *including* the values of the
variables in its stack frames, even for frames which are not ancestors
of the currently executing call.

runtime/mercury_stack_trace.[ch]:
	Add functions for traversing the nondet stack, and for keeping track of
	through which label control returns to each nondet stack frame, so that
	we know which label's layout structure to interpret the stack frame's
	contents. For some, this will be the return label of a call; for
	others, it will be the label of a resumption point stored in a
	redoip slot.

	Rename an old function to allow the new one to fit into our naming
	scheme.

runtime/mercury_stack_trace.[ch]:
runtime/mercury_tabling.c:
library/exception.m:
trace/mercury_trace.c:
	Add MR_ prefixes to the values of the enum returned by
	MR_stack_walk_step.

	Rename references to the renamed function.

runtime/mercury_conf_param.h:
	Add macros for debugging label names and for debugging retries (which
	needs label names, just as debugging tabling does).

	Add a macro for controlling whether mercury_debug.c prints raw
	addresses as well as offsets (for stack pointers) or label names (for
	labels). The raw pointers can be useful in debugging, but they need to
	be turned off in test cases one wants to be reproducible.

runtime/mercury_label.h:
runtime/mercury_conf_param.h:
	Move the MR_NEED_ENTRY_LABEL_ARRAY and MR_NEED_ENTRY_LABEL_INFO macros
	from mercury_label.h to mercury_conf_param.h, since mercury_debug.c
	also needs them now.

runtime/mercury_debug.c:
	addresses as well as offsets (for stack pointers) or label names (for
	labels). The raw pointers can be useful in debugging, but they need to
	be turned off in test cases one wants to be reproducible.

runtime/mercury_init.h:
runtime/mercury_wrapper.[ch]:
util/mkinit.c:
	Add a global variable pointing to a function through which the stack
	walk code in runtime/mercury_stack_trace.c can invoke code from the
	debugger to print the values of the variables in nondet stack frames
	without breaking the rule prohibiting references to the trace directory
	from the runtime directory.

runtime/mercury_wrapper.c:
	Define the succip of the dummy frame at the bottom of the nondet stack,
	to avoid dereferencing a garbage pointer during detailed stack dumps.

runtime/mercury_goto.h:
	Add a mechanism for always registering the name of a specific label,
	even if label names are not being registered in general. This mechanism
	is intended to be used for labels such as do_fail, which occur
	frequently in nondet stack traces.

runtime/mercury_context.c:
runtime/mercury_engine.c:
runtime/mercury_ho_call.c:
runtime/mercury_trace_base.c:
runtime/mercury_wrapper.c:
	Use this mechanism for the labels defined in these modules.

library/builtin.m:
	Define type_ctor_infos for the pseudotypes representing nondet stack
	frame slots unconditionally, since the debugger may now need them.

trace/mercury_trace.c:
	Add conditionally enabled to code to make debugging retry easier.

trace/mercury_trace_internal.c:
	Add a -d option to the nondet_stack command that causes it to print
	detailed nondet stack dumps, including the names and values of the
	variables in each nondet stack frame.

trace/mercury_trace_vars.c:
	Provide a mechanism for printing the variables of a stack frame
	even when that stack frame is not an ancestor of the current call.

doc/user_guide.texi:
	Document the new option of the nondet_stack command.

tests/debugger/nondet_stack.{m,inp,exp,exp2}:
	A new test case to test "nondet_stack -d".

tests/debugger/Mmakefile:
	Enable the new test case.
2001-12-04 00:44:41 +00:00
..

This directory holds the trace subsystem,
i.e. the part of the Mercury debugger that is written in C code.


Notes on interfacing with other subsystems
------------------------------------------

If tracing is enabled, the compiler includes calls to MR_trace() in the
generated C code.  The trace subsystem in this directory is therefore
called directly from Mercury code, via MR_trace() in
runtime/mercury_trace_base.c.

One of the first things it does is to save the original values
of the Mercury registers in a variable called `saved_regs'.
The reason it needs to do this is that the code here may
modify registers, e.g. by allocating memory using incr_hp
or by calling Mercury code.  Once the original values of
the registers have been saved, the trace subsystem is free
to modify the Mercury registers.

So for all code in this directory, the usual convention is that the
original values of the Mercury registers are in `saved_regs',
while the current (scratch) values for the normal non-transient
Mercury registers etc. are in their normal locations, not in the
fake_reg copies, and the transient (register window) registers,
if any, are in the fake_reg copies.

Any code which uses macros such as incr_hp(), list_cons(),
make_aligned_string(), etc. that modify the heap pointer must call
restore_transient_regs() beforehand and must call save_transient_regs()
afterwards.  The simplest way to do this is to use the macro
MR_TRACE_USE_HP() in trace/mercury_trace_util.h.

The tracer may invoke Mercury code defined in the browser or library
directories if that code is exported to C using `pragma export'.
But any calls from functions here to code defined in Mercury
and exported using `pragma export', i.e. functions starting with `ML_'
prefixes, must be preceded by a call to save_registers() and
followed by a call to restore_registers().
The simplest way to do this is to use the macro
MR_TRACE_CALL_MERCURY() in trace/mercury_trace_util.h.