yaxpeax_core/
debug.rs

1pub mod gdb_remote;
2
3pub enum RunResult {
4    Ok,
5    HitBreakCondition,
6    ExecutionError(String)
7}
8
9pub trait Peek {
10    fn read_bytes<A: yaxpeax_arch::Address, W: std::io::Write>(&self, addr: A, len: u64, buf: &mut W) -> Option<()>;
11    // TODO: actual failure modes more precise than None
12    fn read<A: yaxpeax_arch::Address>(&self, addr: A) -> Option<u8> {
13        let mut buf = [0u8; 1];
14        if self.read_bytes(addr, buf.len() as u64, &mut &mut buf[..]).is_none() {
15            return None;
16        } else {
17            return Some(buf[0]);
18        }
19    }
20    fn read16<A: yaxpeax_arch::Address>(&self, addr: A) -> Option<[u8; 2]> {
21        let mut buf = [0u8; 2];
22        if self.read_bytes(addr, buf.len() as u64, &mut &mut buf[..]).is_none() {
23            return None;
24        } else {
25            return Some(buf);
26        }
27    }
28    fn read32<A: yaxpeax_arch::Address>(&self, addr: A) -> Option<[u8; 4]> {
29        let mut buf = [0u8; 4];
30        if self.read_bytes(addr, buf.len() as u64, &mut &mut buf[..]).is_none() {
31            return None;
32        } else {
33            return Some(buf);
34        }
35    }
36    fn read64<A: yaxpeax_arch::Address>(&self, addr: A) -> Option<[u8; 8]> {
37        let mut buf = [0u8; 8];
38        if self.read_bytes(addr, buf.len() as u64, &mut &mut buf[..]).is_none() {
39            return None;
40        } else {
41            return Some(buf);
42        }
43    }
44}
45
46pub trait DebugTarget<'a, Target> {
47    type WatchTarget;
48    type BreakCondition;
49    fn attach(_: &'a mut Target) -> Self;
50    fn single_step(&mut self) -> Result<(), String>;
51    fn run(&mut self) -> RunResult;
52    fn add_watch(&mut self, _: Self::WatchTarget) -> Result<(), String>;
53    fn add_break_condition(&mut self, _: Self::BreakCondition) -> Result<(), String>;
54}
55
56pub trait DBTarget2<Target> {
57    type WatchTarget;
58    type BreakCondition;
59    fn attach(_: Target) -> Self;
60    fn detach(self) -> Target;
61    fn single_step(&mut self) -> Result<(), String>;
62    fn run(&mut self) -> RunResult;
63    fn add_watch(&mut self, _: Self::WatchTarget) -> Result<(), String>;
64    fn add_break_condition(&mut self, _: Self::BreakCondition) -> Result<(), String>;
65}