SWI-Prolog has a 6-port tracer, extending the standard 4-port tracer Clocksin & Melish, 1987 with two additional ports. The optional unify port allows the user to inspect the result after unification of the head. The exception port shows exceptions raised by throw/1 or one of the built-in predicates. See section 3.8.
The standard ports are called call
, exit
, redo
,
fail
and unify
. The tracer is started by the trace/0
command, when a spy point is reached and the system is in debugging mode
(see spy/1
and debug/0)
or when an exception is raised.
The interactive toplevel goal trace/0
means ``trace the next query''. The tracer shows the port, displaying
the port name, the current depth of the recursion and the goal. The goal
is printed using the Prolog predicate write_term/2.
The style can be modified to include the
ignore_ops
and/or portray
options using the w
,
p
or d
command.
1 ?- visible(+all), leash(-exit). Yes 2 ?- trace, min([3, 2], X). Call: ( 3) min([3, 2], G235) ? creep Unify: ( 3) min([3, 2], G235) Call: ( 4) min([2], G244) ? creep Unify: ( 4) min([2], 2) Exit: ( 4) min([2], 2) Call: ( 4) min(3, 2, G235) ? creep Unify: ( 4) min(3, 2, G235) Call: ( 5) 3 < 2 ? creep Fail: ( 5) 3 < 2 ? creep Redo: ( 4) min(3, 2, G235) ? creep Exit: ( 4) min(3, 2, 2) Exit: ( 3) min([3, 2], 2) Yes [trace] 3 ?- |
On leashed ports (set with the predicate leash/1,
default are
call
, exit
, redo
and fail
)
the user is prompted for an action. All actions are single character
commands which are executed without waiting for a return, unless
the command line option -tty is active. Tracer options:
\Splus
)
\Sminus
)
\Sdiv
)/f | Search for any fail port |
/fe solve | Search for a fail or exit
port of any goal with name solve |
/c solve(a, _) | Search for a call to solve/2
whose first argument is a variable or the atom a |
/a member(_, _) | Search for any port on member/2. This is equivalent to setting a spy point on member/2. |
\Sdot
)
A
)
C
)on
the context module of the goal
is displayed between square brackets (see section 4).
Default is off
.
L
)
a
)
b
)
c
)
d
)ignore_ops
option.
e
)
f
)
g
)
h
)
i
)
l
)
n
)
p
)portray
option (default).
r
)
s
)
u
)
w
)portray
option.
The ideal 4 port model as described in many Prolog books Clocksin & Melish, 1987 is not visible in many Prolog implementations because code optimisation removes part of the choice- and exit-points. Backtrack points are not shown if either the goal succeeded deterministically or its alternatives were removed using the cut. When running in debug mode (debug/0) choice points are only destroyed when removed by the cut. In debug mode, tail recursion optimisation is switched off. (4)