Inspecting registers in step-by-step

This commit is contained in:
Elnath 2025-04-18 19:22:20 +02:00
parent 775d909585
commit fa83367ebf
1 changed files with 7 additions and 3 deletions

View File

@ -4,6 +4,7 @@ use nix::sys::ptrace::*;
use nix::sys::wait::waitpid;
use nix::unistd::{ForkResult, fork};
use std::ffi::CString;
use std::io;
use std::process::ExitCode;
fn main() -> ExitCode {
@ -13,8 +14,8 @@ fn main() -> ExitCode {
Ok(ForkResult::Child) => child::starti(child_exec_path),
Ok(ForkResult::Parent { child: child_pid }) => {
println!("✔️ Started child {child_pid}");
println!("⚙️ Waiting for child signals...");
let mut before_instruction = 0;
loop {
use nix::sys::signal::Signal::*;
use nix::sys::wait::WaitStatus::*;
@ -36,8 +37,11 @@ fn main() -> ExitCode {
s => println!("💡 Child received signal {s:?}"),
},
Stopped(_pid, _signal) => {
println!("⚙️ Single-stepping child");
step(child_pid, None).unwrap()
let regs = getregs(child_pid).unwrap();
println!("🔎 [{}] rip= 0x{:016X}, rax = 0x{rax:X} ({rax})", before_instruction, regs.rip, rax = regs.rax);
io::stdin().read_line(&mut String::new()).unwrap();
before_instruction += 1;
step(child_pid, None).unwrap();
}
status => {
println!("⚠️ Other (unexpected) wait status: {status:?}");