#backtrace #trace #stack #runtime

backtrace

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

40 releases

new 0.3.26 May 25, 2019
0.3.15 Apr 3, 2019
0.3.14 Feb 19, 2019
0.3.13 Dec 14, 2018
0.1.4 Jul 16, 2015
Download history 78336/week @ 2019-02-09 82978/week @ 2019-02-16 91675/week @ 2019-02-23 90327/week @ 2019-03-02 90360/week @ 2019-03-09 85105/week @ 2019-03-16 79581/week @ 2019-03-23 98617/week @ 2019-03-30 102410/week @ 2019-04-06 94408/week @ 2019-04-13 90100/week @ 2019-04-20 88722/week @ 2019-04-27 88193/week @ 2019-05-04 117667/week @ 2019-05-11 135772/week @ 2019-05-18

401,487 downloads per month
Used in 2,237 crates (71 directly)

MIT/Apache

293KB
7K SLoC

Rust 3K SLoC // 0.3% comments C 2.5K SLoC // 0.2% comments Shell 1.5K SLoC // 0.1% comments

backtrace-rs

Build Status

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"

Note that this crate requires cc and ar to be present on Unix systems when libbacktrace is used (which is the default). For configuring C compilers see the cc crate documentation.

Usage

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

extern crate backtrace;

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.

extern crate backtrace;

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

~1.5MB
~24K SLoC