#backtrace #trace #printing #stack #runtime

backtrace

A library to acquire a stack trace (backtrace) at runtime in a Rust program

68 releases

0.3.56 Jan 21, 2021
0.3.55 Nov 20, 2020
0.3.54 Oct 30, 2020
0.3.50 Jul 7, 2020
0.1.4 Jul 16, 2015
Download history 212183/week @ 2020-11-07 219228/week @ 2020-11-14 214568/week @ 2020-11-21 226430/week @ 2020-11-28 221762/week @ 2020-12-05 210629/week @ 2020-12-12 147269/week @ 2020-12-19 130354/week @ 2020-12-26 216029/week @ 2021-01-02 232710/week @ 2021-01-09 217831/week @ 2021-01-16 250645/week @ 2021-01-23 256815/week @ 2021-01-30 242259/week @ 2021-02-06 239769/week @ 2021-02-13 224296/week @ 2021-02-20

876,782 downloads per month
Used in 2,914 crates (195 directly)

MIT/Apache

215KB
4.5K SLoC

backtrace-rs

Documentation

A library for acquiring backtraces at runtime for Rust. This library aims to enhance the support of the standard library by providing a programmatic interface to work with, but it also supports simply easily printing the current backtrace like libstd's panics.

Install

[dependencies]
backtrace = "0.3"

Usage

To simply capture a backtrace and defer dealing with it until a later time, you can use the top-level Backtrace type.

use backtrace::Backtrace;

fn main() {
    let bt = Backtrace::new();

    // do_some_work();

    println!("{:?}", bt);
}

If, however, you'd like more raw access to the actual tracing functionality, you can use the trace and resolve functions directly.

fn main() {
    backtrace::trace(|frame| {
        let ip = frame.ip();
        let symbol_address = frame.symbol_address();

        // Resolve this instruction pointer to a symbol name
        backtrace::resolve_frame(frame, |symbol| {
            if let Some(name) = symbol.name() {
                // ...
            }
            if let Some(filename) = symbol.filename() {
                // ...
            }
        });

        true // keep going to the next frame
    });
}

License

This project is licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in backtrace-rs by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~0–1.2MB
~26K SLoC