#backtrace #stack #unknown #overflow

backtrace-on-stack-overflow

Best effort backtrace printing

4 releases (2 breaking)

0.3.0 Jan 24, 2023
0.2.0 Jul 1, 2022
0.1.1 Nov 4, 2020
0.1.0 Nov 4, 2020

#524 in Debugging

Download history 623/week @ 2023-10-10 578/week @ 2023-10-17 675/week @ 2023-10-24 727/week @ 2023-10-31 757/week @ 2023-11-07 686/week @ 2023-11-14 568/week @ 2023-11-21 566/week @ 2023-11-28 882/week @ 2023-12-05 1132/week @ 2023-12-12 872/week @ 2023-12-19 403/week @ 2023-12-26 300/week @ 2024-01-02 254/week @ 2024-01-09 1756/week @ 2024-01-16 4624/week @ 2024-01-23

7,087 downloads per month
Used in 11 crates (3 directly)

MIT/Apache

8KB

backtrace-on-stack-overflow

By default, Rust aborts on stackoverflow without printing a backtrace:

λ bat src/main.rs
fn main() {
    f(92)
}

fn f(x: u64) {
    f(x)
}
λ cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 0.00s
     Running `target/debug/so`

thread 'main' has overflowed its stack
fatal runtime error: stack overflow
fish: Job 1, 'cargo run' terminated by signal SIGABRT (Abort)

This crate fixes this:

λ bat src/main.rs
fn main() {
    unsafe { backtrace_on_stack_overflow::enable() };
    f(92)
}

fn f(x: u64) {
    f(x)
}
λ cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 0.01s
     Running `target/debug/so`
Stack Overflow:
   0: backtrace_on_stack_overflow::handle_sigsegv
             at /home/matklad/p/backtrace-on-stack-overflow/src/lib.rs:33:40
   1: <unknown>
   2: so::f
             at src/main.rs:6
   3: so::f
             at src/main.rs:7:5
   4: so::f
             at src/main.rs:7:5
   5: so::f
             at src/main.rs:7:5
   6: so::f
             at src/main.rs:7:5
   7: so::f
             at src/main.rs:7:5
   8: so::f
             at src/main.rs:7:5
   9: so::f
             at src/main.rs:7:5
  10: so::f
             at src/main.rs:7:5

This crate works for debugging, but is unsuited for being enabled in production.

Dependencies

~1.6–2.4MB
~51K SLoC