Files
mercury/trace
Simon Taylor 32051f5467 Add support for command line completion to mdb.
Estimated hours taken: 40
Branches: main

Add support for command line completion to mdb.

NEWS:
	Document the change.

trace/mercury_trace_completion.{c,h}:
	Define the framework for completion.
	Examine command lines to determine which completers to use.

trace/mercury_trace_alias.{c,h}:
trace/mercury_trace_help.{c,h}:
trace/mercury_trace_internal.{c,h}:
trace/mercury_trace_tables.{c,h}:
trace/mercury_trace_vars.{c,h}:
	Define context-specific completers.

trace/mercury_trace_help.c:
	Record all help topics in an array for use by the completer.

trace/mercury_trace_internal.c:
	Add completion information to the list of commands.
	Add a function MR_trace_command_completion_info to access
	that information.

runtime/mercury_wrapper.{c,h}
	Add a runtime option `--force-readline', which tells mdb to
	use readline even if MR_mdb_in is not a tty. This is needed
	for tests/debugger/completion. `--force-readline' is not
	documented because I'm not sure that it will work properly
	in all situations (it's fine for the test).

	Fix capitalisation in references to the Mercury User's Guide
	in error messages.

trace/mercury_trace_readline.c:
	Tell Readline to use our completer.

	Handle `--force-readline'. Disable some Readline terminal
	initialisation code which reports spurious warnings if the
	input stream is not a tty.

trace/Mmakefile:
	Add mercury_trace_completion.{c,h}.

runtime/mercury_array_macros.h:
	Define a macro MR_find_first_match, which is like MR_bsearch
	except that it finds the first match, not an arbitrary match.

runtime/mercury_memory.c:
	Handle NULL pointers in MR_copy_string();

runtime/mercury_memory.h:
	Add a macro MR_free_func which returns the address of free().
	Used where it is necessary to pass the address of MR_free().

tests/debugger/Mmakefile:
tests/debugger/completion.m:
tests/debugger/completion.exp:
tests/debugger/completion.inp:
tests/debugger/completion.inputrc:
tests/debugger/completion.sub1.m:
tests/debugger/completion.sub2.m:
tests/debugger/completion.sub2.sub3.m:
	Test case.
2002-03-06 14:35:06 +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.