mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-18 07:15:19 +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".
130 lines
4.5 KiB
Mathematica
130 lines
4.5 KiB
Mathematica
%---------------------------------------------------------------------------%
|
|
% vim: ft=mercury ts=4 sw=4 et
|
|
%---------------------------------------------------------------------------%
|
|
% 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.
|
|
%---------------------------------------------------------------------------%
|
|
|
|
% This module computes diffs between terms.
|
|
|
|
:- module mdb.diff.
|
|
|
|
:- interface.
|
|
|
|
:- import_module int.
|
|
:- import_module io.
|
|
:- import_module std_util.
|
|
|
|
:- pred report_diffs(int::in, int::in, univ::in, univ::in, io::di, io::uo)
|
|
is cc_multi.
|
|
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- implementation.
|
|
|
|
:- import_module mdbcomp.program_representation.
|
|
|
|
:- import_module deconstruct.
|
|
:- import_module list.
|
|
:- import_module require.
|
|
:- import_module string.
|
|
:- import_module type_desc.
|
|
|
|
:- pragma export(report_diffs(in, in, in, in, di, uo), "ML_report_diffs").
|
|
|
|
report_diffs(Drop, Max, Univ1, Univ2, !IO) :-
|
|
(
|
|
Type1 = univ_type(Univ1),
|
|
Type2 = univ_type(Univ2),
|
|
Type1 = Type2
|
|
->
|
|
compute_diffs(Univ1, Univ2, [], [], RevDiffs),
|
|
list__reverse(RevDiffs, AllDiffs),
|
|
list__length(AllDiffs, NumAllDiffs),
|
|
(
|
|
list__drop(Drop, AllDiffs, Diffs),
|
|
Diffs = [_ | _]
|
|
->
|
|
FirstShown = Drop + 1,
|
|
LastShown = min(Drop + Max, NumAllDiffs),
|
|
( FirstShown = LastShown ->
|
|
io__format("There are %d diffs, showing diff %d:\n",
|
|
[i(NumAllDiffs), i(FirstShown)], !IO)
|
|
;
|
|
io__format("There are %d diffs, showing diffs %d-%d:\n",
|
|
[i(NumAllDiffs), i(FirstShown), i(LastShown)], !IO)
|
|
),
|
|
list__take_upto(Max, Diffs, ShowDiffs),
|
|
list__foldl2(show_diff, ShowDiffs, Drop, _, !IO)
|
|
;
|
|
( NumAllDiffs = 0 ->
|
|
io__write_string("There are no diffs.\n", !IO)
|
|
; NumAllDiffs = 1 ->
|
|
io__write_string("There is only one diff.\n", !IO)
|
|
;
|
|
io__format("There are only %d diffs.\n", [i(NumAllDiffs)], !IO)
|
|
)
|
|
)
|
|
;
|
|
io__write_string("The two values are of different types.\n", !IO)
|
|
).
|
|
|
|
:- type term_path_diff
|
|
---> term_path_diff(term_path, univ, univ).
|
|
|
|
:- pred compute_diffs(univ::in, univ::in, term_path::in,
|
|
list(term_path_diff)::in, list(term_path_diff)::out) is cc_multi.
|
|
|
|
compute_diffs(Univ1, Univ2, !.RevPath, !RevDiffs) :-
|
|
deconstruct(univ_value(Univ1), include_details_cc, Functor1, _, Args1),
|
|
deconstruct(univ_value(Univ2), include_details_cc, Functor2, _, Args2),
|
|
( Functor1 = Functor2 ->
|
|
compute_arg_diffs(Args1, Args2, !.RevPath, 1, !RevDiffs)
|
|
;
|
|
list__reverse(!.RevPath, Path),
|
|
!:RevDiffs = [term_path_diff(Path, Univ1, Univ2) | !.RevDiffs]
|
|
).
|
|
|
|
:- pred compute_arg_diffs(list(univ)::in, list(univ)::in, term_path::in,
|
|
int::in, list(term_path_diff)::in, list(term_path_diff)::out) is cc_multi.
|
|
|
|
compute_arg_diffs([], [], _, _, !RevDiffs).
|
|
compute_arg_diffs([], [_ | _], _, _, !RevDiffs) :-
|
|
error("compute_arg_diffs: argument list mismatch").
|
|
compute_arg_diffs([_ | _], [], _, _, !RevDiffs) :-
|
|
error("compute_arg_diffs: argument list mismatch").
|
|
compute_arg_diffs([Arg1 | Args1], [Arg2 | Args2], !.RevPath, ArgNum,
|
|
!RevDiffs) :-
|
|
compute_diffs(Arg1, Arg2, [ArgNum | !.RevPath], !RevDiffs),
|
|
compute_arg_diffs(Args1, Args2, !.RevPath, ArgNum + 1, !RevDiffs).
|
|
|
|
:- pred show_diff(term_path_diff::in, int::in, int::out, io::di, io::uo)
|
|
is cc_multi.
|
|
|
|
show_diff(Diff, !DiffNum, !IO) :-
|
|
!:DiffNum = !.DiffNum + 1,
|
|
io__format("%d: ", [i(!.DiffNum)], !IO),
|
|
Diff = term_path_diff(Path, Univ1, Univ2),
|
|
(
|
|
Path = [],
|
|
io__write_string("mismatch at root", !IO)
|
|
;
|
|
Path = [Posn | Posns],
|
|
io__write_int(Posn, !IO),
|
|
show_path_rest(Posns, !IO)
|
|
),
|
|
io__write_string(": ", !IO),
|
|
functor(univ_value(Univ1), include_details_cc, Functor1, Arity1),
|
|
functor(univ_value(Univ2), include_details_cc, Functor2, Arity2),
|
|
io__format("%s/%d vs %s/%d\n",
|
|
[s(Functor1), i(Arity1), s(Functor2), i(Arity2)], !IO).
|
|
|
|
:- pred show_path_rest(list(int)::in, io::di, io::uo) is det.
|
|
|
|
show_path_rest([], !IO).
|
|
show_path_rest([Posn | Posns], !IO) :-
|
|
io__write_string("/", !IO),
|
|
io__write_int(Posn, !IO),
|
|
show_path_rest(Posns, !IO).
|