mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-23 13:23:47 +00:00
784dc26cabb5b24beb94de12a0ff6faae3536d47
18 Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
c460b3eec3 |
Fix a bug: MR_stack_trace_bottom and MR_nondet_stack_trace_bottom
Estimated hours taken: 0.25 runtime/mercury_stack_trace.h: runtime/mercury_stack_trace.c: Fix a bug: MR_stack_trace_bottom and MR_nondet_stack_trace_bottom were being _defined_ in the header file. I changed it so that they were only _declared_ in the header file, and defined in the .c file. |
||
|
|
cc61b711cd |
Moves the definition of MR_dump_stack_record_print() and MR_print_proc_id()
Estimated hours taken: 3 Moves the definition of MR_dump_stack_record_print() and MR_print_proc_id() from trace/ to runtime/ to be able to call MR_dump_stack_record_print() from MR_dump_stack(). Indeed we can not pass down *MR_dump_stack_record_print() as a parameter of MR_dump_stack() since MR_dump_stack() is called from the library and we have to repect the invariant "trace -> library -> runtime". runtime/mercury_stack_trace.c: Add the missing argument of MR_dump_stack_from_layout() in the body of MR_dump_stack(). runtime/mercury_stack_trace.[ch]: trace/mercury_trace_internal.c: trace/mercury_trace_tables.[ch]: Move the definition of MR_dump_stack_record_print() from mercury_trace_internal.c to mercury_stack_trace.c and MR_print_proc_id() from mercury_trace_tables.c to mercury_stack_trace.c runtime/mercury_stack_trace.[ch]: trace/mercury_trace.[ch]: Move the definition of MR_detism_names[] from mercury_trace.c to mercury_stack_trace.c. |
||
|
|
f31b6bf9ed |
Fix some warnings about incompatible pointer types.
Estimated hours taken: 0.2 runtime/mercury_stack_trace.h: runtime/mercury_stack_trace.c: Fix some warnings about incompatible pointer types. |
||
|
|
9760975d5e |
This change implement stack dump commands for the external debugger.
Estimated hours taken: 7 This change implement stack dump commands for the external debugger. The MR_dump_stack_record_print() defined in runtime/mercury_stack_trace.c is the function that prints the contents of the stack. We move the definition of this function to mercury_trace_internal.c and we pass down that function as a parameter of MR_dump_stack_from_layout(). The rational for this change is that we can then define a new MR_dump_stack_record_print_to_socket() in mercury_trace_external.c that prints the data to the socket as a Prolog term and pass down the address of that new function to MR_dump_stack_from_layout(). browser/debugger_interface.m: Add three new kinds of requests: stack, nondet_stack and stack_regs. trace/mercury_trace_external.c: Define new MR_dump_stack_record_print_to_socket() and MR_print_proc_id_to_socket() that sends data to the socket as Prolog terms. Add support for stack, nondet stack and stack_regs requests. runtime/mercury_stack_trace.[ch] trace/mercury_trace.[ch]: trace/mercury_trace_internal.[ch]: Move the definition of MR_dump_stack_record_print(), from mercury_stack_trace.c to mercury_trace_internal.c. Add MR_dump_stack_record_print() as an argument of all the functions that need it in mercury_stack_trace.c. Move the definition of detism_names[] from mercury_stack_trace.c to mercury_trace.c. This function is needed by both versions of MR_dump_stack_record_print(). Rename detism_names[] by MR_detism_names[]. runtime/mercury_stack_trace.[ch] trace/mercury_trace_tables.[ch]: Move the definition of MR_print_proc_id() and MR_print_proc_id_for_debugger() from mercury_stack_trace.c to mercury_trace_tables.c since MR_print_proc_id() is called in that module. Include mercury_trace.h since we now make use of detism_names[] there. |
||
|
|
9d0fd6601a |
Add support to mdb for doing the debugger I/O in a different
Estimated hours taken: 4 Add support to mdb for doing the debugger I/O in a different window to the I/O of the program being debugged. (TODO: I/O from the browser still goes to the standard I/O streams rather than the debugger I/O streams. I will commit that soon as a separate change.) runtime/mercury_wrapper.h: runtime/mercury_wrapper.c: Add new runtime options for specifying filenames for the mdb I/O streams. doc/user_guide.texi: Document the new options. trace/mercury_trace_internal.c: Add three new variables holding the mdb I/O streams. Initialise them based on the option settings. Change the code so that all I/O goes through these streams. trace/mercury_trace_tables.c: trace/mercury_trace_tables.h: Pass a `void *' parameter through MR_process_matching_procedures() to the function it calls. This is needed by mercury_trace_internal.c to pass `MR_mdb_in' down to MR_print_proc_id_for_debugger(). runtime/mercury_stack_trace.c: runtime/mercury_stack_trace.h: Add a `FILE *' parameter to MR_print_proc_id_for_debugger(). tests/debugger/Mmakefile: When creating the `.out' files, redirect stderr as well as stdout, since debugger error messages now go to stderr rather than stdout. |
||
|
|
9aee4beb06 |
Provide feedback for the "up", "down" and "level" commands in the debugger,
Estimated hours taken: 4
Provide feedback for the "up", "down" and "level" commands in the debugger,
in the form of a line from an enhanced stack dump.
runtime/mercury_stack_layout.h:
Fix the documentation of the call event number slot.
runtime/mercury_stack_trace.[ch]:
Generalize the stack dump routines, to make them capable of printing
the call event number, call sequence number and call depth slots
of calls to traced procedures.
trace/mercury_trace_internal.c:
Add a new option, -d or --detailed, to the stack command, which
prints the call event number, call sequence number and call depth slots
of every ancestor procedure that is execution traced.
When changing levels, provide feedback by identifying the call
to which the level is now set. The feedback is the detailed stack
trace line for that call.
When changing levels, check that we have exec trace info for the call,
not just stack trace info.
Fix an old bug: tables of long options should be and now are
terminated by a NULL row.
doc/user_guide.texi:
Document the new option of the stack command.
Fix the documentation of the errors in the level change commands.
tests/debugger/queens.{inp,exp}:
Test the new functionality of the stack command, and update the
expected output.
|
||
|
|
fbd55b8d7c |
Fix the code in the runtime so that `mmake check_headers' succeeds.
Estimated hours taken: 3
Fix the code in the runtime so that `mmake check_headers' succeeds.
runtime/*.h:
Add #include statements to make all the header files
self-contained.
runtime/mercury_table.h:
runtime/mercury_table.c:
Delete these empty files.
For some reason zs left these files as empty instead of deleting
them when he renamed the module as mercury_hash_table.{h,c}.
runtime/mercury_table_builtins.h:
runtime/mercury_table_enum.h:
runtime/mercury_table_any.h:
runtime/mercury_table_type_info.h:
runtime/mercury_table_builtins.c:
runtime/mercury_table_enum.c:
runtime/mercury_table_any.c:
runtime/mercury_table_type_info.c:
runtime/mercury_tabling.h:
runtime/mercury_tabling.c:
Avoid a circular dependency problem (mercury_tabling.h
depended on mercury_table_*.h which in turn depended on
mercury_tabling.h) by moving all the tabling code into
a single module mercury_tabling.{h,c}.
The new module is a total of 1100 lines of code,
which is not too large IMHO.
Also improve the documentation a little.
runtime/Mmakefile:
Update the reflect the added and removed files.
Also update the rule for `mmake check_headers' so that
it can make use of parallelism in parallel makes.
And make a start towards enforcing namespace cleanliness --
I've added code to check it, but not to enforce it.
|
||
|
|
426ce95ad0 |
Fix a spelling error in a comment.
Estimated hours taken: 0.05 runtime/mercury_stack_trace.h: Fix a spelling error in a comment. |
||
|
|
8a0ceb49aa |
This checkin has several major purposes, set out in the sections below,
Estimated hours taken: 240
This checkin has several major purposes, set out in the sections below,
all connected with the implementation of the new debugger command set.
DOCUMENT NEW DEBUG COMMAND SET
doc/user_guide.texi:
Add a new section on the debugger. The description of the commands
is complete, but some of the background sections, and the section
about how to build debuggable executables, are not yet done.
Update the documentation of the tracing options.
doc/generate_mdb_doc:
A new shell script that automatically converts some of the new
sections of the user guide into the online documentation of the
debugger.
doc/mdb_categories:
The fixed initial part of the online documentation.
doc/Mmakefile:
Add rules for creating mdb_doc, the file that is the online
documentation of the debugger, and for installing it together
with mdbrc.
Mmake.common.in:
Define INSTALL_DOC_DIR for doc/Mmakefile.
scripts/mdbrc.in:
A debugger command script that reads in the online documentation
and then defines some standard aliases.
configure.in:
Define the variable that scripts/mdb.in and scripts/mdbrc.in use
to find the right files, and get configure to perform the
substitutions.
configure.in:
scripts/mdb:
scripts/mdb.in:
Replace mdb with mdb.in. Mdb is now created during configuration
from mdb.in, filling in the name of the file that contains the default
debugger initialization commands.
util/info_to_mdb.c:
A program that does most of the work involved in automatically
converting user guide sections into online documentation.
(This couldn't easily be written in sh, because sh's read
command has no notion of pushback.)
util/Mmakefile:
Add info_to_mdb to the list of targets.
tools/bootcheck:
Make sure that the tests in tests/debugger are executed with an
initialization setup that is equivalent to what users will see
by default.
REORGANIZE TRACING OPTIONS
compiler/globals.m:
compiler/handle_options.m:
compiler/options.m:
compiler/trace.m:
Reorganize the handling of trace levels around the new options
--trace-internal, --trace-redo, and --trace-return.
compiler/*.m:
Use the new ways of getting at trace levels.
tests/hard_coded/typeclasses/Mmakefile:
s/--trace all/--trace deep/
SUPPORT RETRY
compiler/trace.m:
After every call to MR_trace(), emit code that checks whether it
should jump away, and if yes, performs the jump. This is used to
implement retry. (The debugger cannot execute the jump itself
because it is in the wrong C stack frame.)
compiler/llds.m:
compiler/continuation_info.m:
compiler/stack_layout.m:
Modify the data structures that record information about live
value at program points, to record the identity of each variable.
This is necessary for the implementation of the restart command,
since we do not want to confuse two distinct variables just because
they have the same name. For example, a variable whose name is X
and number is 5 is now recorded in the name array as "5:X".
Clean up the data structure a bit, so that we don't have to store
dummy names for values that are not variables.
compiler/*.m:
Minor changes to conform to the data structure changes.
runtime/mercury_stack_layout.h:
Redefine an existing macro to strip away the initial number: prefix
from the "name" of a variable (keeping its original function on
changed data), and add a new one to access the raw unstripped data.
runtime/mercury_init.h:
runtime/mercury_wrapper.h:
Update the prototype of MR_trace_{fake,real}, and the type of the
global that points to them.
runtime/mercury_layout_util.h:
Add an extra function, MR_get_register_number, for use by retry.
USE FIXED STACK SLOTS FOR TRACE INFO
compiler/code_gen.m:
compiler/code_info.m:
compiler/live_vars.m:
compiler/trace.m:
If execution tracing is enabled, reserve the first few stack slots
to hold the event number of the call event, the call number, the
call depth, the redo layout structure address (if generating redo
events) and the from_full flag at the time of call (if we are doing
shallow tracing). By allocating the first four of these to fixed stack
slots, the debugger knows where to look for them without having
to be told. It finds out the location of the fifth, if needed,
from a new slot in the proc layout structure. (It is not possible
to allocate all five to fixed stack slots without wasting stack space
in some cases.)
compiler/trace.m:
Remove from the call to MR_trace the parameters that are now in fixed
stack slots, since MR_trace can now look them up itself.
compiler/continuation_info.m:
compiler/stack_layout.m:
Add an extra field to the proc_layout_info. If the module is shallow
traced, this field says which stack slot holds the saved value of
MR_from_full. If it is not shallow traced, this field says that
there is no such stack slot.
runtime/mercury_stack_layout.h:
Add macros for accessing the fixed stack slots holding the event
number of the call event, the call number, the call depth, and,
at a redo event, the redo layout structure address.
Support the new field in proc layouts that gives the location of the
from-full flag (if any).
runtime/mercury_trace_base.[ch]:
trace/mercury_trace.[ch]:
Remove the call number and call depth arguments from MR_trace
and its avatars, since this info is now in fixed stack slots
in every procedure that can call MR_trace. This should reduce
the size of the executable significantly, since there are lots
of calls to MR_trace.
runtime/mercury_init.h:
runtime/mercury_wrapper.h:
Update the prototype of MR_trace_{fake,real}, and the type of the
global that points to them.
START NUMBERING FRAMEVARS FROM ONE
compiler/code_info.m:
compiler/live_vars.m:
compiler/llds_out.m:
compiler/trace.m:
Start numbering framevars from 1 internally to the compiler;
the runtime already starts from 1. This simplifies several tasks.
ADD REDO EVENTS
compiler/trace.m:
compiler/code_gen.m:
Before the code that executes "succeed()", emit code to push a
a temp nondet frame whose redoip points to a label in the runtime
that calls MR_trace for a REDO event and then fails, provided
--trace-redo is set.
compiler/llds.m:
Add a new code address constant, do_trace_redo_fail, which stands
for the address in the trace system to which calls MR_trace for
the redo event and then fails.
compiler/trace.m:
compiler/llds_out.m:
Provided we are doing redo tracing, fill in the slot that holds
the layout information for the REDO event.
compiler/*.m:
Minor changes to conform to handle the new code address constant.
browser/debugger_interface.m:
Add redo to trace_port_type.
runtime/mercury_trace_base.[ch]:
Add a C module containing the code that calls MR_trace for REDO
events.
ENSURE THAT INPUT ARGUMENTS ARE ALWAYS VISIBLE
compiler/trace.m:
When generating the set of live variables at internal ports,
the variables that are in the pre-death set of the goal into which
we are entering may not be available. However, the variables in the
pre-death set that are also in the resume vars set will be available,
so now include info about them in the layout structure for the event.
Since with tracing the non-clobbered input args are in all resume vars
sets, this ensures that these input args will be available from all
internal events.
compiler/code_info.m:
Export a previously internal predicate (current_resume_point_vars)
to make this possible.
BUG FIX: WANT RETURN LAYOUTS
compiler/globals.m:
compiler/call_gen.m:
compiler/code_info.m:
compiler/mercury_compile.m:
Add a new pred globals__want_return_layouts, which says whether the
compiler should generate layout structures for call returns. This pred
centralizes the several previous copies of the test. One of those
copies (the one in call_gen) was faulty, leading to a bug: in the
presence of execution tracing but the absence of accurate gc,
information about the variables that are live at the call return
wasn't being gathered properly.
BUG FIX: #include mercury_trace_base.h
compiler/llds_out.m:
#include mercury_trace_base.h, not mercury_trace.h, since now
mercury_trace_base.h defines everything directly accessible from
modules compiled with tracing.
RECAST MERCURY_TRACE_UTIL AS MERCURY_LAYOUT_UTIL
runtime/mercury_trace_util.[ch]:
runtime/mercury_layout_util.[ch]:
Rename this module from trace_util to layout_util, since it is also
used by the native garbage collector. Remove "trace" from the names
of functions.
Get rid of the global variable MR_saved_regs, and instead thread
a pointer to this data structure through the relevant functions
as an extra argument.
Add a lot more documentation in the header file.
runtime/Mmakefile:
Reflect the module rename.
runtime/*.c:
Refer to the new module.
DELETE EASY-TO-MISUSE MACROS
runtime/mercury_stacks.h:
Delete the based_framevar and based_detstackvar macros, since their
continued use can lead to off-by-one errors, and the saved_framevar
and saved_detstackvar macros, since they are no longer used.
runtime/*.c
Update any references to any macros removed from mercury_stacks.h.
MISC RUNTIME CHANGES
runtime/mercury_trace_base.[ch]:
trace/mercury_trace*.[ch]:
Make typedef'd names conform to the naming convention.
Make MR_trace_call_{seqno,depth} consistently Unsigned, rather than
sometimes Word and sometimes Unsigned.
FIX BUG: MAKE THE DEBUGGER PRINT TO STDOUT, NOT THE CURRENT STREAM
library/io.m:
Export to C code the predicates that return the identities and types
of stdin, stdout and stderr, as well as io__print/[34].
library/std_util.m:
Export to C code a predicate that returns the type_info for the
type stdutil:type_info. This type_info is required if C code
wants to invoke make_permanent on any type_info structure,
as the debugger does.
runtime/mercury_init.h:
Add extern declarations for the C functions now exported from io.m.
runtime/mercury_wrapper.[ch]:
Add new global variables to hold the addresses of these C functions.
runtime/mercury_layout_util.c:
Use indirect calls through these global variables to print Mercury
values, instead of lower-level code.
util/mkinit.c:
Assign the addresses of the functions exported from io.m to the
global variables defined in mercury_wrapper.h.
BUG FIX: STACK TRACE FUNCTIONS DEPEND ON THE LABEL TABLE
runtime/mercury_stack_trace.c:
On entry to any of the functions exported from this module,
ensure that the label table is loaded by calling do_init_modules.
Without a filled-in label table, the stack trace will not be able to
find any stack layout info.
BUG FIX: REMOVE BROWSER/*.C
configure.in:
When removing .c files generated by the C compiler, remove those
in the browser directory as well as the compiler, library and
profiler directories.
IMPLEMENT NEW DEBUGGER COMMAND SET
runtime/mercury_stack_trace.[ch]:
Factor out the code that prints the id of a procedure into a function
of its own, so that it can also be used from the debugger, ensuring
appearance commonality.
Add more documentation in the header file.
trace/mercury_trace_internal.c:
Implement the proposed command set. Command names are now words,
and several commands now have options allowing the user to override
the default print level or strictness of the command, or the
invocation conditions or action of a break point. Allows control
over command echoing and the scrolling of sequences of event reports.
Supports aliases, command file sourcing etc. Implements the retry
command, using the info in the fixed stack slots.
trace/mercury_trace.[ch]:
Extend the trace controls to support the new functionalities
required by the new debugger language, which are print levels,
variable-strictness commands, a more flexible finish command,
and the retry command.
Pass the command structure to MR_trace_event_report, since
the user can now forcibly terminate the scrolling of reports.
trace/mercury_trace_alias.[ch]:
New module to manage aliases for the debugger.
trace/mercury_trace_help.[ch]:
New module to interface to browser/help.m.
trace/mercury_trace_spy.[ch]:
New module to manage break points. The test of whether an event
matches a break point is now much more efficient than before.
The new module also allows several breakpoints with different
actions and different invocation conditions (e.g. all ports,
entry port, interface ports or specific (possibly internal) port)
to be defined on the same procedure.
trace/mercury_trace_tables.[ch]:
New module to manage a table of the debuggable modules, in which
each such module is linked to the list of the layouts of all the
procedures defined in that module. This information allows the
debugger to turn the name of a predicate/function (possibly together
with its arity and mode number) into the procedure layout structure
required by the spy point module. Eventually it may also be useful
in supplying lists of identifiers for command line completion.
Modules for which no stack layout information is available will
not be included in the table, since do_init_modules will not
register any labels for them in the label table.
trace/Mmakefile:
Mention the new files.
runtime/mercury_array_macros.h:
A new file holding macros that can be useful in more than one module.
runtime/Mmakefile:
Mention the new file.
runtime/mercury_conf.h.in:
Mention a new configuration macro, MR_CANNOT_USE_STRUCTURE_ASSIGNMENT,
used by runtime/mercury_array_macros.h.
configure.in:
Find out whether we need to define MR_CANNOT_USE_STRUCTURE_ASSIGNMENT.
ADD TRACE DEPTH HISTOGRAMS
runtime/mercury_conf_param.h:
Document MR_TRACE_HISTOGRAM.
runtime/mercury_trace_base.[ch]:
Define the data structures for the histogram, and print the histogram
when a traced program exits if MR_TRACE_HISTOGRAM is set.
trace/mercury_trace.[ch]:
If MR_TRACE_HISTOGRAM is defined, record a count of the number of
events at each depth. This information can help us evaluate space-time
tradeoffs.
FACTOR OUT SHELL CODE HANDLING GRADE IMPLICATIONS
scripts/final_grade_options.sh-subr:
A new file to contain any code that implements implications between
grade flags; currently implements the implication debug -> use trail.
scripts/mgnuc.in:
scripts/ml.in:
Replace the code that is now in final_grade_options.sh-subr with
an inclusion of final_grade_options.sh-subr.
configure.in:
Handle final_grade_options.sh-subr as {init,parse}_grade_options.sh-subr
are handled.
SIMPLIFY THE MAINTAINANCE OF CONSISTENCY BETWEEN DEBUGGER CODE AND DOCUMENTATION
doc/Mmakefile:
Add rules for creating mdb_command_list, a C code fragment
that can included manually in trace/mercury_trace_internal.c
to supply the list of valid commands, and mdb_command_test.inp,
which is a list of invalid invocations of debugger commands,
which tests whether the help message for such invocations
can be located as expected.
doc/generate_mdb_command_list:
doc/generate_mdb_command_test:
Awk scripts to create mdb_command_list and mdb_command_test.inp
respectively from mdb_doc.
tools/bootcheck:
Copy mdb_command_test.inp from doc to tests/debugger.
tests/debugger/Mmakefile:
Add a new test that checks whether we get an internal error, unable
to locate the right help node, for each invalid command invocation in
mdb_command_test.inp.
UPDATE TEST CASES
tests/debugger/Mmakefile:
Reenable queens. Conform to the new set of options.
tests/debugger/*.inp:
tests/debugger/*.exp:
Update the inputs and expected outputs of the debugger test cases
to use the new command set and output formats.
|
||
|
|
376f2c69af |
An initial implementation of the accurate garbage collector.
Estimated hours taken: 90 An initial implementation of the accurate garbage collector. WORK_IN_PROGRESS: Add an entry for the accurate garbage collector. library/builtin.m: library/mercury_builtin.m: library/std_util.m: runtime/mercury_tabling.h: Deep copy terms using the address of the value instead of just the value. library/io.m: Initialize the garbage collector's rootset with the globals. runtime/Mmakefile: Add new files to the Mmakefile. runtime/mercury_accurate_gc.h: runtime/mercury_accurate_gc.c: The new garbage collector. runtime/mercury_agc_debug.c: runtime/mercury_agc_debug.h: Debugging utilities for the new garbage collector. runtime/mercury_deep_copy.c: runtime/mercury_deep_copy.h: runtime/mercury_deep_copy_body.h: Put the deep copy code in mercury_deep_copy_body.h, and #include it with appropriate #defines in order to get a variant for deep_copy(), and one for agc_deep_copy(). agc_deep_copy() forwards pointers as it copies. Also, deep_copy (all variants) have been modified to take a pointer to the data to be copied, because some variants need to be able to modify it. runtime/mercury_engine.c: runtime/mercury_engine.h: Add a second heap_zone which is the to-space of the copying collector. Add a debug_heap_zone, which is used as a scratch heap for debugging. runtime/mercury_label.c: Instead of realloc(entry_table, ....) do entry_table = realloc(entry_table, ....) to avoid horrible bugs. Also, make sure the tables get initialized before looking up an entry label. runtime/mercury_imp.h: Include mercury_debug.h before most of the modules. (mercury_engine.h adds a new MemoryZone only if we are debugging accurate GC). runtime/mercury_memory.c: Setup the debug_memory_zone sizes. Remove an unnecessary prototype. runtime/mercury_memory_handlers.c: Add code to get the program counter and the stack pointer from the signal context. Call MR_schedule_agc() from default_handler() if doing accurate gc. runtime/mercury_memory_zones.c: Setup the hardzone regardless of whether redzones are used. Add some more debugging information. runtime/mercury_regorder.h: runtime/machdeps/alpha_regs.h: runtime/machdeps/i386_regs.h: Add definitions to make the real machine registers name/number for MR_sp available. runtime/mercury_trace_internal.c: runtime/mercury_trace_util.c: runtime/mercury_trace_util.h: Add MR_trace_write_variable(), which writes terms given their value and type_info. runtime/mercury_wrapper.c: runtime/mercury_wrapper.h: Change the size of the heap redzone when doing accurate GC. Use a small heap when debugging agc. runtime/mercury_debug.h: runtime/mercury_conf_param.h: Add new debugging macros and document them. runtime/mercury_type_info.c: Add const to the pointer arguments of MR_make_type_info. |
||
|
|
d1855187e5 |
Implement new methods of handling failures and the end points of branched
Estimated hours taken: 260
Implement new methods of handling failures and the end points of branched
control structures.
compiler/notes/failure.html:
Fix an omission about the handling of resume_is_known in if-then-elses.
(This omission lead to a bug in the implementation.)
Optimize cuts across multi goals when curfr is known to be equal
to maxfr.
Clarify the wording in several places.
compiler/code_info.m:
Completely rewrite the methods for handling failure.
Separate the fields of code_info into three classes: those which
do not change after initialization, those which record state that
depends on where in the HLDS goal we are, and those which contain
persistent data such as label and cell counters.
Rename grab_code_info and slap_code_info as remember_position
and reset_to_position, and add a wrapper around the remembered
code_info to make it harder to make mistakes in its use.
(Only the location-dependent fields of the remembered code_info
are used, but putting only them into a separate data structure would
result in more, not less, memory being allocated.)
Gather the predicates that deal with handling branched control
structures into a submodule.
Reorder the declarations and definitions of access predicates
to conform to the new order of fields.
Reorder the declarations and definitions of the failure handling
submodule to better reflect the separation of higher-level and
lower-level predicates.
compiler/code_gen.m:
Replace code_gen__generate_{det,semi,non}_goal_2 with a single
predicate, since for most HLDS constructs the code here is the same
anyway (the called preds check the code model when needed).
Move classification of the various kinds of unifications to unify_gen,
since that is where it belongs.
Move responsibility for initializing the code generator's trace
info to code_info.
Move the generation of code for negations to ite_gen, since the
handling of negations is a cut-down version of the handling of
negations. This should make the required double maintenance easier,
and more likely to happen.
compiler/disj_gen.m:
compiler/ite_gen.m:
These are the two modules that handle most failures; they have
undergone a significant rewrite. As part of this rewrite, factor
out the remaining common code between model_non and model_{det,semi}
goals.
compiler/unify_gen.m:
Move classification of the various kinds of unifications here from
code_gen. This allows us to keep several previously exported
predicates private.
compiler/call_gen.m:
Factor out some code that was common to ordinary calls, higher order
calls and method calls. Move the common code that checks whether
we are doing tracing to trace.m.
Replace call_gen__generate_{det,semi,nondet}_builtin with a single
predicate.
Delete the commented out call_gen__generate_complicated_unify,
since it will never be needed and in any case suffered from
significant code rot.
compiler/llds.m:
Change the mkframe instruction so that depending on one of its
arguments, it can create either ordinary frames, or the cut-down
frames used by the new failure handling algorithm (they have only
three fixed fields: prevfr, redoip and redofr).
compiler/llds_out.m:
Emit a #define MR_USE_REDOFR before including mercury_imp.h, to
tell the runtime we are using the new failure handling scheme.
This effectively changes the grade of the compiled module.
Emit MR_stackvar and MR_framevar instead of detstackvar and framevar.
This is a step towards cleaning up the name-space, and a step towards
making both start numbering at 0. For the time being, the compiler
internally still starts counting framevars at 0; the code in llds_out.m
adds a +1 offset.
compiler/trace.m:
Change the way trace info is initialized to fit in with the new
requirements of code_info.m.
Move the "are we tracing" check from the callers to the implementation
of trace__prepare_for_call.
compiler/*.m:
Minor changes in accordance with the major ones above.
compiler/options.m:
Introduce a new option, allow_hijacks, which is set to "yes" by
default. It is not used yet, but the idea is that when it is set to no,
the code generator will not generate code that hijacks the nondet
stack frame of another procedure invocation; instead, it will create
a new temporary nondet stack frame. If the current procedure is
model_non, it will have three fields: prevfr, redoip and redofr.
If the current procedure is model_det or model_semi, it will have
a fourth field that is set to the value of MR_sp. The idea is that
the runtime system, which will be able to distinguish between
ordinary frames (whose size is at least 5 words), 3-word and 4-word
temporary frames, will now be able to use the redofr slots of
all three kinds of frames and the fourth slot values of 4-word
temporary frames as the addresses relative to which framevars
and detstackvars respectively ought to be offset in stack layouts.
compiler/handle_options.m:
Turn off allow_hijacks if the gc method is accurate.
runtime/mercury_stacks.h:
Change the definitions for the nondet stack handling macros
to accommodate the new nondet stack handling discipline.
Define a new macro for creating temp nondet frames.
Define MR_based_stackvar and MR_based_framevar (both of which start
numbering slots at 1), and express other references, including
MR_stackvar and MR_framevar and backward compatible definitions of
detstackvar and framevar for hand-written C code, in terms of those
two.
runtime/mercury_stack_trace.[ch]:
Add a new function to print a dump of the fixed elements nondet stack,
for debugging my changes. (The dump does not include variable values.)
runtime/mercury_trace_internal.c:
Add a new undocumented command "D" for dumping the nondet stack
(users should not know about this command, since the output is
intelligible only to implementors).
Add a new command "toggle_echo" that can cause the debugger to echo
all commands. When the input to the debugger is redirected, this
echo causes the output of the session to be much more readable.
runtime/mercury_wrapper.c:
Save the address of the artificial bottom nondet stack frame,
so that the new function in mercury_stack_trace.c can find out
where to stop.
runtime/mercury_engine.c:
runtime/mercury_wrapper.c:
Put MR_STACK_TRACE_THIS_MODULE at the tops of these modules, so that
the labels they define (e.g. do_fail and global_success) are registered
in the label table when their module initialization functions are
called. This is necessary for a meaningful nondet stack dump.
runtime/mercury_grade.h:
Add a new component to the grade string that specifies whether
the code was compiled with the old or the new method of handling
the nondet stack. This is important, because modules compiled
with different nondet stack handling disciplines are not compatible.
This component depends on whether MR_USE_REDOFR is defined or not.
runtime/mercury_imp.h:
If MR_DISABLE_REDOFR is defined, undefine off MR_USE_REDOFR before
including mercury_grade.h. This is to allow people to continue
working on un-updated workspaces after this change is installed;
they should put "EXTRA_CFLAGS = -DMR_DISABLE_REDOFR" into
Mmake.stage.params. (This way their stage1 will use the new method
of handling failure, while their stage2 2&3 will use the old one.)
This change should be undone once all our workspaces have switched
over to the new failure handling method.
tests/hard_coded/cut_test.{m,exp}:
A new test case to tickle the various ways of handling cuts in the
new code generator.
tests/hard_coded/Mmakefile:
Enable the new test case.
|
||
|
|
4ada219856 |
Reorganize the label table to better fit the needs of accurate gc
Estimated hours taken: 25
Reorganize the label table to better fit the needs of accurate gc
and the tracer, and reduce the size of executables.
With these changes, the size of hello world, compiled with static
Mercury libraries but dynamic C libraries, goes from 150+ Kb to
138+ Kb, much of which is beyond our control (e.g. Boehm gc).
runtime/mercury_label.[ch]:
The old label table contained both entry labels and internal labels,
even though they had different kinds of layouts associated with them
(proc layouts and label layouts respectively). The two kinds of labels
have different usage patterns. Internal labels are needed for stack
walking, which requires random access by exact label address. Entry
labels are needed for finding which procedure a program counter is in
for accurate GC, which requires lower-bound inexact search.
The module now has two separate data structures for the two
different kinds of labels. Internal labels are in a hash table,
as before. Entry labels are in an array (resized on demand),
which is sorted for binary search. The entry label array and
its associated functions are present only if they are needed.
runtime/mercury_goto.h:
Call the new functions in mercury_label.c from the
init_{local,label,entry}{,_sl} macros.
runtime/mercury_misc.[ch]
Use the new functions in mercury_label. Fix some software rot,
so that the code now compiles with MR_DEBUG_GOTOS. (It still does not
compile with MR_LOWLEVEL_DEBUG, but the fix for that would conflict
with Tom's planned change to zone handling, so that fix should be
done after Tom is done.)
Note that mercury_misc.c still defines newmem() and oldmem()
although they are declared in mercury_std.h.
runtime/mercury_stack_trace.c:
Use the new functions in mercury_label. As a result, we also need
to make a few more pointers const.
runtime/mercury_table.[ch]:
Add a new traversal predicate to support a new function in
mercury_label.c. (That function is not used yet, but will be soon.)
runtime/mercury_trace.[ch]:
runtime/mercury_trace_base.[ch]:
Split the old mercury_trace module into two. The functions and
variables that will always be linked in (because they are referenced
from modules such as mercury_wrapper which are always needed) are
now in mercury_trace_base; the other functions and variables
stay in mercury_trace. This way, mercury_trace.o will be linked in
only if some module was compiled with execution tracing. Since
mercury_trace.o drags in mercury_trace_internal.o which drags in
everything needed for printing arbitrary terms (which is a lot),
this can be a significant win.
runtime/Mmakefile:
Include the new module in the library.
runtime/mercury_wrapper.c:
runtime/mercury_conf_param.h:
Remove some obsolete MERCURY_OPTIONS options, which would be
difficult to support with the new label table.
Move the #ifdefs around the -P option, so that programs not
compiled with MR_THREAD_SAFE will accept but ignore the option,
instead of aborting with the usage message.
Replace the long usage message for malformed MERCURY_OPTIONS
environment variables with a pointer to the user's guide.
This saves about 1 Kb on every executable.
runtime/mercury_conf_param.h:
Document MR_STACK_TRACE_THIS_MODULE.
util/mkinit.c:
Add a new flag, -i. If this flag is given, include the initialization
code regardless of grade. If it is not given, include the init code
only if the grade requires it.
The -i should be given if you want the executable to support stack
tracing, or uplevel printing in execution tracing, at the cost of
making the executable link in the init functions of all the modules
in the library.
Put the option handling code in alphabetical order.
Fix the wrong default name of the entry point. (It only worked because
c2init was always overriding the default.)
scripts/c2init.in:
Pass through the -i flag to mkinit.
Put the option handling code in alphabetical order.
compiler/mercury_compile.m:
If the trace level specifies any kind of tracing, pass -i to c2init.
tests/debugger/Mmakefile:
Add -i to the c2init flags.
tests/debugger/*
Update the other half the test cases (those which assume a traced
library) to conform to the changes in the debugger interface.
The first half were updated earlier.
doc/user_guide.texi:
In the environment variable section, modify the entry for
MERCURY_OPTIONS to document all the options it makes sense
for non-developers to use.
Slight changes to two other parts of the guide to reduce duplication
with the new material.
|
||
|
|
4ab3f397b1 |
Allow the debugger to print the values of variables in ancestors
Estimated hours taken: 20 Allow the debugger to print the values of variables in ancestors of the current call. This requires knowledge about which named variables are live at call return sites. Providing this information properly required fixing the interaction of execution tracing and accurate garbage collection. compiler/globals.m: Introduce a new trace level, so that there are now four: none, interface, interface_ports (corresponding to the existing three levels) and the new level interface_ports_returns, each of which requires all the information required by lower levels. Make the trace level abstract, since in the future we may want to introduce trace levels for new combinations, e.g. interfaces and returns but not internal ports. Introduce the necessary new predicates. compiler/continuation_info.m: Redefine internal_label_info to allow us to record separate info about the sets of vars needed at (a) internal ports of execution tracing and at (b) call return points for accurate gc or (now) uplevel printing during execution tracing. Neither is a subset of the other, and they need to be treated differently. compiler/mercury_compile.m: Gather information about vars at return labels if the trace level requires uplevel printing capability, even if agc is off. compiler/stack_layout.m: Fix the handling of labels which are needed both by agc and by execution tracing. If information at a return label is needed only by uplevel printing in execution tracing and not by agc, then discard all info about lvals which do not hold named variables or their typeinfos (in fact we keep all typeinfos at the moment). If a label is both the label of a port and a return label, we include in the layout structure the union of the information recorded for the two roles. Sort the var_info vector before using it to generate layout structures in an attempt to make llds_common more effective and to make lists of variables printed by the debugger look better. Record a distinguished value when there is no info about the vars live at a label, rather than (incorrectly) recording that there are no live variables. Before up-level printing, the lie was harmless; now it isn't. Remove the label number from return label layouts, since the tracer isn't expecting it. It used to be included for debugging purposes if the label was for agc, but it is possible for a label to be needed both for agc and for execution tracing. If Tyson finds he needs the label number, it can be easily turned back on for all label layouts. compiler/code_info.m: Conform to the new definition of internal_label_info. Rename an internal pred for clarity. Rename some bool parameter to correctly reflect their new meaning. compiler/*.m: Trivial changes, mostly due to making trace_level an abstract type. runtime/mercury_stack_layout.h: Remove the label number from return label layouts, since the tracer isn't expecting it. runtime/mercury_stack_trace.[ch]: Add a new function that returns the label layout structure at the Nth ancestor return continuation, together with the values of sp and curfr at that point. This required changing MR_stack_walk_step to step from an entry layout only to the return label layout. runtime/mercury_stacks.h: Add macros that let us access detstackvars and framevars based on these synthesized values of sp and curfr. runtime/mercury_trace_util.[ch]: Generalize several functions to allow them to use synthesized (as opposed to saved) values of sp and curfr in looking up values. Retain functions with the original names and signatures that call the new, general versions with the necessary additional parameters. runtime/mercury_trace_internal.c: Add a new command that sets the "ancestor level". For example, "l 2" sets it to 2, which means that the command "v" and "p" will refer to the grandparent of the current call. The ancestor level persists while the debugger is at the current event; after that it is reset to 0. The implementation involves calling the new function in mercury_stack_trace.c and the generalized functions in mercury_trace_util.c. Also add a deliberately undocumented extra command, X, which prints the stack pointers. NEWS: Add a reminder about removing the X command before release. tests/debugger/* Update half the test cases (those which assume a non-debug-grade library) to conform to the changes in the debugger interface. The others will need to be updated later. |
||
|
|
09141817ba |
Fergus's recent change to the handling of some builtins broke the tracing
Estimated hours taken: 20 Fergus's recent change to the handling of some builtins broke the tracing of those builtins. The following changes are a fix for this. compiler/polymorphism.m: Export the predicate that checks whether a predicate is a builtin that lacks the usually necessary typeinfos. Comment out a misleading and in any case not very useful progress message. compiler/liveness.m: Turn off type_info liveness for builtins without typeinfos. Since these builtins establish no gc points and shouldn't be execution traced, this is OK. Make type_info liveness part of live_info, since it can now be incorrect to look up the value of the option. (This may yield a speedup.) compiler/live_vars.m: compiler/store_alloc.m: Pass the pred_id to initial_liveness to liveness.m can do the test. compiler/passes_aux.m: Add a new traversal type that passes along the pred_id. compiler/mercury_compile.m: Turn off execution tracing for the modules builtin.m and private_builtin.m. The latter contains the interface predicates for the builtins without typeinfos. Since the interface predicates also lack the typeinfos, the compiler would get an internal abort if we left execution tracing on. In any case, these two modules contain stuff that users should consider language builtins, which means they should not be execution traced (they can still be stack traced in the right grade). Use the new traversal type for the modules that now need the pred_id. compiler/globals.m: Allow the trace level to be set from outside, in this case mercury_compile.m. The next batch of changes have to do with adding a stack dump command to the debugger. Since debugging is possible even in non-debug grades, this in turn requires allowing stack tracing to work in non-debug grades, on programs in which only some modules are compiled with execution (and hence stack) tracing. compiler/llds_out.m: compiler/mercury_compile.m: runtime/mercury_conf_param.h: Llds_out used to output "#include <mercury_imp.h>" as the first substantive thing in the generated C file. The set of #define parameters in effect when mercury_imp.h is processed determines whether the macros that optionally register stack layouts for label actually do so or not. The values of these parameters are derived from the grade, which means that with this setup it is not possible for a non-debug grade program to register its stack layouts in the label table. The new version of llds_out looks up the option that says whether this module is compiled with execution tracing or not, and if it is, it generates a #define MR_STACK_TRACE_THIS_MODULE *before* the #include of mercury_imp.h. This causes mercury_conf_param.h, included from mercury_imp.h, to define the macros MR_USE_STACK_LAYOUTS and and MR_INSERT_LABELS, which in turn cause stack layouts for labels in this module to be generated and to be inserted into the label table, *without* changing the grade string (this last part is why we do not simply define MR_STACK_TRACE). Use the same mechanism to #include mercury_trace.h when doing execution tracing, since it is simpler than the mechanism we used to use (mercury_compile.m including the #include in a list of C header file fragments). compiler/mercury_compile.m: runtime/mercury_conf_param.h: Split the MR_NEED_INITIALIZATION_CODE macro into two parts. The first, MR_MAY_NEED_INITIALIZATION, now controls whether initialization code makes it into the object file of a module. The second, MR_NEED_INITIALIZATION_AT_START, determines whether the initialization code is called before main/2. When a module is compiled with execution tracing, the macro MR_INSERT_LABELS turns on MR_MAY_NEED_INITIALIZATION but not MR_NEED_INITIALIZATION_AT_START. The debugger will make sure that the initialization code has been called before it tries to do a stack dump (which needs the initialization code to have been executed, because it needs labels to have been put into the label table so that from a return address it can find the layout of the proc to which it belongs). Define MR_NEED_INITIALIZATION_AT_START if PROFILE_TIME is defined, since if PROFILE_TIME is defined mercury_wrapper.c calls init_modules. The fact that MR_NEED_INITIALIZATION_CODE didn't used to be defined when PROFILE_TIME was defined was, I believe, a bug, which was not detected because we do not turn on PROFILE_TIME without also turning on PROFILE_CALLS. runtime/mercury_stack_trace.[ch]: Change the way stack dumps are done, to make it possible to print stack dumps from the debugger and to use trivial run-length encoding on the output (so that 100 consecutive calls to p yield the line "p * 100", rather than 100 lines of "p"). The stack routine now returns an indication of whether the stack dump was fully successful, and if not, a description of the reason why not. This requires knowing when we have found the end of the stack dump, so we provide a global variable, MR_stack_trace_bottom, which mercury_wrapper.c will set to global_success, the address main/2 goes to on success. s/multidet/multi/ runtime/mercury_wrapper.c: Set MR_stack_trace_bottom to the address of globals_success. Use MR_NEED_INITIALIZATION_AT_START to decide whether to call do_init_modules. runtime/mercury_stacks.h: Provide variants of detstackvar(n) and framevar(n) that look up sp and curfr in an array of saved regs, for use by the debugger. runtime/mercury_trace_util.c: Use the new variants of detstackvar(n) and framevar(n). This fixes an old bug on SPARCs. runtime/mercury_trace_internal.c: Completely reorganize the way debugger commands are handled. Centralize reading in command lines, and the breaking up of command lines into words. The command names are the same as they were, but command syntax is now much easier to change. Add a new command "d" to dump as much of the stack as the available information will allow. runtime/mercury_goto.h: Cosmetic changes to avoid the use of two different conditional compilation layout styles. util/mkinit.c: Since we cannot know when we generate the _init.c file whether any modules will be compiled with execution tracing and will thus need stack tracing, we must now include in the generated _init.c file the code to call the initialization functions in all the modules, even if MR_NEED_INITIALIZATION_AT_START is not set, since init_modules can be called later, from the debugger. (We should be able to use the same approach with the accurate collector.) |
||
|
|
baa8904877 |
Fix spelling error in comment.
Estimated hours taken: 0.02 runtime/mercury_stack_trace.h: Fix spelling error in comment. |
||
|
|
f89be73c94 |
Fix stack traces dying in -O-1.
Estimated hours taken: 3 Fix stack traces dying in -O-1. error/1 is usually generated with no stack frame, but in -O-1 it is generated with one (but doesn't need it). error/1 passes MR_dump_stack MR_succip and MR_sp, and MR_dump_stack assumes that MR_succip is for the topmost stack frame, but if error/1 has a stack frame, this is not true. library/require.m: Make sure the caller of MR_dump_stack has no stack frame by using handwritten code. We call the handwritten code from error/1, and so we have the nice side effect that error now appears in the stack dump. runtime/mercury_stack_trace.h: Document that MR_dump_stack assumes the succip is for the topmost stack frame. runtime/mercury_label.h: Fix a comment, layout info is for a label, not a procedure. |
||
|
|
951ed445bf |
Implement nondet stack dumps.
Estimated hours taken: 1 Implement nondet stack dumps. library/require.m: Call MR_dump_stack with MR_curfr. runtime/mercury_stack_trace.c: runtime/mercury_stack_trace.h: Get MR_curfr as input. If we hit a nondet stack frame, handle moving down a frame a little differently. |
||
|
|
f58ee880df |
Add support for stack dumps, do a stack dump from error/1.
Estimated hours taken: 12 Add support for stack dumps, do a stack dump from error/1. compiler/Mmakefile: library/Mmakefile: profiler/Mmakefile: runtime/Mmakefile: Insert EXTRA_MGNUCFLAGS before CFLAGS or EXTRA_CFLAGS becasue mgnuc stops processing its options when it encounters a non-mgnuc option. library/require.m: Call MR_dump_stack if error is called. runtime/Mmakefile: runtime/mercury_imp.h: Add #includes of new files. runtime/mercury_type_info.h: Remove conditional definition of MR_STATIC_CODE_ADDRESSES (moved into mercury_conf.h.in). runtime/mercury_accurate_gc.h: Remove stack_layout stuff, leave this file for accurate GC specific definitions. runtime/mercury_conf.h.in: Add conditional definitions of MR_INSERT_LABELS, MR_USE_STACK_LAYOUTS, MR_NEED_INITIALIZATION_CODE and MR_STATIC_CODE_ADDRESSES, depending on various other options. runtime/mercury_goto.h: Insert labels into label table if MR_INSERT_LABELS is defined, rather than NATIVE_GC. util/mkinit.c: Initialize if MR_NEED_INITIALIZATION_CODE is defined, rather than NATIVE_GC. runtime/mercury_stack_layout.h: All the old stack layout definitions from mercury_accurate_gc.h. Add code for MR_DETISM_DET_CODE_MODEL. runtime/mercury_stack_trace.c: runtime/mercury_stack_trace.h: Implement MR_dump_stack which just provides a dump of the stack as far as possible. Set MR_INSERT_LABELS and MR_USE_STACK_LAYOUTS if MR_STACK_TRACE is set. runtime/mercury_grade.h: Add _strce if stack tracing is enabled in the grade. This might not be a permanent change. runtime/mercury_ho_call.c: Remove unused label declarations. scripts/mgnuc.in: Add --stack-trace and --no-stack-trace options. Consolidate some duplicate code. |