backtrace
The Rust crate for capturing, symbolizing, and printing stack backtraces at runtime.
Repository Health
Technical Analysis
backtrace is a foundational Rust library for acquiring stack backtraces programmatically at runtime. Maintained under the rust-lang organization, it underpins the standard library’s own panic backtraces while also exposing a rich programmatic interface for capturing and inspecting frames yourself.
With over 446 million downloads, it is one of the most widely depended-on crates in the ecosystem, used anywhere code needs to record where it is executing, symbolize instruction pointers into function names and source locations, or print human-readable traces.
What You Get
- A top-level
Backtracetype that captures the current stack and resolves symbols on demand - Low-level
trace()andresolve()functions for walking frames and symbolizing instruction pointers directly - Access to per-frame details: instruction pointer, symbol name, file name, line, and column
- Automatic platform backend selection (libunwind, Windows dbghelp, gimli-based symbolization)
- Optional serde serialization of captured backtraces behind a Cargo feature
Common Use Cases
- Attaching a captured backtrace to a custom error type for richer diagnostics
- Building panic hooks or crash reporters that print or log where a failure occurred
- Symbolizing raw instruction pointers collected by a profiler or sampler
- Recording deferred backtraces cheaply and resolving them only when actually displayed
Under The Hood
Architecture - The crate separates capture from symbolization. capture.rs defines the owned Backtrace, BacktraceFrame, and BacktraceSymbol types with lazy resolve(). The backtrace/ module provides platform frame-walkers (libunwind.rs, win32.rs/win64.rs, miri.rs, noop.rs) behind cfg selection, while symbolize/ maps instruction pointers to names and source locations via gimli or Windows dbghelp. print.rs formats traces for display. Tech Stack - Rust edition 2024 (MSRV 1.88) with minimal dependencies: cfg-if for target selection, rustc-demangle for symbol names, and optional serde; gimli/object handle DWARF parsing on supported platforms. Code Quality - As a rust-lang-maintained core crate it carries an extensive test suite (accuracy, smoke, concurrent-panics, skip-inner-frames) and careful, well-commented unsafe platform code. API Design - The two-tier API pairs a beginner-friendly Backtrace type with expert-level trace/resolve primitives, and its deferred-resolution model keeps capture cheap until output is actually needed.
Used by 2 apps in this directory
GitButler
Developer Tools · Devops · AI Development
Git, but better — a modern version control client with stacked branches, parallel workflows, unlimited undo, and first-class support for AI-powered development.
SlateDB
Databases · Developer Tools
Embedded KV store built on object storage with zero replication cost