Download SWI-Prolog 5.0 Reference Manual

Transcript
214
APPENDIX B. HACKERS CORNER
context module
Value is unified with the name of the context module of the environment.
top
Value is unified with true if Frame is the top Prolog goal from a recursive call back from
the foreign language. false otherwise.
hidden
Value is unified with true if the frame is hidden from the user, either because a parent has
the hide-childs attribute (all system predicates), or the system has no trace-me attribute.
pc
Value is unified with the program-pointer saved on behalve of the parent-goal if the parentgoal is not owned by a foreign predicate.
argument(N)
Value is unified with the N-th slot of the frame. Argument 1 is the first argument of the
goal. Arguments above the arity refer to local variables. Fails silently if N is out of range.
deterministic
Succeeds if there are no choicepoints that are more recent than the parent frame.
B.2
Intercepting the Tracer
prolog trace interception(+Port, +Frame, +PC, -Action)
Dynamic predicate, normally not defined. This predicate is called from the SWI-Prolog debugger just before it would show a port. If this predicate succeeds the debugger assumes the trace
action has been taken care of and continues execution as described by Action. Otherwise the
normal Prolog debugger actions are performed.
Port is one of call, redo, exit, fail or unify. Frame is an integer reference to the
current local stack frame. PC is the current value of the program-counter, relative to the start
of the current clause, or 0 if it is invalid, for example because the current frame runs a foreign predicate, or no clause has been selected yet. Action should be unified with one of the
atoms continue (just continue execution), retry (retry the current goal) or fail (force the
current goal to fail). Leaving it a variable is identical to continue.
Together with the predicates described in section 4.42 and the other predicates of this chapter
this predicate enables the Prolog user to define a complete new debugger in Prolog. Besides
this it enables the Prolog programmer monitor the execution of a program. The example below
records all goals trapped by the tracer in the database.
prolog_trace_interception(Port, Frame, _PC, continue) :prolog_frame_attribute(Frame, goal, Goal),
prolog_frame_attribute(Frame, level, Level),
recordz(trace, trace(Port, Level, Goal)).
To trace the execution of ‘go’ this way the following query should be given:
?- trace, go, notrace.
SWI-Prolog 5.0 Reference Manual