/
/
Code that runs only
for
parent
fn run_parent(pid: Pid, breakpoints: &[u64]) {
let mut saved_values
=
HashMap::new();
/
/
Placing breakpoints
wait().unwrap();
for
addr
in
breakpoints.
iter
() {
let orig
=
set_breakpoint(pid,
*
addr);
saved_values.insert(
*
addr, orig);
}
ptrace::cont(pid,
None
).expect(
"Failed continue process"
);
loop {
match wait() {
Ok(status)
=
> {
match status {
WaitStatus::Stopped(pid_t, sig_num)
=
> {
match sig_num {
Signal::SIGTRAP
=
> {
handle_sigstop(pid_t, &saved_values);
}
Signal::SIGSEGV
=
> {
let regs
=
ptrace::getregs(pid_t).unwrap();
println!(
"Segmentation fault at 0x{:x}"
, regs.rip);
break
}
_
=
> {
println!(
"Some other signal - {}"
, sig_num);
break
}
}
},
WaitStatus::Exited(pid, exit_status)
=
> {
println!(
"Process with pid: {} exited with status {}"
,
pid, exit_status);
break
;
},
_
=
> {
println!(
"Received status: {:?}"
, status);
ptrace::cont(pid,
None
).expect(
"Failed to deliver signal"
);
}
}
}
Err(err)
=
> {
println!(
"Some kind of error - {:?}"
,err);
},
}
}
}