Support for debugging threads is still very limited. Debug and trace
mode are flags that are local to each thread. Individual threads can be
debugged either using the graphical debugger described in
section 3.5 (see tspy/1
and friends) or by attaching a console to the thread and running the
traditional command line debugger (see
attach_console/0).
When using the graphical debugger, the debugger must be loaded
from the main thread (for example using guitracer) before gtrace/0
can be called from a thread.
- attach_console
- If the current thread has no console attached yet, attach one and
redirect the user streams (input, output, and error) to the new console
window. On Unix systems the console is an xterm application. On
Windows systems this requires the GUI version swipl-win.exe
rather than the console-based swipl.exe.
This predicate has a couple of useful applications. One is to
separate (debugging) I/O of different threads. Another is to start
debugging a thread that is running in the background. If thread 10 is
running, the following sequence starts the tracer on this thread:
?- thread_signal(10, (attach_console, trace)).
- tdebug(+ThreadId)
- Prepare ThreadId for debugging using the graphical tracer.
This implies installing the tracer hooks in the thread and switching the
thread to debug mode using debug/0.
The call is injected into the thread using thread_signal/2.
We refer to the documentation of this predicate for asynchronous
interaction with threads. New threads created inherit their debug mode
from the thread that created them.
- tdebug
- Call tdebug/1
in all running threads.
- tnodebug(+ThreadId)
- Disable debugging thread ThreadId.
- tnodebug
- Disable debugging in all threads.
- tspy(:Spec,
+ThreadId)
- Set a spy point as spy/1
and enable the thread for debugging using
tdebug/1.
Note that a spy point is a global flag on a predicate that is visible
from all threads. Spy points are honoured in all threads that are in
debug mode and ignored in threads that are in nodebug mode.
- tspy(:Spec)
- Set a spy point as spy/1
and enable debugging in all threads using
tdebug/0.
Note that removing spy points can be done using nospy/1.
Disabling spy points in a specific thread is achieved by tnodebug/1.