mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-17 06:47:17 +00:00
Estimated hours taken: 8 Branches: main Fix some bugs in my previous diff that optimized away stack slots storing dummy values that manifested themselves as warnings from the C compiler about integers too big to fit into 8 or 16 bits being implicitly truncated. They did not lead to the failure of any test case, since it doesn't matter whether the debugger gets the values it ignores (I/O states or stores) from valid stack slots or not. When generating RTTI for gc and the debugger, the compiler had three places that generated references to stack slots: the return sites of calls, resume points, and trace events. The previous diff updated only the first of these. This diff updates the other two, and ensures there are no more. Since the debugger needs to know whether a procedure has a pair of I/O state arguments (e.g. when performing a retry), we add a field to proc layouts to hold this information. runtime/mercury_grade.h: Increment the debug grade runtime compatibility version number to reflect the change in layout structures. runtime/mercury_stack_layout.h: Add an extra field to proc layouts to specify flags. At the moment, the only flag says whether the procedure has a pair of I/O state arguments. Add an extra field to proc layouts to specify the trace level of a procedure. This used to be the same as the module's trace level, but one of my bug fixes a couple of months ago broke that link. We don't yet use this field, but it makes sense to do it at the same time as the increment of the compatibility version number. compiler/continuation_info.m: Attach to every description of a live value a description of where in the compiler that description was created. Rename the type involved to avoid an ambiguity. Ignore dummy types when generating resume layouts. Add some sanity checks. Add new fields to the continuation_info data structure to allow stack_layout.m to fill in the new fields in proc layout structures. compiler/trace.m: Do not generate references to dummy values at trace events, except at call ports. At those ports, all live variables should be in registers. compiler/stack_layout.m: Make the check for whether a value fits into an unsigned 8 bit value a direct rather than an indirect one. The indirect one assumed that stack slot numbers are all positive, which is now a bad assumption. Check for negative stack slot numbers in all RTTI stack slot descriptions. Fill in the two new slots in proc layout structures. compiler/layout.m: Reserve space for the two new slots in proc layout structures. compiler/layout_out.m: Output the two new slots in proc layout structures. compiler/code_gen.m: Preserve the information needed by stack_layout.m for the two new fields. compiler/llds_out.m: Add some code that ensures that we never output an integer constant that doesn't fit into the range of its type. Since this code is executed many millions of times, it is designed to be enabled only when the checking is manually enabled. It is normally off, but I got a clean bootcheck in the debug grade (which is the best stress test) with it enabled. compiler/trace_params.m: Update a comment. compiler/code_info.m: Export a function for use by trace.m. compiler/hlds_pred.m: Export a predicate for use by stack_layout.m. compiler/Mercury.options: Enable inlining for llds_out.m, to get rid of the sanity checking overhead if it is not enabled. tests/debugger/completion.exp*: tests/debugger/interpreter.exp*: tests/debugger/multi_parameter.exp*: tests/debugger/queens.exp*: tests/debugger/print_goal.exp*: tests/debugger/tabled_read.exp*: tests/debugger/tabled_read_decl.exp*: tests/debugger/declarative/io_stream_test.exp*: tests/debugger/declarative/tabled_read_decl.exp*: Update these expected output files to not expect dummy values that aren't kept anymore.
225 lines
7.5 KiB
Mathematica
225 lines
7.5 KiB
Mathematica
%-----------------------------------------------------------------------------%
|
|
% Copyright (C) 2001-2004 The University of Melbourne.
|
|
% This file may only be copied under the terms of the GNU General
|
|
% Public License - see the file COPYING in the Mercury distribution.
|
|
%-----------------------------------------------------------------------------%
|
|
%
|
|
% Definitions of Mercury types for representing layout structures within
|
|
% the compiler. Layout structures are generated by the compiler, and are
|
|
% used by the parts of the runtime system that need to look at the stacks
|
|
% (and sometimes the registers) and make sense of their contents. The parts
|
|
% of the runtime system that need to do this include exception handling,
|
|
% the debugger, the deep profiler and (eventually) the accurate garbage
|
|
% collector.
|
|
%
|
|
% When output by layout_out.m, values of most these types will correspond
|
|
% to the C types defined in runtime/mercury_stack_layout.h or
|
|
% runtime/mercury_deep_profiling.h; the documentation of those types
|
|
% can be found there. The names of the C types are listed next to the
|
|
% function symbol whose arguments represent their contents.
|
|
%
|
|
% The code to generate values of these types is in stack_layout.m and
|
|
% deep_profiling.m.
|
|
%
|
|
% This module should be, but as yet isn't, independent of whether we are
|
|
% compiling to LLDS or MLDS.
|
|
%
|
|
% Author: zs.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- module ll_backend__layout.
|
|
|
|
:- interface.
|
|
|
|
:- import_module backend_libs__proc_label.
|
|
:- import_module hlds__hlds_pred.
|
|
:- import_module libs__trace_params.
|
|
:- import_module ll_backend__llds.
|
|
:- import_module parse_tree__prog_data.
|
|
|
|
:- import_module bool, std_util, list, assoc_list.
|
|
|
|
% This type is for strings which may contain embedded null characters.
|
|
:- type string_with_0s ---> string_with_0s(string).
|
|
|
|
:- type layout_data
|
|
---> label_layout_data( % defines MR_Label_Layout
|
|
proc_label :: proc_label,
|
|
label_num :: int,
|
|
proc_layout_name :: layout_name,
|
|
maybe_port :: maybe(trace_port),
|
|
maybe_is_hidden :: maybe(bool),
|
|
label_num_in_module :: int,
|
|
maybe_goal_path :: maybe(int), % offset
|
|
maybe_var_info :: maybe(label_var_info)
|
|
)
|
|
; proc_layout_data( % defines MR_Proc_Layout
|
|
proc_layout_label :: rtti_proc_label,
|
|
proc_layout_trav :: proc_layout_stack_traversal,
|
|
proc_layout_more :: maybe_proc_id_and_more
|
|
)
|
|
; module_layout_data( % defines MR_Module_Layout
|
|
module_name :: module_name,
|
|
string_table_size :: int,
|
|
string_table :: string_with_0s,
|
|
proc_layout_names :: list(layout_name),
|
|
file_layouts :: list(file_layout_data),
|
|
trace_level :: trace_level,
|
|
suppressed_events :: int,
|
|
num_label_exec_count :: int
|
|
)
|
|
; closure_proc_id_data( % defines MR_Closure_Id
|
|
caller_proc_label :: proc_label,
|
|
caller_closure_seq_no :: int,
|
|
closure_proc_label :: proc_label,
|
|
closure_module_name :: module_name,
|
|
closure_file_name :: string,
|
|
closure_line_number :: int,
|
|
closure_goal_path :: string
|
|
)
|
|
; table_io_decl_data(
|
|
table_io_decl_proc_ptr :: rtti_proc_label,
|
|
table_io_decl_kind :: proc_layout_kind,
|
|
table_io_decl_num_ptis :: int,
|
|
table_io_decl_ptis :: rval,
|
|
% pseudo-typeinfos for headvars
|
|
table_io_decl_type_params :: rval
|
|
)
|
|
; table_gen_data(
|
|
table_gen_proc_ptr :: rtti_proc_label,
|
|
table_gen_num_inputs :: int,
|
|
table_gen_num_outputs :: int,
|
|
table_gen_steps :: list(table_trie_step),
|
|
table_gen_ptis :: rval,
|
|
% pseudo-typeinfos for headvars
|
|
table_gen_type_params :: rval
|
|
).
|
|
|
|
:- type label_var_info
|
|
---> label_var_info( % part of MR_Label_Layout
|
|
encoded_var_count :: int,
|
|
locns_types :: rval,
|
|
var_nums :: rval,
|
|
type_params :: rval
|
|
).
|
|
|
|
:- type proc_layout_stack_traversal % defines MR_Stack_Traversal
|
|
---> proc_layout_stack_traversal(
|
|
entry_label :: maybe(label),
|
|
% The proc entry label; will be
|
|
% `no' if we don't have static
|
|
% code addresses.
|
|
succip_slot :: maybe(int),
|
|
stack_slot_count :: int,
|
|
detism :: determinism
|
|
).
|
|
|
|
% The deep_slot_info gives the stack slot numbers that hold
|
|
% the values returned by the call port code, which are needed to let
|
|
% exception.throw perform the work we need to do at the excp port.
|
|
% The old_outermost slot is needed only with the save/restore approach;
|
|
% the old_outermost field contain -1 otherwise. All fields will contain
|
|
% -1 if the variables are never saved on the stack because the
|
|
% predicate makes no calls (in which case it cannot throw exceptions,
|
|
% because to do that it would need to call exception.throw, directly or
|
|
% indirectly.)
|
|
:- type deep_excp_slots
|
|
---> deep_excp_slots(
|
|
top_csd :: int,
|
|
middle_csd :: int,
|
|
old_outermost :: int
|
|
).
|
|
|
|
:- type proc_layout_proc_static
|
|
---> proc_layout_proc_static(
|
|
hlds_proc_static :: hlds_proc_static,
|
|
deep_excp_slots :: deep_excp_slots
|
|
).
|
|
|
|
:- type maybe_proc_id_and_more
|
|
---> no_proc_id
|
|
; proc_id(
|
|
maybe(proc_layout_proc_static),
|
|
maybe(proc_layout_exec_trace)
|
|
).
|
|
|
|
:- type proc_layout_exec_trace % defines MR_Exec_Trace
|
|
---> proc_layout_exec_trace(
|
|
call_label_layout :: layout_name,
|
|
proc_body :: maybe(rval),
|
|
maybe_table_info :: maybe(layout_name),
|
|
head_var_nums :: list(int),
|
|
% The variable numbers of the
|
|
% head variables, including the
|
|
% ones added by the compiler,
|
|
% in order. The length of the
|
|
% list must be the same as the
|
|
% procedure's arity.
|
|
var_names :: list(int),
|
|
% Each variable name is an
|
|
% offset into the module's
|
|
% string table.
|
|
max_var_num :: int,
|
|
max_r_num :: int,
|
|
maybe_from_full_slot :: maybe(int),
|
|
maybe_io_seq_slot :: maybe(int),
|
|
maybe_trail_slot :: maybe(int),
|
|
maybe_maxfr_slot :: maybe(int),
|
|
eval_method :: eval_method,
|
|
maybe_call_table_slot :: maybe(int),
|
|
eff_trace_level :: trace_level,
|
|
exec_trace_flags :: int
|
|
).
|
|
|
|
:- type file_layout_data
|
|
---> file_layout_data(
|
|
file_name :: string,
|
|
line_no_label_list :: assoc_list(int, layout_name)
|
|
).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- type layout_name
|
|
---> label_layout(proc_label, int, label_vars)
|
|
; proc_layout(rtti_proc_label, proc_layout_kind)
|
|
% A proc layout structure for stack tracing, accurate gc,
|
|
% deep profiling and/or execution tracing.
|
|
; proc_layout_exec_trace(rtti_proc_label)
|
|
; proc_layout_head_var_nums(rtti_proc_label)
|
|
% A vector of variable numbers, containing the numbers of the
|
|
% procedure's head variables, including the ones generated by
|
|
% the compiler.
|
|
; proc_layout_var_names(rtti_proc_label)
|
|
% A vector of variable names (represented as offsets into
|
|
% the string table) for a procedure layout structure.
|
|
; table_io_decl(rtti_proc_label)
|
|
; table_gen_info(rtti_proc_label)
|
|
; table_gen_enum_params(rtti_proc_label)
|
|
; table_gen_steps(rtti_proc_label)
|
|
; closure_proc_id(proc_label, int, proc_label)
|
|
; file_layout(module_name, int)
|
|
; file_layout_line_number_vector(module_name, int)
|
|
; file_layout_label_layout_vector(module_name, int)
|
|
; module_layout_string_table(module_name)
|
|
; module_layout_file_vector(module_name)
|
|
; module_layout_proc_vector(module_name)
|
|
; module_layout_label_exec_count(module_name, int)
|
|
; module_layout(module_name)
|
|
; proc_static(rtti_proc_label)
|
|
; proc_static_call_sites(rtti_proc_label).
|
|
|
|
:- type label_vars
|
|
---> label_has_var_info
|
|
; label_has_no_var_info.
|
|
|
|
:- type proc_layout_kind
|
|
---> proc_layout_traversal
|
|
; proc_layout_proc_id(proc_layout_user_or_uci).
|
|
|
|
:- type proc_layout_user_or_uci
|
|
---> user
|
|
; uci.
|
|
|
|
%-----------------------------------------------------------------------------%
|