|Did you know ...||Search Documentation:|
|SWI-Prolog --- Source-level debugger|
SWI-Prolog and XPCE concentrate on program development by offering an environment that is especially suitable for (rapid) prototyping and debugging. This is supported by the fast incremental SWI-Prolog compiler, the debugger that is capable of debugging compiled code and the built-in commandline editor that supports Prolog specific completion.
Tracing Prolog programs using a traditional 4-port debugger on a terminal is difficult. Large Prolog terms make the trace hard to read, difficult to understand determinism and backtracking, and hard to examine the running clauses. That is why SWI-Prolog provides a source-level debugger.
The XPCE-based graphical tracer is the cornerstone of the IDE environment and probably the most useful tool for experts as well as for beginners. It provides three simultaneous views on the status of the environment:
In this picture, the top-left window indicates the binding. B is not listed as this variable is unbound. The top-right window displays the call-stack. The icon indicates the called predicate is a normal user-defined predicate. The icon indicates the call is deterministic, while the icon indicates the frame has choice-points left. The user can click on any frame to switch both source and bindings window to the clicked frame. The trace was started using
?- gtrace, test_chat.
The source-level debugger is controlled by gtrace/0 or gspy/1. These predicates enable the debugger using guitracer/0 and then call trace/0 or spy/1. Like trace/0, gtrace/0 can be called from anywhere in a program to start debugging at a specific location. In the unlikely event that you want to switch back to the traditional tracer in the same session, call noguitracer/0.
?- gspy(dubious/1). % The graphical front-end will be used for subsequent tracing Spy point on dubious/1 true. [debug] ?- go.