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

#7 in #stacktrace

Download history 314/week @ 2022-08-01 276/week @ 2022-08-08 431/week @ 2022-08-15 304/week @ 2022-08-22 469/week @ 2022-08-29 471/week @ 2022-09-05 163/week @ 2022-09-12 196/week @ 2022-09-19 146/week @ 2022-09-26 125/week @ 2022-10-03 127/week @ 2022-10-10 80/week @ 2022-10-17 323/week @ 2022-10-24 187/week @ 2022-10-31 350/week @ 2022-11-07 287/week @ 2022-11-14

1,152 downloads per month
Used in 3 crates (2 directly)

MIT/Apache

33KB
778 lines

rstack

Documentation

Remote stack tracing.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.


lib.rs:

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

~5MB
~106K SLoC