#backtrace #trace #printing #runtime #stack

backtrace

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

75 releases

0.3.63 Nov 1, 2021
0.3.61 Jul 26, 2021
0.3.56 Jan 21, 2021
0.3.55 Nov 20, 2020
0.1.4 Jul 16, 2015
Download history 312348/week @ 2021-08-09 315712/week @ 2021-08-16 318411/week @ 2021-08-23 296107/week @ 2021-08-30 291515/week @ 2021-09-06 344319/week @ 2021-09-13 315290/week @ 2021-09-20 310893/week @ 2021-09-27 341272/week @ 2021-10-04 392547/week @ 2021-10-11 391297/week @ 2021-10-18 364506/week @ 2021-10-25 369914/week @ 2021-11-01 350683/week @ 2021-11-08 358130/week @ 2021-11-15 293928/week @ 2021-11-22

1,402,803 downloads per month
Used in 3,203 crates (254 directly)

MIT/Apache

220KB
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

~4MB
~79K SLoC