libbacktrace Documentation

repository·master·Indexed 22 days ago

https://github.com/ianlancetaylor/libbacktrace

A 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.

Tokens
406
Snippets
0
Records
4
Agent score
29%

What's inside libbacktrace

  1. Overview of libbacktrace

    master
    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.
  2. How to use libbacktrace safely in signal handlers and malloc

    master

    Most 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 triggers dl_iterate_phdr, which is not async-signal-safe.

    To avoid deadlocks or undefined behavior, follow these rules:

    1. 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.
    2. Inside malloc: Since dl_iterate_phdr can call malloc, you must make an initial call to a libbacktrace function outside of malloc before attempting to call libbacktrace functions from within a malloc implementation.
  3. Integrate libbacktrace into your project

    master

    To use libbacktrace in your C/C++ project:

    1. Include the public header: #include "backtrace.h".
    2. Link the libbacktrace library into your program or library.
    3. (Optional) Use the generated backtrace-supported.h file to check for feature support at compile time using the macros defined within it.