Commit Graph

9 Commits

Author SHA1 Message Date
Zoltan Somogyi
2bef47ce85 Extend the information we record about procedures when debugging is enabled
Estimated hours taken: 20
Branches: main (for now, after more testing, on release branch too)

Extend the information we record about procedures when debugging is enabled
to include information about the tabling transformation, if the procedure
in question is tabled. This is useful to developers in debugging the tabling
mechanism, and can be useful to general users by helping them understand the
space (and hence time) costs of tabling.

Add a new mdb command "table" that uses this information to print
programmer-selected subsets of the tables of a tabled procedure.

compiler/hlds_pred.m:
	Generalize the existing field in procedures that used to hold
	information about I/O tabling to contain information about tabling
	in general, including forms other than I/O tabling.

compiler/continuation_info.m:
compiler/code_gen.m:
compiler/stack_layout.m:
	Conform to the changes in hlds_pred.m.

compiler/layout.m:
	Provide Mercury parallels for the new data structures in
	mercury_stack_layout.h.

compiler/layout_out.m:
	Generate the new data structures in mercury_stack_layout.h.

compiler/table_gen.m:
	Generate the new data structures in hlds_pred.m.

compiler/llds_common.m:
compiler/opt_debug.m:
	Conform to the changes in layout.m

compiler/llds_out.m:
	Abstract out existing code into a new procedure to make it available
	to layout_out.m.

	Make tabling pointer variables their natural type.

compiler/modules.m:
	Fix an old bug: implicitly import table_builtin.m in .mm grades.

doc/mdb_categories:
doc/user_guide.texi:
	Document the new mdb command "table".

runtime/mercury_types.h:
	Move some type definitions here from mercury_tabling.h and
	mercury_stack_layout.h. This was necessary to avoid problems with
	circular #includes, in which a.h #includes b.h to get access to a
	definition, but b.h #includes a.h, which is prevented by the macro
	guarding against duplicate definition, which causes syntax errors
	in the rest of b.h because the rest of b.h depends on typedefs in
	a.h that occur in a.h *after* the #include of b.h.

runtime/mercury_label.h:
	Adjust the list of #includes after the change to mercury_types.h.

runtime/mercury_stack_layout.h:
	Extend the debugging data structures with constructs that describe
	the call tables, answer tables and answer blocks of tabled procedures.

	Delete typedefs that are now in mercury_types.h.

runtime/mercury_tabling.[ch]:
	Add new functions to allow lookups without insertions in hash tables
	containing ints, floats and strings.

	Add new functions to return the entire contents of these hash tables.

	Change to four-space indentation where this wasn't done previously.

runtime/mercury_grade.h:
	Increment the binary compatbility version number, partially to
	account for the change to mercury_stack_layout.h in this diff, but
	mostly to account for all the other diffs to mercury_stack_layout.h
	since the last released version.

trace/mercury_trace_tables.[ch]:
	Rename MR_print_proc_id_for_debugger as MR_print_proc_id_and_nl,
	since this better describes what the function does.

trace/mercury_trace_util.[ch]:
	Add a new function MR_trace_is_integer that reads in signed integers.

	Rename MR_trace_is_number as MR_trace_is_natural_number, since the
	former would now be ambiguous.

	Add a new function MR_trace_is_float that reads in floating point
	values.

library/string.m:
	Document that MR_trace_is_float uses the same logic as
	MR_trace_is_float.

trace/mercury_trace_browse.c:
trace/mercury_trace_vars.c:
	Update calls to MR_trace_is_number.

trace/mercury_trace_internal.c:
	Implement the new mdb command "table".

	Update calls to MR_trace_is_number and to
	MR_print_proc_id_for_debugger.

tests/debugger/print_table.{m,inp,exp}:
	New test case to test the new mdb command.

tests/debugger/Mmakefile:
	Enable the new test case.

	Disable the sensitive test cases in .mm grades.

tests/debugger/completion.exp:
	Update the expected output to include the new mdb command.

tests/debugger/mdb_command_test.inp:
	Update this automatically generated file to include the new mdb
	command.
2002-11-15 04:50:49 +00:00
Zoltan Somogyi
048f8357cf Until now, programmers could add `tabled_for_io' annotations to foreign_procs
Estimated hours taken: 12
Branches: main

Until now, programmers could add `tabled_for_io' annotations to foreign_procs
that do I/O, which asks the compiler to make those foreign_procs idempotent,
i.e. ensures that they are performed at most once even in the presence of a
retry operation in the debugger. This change adds a compiler option,
--trace-table-io-require, which generates an error if a foreign_proc that does
I/O does not have this annotation. Specifying this option thus ensures
that all I/O done by the program is idempotent.

In the future, we may want to have this option turned on in all debugging
grades. Until we decide about, the new option is not yet documented.

compiler/options.m:
	Add the new option --trace-table-io-require.

compiler/handle_options.m:
	Make --trace-table-io-require imply --trace-table-io.

compiler/table_gen.m:
	If --trace-table-io-require is enabled, require all I/O primitives
	to have the tabled_for_io annotation.

compiler/mercury_compile.m:
	Pass I/O states to table_gen.m, since it can now generate error
	messages.

trace/mercury_trace_util.h:
trace/mercury_trace_vars.c:
	When calling Mercury code from the trace directory, disable I/O
	tabling, since any I/O actions executed by Mercury code in the browser
	directory (or by library code called from there) should not be tabled,
	not being part of the user program.

	Due to the depth of nesting, make mercury_trace_vars.c use four-space
	indentation.

browser/collect_lib.m:
browser/declarative_debugger.m:
browser/declarative_execution.m:
browser/dl.m:
browser/io_action.m:
browser/mdb.m:
browser/name_mangle.m:
browser/util.m:
compiler/gcc.m:
compiler/mercury_compile.m:
compiler/passes_aux.m:
compiler/process_util.m:
compiler/stack_layout.m:
library/io.m:
library/time.m:
tests/debugger/declarative/tabled_read_decl.m:
	Add a whole lot of tabled_for_io annotations, to enable the compiler to
	bootstrap with --trace-table-io-require enabled.

	In many cases, this required turning old-style pragma c_code into
	pragma foreign_proc. While doing that, I standardized the layouts
	of pragma foreign_procs.

browser/util.m:
	Turn an impure semidet predicate into a pure det predicate with I/O
	states, to allow it to be tabled. Make it return a Mercury bool
	to indicate success or failure.

library/bool.m:
	Add functions that allow C code to get their hands on the constants
	`yes' and `no', for communication with Mercury code.

library/table_builtin.m:
	Add debugging code to the main primitive of I/O tabling. This is
	controlled both by the macro for retry debugging and a boolean global.

library/mercury_trace_base.[ch]:
	Add the boolean global variable to switch the new debugging code in
	table_builtin.m on and off.

library/mercury_trace_internal.c:
	When starting I/O tabling with retry debug enabled, turn on the switch.

tests/debugger/queens.exp3:
	New expected output file that applies when the library is compiled with
	--trace-table-io-require.
2002-07-22 07:13:14 +00:00
Simon Taylor
b7c4a317e9 Add MR_ prefixes to the remaining non-prefixed symbols.
Estimated hours taken: 4
Branches: main

Add MR_ prefixes to the remaining non-prefixed symbols.

This change will require all workspaces to be updated
The compiler will start generating references to MR_TRUE,
MR_bool, etc., which are not defined in the old runtime
header files.

runtime/mercury_std.h:
	Add MR_ prefixes to bool, TRUE, FALSE, max, min,
	streq, strdiff, strtest, strntest, strneq, strndiff,
	strntest, NO_RETURN.

	Delete a commented out definition of `reg'.

runtime/mercury_tags.h:
	Add an MR_ prefix to TAGBITS.

configure.in:
runtime/mercury_goto.h:
runtime/machdeps/i386_regs.h/mercury_goto.h:
	Add an MR_ prefix to PIC.

runtime/mercury_conf_param.h:
	Allow non-prefixed PIC and HIGHTAGS to be defined on
	the command line.

runtime/mercury_bootstrap.h:
	Add backwards compatibility definitions.

RESERVED_MACRO_NAMES:
	Remove the renamed macros.

compiler/export.m:
compiler/ml_code_gen.m:
	Use MR_bool rather than MR_Bool (MR_Bool is
	meant to be for references to the Mercury type
	bool__bool).

runtime/mercury_types.h:
	Add a comment the MR_Bool is for references to
	bool__bool.

*/*.c:
*/*.h:
*/*.m:
	Add MR_ prefixes.
2002-02-18 07:01:33 +00:00
Simon Taylor
b5a84362e8 Fix a bug which caused the output of mdb's help command
Estimated hours taken: 1

Fix a bug which caused the output of mdb's help command
to go to the program's output stream, not mdb's.

trace/mercury_trace_help.c:
	Fix the output stream handling.

trace/mercury_trace_browse.c:
trace/mercury_trace_util.c:
trace/mercury_trace_util.h:
	Move `MR_c_file_to_mercury_file()' to mercury_trace_util.c,
	for use by mercury_trace_help.c.
2002-01-23 05:37:09 +00:00
Zoltan Somogyi
0d091c5870 Check the trace directory for namespace cleanliness.
Estimated hours taken: 3

Check the trace directory for namespace cleanliness.

Mmake.common.in:
runtime/Mmakefile:
	Move the rules for checking namespace violations from runtime/Mmakefile
	to Mmake.common.

trace/Mmakefile:
	Add entries for checking the name-space cleanliness of the trace
	directory, using the rules now in Mmake.common. These entries follow
	the same rules as the ones in the runtime directory. Note that the
	the header files of the trace directory must be allowed to define
	all the macros that the runtime directory's header files can, since
	some trace directory header files include header files from the runtime
	directory.

trace/*.h:
	Make these header files self-contained.

tools/bootcheck:
	Check the trace directory for namespace cleanliness as well as the
	runtime directory.
2001-02-13 08:28:28 +00:00
Zoltan Somogyi
090552c993 Make everything in the runtime use MR_ prefixes, and make the compiler
Estimated hours taken: 10

Make everything in the runtime use MR_ prefixes, and make the compiler
bootstrap with -DMR_NO_BACKWARDS_COMPAT.

runtime/mercury_*.[ch]
	Add MR_ prefixes to all functions, global variables and almost all
	macros that could pollute the namespace. The (intentional) exceptions
	are

	1. some function, variable, type and label names that already start
	   with MR_, mercury_, Mercury or _entry;
	2. some standard C macros in mercury_std.h;
	3. the macros used in autoconfiguration (since they are used in scripts
	   as well as the runtime, the MR_ prefix may not be appropriate for
	   those).

	In some cases, I deleted things instead of adding prefixes
	if the "things" were obsolete and not user visible.

runtime/mercury_bootstrap.h:
	Provide MR_-less forms of the macros for bootstrapping and for
	backward compatibility for user code.

runtime/mercury_debug.[ch]:
	Add a FILE * parameter to a function that needs it.

compiler/code_info.m:
compiler/export.m:
compiler/fact_table.m:
compiler/llds.m:
compiler/llds_out.m:
compiler/pragma_c_gen.m:
compiler/trace.m:
	Add MR_ prefixes to the C code generated by the compiler.

library/*.m:
	Add MR_ prefixes to handwritten code.

trace/mercury_trace_*.c:
util/mkinit.c:
	Add MR_ prefixes as necessary.

extras/concurrency/semaphore.m:
	Add MR_ prefixes as necessary.
2000-11-23 02:01:11 +00:00
Zoltan Somogyi
fdccd65e30 The debugger's retry command at the moment works only from a final port for
Estimated hours taken: 60

The debugger's retry command at the moment works only from a final port for
the call to be retried, the reason being that the RTTI does not have the
information required to make sure that the state of the stacks is reset
correctly. If you invoke retry from a non-final port, the current
implementation skips forward to a final port and then does the retry;
this does not work if you get a core dump or a infinite loop during the forward
skip. This change adds the required info to the RTTI and thus enables
direct retries from the middle of calls.

The information added has two components. First, if a procedure that lives on
the nondet stack allocates any temporary nondet stack frames, then it must
record the old value of maxfr in a stack slot so that retry can restore it.
Second, if a procedure is tabled, then it must record the call table tip node
corresponding to the actual input arguments, so we can reset this node to
uninitialized (if we don't, then the retried call will find the active call
marker and report an infinite loop error).

The support for retries across minimal model calls is not finished yet.
Finding out what the right thing to do in such cases is a research project,
one that cannot even be started until minimal model tabling works reliably
in the *absence* of retries. However, such retries do grossly wrong things
at the moment; this change is a definite improvement. It attempts to perform
the retry from the fail port, since that is the only time when the minimal
model tabling data structures are quiescent. The "fail" command I added to
the debugger command set to let this be done is not complete yet and is
therefore undocumented; the problem is that a call to a model_non predicate
in a committed choice context will not get to the fail port. I added goal paths
to return layouts so that we will eventually be able to tell when execution
leaves a committed choice context surrounding an ancestor of a model_non
predicate call, but this functionality is not yet implemented.

compiler/stack_layout.m:
	Generate the three new fields: the evaluation method, (maybe) the id
	of the stack slot containing the saved value of maxfr, and (maybe)
	the id of the stack slot containing the call table tip.

compiler/continuation_info.m:
	Record the information about the new fields for later use by
	stack_layout.m.

	Add a new field to record the goal path of calls for their return
	layouts.

	Fix a screwed comment for the continuation_info data structure.

compiler/llds.m:
	Add a new field to call() instructions to hold the goal path of the
	call.

	Add a utility function for use by trace.m.

compiler/call_gen.m:
	Fill in this new field.

compiler/trace.m:
compiler/live_vars.m:
	Reserve the fixed stack slot for the saved maxfr if necessary,
	and if the call table tip node is needed, make sure that the variable
	holding its address is allocated a low-numbered stack slot (otherwise,
	its number may not fit into the MR_int_least8_t field in the
	proc_layout).

compiler/trace.m:
	If necessary, fill in the saved maxfr slot.

	If necessary, initialize the call table tip slot.

compiler/hlds_goal.m:
	Add a goal feature which marks its goal as defining the variable
	representing the call table tip node.

	Add a field to the goal path step representing quantification;
	the field says whether the quantification changes the determinism of
	the goal (i.e. whether it cuts away solutions).

compiler/hlds_pred.m:
compiler/hlds_out.m:
	Add two fields to proc_infos which (a) record which variable, if any,
	holds the call table tip node, and (b) record whether the procedure's
	layout structure needs to reserve a slot for the saved value of maxfr.

compiler/table_gen.m:
	Put this feature on the appropriate goal.

	Also, rename a predicate to make it reflect its purpose better.

compiler/code_gen.m:
	Generate code to put the call table tip variable in its stack slot
	immediately after it has been generated.

	Add a sanity check to ensure that if a procedure that lives on the det
	stack can create a temporary nondet frame, and debugging is enabled,
	then it did have a stack slot reserved for the saved maxfr.

compiler/code_util.m:
	Add a predicate to make a conservative prediction of whether a
	procedure may allocate a temporary nondet stack frame. We cannot
	just generate the code and see, because the code generator needs to
	know which variables live in which stack slots, and we cannot decide
	that until we know whether we need a stack slot for the saved value of
	maxfr.

	Make an unrelated predicate semidet procedure use a det helper, in
	order to make it more robust in the face of changes to the HLDS
	(e.g. it was missing code for handling bi_implications).

compiler/code_info.m:
	Record whether a procedure has in fact created a temporary nondet stack
	frame.

compiler/handle_options.m:
	Disable hijacks if debugging is enabled. The code we now use to
	restore the stacks for direct retries works only if the retry does not
	"backtrack" over a hijacked nondet stack frame whose hijack has not
	been undone. Note that code compiled without debugging may still hijack
	nondet stack frames. Execution may reemerge from the nondebugged region
	in one of two ways. If the nondebugged code returns, then it will have
	undone hijack, and the retry code will work. If the nondebugged code
	calls debugged code, there will be a region on the stacks containing
	no debugging information, and the retry command will refuse to perform
	retries that go into or beyond this region. Both cases preserve
	correctness.

compiler/*.m:
	Trivial changes to conform to changes in data structures.

runtime/mercury_stack_layout.h:
	Add three new fields to proc layouts: the numbers of the stack slots
	(if any) storing the saved maxfr and the call table tip, and a
	representation of the procedure's evaluation method.

runtime/mercury_stack_trace.[ch]:
	Now that return layouts contain goal paths, print them in stack dumps
	only if the include_trace_data flag is set (in mdb, this requires the
	-d flag of the "stack" command).

	Pass this flag around directly, instead of encoding its value in
	the NULL vs non-NULL values of sp and curfr.

runtime/mercury_regorder.h:
	Provide a mechanism to access the values of the first few rN registers
	from a save area, for use in debugging low-level C code in the runtime
	and the trace directories.

trace/mercury_trace.[ch]:
	Reimplement MR_trace_retry to allow retries from the middle.
	If the stack segment being retried over contains minimal model
	procedures, we must still arrange to skip to the end of the retried
	call. If this call is a minimal model generator, skipping to just any
	final port is not sufficient to guarantee correctness on retry; to
	ensure that subgoal is complete, we must skip to a fail port.

trace/mercury_trace.[ch]:
trace/mercury_trace_internal.c:
	Implement a debugger command, "fail", which skips to the fail port or
	the exception port of the specified ancestor. Since procedures that are
	not model_non are not guaranteed to get to such a port, this
	command reports an error if the specified call is not model_non.
	Actually, even calls to model_non procedures may not get to the fail
	port, as explained above; this is why the command is not yet
	documented.

trace/mercury_trace.c:
trace/mercury_trace_util.[ch]:
	Move some functions to print parts of the Mercury abstract machine
	state from mercury_trace to mercury_trace_util, so that they are
	available for use in debugging e.g. mercury_trace_declarative.

trace/mercury_trace_internal.c:
trace/mercury_trace_external.c:
trace/mercury_trace_declarative.c:
	Use the new implementation of retries. At the moment, only the
	internal debugger implements the full functionality. The declarative
	debugger issues retry commands only from situations where the missing
	functionality is not (yet) needed. The external debugger should
	continue to work correctly, but Erwan may wish to update it to
	exploit the availability of the fail command.

trace/mercury_trace*.[ch]:
	Fix MR_prefixes, and a signed/unsigned mismatch.

doc/user_guide.texi:
	Document the new "fail" command, but comment it out for now.

tests/debugger/retry.{m,inp,exp,exp2}:
	A new test case for exercising retry.

tests/debugger/Mmakefile:
	Enable the new test case.

tests/debugger/*.exp:
	Update the expected output, given the extra info now output e.g. for
	exception events and detailed stack traces.
2000-10-13 04:06:52 +00:00
Zoltan Somogyi
15563f3ff5 Allow users to request the printouts of only parts of variables.
Estimated hours taken: 4

Allow users to request the printouts of only parts of variables.
Instead of the old sequence

	browse Varnameornum
	^1^2^3^4
	p
	^D

users can now just a single command: print Varnameornum^1^2^3^4, or print
Varnameornum/1/2/3/4. The required component is given by a sequence of
argument numbers, separated by ^s or /s.

(This syntax should eventually be extended to support the use of field names
instead of argument numbers. However, implementation of this extension will
need to wait until the RTTI interface to field names is stable.)

trace/mercury_trace_vars.[ch]:
	Provide a mechanism to print not just the whole value of a variable,
	but also just a component, if that is what the user wants.

trace/mercury_trace_internal.c:
	Use the new mechanism in mercury_trace_vars.c.

trace/mercury_trace_util.[ch]:
	Move a function to the new file mercury_trace_util.c from
	mercury_trace_internal.c, since new mercury_trace_vars.c also
	wants to use it.

trace/Mmakefile:
	Add the new file to the list of source files.

tests/debugger/browser_test.{inp,exp,exp2}:
	Test the new functionality.
2000-07-18 05:53:17 +00:00
Fergus Henderson
55cbda8153 Fix a bug in mdb (for non-conservative-gc grades) where manual memory
Estimated hours taken: 8

Fix a bug in mdb (for non-conservative-gc grades) where manual memory
allocations in the tracer and memory allocations in the Mercury code
that the tracer calls were overwriting each other, due to confusion
about whether the heap pointer was in its real reg or in its fake_reg
slot.

trace/README:
	Document some conventions for dealing with registers,

trace/mercury_trace_util.h:
	Define macros to allow easy adherence to those conventions.

trace/mercury_trace_external.c:
trace/mercury_trace_help.c:
trace/mercury_trace_internal.c:
	Use the new macros to enforce adherence to the conventions.
1998-11-06 10:35:41 +00:00