MCPcopy Index your code
hub / github.com/benfred/remoteprocess

github.com/benfred/remoteprocess @v0.5.2

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.5.2 ↗ · + Follow
500 symbols 724 edges 20 files 13 documented · 3%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

remoteprocess

Build Status FreeBSD Build Status

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:

  • Suspending the execution of the process
  • Getting the process executable name and current working directory
  • Get the command line of the process
  • Listing all the threads in the process
  • Get all the child processes of the process
  • Figure out if a thread is active or not
  • Read memory from the other processes (using read_proceses_memory crate)

By enabling the unwind feature you can also:

  • Get a stack trace for a thread in the target process
  • Resolve symbols for an address in the other process

This crate provides implementations for Linux, OSX, FreeBSD and Windows

Usage

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.

Limitations

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

Credits

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.

Extension points exported contracts — how you extend this code

ProcessMemory (Interface)
(no doc) [5 implementers]
src/lib.rs

Core symbols most depended-on inside this repo

threads
called by 9
src/freebsd/mod.rs
active
called by 9
src/freebsd/mod.rs
as_mut_ptr
called by 8
src/freebsd/kinfo_proc.rs
clone
called by 8
src/freebsd/kinfo_proc.rs
trace_perl_program
called by 6
src/freebsd/mod.rs
as_ptr
called by 6
src/freebsd/kinfo_proc.rs
lock
called by 5
src/freebsd/mod.rs
register
called by 5
src/linux/libunwind/mod.rs

Shape

Class 249
Function 132
Method 115
Enum 3
Interface 1

Languages

Rust100%

Modules by API surface

src/freebsd/kinfo_proc.rs156 symbols
src/linux/libunwind/bindings_aarch64.rs109 symbols
src/linux/libunwind/bindings_arm.rs33 symbols
src/linux/mod.rs26 symbols
src/linux/libunwind/bindings_x86_64.rs23 symbols
src/freebsd/mod.rs23 symbols
src/osx/mod.rs22 symbols
src/windows/mod.rs20 symbols
src/linux/libunwind/mod.rs17 symbols
src/lib.rs16 symbols
src/windows/unwinder.rs11 symbols
src/windows/symbolication.rs11 symbols

For agents

$ claude mcp add remoteprocess \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact