libbacktrace Documentation
repository·master·Indexed 22 days ago
https://github.com/ianlancetaylor/libbacktraceA C library for generating symbolic backtraces in C/C++ applications. It supports DWARF debugging information and multiple executable formats, including ELF, PE/COFF, Mach-O, and XCOFF, across platforms such as GNU/Linux, BSD, macOS, Windows, and AIX.
What's inside libbacktrace
- libbacktrace is a C library designed to be linked into C/C++ programs to produce symbolic backtraces. It is useful for printing detailed backtraces during error handling or for gathering profiling information. It supports multiple executable formats and debugging information types, including ELF, PE/COFF, Mach-O, and XCOFF with DWARF.
How to use libbacktrace safely in signal handlers and malloc
masterMost functions in libbacktrace are async-signal-safe and can be called from a signal handler. However, there is a critical exception: on systems using
dl_iterate_phdr(such as GNU/Linux), the very first call to any libbacktrace function triggersdl_iterate_phdr, which is not async-signal-safe.To avoid deadlocks or undefined behavior, follow these rules:
- Signal Handlers: Ensure you make an initial call to a libbacktrace function from outside of a signal handler before attempting to call it from within one.
- Inside malloc: Since
dl_iterate_phdrcan callmalloc, you must make an initial call to a libbacktrace function outside ofmallocbefore attempting to call libbacktrace functions from within amallocimplementation.
Integrate libbacktrace into your project
masterTo use libbacktrace in your C/C++ project:
- Include the public header:
#include "backtrace.h". - Link the libbacktrace library into your program or library.
- (Optional) Use the generated
backtrace-supported.hfile to check for feature support at compile time using the macros defined within it.
- Include the public header:
Supported platforms and formats
masterAs of July 2024, libbacktrace supports the following:
Executable Formats:
- ELF
- PE/COFF
- Mach-O
- XCOFF
Debugging Information:
- DWARF
Supported Operating Systems:
- GNU/Linux
- *BSD
- macOS
- Windows
- AIX