---
name: "unw_backtrace"
section: "3"
platform: "linux"
package: "libunwind"
version: "1.8.3-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/unw_backtrace"
---

# unw\_backtrace(3)

## NAME

unw\_backtrace -- return backtrace for the calling program

## SYNOPSIS

\#include \<libunwind.h\>\

int unw\_backtrace(void \*\*buffer, int size);\
 int unw\_backtrace2(void \*\*buffer, int size, unw\_context\_t \*ctxt, int flag);\

\#include \<execinfo.h\>\

int backtrace(void \*\*buffer, int size);\

## DESCRIPTION

unw\_backtrace() is a convenient routine for obtaining the backtrace for  the calling program. The routine fills up to size addresses in the array  pointed by buffer. The routine is only available for local unwinding.

Note that many (but not all) systems provide a practically identical function  called backtrace(). The prototype for this function is usually obtained  by including the \<execinfo.h\> header file -- a prototype for  backtrace() is not provided by libunwind. libunwind weakly  aliases backtrace() to unw\_backtrace(), so when a program  calling backtrace() is linked against libunwind, it may end up  calling unw\_backtrace().

In case you want to obtain the backtrace from a specific unw\_context\_t, you can call unw\_backtrace2 with that context passing 0 for flag.  If the unw\_context\_t is known to be a signal frame (i.e., from the third argument  in a sigaction handler on linux), unw\_backtrace2 can be used to collect  only the frames before the signal frame passing the UNW\_INIT\_SIGNAL\_FRAME flag.

## RETURN VALUE

The routine returns the number of addresses stored in the array pointed by  buffer. The return value may be zero to indicate that no addresses were  stored.

## SEE ALSO

libunwind(3libunwind), unw\_step(3libunwind)

## AUTHOR

David Mosberger-Tang\
 Email: **dmosberger@gmail.com**\
 WWW: **http://www.nongnu.org/libunwind/**.
