| BACKTRACE(3) | Library Functions Manual | BACKTRACE(3) |
backtrace,
backtrace_symbols,
backtrace_symbols_fd,
backtrace_symbols_fmt,
backtrace_symbols_fd_fmt —
fill in the backtrace of the currently executing
thread
Backtrace Information Library (libexecinfo, -lexecinfo)
#include
<execinfo.h>
size_t
backtrace(void
**addrlist, size_t
len);
int
backtrace_sandbox_init(void);
void
backtrace_sandbox_fini(void);
char **
backtrace_symbols(void
* const *addrlist, size_t
len);
int
backtrace_symbols_fd(void
* const *addrlist, size_t
len, int fd);
char **
backtrace_symbols_fmt(void
* const *addrlist, size_t
len, const char
*fmt);
int
backtrace_symbols_fd_fmt(void
* const *addrlist, size_t
len, int fd,
const char *fmt);
The
backtrace()
function places into the array pointed by addrlist the
array of the values of the program counter for each frame called up to
len frames. The number of frames found (which can be
fewer than len) is returned.
The
backtrace_sandbox_init()
and
backtrace_sandbox_fini()
functions are intended to enable sandbox usage of
backtrace. The
backtrace_sandbox_init() function must be called
before the sandbox is entered, and will acquire any resources needed to
function in a sandbox. The backtrace_sandbox_fini()
function will release the resources it acquired.
The
backtrace_symbols_fmt()
function takes an array of previously filled addresses from
backtrace() in addrlist of
len elements, and uses fmt to
format them. The formatting characters available are:
andDfThe array of formatted strings is returned as a contiguous memory address which can be freed by a single free(3).
The
backtrace_symbols()
function is equivalent of calling
backtrace_symbols_fmt() with a format argument of
“%a <%n%D> at %f”
The
backtrace_symbols_fd()
and
backtrace_symbols_fd_fmt()
are similar to the non _fd named functions, only instead of returning an
array of strings, they print a new-line separated array of strings in fd,
and return 0 on success and
-1 on failure.
The backtrace() function returns the
number of elements that were filled in the backtrace. The
backtrace_symbols() and
backtrace_symbols_fmt() return a string array on
success, and NULL on failure, setting
errno. Diagnostic output may also be produced by the
ELF symbol lookup functions.
The backtrace() library of functions first
appeared in NetBSD 7.0.
| January 22, 2025 | NetBSD 11.0 |