ianlancetaylor/libbacktrace logo

ianlancetaylor/libbacktrace

Free

A C library that may be linked into a C/C++ program to produce symbolic backtraces

FreeFree tier
Type
Open Source

About ianlancetaylor/libbacktrace

libbacktrace is a C library designed to be linked into C/C++ programs to generate symbolic backtraces. It was initially written by Ian Lance Taylor and is released under a BSD license. The library's public API is declared in backtrace.h. It is notable for being async-signal-safe in general, allowing safe use from signal handlers, though the first call may invoke dl_iterate_phdr (not async-signal-safe) on systems like GNU/Linux. As of July 2024, libbacktrace supports ELF, PE/COFF, Mach-O, and XCOFF executables with DWARF debugging information, covering GNU/Linux, *BSD, macOS, Windows, and AIX. It is open source and hosted on GitHub.

Key Features

Produces symbolic backtraces from C/C++ programs
Async-signal-safe (with first-call caveat for dl_iterate_phdr)
Supports ELF, PE/COFF, Mach-O, and XCOFF executable formats with DWARF debugging info
Works on GNU/Linux, *BSD, macOS, Windows, and AIX
Public API documented in backtrace.h
BSD licensed, open source

Pros & Cons

Pros
  • Async-signal-safe for use in signal handlers (after initial call)
  • Supports multiple platforms including Linux, macOS, Windows, AIX
  • BSD licensed, easy to integrate into proprietary or open-source projects
  • Lightweight library that can be linked into programs or libraries
Cons
  • First call may invoke dl_iterate_phdr which is not async-signal-safe
  • Requires DWARF debugging information in executables for symbolic backtraces
  • Limited to supported executable formats (ELF, PE/COFF, Mach-O, XCOFF)

Best For

Printing detailed backtraces when an error or exception occursGathering detailed profiling information in a programSignal handler backtrace generationDebugging and crash analysis in C/C++ applications

FAQ

What platforms does libbacktrace support?
As of July 2024, libbacktrace supports ELF, PE/COFF, Mach-O, and XCOFF executables with DWARF debugging information, covering GNU/Linux, *BSD, macOS, Windows, and AIX.
Is libbacktrace safe to use from a signal handler?
In general, the functions provided are async-signal-safe, but on systems that use dl_iterate_phdr (e.g., GNU/Linux), the first call to a libbacktrace function will call dl_iterate_phdr, which is not async-signal-safe. It is recommended to make an initial call from outside a signal handler.
What license is libbacktrace under?
The libbacktrace library is provided under a BSD license. See the source files for the exact license text.