mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-05-01 17:24:34 +00:00
Estimated hours taken: 16
Branches: main, release
Implement a new mdb command, "condition", which associates a condition with
an existing breakpoint. The condition is a match between a variable live at
the breakpoint, or a part thereof, and a term provided as part of the condition
command. If execution arrives at the breakpoint but the match doesn't have the
required outcome, execution will continue without stopping.
NEWS:
Mention the new capability.
doc/user_guide.texi:
Document the new capability.
runtime/mercury_trace_term.[ch]:
This new module has facilities for converting strings to a structured
representation of terms. The debugger uses this representation for the
term being matched.
runtime/Mmakefile:
Add the new module to the list of modules in the runtime library.
browser/cterm.m:
This new module tests whether a value in the program being debugged
matches a term represented by the data structure defined in
mercury_trace_term.
browser/mdb.m:
Include the new module in the browser library.
trace/mercury_trace_spy.[ch]:
Change the code that checks for breakpoints to check breakpoints'
conditions.
Fix an old bug: set the number of the most recent breakpoint
even when reusing an existing slot.
trace/mercury_trace_vars.c:
Change the code that checks for breakpoints to also evaluate the
condition, if any.
Provide the facilities required to implement conditions. Besides
exporting some previously private functions, this involved breaking up
two existing functions into two pieces each, because condition checking
wanted to reuse only parts of them.
Modify the implementation of the functions manipulating breakpoints
to handle the new parts of spy point structures.
Modify the way we delete spy point structures to make doubly sure
that we don't free memory twice; it is now MR_delete_spy_point that
sets the spy_exists field to FALSE, after checking it.
Give more meaningful names to some variables.
trace/mercury_trace_internal.[ch]:
Implement the condition command.
Conform to the changes in mercury_trace_vars.c
When the condition of a breakpoint cannot be evaluated, print an error
message.
Extend the command parser to support double quotes, since this is now
needed to allow strings in terms in the condition command.
Flush any error messages resulting from an mdb command immediately
after the command. This was useful in debugging the change.
tests/debugger/cond.{m,inp,exp*}:
Add this new test case to test the new capability.
tests/debugger/Mmakefile:
Include the new test case in the list of test cases.
tests/debugger/completion.exp:
tests/debugger/mdb_command_test.inp:
Update to reflect the new command.
tests/debugger/cmd_quote.exp:
Update the error message.
99 lines
1.3 KiB
Mathematica
99 lines
1.3 KiB
Mathematica
:- module cond.
|
|
|
|
:- interface.
|
|
|
|
:- import_module io.
|
|
|
|
:- pred main(io::di, io::uo) is det.
|
|
|
|
:- implementation.
|
|
|
|
:- import_module list, int, std_util.
|
|
|
|
:- type t
|
|
---> empty
|
|
; node(t, int, t).
|
|
|
|
main(!IO) :-
|
|
test_maybe(!IO),
|
|
test_maybe(!IO),
|
|
test_maybe(!IO),
|
|
test_maybe(!IO),
|
|
test_string(!IO),
|
|
test_string(!IO),
|
|
test_tree(!IO),
|
|
test_tree(!IO),
|
|
test_tree(!IO),
|
|
test_tree(!IO),
|
|
test_tree(!IO).
|
|
|
|
:- pred test_maybe(io::di, io::uo) is det.
|
|
|
|
test_maybe(!IO) :-
|
|
p(no, A),
|
|
p(yes(2), B),
|
|
p(yes(3), C),
|
|
io__write([A, B, C], !IO),
|
|
io__nl(!IO).
|
|
|
|
:- pred test_string(io::di, io::uo) is det.
|
|
|
|
test_string(!IO) :-
|
|
q("abc", A),
|
|
io__write_string(A, !IO),
|
|
io__nl(!IO),
|
|
q("def", B),
|
|
io__write_string(B, !IO),
|
|
io__nl(!IO),
|
|
q("ghi", C),
|
|
io__write_string(C, !IO),
|
|
io__nl(!IO).
|
|
|
|
:- pred test_tree(io::di, io::uo) is det.
|
|
|
|
test_tree(!IO) :-
|
|
r(1, A),
|
|
s(A, AA),
|
|
io__write(AA, !IO),
|
|
io__nl(!IO),
|
|
r(2, B),
|
|
s(B, BB),
|
|
io__write(BB, !IO),
|
|
io__nl(!IO).
|
|
|
|
:- pred p(maybe(int)::in, maybe(int)::out) is det.
|
|
|
|
p(X, Y) :-
|
|
(
|
|
X = no,
|
|
Y = no
|
|
;
|
|
X = yes(Z),
|
|
Y = yes(Z + 1)
|
|
).
|
|
|
|
:- pred q(string::in, string::out) is det.
|
|
|
|
q(X, Y) :-
|
|
( X = "abc" ->
|
|
Y = "xabcx"
|
|
; X = "def" ->
|
|
Y = "ydefy"
|
|
;
|
|
Y = "else"
|
|
).
|
|
|
|
:- pred r(int::in, t::out) is det.
|
|
|
|
r(X, Y) :-
|
|
( X = 0 ->
|
|
Y = empty
|
|
;
|
|
r(X - 1, S),
|
|
Y = node(S, X, S)
|
|
).
|
|
|
|
:- pred s(t::in, t::out) is det.
|
|
|
|
s(X, X).
|