mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-15 01:13:30 +00:00
Estimated hours taken: 8
Branches: main
Add two new capabilities to the debugger.
The first capability is the idea of "held variables", variables that the
debugger holds onto even when execution has left the event they came from.
You can hold onto a variable via the mdb command "hold varname heldvarname".
You can suffix the name of the existing variable with a term path, in which
case the new held variable will refer only to the specified part of the term.
Later mdb commands can refer to the held variable by prefixing its name with
a dollar sign. For example, after "hold HeadVar__1^2 x", "$x" will refer to
the term that was the second argument of HeadVar__1 at the program point
at which the "hold" command was executed.
The second capability is the ability to compute the diff of two terms and
express those diffs as the term paths of the function symbols at which the two
terms differ, instead of the line numbers you get by using save_to_file and the
usual Unix diff command. The mdb command is "diff var1 var2". We limit the
number of term paths of difference sites that we display at any one time;
the mdb diff command has options to control this.
NEWS:
Mention the new capabilities.
doc/user_guide.texi:
Document the new mdb commands "hold" and "diff", the new mdb command
"held_vars" which simply lists the names of all the held variables
(just as "vars" lists the names of all the nonheld variables currently
accessible), and the concept of held variables.
doc/mdb_categories:
Update this file for the new mdb commands and concepts.
browser/browse_diff.m:
This new module implements the diff operation on terms.
browser/mdb.m:
Add the new module to the list of submodules of the mdb package.
browser/*.m:
Minor cleanups, such as importing only one module per line; there
are no algorithmic changes.
trace/mercury_trace_hold_vars.[ch]:
This new module implements the database of held variables.
trace/Mmakefile:
Mention the new module.
trace/mercury_trace_internal.c:
Implement the three new mdb commands.
trace/mercury_trace_vars.[ch]:
Modify the functions that recognize variable specifications or
process them to work with held variables as well as variables from
the current environment. This required some reorganization of the
internals of this module.
Provide some a utility function, MR_trace_parse_lookup_var_path,
for converting a string representing the specification of a term
(a variable and possibly some path within it) to the type and value
of that term. Make the utility function this is based upon,
MR_lookup_unambiguous_var_spec, replace the previous but less capable
MR_convert_var_spec_to_type_value.
trace/mercury_trace_spy.c:
Conform to the change in mercury_trace_vars.c.
trace/mercury_trace_util.c:
Make a utility function more robust.
trace/mercury_trace_alias.c:
Minor cleanups.
tests/debugger/queens.{inp,exp*}:
Update this test case to test the debugger's new capabilities.
tests/debugger/completion.{inp,exp*}:
Update this test case to expect the new mdb commands, and avoid the
ambiguity between "help" and "held_vars".
83 lines
2.2 KiB
C
83 lines
2.2 KiB
C
/*
|
|
** vim: ts=4 sw=4 expandtab
|
|
*/
|
|
/*
|
|
** Copyright (C) 2005 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.
|
|
*/
|
|
|
|
#include "mercury_imp.h"
|
|
#include "mercury_array_macros.h" /* MR_bsearch etc */
|
|
#include "mercury_trace_base.h" /* MR_TRACE_CALL_MERCURY */
|
|
#include "type_desc.mh" /* ML_get_type_info_for_type_info */
|
|
#include "mercury_trace_hold_vars.h"
|
|
|
|
typedef struct {
|
|
const char *MR_held_name;
|
|
MR_TypeInfo MR_held_type;
|
|
MR_Word MR_held_value;
|
|
} MR_Held_Var;
|
|
|
|
/* The initial size of the held vars table. */
|
|
#define MR_INIT_HELD_VARS 10
|
|
|
|
static MR_Held_Var *MR_held_vars;
|
|
static int MR_held_var_max = 0;
|
|
static int MR_held_var_next = 0;
|
|
|
|
MR_bool
|
|
MR_add_hold_var(const char *name, const MR_TypeInfo typeinfo, MR_Word value)
|
|
{
|
|
MR_TypeInfo old_type;
|
|
MR_Word old_value;
|
|
int slot;
|
|
MR_Word typeinfo_type_word;
|
|
|
|
if (MR_lookup_hold_var(name, &old_type, &old_value)) {
|
|
return MR_FALSE;
|
|
}
|
|
|
|
MR_TRACE_CALL_MERCURY(
|
|
typeinfo_type_word = ML_get_type_info_for_type_info();
|
|
);
|
|
|
|
MR_ensure_room_for_next(MR_held_var, MR_Held_Var, MR_INIT_HELD_VARS);
|
|
MR_prepare_insert_into_sorted(MR_held_vars, MR_held_var_next, slot,
|
|
strcmp(MR_held_vars[slot].MR_held_name, name));
|
|
MR_held_vars[slot].MR_held_name = strdup(name);
|
|
MR_held_vars[slot].MR_held_type = (MR_TypeInfo) MR_make_permanent(typeinfo,
|
|
typeinfo_type_word);
|
|
MR_held_vars[slot].MR_held_value = MR_make_permanent(value, typeinfo);
|
|
|
|
return MR_TRUE;
|
|
}
|
|
|
|
MR_bool
|
|
MR_lookup_hold_var(const char *name, MR_TypeInfo *typeinfo,
|
|
MR_Word *value)
|
|
{
|
|
MR_bool found;
|
|
int slot;
|
|
|
|
MR_bsearch(MR_held_var_next, slot, found,
|
|
strcmp(MR_held_vars[slot].MR_held_name, name));
|
|
if (found) {
|
|
*typeinfo = MR_held_vars[slot].MR_held_type;
|
|
*value = MR_held_vars[slot].MR_held_value;
|
|
return MR_TRUE;
|
|
} else {
|
|
return MR_FALSE;
|
|
}
|
|
}
|
|
|
|
void
|
|
MR_trace_list_held_vars(FILE *fp)
|
|
{
|
|
int i;
|
|
|
|
for (i = 0; i < MR_held_var_next; i++) {
|
|
fprintf(fp, "$%s\n", MR_held_vars[i].MR_held_name);
|
|
}
|
|
}
|