#backtrace #trace #printing #stack #runtime

backtrace

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

48 releases

✓ Uses Rust 2018 edition

new 0.3.35 Aug 19, 2019
0.3.34 Jul 31, 2019
0.3.32 Jun 26, 2019
0.3.14 Feb 19, 2019
0.1.4 Jul 16, 2015
Download history 87541/week @ 2019-05-06 122618/week @ 2019-05-13 140864/week @ 2019-05-20 113904/week @ 2019-05-27 131159/week @ 2019-06-03 112476/week @ 2019-06-10 108969/week @ 2019-06-17 120267/week @ 2019-06-24 99682/week @ 2019-07-01 99888/week @ 2019-07-08 110787/week @ 2019-07-15 113422/week @ 2019-07-22 119720/week @ 2019-07-29 122548/week @ 2019-08-05 117157/week @ 2019-08-12

491,596 downloads per month
Used in 2,608 crates (81 directly)

MIT/Apache

169KB
3.5K SLoC

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

~2MB
~32K SLoC