1# backtrace-rs 2 3[Documentation](https://docs.rs/backtrace) 4 5A library for acquiring backtraces at runtime for Rust. This library aims to 6enhance the support of the standard library by providing a programmatic 7interface to work with, but it also supports simply easily printing the current 8backtrace like libstd's panics. 9 10## Install 11 12```toml 13[dependencies] 14backtrace = "0.3" 15``` 16 17## Usage 18 19To simply capture a backtrace and defer dealing with it until a later time, 20you can use the top-level `Backtrace` type. 21 22```rust 23use backtrace::Backtrace; 24 25fn main() { 26 let bt = Backtrace::new(); 27 28 // do_some_work(); 29 30 println!("{bt:?}"); 31} 32``` 33 34If, however, you'd like more raw access to the actual tracing functionality, you 35can use the `trace` and `resolve` functions directly. 36 37```rust 38fn main() { 39 backtrace::trace(|frame| { 40 let ip = frame.ip(); 41 let symbol_address = frame.symbol_address(); 42 43 // Resolve this instruction pointer to a symbol name 44 backtrace::resolve_frame(frame, |symbol| { 45 if let Some(name) = symbol.name() { 46 // ... 47 } 48 if let Some(filename) = symbol.filename() { 49 // ... 50 } 51 }); 52 53 true // keep going to the next frame 54 }); 55} 56``` 57 58# Supported Rust Versions 59 60The `backtrace` crate is a core component of the standard library, and must 61at times keep up with the evolution of various platforms in order to serve 62the standard library's needs. This often means using recent libraries 63that provide unwinding and symbolication for various platforms. 64Thus `backtrace` is likely to use recent Rust features or depend on a library 65which itself uses them. Its minimum supported Rust version, by policy, is 66within a few versions of current stable, approximately "stable - 2". 67 68This policy takes precedence over versions written anywhere else in this repo. 69 70# License 71 72This project is licensed under either of 73 74 * Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or 75 https://www.apache.org/licenses/LICENSE-2.0) 76 * MIT license ([LICENSE-MIT](LICENSE-MIT) or 77 https://opensource.org/licenses/MIT) 78 79at your option. 80 81### Contribution 82 83Unless you explicitly state otherwise, any contribution intentionally submitted 84for inclusion in backtrace-rs by you, as defined in the Apache-2.0 license, shall be 85dual licensed as above, without any additional terms or conditions. 86