rstack-self 0.1.3

Stack traces of all threads of a process
Documentation

Retrieve stack traces of all threads of the process.

This is implemented using the rstack crate, which itself uses libunwind's ability to trace remote processes using ptrace. Because processes cannot ptrace themselves, we're forced to use spawn a child process which does that work.

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();
    }
}