This library is a SWISH specific replacement for library(debug) that allows for debug/3 messages in SWISH code as well as libraries loaded into SWISH. Unlike library(debug), this library maintains the debug state per thread (Pengine).
This library allows for debug/3 calls inside user programs stored in SWISH as well as libraries preloaded into SWISH. Libraries that wish to enable debugging by SWISH users must include this file rather than library(debug). This may be done dynamically using the following snippet.
:- if(exists_source(swish(lib/swish_debug))). :- use_module(swish(lib/swish_debug)). :- else. :- use_module(library(debug)). :- endif.
debugging(+Topic)
may be used to
perform more complex debugging tasks. A typical usage skeleton
is:
( debugging(mytopic) -> <perform debugging actions> ; true ), ...
The other two calls are intended to examine existing and enabled debugging tokens and are typically not used in user programs.
nodebug(_)
removes all
topics. Gives a warning if the topic is not defined unless it is
used from a directive. The latter allows placing debug topics at the
start of a (load-)file without warnings.
For debug/1, Topic can be a term Topic > Out
, where Out is
either a stream or stream-alias or a filename (an atom). This
redirects debug information on this topic to the given output. On
Linux systems redirection can be used to make the message appear,
even if the user_error
stream is redefined using
?- debug(Topic > '/proc/self/fd/2').
A platform independent way to get debug messages in the current
console (for example, a swipl-win
window, or login using ssh
to
Prolog running an SSH server from the libssh
pack) is to use:
?- stream_property(S, alias(user_error)), debug(Topic > S).
Do not forget to disable the debugging using nodebug/1 before quitting the console if Prolog must remain running.
[search(String)]
or a normal option list. Defined options are:
true
) or inactive
(false
).user_error
, but only prints if Topic is activated through
debug/1. Args is a meta-argument to deal with goal for the
@-command. Output is first handed to the hook
prolog:debug_print_hook/3. If this fails, Format+Args is
translated to text using the message-translation (see
print_message/2) for the term debug(Format, Args)
and then
printed to every matching destination (controlled by debug/1)
using print_message_lines/3.
The message is preceded by '% ' and terminated with a newline.
The following predicates are exported from this file while their implementation is defined in imported modules or non-module files loaded by this module.
nodebug(_)
removes all
topics. Gives a warning if the topic is not defined unless it is
used from a directive. The latter allows placing debug topics at the
start of a (load-)file without warnings.
For debug/1, Topic can be a term Topic > Out
, where Out is
either a stream or stream-alias or a filename (an atom). This
redirects debug information on this topic to the given output. On
Linux systems redirection can be used to make the message appear,
even if the user_error
stream is redefined using
?- debug(Topic > '/proc/self/fd/2').
A platform independent way to get debug messages in the current
console (for example, a swipl-win
window, or login using ssh
to
Prolog running an SSH server from the libssh
pack) is to use:
?- stream_property(S, alias(user_error)), debug(Topic > S).
Do not forget to disable the debugging using nodebug/1 before quitting the console if Prolog must remain running.
[search(String)]
or a normal option list. Defined options are:
true
) or inactive
(false
).The following predicates are exported, but not or incorrectly documented.