Crates.io | remoteprocess |
lib.rs | remoteprocess |
version | 0.5.0 |
source | src |
created_at | 2019-07-07 22:49:47.117168 |
updated_at | 2024-10-28 19:52:38.176136 |
description | cross platform api for getting information on a running processes |
homepage | https://github.com/benfred/remoteprocess |
repository | https://github.com/benfred/remoteprocess |
max_upload_size | |
id | 147435 |
size | 331,431 |
This crate provides a cross platform way of querying information about other processes running on the system. This let's you build profiling and debugging tools.
Features:
By enabling the unwind feature you can also:
This crate provides implementations for Linux, OSX, FreeBSD and Windows
To show a stack trace from each thread in a program
fn get_backtrace(pid: remoteprocess::Pid) -> Result<(), remoteprocess::Error> {
// Create a new handle to the process
let process = remoteprocess::Process::new(pid)?;
// lock the process to get a consistent snapshot. Unwinding will fail otherwise
let _lock = process.lock()?;
// Create a stack unwind object, and use it to get the stack for each thread
let unwinder = process.unwinder()?;
for thread in process.threads()?.iter() {
println!("Thread {}", thread);
// Iterate over the callstack for the current thread
for ip in unwinder.cursor(thread)? {
let ip = ip?;
// Lookup the current stack frame containing a filename/function/linenumber etc
// for the current address
unwinder.symbolicate(ip, &mut |sf| {
println!("{}", sf);
})?;
}
}
Ok(())
}
A complete program with this code can be found in the examples folder.
Currently we only have implementations for getting stack traces on some platforms:
Linux | Windows | OSX | FreeBSD | |
---|---|---|---|---|
i686 | ||||
x86-64 | yes | yes | ||
ARM | yes | |||
Aarch64 | yes |
This crate heavily relies on the gimli project. Gimli is an amazing tool for parsing DWARF debugging information, and we are using it here for looking up filename and line numbers given an instruction pointer.