Files
mercury/trace
Zoltan Somogyi 8b9d436cbb More improvements for minimal model tabling.
Estimated hours taken: 12
Branches: main

More improvements for minimal model tabling.

runtime/mercury_engine.[ch]:
	Provide a debug flag to control the printing of debug stack slots
	in nondet stack dumps.

runtime/mercury_stack_trace.[ch]:
	Provide a mechanism that allows a dump of the nondet stack to print
	the principal debugging stack slots of the stack frames of procedures
	that were compiled with debugging, to help debug problems where
	these are overwritten during stack segment saves/restores.

	Add a mechanism for limiting the output of a nondet stack trace
	to a segment of the nondet stack.

runtime/mercury_minimal_model.[ch]:
	Limit the output of a diagnostic nondet stack trace to just the
	segment being saved or restored.

	Provide a label layout structure for the entry point of the suspend
	predicate, since this is necessary for correct nondet stack traces
	at suspensions and resumptions.

	Store the layout structure of the top nondet stack frame with each
	saved state, to allow the saved nondet stack segment to be dumped
	at resumptions as well as suspensions.

	Fix an old bug: when extending a saved stack segment, use the same
	algorithm for determining its lower bound as when the stack segment
	was created in the first place.

	Factor out some repeated definitions.

	Note problems to be fixed later.

	Improve debugging output.

runtime/mercury_stacks.[ch]:
	Move the documentation of the generator stack, the cut stack and the
	pneg stack from the source file to the header file, and expand it
	considerably.

	Make the routines for printing entries of these stacks generate more
	consistently formatted output.

	Simplify some code.

runtime/mercury_stack_layout.h:
	Provide a macro for use by mercury_minimal_model.c.

runtime/mercury_trace_base.[ch]:
	Save and restore the global variables holding event numbers,
	call sequence numbers and call depths across debugging Mercury code.
	We already used to do this for Mercury code invoked by the debugger,
	but now that we can invoke Mercury code to print the values of
	variables as diagnostics from within the suspend and resume predicates
	*outside* the debugger, we need to do it more generally.

trace/mercury_trace.c:
	Fix a bug: provide the layout structure of the current procedure
	to the diagnostic routines for minimal model tabling even if the
	debugger doesn't stop at that procedure.

trace/mercury_trace_internal.c:
	Add two new mdb commands to help debug minimal model tabling.

	The "mm_stack" command has the same effect as the existing commands
	"gen_stack", "cut_stack" and "pneg_stack" executed in sequence.

	The "debug_vars" command prints the counters for event numbers,
	call sequence numbers and call depths, both from their global variables
	and their saved copies, for debugging problems where they are
	overwritten, such as the one fixed by the changes to
	mercury_trace_base.[ch] above.

	Reorder some code for consistency.

trace/mercury_trace_util.[ch]:
	Add a function to implement the "debug_vars" command.

doc/user_guide.texi:
	Document the new mdb commands.

doc/mdb_categories:
	Add the new mdb commands to the list of developer commands, as well
	some others previously left out.

tests/debugger/mdb_command_test.inp:
	Test the documentation of the new mdb commands.

tests/tabling/combine.m:
	Change the code of this test case to what was intended, so that it now
	matches the old expected output.

tests/tabling/completed_consumer_in_solutions.{m,exp}:
	New test case, an easier version of consumer_in_solutions.

tests/tabling/consumer_in_commit.{m,exp}:
	Extend this test case and update the expected output; we can execute
	both the original code and the extension without runtime exceptions.

tests/tabling/seq2.m:
	Fix Kostis's new test case.

tests/tabling/seq4.exp:
	Fix the expected output of Kostis's new test case.

tests/tabling/Mmakefile:
	Enable the new test cases, and some old test cases that we now pass.
2004-03-12 06:02:19 +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.