[][src]Crate rstack_self

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

Structs

Error

The error type returned by methods in this crate.

Frame

Information about a stack frame.

Symbol

Information about a symbol.

Thread

Information about a thread.

Trace

A trace of the threads in a process.

TraceOptions

Options controlling tracing.

Functions

child

The function called by the process spawned by a call to trace.

trace

A convenience wrapper over TraceOptions which uses default options.

Type Definitions

Result

The result type returned by methods in this crate.