backtrace

The Rust crate for capturing, symbolizing, and printing stack backtraces at runtime.

Library
Cargo
v0.3.76
629 stars
MIT OR Apache-2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
67 /100 Good
Development Activity 64
Maintenance 48
Community 76
Maturity 60
Momentum 20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
86 /100 Excellent
Architecture 90
Code Quality 90
Innovation 85
Learning Curve 78

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 Backtrace type that captures the current stack and resolves symbols on demand
  • Low-level trace() and resolve() 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.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers