Inspecting registers in step-by-step
This commit is contained in:
parent
775d909585
commit
fa83367ebf
10
src/main.rs
10
src/main.rs
|
|
@ -4,6 +4,7 @@ use nix::sys::ptrace::*;
|
||||||
use nix::sys::wait::waitpid;
|
use nix::sys::wait::waitpid;
|
||||||
use nix::unistd::{ForkResult, fork};
|
use nix::unistd::{ForkResult, fork};
|
||||||
use std::ffi::CString;
|
use std::ffi::CString;
|
||||||
|
use std::io;
|
||||||
use std::process::ExitCode;
|
use std::process::ExitCode;
|
||||||
|
|
||||||
fn main() -> ExitCode {
|
fn main() -> ExitCode {
|
||||||
|
|
@ -13,8 +14,8 @@ fn main() -> ExitCode {
|
||||||
Ok(ForkResult::Child) => child::starti(child_exec_path),
|
Ok(ForkResult::Child) => child::starti(child_exec_path),
|
||||||
Ok(ForkResult::Parent { child: child_pid }) => {
|
Ok(ForkResult::Parent { child: child_pid }) => {
|
||||||
println!("✔️ Started child {child_pid}");
|
println!("✔️ Started child {child_pid}");
|
||||||
println!("⚙️ Waiting for child signals...");
|
|
||||||
|
|
||||||
|
let mut before_instruction = 0;
|
||||||
loop {
|
loop {
|
||||||
use nix::sys::signal::Signal::*;
|
use nix::sys::signal::Signal::*;
|
||||||
use nix::sys::wait::WaitStatus::*;
|
use nix::sys::wait::WaitStatus::*;
|
||||||
|
|
@ -36,8 +37,11 @@ fn main() -> ExitCode {
|
||||||
s => println!("💡 Child received signal {s:?}"),
|
s => println!("💡 Child received signal {s:?}"),
|
||||||
},
|
},
|
||||||
Stopped(_pid, _signal) => {
|
Stopped(_pid, _signal) => {
|
||||||
println!("⚙️ Single-stepping child");
|
let regs = getregs(child_pid).unwrap();
|
||||||
step(child_pid, None).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 => {
|
status => {
|
||||||
println!("⚠️ Other (unexpected) wait status: {status:?}");
|
println!("⚠️ Other (unexpected) wait status: {status:?}");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue