Software Engineering for Smart Data Analytics & Smart Data Analytics for Software Engineering

User Tools

Site Tools

The SWI-Prolog Tracer

The PDT lets you use all the built-in tracing facilities of SWI-Prolog. The SWI-Prolog tracer is invoked by calling trace before the goal you want to trace. For instance, if you want to trace the execution of p(X,Y,Z) you call:

?- trace, p(X,Y,Z).

What you get as a result of such a call depends on the enabled tracing mode:

Console Tracing

In console tracing mode, each 'RETURN' shows you the next “step” of the logic program's execution. For a full listing of possible console tracing actions hit 'h' and 'RETURN'. Here is how console tracing looks after a series of “step” commands:

The GUI Tracer

Enabling / Disabling the GUI Tracer

A note to Mac users

The GUI tracer is enabled / disabled by using the GUI tracer toggle button in the Prolog Console Toolbar:

Alternatively, the GUI tracer is enabled / disabled by typing guitracer / noguitracer in the Prolog Console 1):
Enabling / disabling the GUI tracer from the console.

The GUI Tracer Window

If GUI tracing is enabled, the query

 ?- trace, p(X,Y,Z).

opens the SWI-Prolog GUI tracer as a new window ( A note to Windows users ) that

  1. Shows bindings of variables
  2. Shows the call stack of the running Prolog process
  3. Shows the contents of the prolog source file and the executed goal.
  4. Shows the type of call: initial call (green), redo (yellow), fail (red) and success (blue).

The SWI-Prolog GUI tracer window

The tool bar of the SWI-Prolog GUI tracer offers some useful shortcuts

The SWI-Prolog GUI tracer toolbar.

The buttons in (1) provide - from left to right - the option to show the unifier for the current goal, step into the current goal's execution, step over it or finish the selected goal. The buttons in (2) provide - from left to right – the option to step to the next spy point, add spy points, set a stop at the caret and to remove spy points. For details on other buttons see the respective tool tip.

Inspecting Variable Bindings

If a variable's value is too long to fit in the bindings frame (1) you can view it in full in a separate window by double clicking the variable in (1)

Viewing large variable bindings in the SWI-Prolog GUI-Tracer

Setting Breakpoints

ViaEdit > Breakpoints you can define spy points on predicates occurring in the program (by entering the predicate's name/arity and then pressing the left-most button – see red arrow).

Setting breakpoints in the SWI-Prolog GUI-Tracer

This might be helpful if the state of the guitracer toggle button is not consistent with the actual state (See PDT-232).
research/pdt/docs_archive/v0.x/gui_tracer.txt · Last modified: 2018/05/09 01:59 (external edit)

SEWiki, © 2021