#backtrace #stack #overflow #stackoverflow #thread

backtrace-on-stack-overflow

Best effort backtrace printing

4 releases (2 breaking)

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

#291 in Concurrency

Download history 23/week @ 2022-10-06 15/week @ 2022-10-13 9/week @ 2022-10-20 20/week @ 2022-10-27 28/week @ 2022-11-03 21/week @ 2022-11-10 43/week @ 2022-11-17 54/week @ 2022-11-24 47/week @ 2022-12-01 25/week @ 2022-12-08 20/week @ 2022-12-15 19/week @ 2022-12-22 267/week @ 2022-12-29 445/week @ 2023-01-05 128/week @ 2023-01-12 112/week @ 2023-01-19

954 downloads per month
Used in 8 crates (2 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

~5MB
~109K SLoC