12.8.1 Foreign debugging functions
AllApplicationManualNameSummaryHelp

  • Documentation
    • Reference manual
      • Foreign Language Interface
        • Notes on Using Foreign Code
          • Foreign debugging functions
            • PL_backtrace()
            • PL_backtrace_string()
            • PL_check_data()
            • PL_check_stacks()
            • prolog_debug/1
            • prolog_nodebug/1
            • PL_prolog_debug()
            • PL_prolog_nodebug()
    • Packages
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.