$ show boostorg/stacktrace
Boost.Stacktrace is a production-grade C++ library for capturing, storing, and printing backtraces (call stacks). It provides a header-only core with optional compiled backends that leverage platform-specific mechanisms: `_Unwind_Backtrace` (POSIX), `backtrace()` (glibc), `libbacktrace`, `addr2line`, or Windows Debug Engine (`dbgeng`). The library offers signal-safe raw dump functions, human-readable frame decoding (function names, source file, line number), and the ability to capture stacktraces at the point an exception is thrown via `from_current_exception()`. The design is modular, with separate compiled libraries for each backend and a no-op backend to disable tracing. The codebase is well-structured, heavily tested across compilers and platforms, and actively maintained. It demonstrates deep knowledge of C++ runtime internals, particularly in the exception interception implementation that hooks into `__cxa_allocate_exception` or uses vectored exception handlers on Windows. While the library itself is the reusable asset, several internal utilities (e.g., address base computation from `/proc/self/maps`, `dladdr` abstraction) embody patterns useful in other debugging and profiling tools.
The LLM identified 2 files worth highlighting for reuse:
Parses /proc/self/maps to determine the base address of the executable for position-independent code (PIE). Given a pointer, it finds the containing mapping and computes the base address as mapping start minus offset. This pattern is reusable in any tool that needs to convert runtime addresses to file offsets, especially for debugging or profiling on Linux. It uses standard C++ streams and is self-contained with no Boost dependencies.
Provides a cross-platform abstraction to obtain the shared object or executable path from a code address. On POSIX it uses `dladdr`, on Windows it uses `VirtualQuery` and `GetModuleFileName`. This pattern is useful for any library or tool that needs to map addresses to binaries, such as debuggers, profilers, or custom crash reporters. The AIX fallback uses `loadquery` to emulate `dladdr`. The class is designed for the specific needs of stacktrace but can be adapted.