Availability:C-language interface function
char * PL_backtrace_string(int
depth, int flags)As PL_backtrace(),
but returns the stack as a string. The string uses UTF-8 encoding. The
returned string must be freed using PL_free().
This function is was added to get stack traces from running servers
where I/O is redirected or discarded. For example, using gdb, a
stack trace is printed in the gdb console regardless of Prolog I/O
redirection using the following command:
(gdb) printf "%s", PL_backtrace_string(25,0)
The source distribution provides the script scripts/swipl-bt
that exploits gdb and PL_backtrace_string()
to print stack traces in various formats for a SWI-Prolog process, given
its process id.