https://github.com/andreafioraldi/sanitizer_stacktrace_rs
A Rust crate to generate backtraces using the LLVM codebase
https://github.com/andreafioraldi/sanitizer_stacktrace_rs
Last synced: about 1 year ago
JSON representation
A Rust crate to generate backtraces using the LLVM codebase
- Host: GitHub
- URL: https://github.com/andreafioraldi/sanitizer_stacktrace_rs
- Owner: andreafioraldi
- License: apache-2.0
- Created: 2022-01-06T14:42:51.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2022-01-06T16:07:21.000Z (over 4 years ago)
- Last Synced: 2025-03-27T13:51:12.487Z (about 1 year ago)
- Language: C++
- Size: 30.3 KB
- Stars: 7
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# sanitizer_stacktrace_rs
A Rust crate to generate backtraces using the LLVM codebase
## Example
You can get a trace of raw addresses from the current context using
```rust
use sanitizer_stacktrace::*;
let mut st = Stacktrace::new();
st.unwind(STACK_TRACE_MAX);
for addr in st.trace() {
println!("{:#x}", previous_pc(*addr));
}
```
To get a symbolized trace, use `symbolize`
```rust
use sanitizer_stacktrace::*;
let mut st = Stacktrace::new();
st.unwind(STACK_TRACE_MAX);
st.symbolize(|addr, sym| {
println!(
"0x{:x}\t{}",
addr,
sym.name().map(|x| x.as_str().unwrap()).unwrap_or("")
);
});
```
You can also generate a stacktrace startign from specific values of PC and BP, like in a signal handler
```rust
pub unsafe fn signal_handler(_sig: c_int, _info: siginfo_t, ctx: *mut ucontext_t) {
let mut st = Stacktrace::new();
st.unwind_from(
STACK_TRACE_MAX,
a.uc_mcontext.gregs[REG_RIP as usize] as usize,
a.uc_mcontext.gregs[REG_RBP as usize] as usize,
con as *const c_void,
);
for addr in st.trace() {
println!("{:#x}", previous_pc(*addr));
}
std::process::exit(1);
}
```