6 releases

0.3.0 Oct 13, 2019
0.2.0 Jan 28, 2019
0.1.3 Aug 22, 2018
0.1.1 Jul 10, 2018
0.1.0 Nov 22, 2017

#48 in #backtrace

Download history 3428/week @ 2023-12-20 2444/week @ 2023-12-27 5111/week @ 2024-01-03 4713/week @ 2024-01-10 5291/week @ 2024-01-17 5879/week @ 2024-01-24 5815/week @ 2024-01-31 5809/week @ 2024-02-07 6914/week @ 2024-02-14 5810/week @ 2024-02-21 5316/week @ 2024-02-28 5796/week @ 2024-03-06 6202/week @ 2024-03-13 5642/week @ 2024-03-20 4447/week @ 2024-03-27 4723/week @ 2024-04-03

22,241 downloads per month

MIT/Apache

34KB
778 lines

Retrieve stack traces of all threads of the process.

This is implemented using the rstack crate, which itself uses ptrace to unwind the threads of the process. Because processes cannot ptrace themselves, we're forced to use spawn a child process which does that work. Multiple unwinding implementations are supported via Cargo features:

By default, the libunwind backend is used. You can switch to libdw via Cargo:

[dependencies]
rstack-self = { version = "0.1", features = ["dw"], default-features = false }

Example

extern crate rstack_self;

use std::env;
use std::process::Command;
use std::thread;

fn main() {
    if env::args_os().count() > 1 {
        let _ = rstack_self::child();
        return;
    }

    // spawn a second thread just for fun
    thread::spawn(background_thread);

    let exe = env::current_exe().unwrap();
    let trace = rstack_self::trace(Command::new(exe).arg("child")).unwrap();

    println!("{:#?}", trace);
}

fn background_thread() {
    loop {
        thread::park();
    }
}

Dependencies

~3–5MB
~102K SLoC