#[cfg(feature = "unwind")]
fn get_backtrace(pid: remoteprocess::Pid) -> Result<(), remoteprocess::Error> {
let process = remoteprocess::Process::new(pid)?;
println!("children {:#?}", process.child_processes()?);
let unwinder = process.unwinder()?;
let symbolicator = process.symbolicator()?;
for thread in process.threads()?.iter() {
println!(
"Thread {} - {}",
thread.id()?,
if thread.active()? { "running" } else { "idle" }
);
let _lock = thread.lock()?;
for ip in unwinder.cursor(&thread)? {
let ip = ip?;
symbolicator.symbolicate(ip, true, &mut |sf| {
println!("\t{}", sf);
})?;
}
}
Ok(())
}
#[cfg(feature = "unwind")]
fn main() {
env_logger::init();
let args: Vec<String> = std::env::args().collect();
let pid = if args.len() > 1 {
args[1].parse().expect("invalid pid")
} else {
std::process::id()
};
if let Err(e) = get_backtrace(pid as remoteprocess::Pid) {
println!("Failed to get backtrace {:?}", e);
}
}
#[cfg(not(feature = "unwind"))]
fn main() {
panic!("unwind not supported!");
}