Skip to content

Commit

Permalink
Merge pull request #12 from godzie44/godzie44/fix_detach
Browse files Browse the repository at this point in the history
fix: better detaching process on a debugger drop
  • Loading branch information
godzie44 authored May 3, 2024
2 parents bb549f7 + 2583564 commit d103e3e
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/debugger/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -964,15 +964,17 @@ impl Drop for Debugger {

// todo currently ok only if all threads in group stop
// continue all threads with SIGSTOP
current_tids.iter().for_each(|tid| {
sys::ptrace::cont(*tid, Signal::SIGSTOP).expect("cont debugee");
});
current_tids.iter().for_each(|tid| {
waitpid(*tid, None).expect("waiting debugee");
});
let prepare_stopped: Vec<_> = current_tids
.into_iter()
.filter(|&tid| sys::ptrace::cont(tid, Signal::SIGSTOP).is_ok())
.collect();
let stopped: Vec<_> = prepare_stopped
.into_iter()
.filter(|&tid| waitpid(tid, None).is_ok())
.collect();
// detach ptrace
current_tids.iter().for_each(|tid| {
sys::ptrace::detach(*tid, None).expect("detach debugee");
stopped.into_iter().for_each(|tid| {
sys::ptrace::detach(tid, None).expect("detach tracee");
});
// kill debugee process
signal::kill(self.debugee.tracee_ctl().proc_pid(), Signal::SIGKILL)
Expand Down

0 comments on commit d103e3e

Please sign in to comment.