Skip to content

Commit

Permalink
Move threads to LinuxTarget only
Browse files Browse the repository at this point in the history
That is the only place it's being used.
  • Loading branch information
fabiim committed Jul 26, 2020
1 parent dc4d549 commit da9e791
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 23 deletions.
36 changes: 18 additions & 18 deletions src/target/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,24 +46,6 @@ impl UnixTarget for LinuxTarget {
fn pid(&self) -> Pid {
self.pid
}

/// Returns the current snapshot view of this debugee process threads
fn threads(
&self,
) -> Result<Vec<Box<dyn Thread<ThreadId = usize>>>, Box<dyn std::error::Error>> {
let tasks: Vec<_> = Process::new(self.pid.as_raw())?
.tasks()?
.flatten()
.collect();

let mut result: Vec<Box<dyn Thread<ThreadId = usize>>> = vec![];
for task in tasks {
let t_stat = task.stat()?;
let thread = LinuxThread::new(&t_stat.comm, task.tid as usize);
result.push(Box::new(thread))
}
Ok(result)
}
}

impl LinuxTarget {
Expand Down Expand Up @@ -93,6 +75,24 @@ impl LinuxTarget {
pub fn read_regs(&self) -> Result<libc::user_regs_struct, Box<dyn std::error::Error>> {
nix::sys::ptrace::getregs(self.pid()).map_err(|err| err.into())
}

/// Returns the current snapshot view of this debugee process threads
fn threads(
&self,
) -> Result<Vec<Box<dyn Thread<ThreadId = usize>>>, Box<dyn std::error::Error>> {
let tasks: Vec<_> = Process::new(self.pid.as_raw())?
.tasks()?
.flatten()
.collect();

let mut result: Vec<Box<dyn Thread<ThreadId = usize>>> = vec![];
for task in tasks {
let t_stat = task.stat()?;
let thread = LinuxThread::new(&t_stat.comm, task.tid as usize);
result.push(Box::new(thread))
}
Ok(result)
}
}

/// A single memory read operation.
Expand Down
5 changes: 0 additions & 5 deletions src/target/unix.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use super::thread::Thread;
use nix::{
sys::ptrace,
sys::wait::waitpid,
Expand All @@ -16,10 +15,6 @@ pub trait UnixTarget {
ptrace::cont(self.pid(), None)?;
Ok(())
}

/// Returns the current snapshot view of this debugee process threads
fn threads(&self)
-> Result<Vec<Box<dyn Thread<ThreadId = usize>>>, Box<dyn std::error::Error>>;
}

/// Launch a new debuggee process.
Expand Down

0 comments on commit da9e791

Please sign in to comment.