mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-23 05:13:48 +00:00
Estimated hours taken: 12 Get the debugger to sort variables better. trace/mercury_trace_vars.[ch]: A new module to manage the debugger's information about the variables live at the current program point (which can be defined as the combination of a specific event and an ancestor level). This new module centralizes the management of the (sorted) list of current variables. This in turn allows us to use a better sorting method, one that orders VarName15 correctly wrt both VarName2 and VarName. The new module also uses the type, not the name, of a variable to decide whether to exclude it from the list of variables that may be presented to the user (e.g. if it is a typeinfo or a typeclassinfo). trace/mercury_trace_internal.c: trace/mercury_trace_external.c: Use the new module's facilities. This factors out some "mostly" common code. trace/Mmakefile: Add the new module. runtime/mercury_layout_util.[ch]: Remove the code recently moved here from trace/mercury_trace_internal, as well as the filtered versions of some functions, since they are not needed anymore. Move the code for MR_make_var_list to trace/mercury_trace_external, since that is the only place where it is used (or is at all likely to be used). Since its new home is next to several very similar functions, this should also reduce the probability that any required maintenance will be overlooked. Also alter its coding style to conform to its new neighbours. Move the definition of MR_Var_Spec to trace/mercury_trace_vars.h. tests/debugger/*.exp: Update the expected output files. In most cases, this is just because the new module outputs different white space, but in some cases, it also reflects that the debugger now prints variables in a different order.
136 lines
5.5 KiB
C
136 lines
5.5 KiB
C
/*
|
|
** Copyright (C) 1998-1999 The University of Melbourne.
|
|
** This file may only be copied under the terms of the GNU Library General
|
|
** Public License - see the file COPYING.LIB in the Mercury distribution.
|
|
*/
|
|
|
|
#ifndef MERCURY_LAYOUT_UTIL_H
|
|
#define MERCURY_LAYOUT_UTIL_H
|
|
|
|
#include "mercury_std.h"
|
|
#include "mercury_types.h"
|
|
#include "mercury_stack_layout.h"
|
|
|
|
/*
|
|
** These two functions copy the register state to and from the provided
|
|
** saved_regs array, which should have room for MAX_FAKE_REG Words.
|
|
*/
|
|
|
|
extern void MR_copy_regs_to_saved_regs(int max_mr_num, Word *saved_regs);
|
|
extern void MR_copy_saved_regs_to_regs(int max_mr_num, Word *saved_regs);
|
|
|
|
/*
|
|
** A MR_Stack_Layout_Vars describes the variables that are live at a given
|
|
** program point. Some of the types of these variables may contain type
|
|
** variables. Since the values of those type variables are not known until
|
|
** runtime, the MR_Stack_Layout_Vars cannot include full typeinfos for the
|
|
** variables. Instead, it contains pseudo-typeinfos, in which some parts
|
|
** of some typeinfo structures may contain an indication "this data is
|
|
** not available at compile time, but at runtime it will be in this location".
|
|
**
|
|
** MR_materialize_typeinfos takes as input a MR_Stack_Layout_Vars
|
|
** structure. It returns a vector of typeinfos which has one entry for each
|
|
** pseudo-typeinfo in the MR_Stack_Layout_Vars structure, with this typeinfo
|
|
** being the pseudo-typeinfo with the runtime-only information substituted in.
|
|
** Since type variable numbers start at one, the element of this array at
|
|
** index zero will be unused. This means that the array will itself look
|
|
** like a typeinfo.
|
|
**
|
|
** The vector returned by MR_materialize_typeinfos is from malloc;
|
|
** it should be freed after last use.
|
|
**
|
|
** MR_materialize_typeinfos looks up locations in the current
|
|
** environment, as indicated by the set of saved registers (including MR_sp
|
|
** and MR_curfr). MR_materialize_typeinfos_base does the same job but
|
|
** assumes the environment is given by the given values of MR_sp and MR_curfr,
|
|
** and does not assume that the registers have valid contents unless saved_regs
|
|
** is non-null.
|
|
*/
|
|
|
|
extern Word *MR_materialize_typeinfos(
|
|
const MR_Stack_Layout_Vars *vars, Word *saved_regs);
|
|
extern Word *MR_materialize_typeinfos_base(
|
|
const MR_Stack_Layout_Vars *vars, Word *saved_regs,
|
|
Word *base_sp, Word *base_curfr);
|
|
|
|
/*
|
|
** If the given encoded location refers to a register, return its number.
|
|
** If it does not, return -1.
|
|
*/
|
|
|
|
extern int MR_get_register_number_long(MR_Long_Lval locn);
|
|
extern int MR_get_register_number_short(MR_Short_Lval locn);
|
|
|
|
/*
|
|
** Given an location either in a long or short form, return the value
|
|
** at that location if possible. *succeeded will say whether the attempt
|
|
** was successful.
|
|
**
|
|
** MR_lookup_{long,short}_lval looks up locations in the current environment,
|
|
** as indicated by the set of saved registers (including MR_sp and MR_curfr).
|
|
** MR_lookup_{long,short}_lval_base does the same job but assumes the
|
|
** environment is given by the given values of MR_sp and MR_curfr, and does
|
|
** not assume that the registers have valid contents unless saved_regs is
|
|
** non-null.
|
|
*/
|
|
|
|
extern Word MR_lookup_long_lval(MR_Long_Lval locn,
|
|
Word *saved_regs, bool *succeeded);
|
|
extern Word MR_lookup_long_lval_base(MR_Long_Lval locn,
|
|
Word *saved_regs, Word *base_sp, Word *base_curfr,
|
|
bool *succeeded);
|
|
extern Word MR_lookup_short_lval(MR_Short_Lval locn,
|
|
Word *saved_regs, bool *succeeded);
|
|
extern Word MR_lookup_short_lval_base(MR_Short_Lval locn,
|
|
Word *saved_regs, Word *base_sp, Word *base_curfr,
|
|
bool *succeeded);
|
|
|
|
/*
|
|
** Given information about the location of a variable (var) and a vector giving
|
|
** the typeinfos corresponding to the type variables that may occur in
|
|
** the type of that variable (type_params), try to return the value of the
|
|
** variable in *value and the typeinfo describing its type in *type_info.
|
|
** *succeeded will say whether the attempt was successful.
|
|
**
|
|
** The type_params array should have the same format as the array returned
|
|
** by MR_materialize_typeinfos.
|
|
**
|
|
** MR_get_type_and_value looks up locations in the current environment,
|
|
** as indicated by the set of saved registers (including MR_sp and MR_curfr).
|
|
** MR_get_type_and_value_base does the same job but assumes the
|
|
** environment is given by the given values of MR_sp and MR_curfr, and does
|
|
** not assume that the registers have valid contents unless saved_regs is
|
|
** non-null.
|
|
**
|
|
** MR_get_type and MR_get_type_base are similar but do not
|
|
** return the value.
|
|
**
|
|
** All of these functions may need to allocate memory (to hold the
|
|
** type_infos that they return); any memory that they allocate will
|
|
** be allocated on the Mercury heap.
|
|
*/
|
|
|
|
extern bool MR_get_type_and_value(const MR_Stack_Layout_Vars *vars,
|
|
int var, Word *saved_regs,
|
|
Word *type_params, Word *type_info, Word *value);
|
|
extern bool MR_get_type_and_value_base(const MR_Stack_Layout_Vars *vars,
|
|
int var, Word *saved_regs,
|
|
Word *base_sp, Word *base_curfr,
|
|
Word *type_params, Word *type_info, Word *value);
|
|
extern bool MR_get_type(const MR_Stack_Layout_Vars *vars, int var,
|
|
Word *saved_regs, Word *type_params, Word *type_info);
|
|
extern bool MR_get_type_base(const MR_Stack_Layout_Vars *vars, int var,
|
|
Word *saved_regs, Word *base_sp, Word *base_curfr,
|
|
Word *type_params, Word *type_info);
|
|
|
|
/*
|
|
** MR_write_variable:
|
|
** Write a variable to stdout.
|
|
** This uses the fake_reg copies of the registers,
|
|
** and it may also clobber the real registers.
|
|
*/
|
|
|
|
extern void MR_write_variable(Word type_info, Word value);
|
|
|
|
#endif /* MERCURY_LAYOUT_UTIL_H */
|