1 //! Enable or disable catching syscalls from the inferior process. 2 3 use crate::arch::Arch; 4 use crate::target::{Target, TargetResult}; 5 6 /// Target Extension - Enable and disable catching syscalls from the inferior 7 /// process. 8 /// 9 /// Implementing this extension allows the target to support the `catch syscall` 10 /// GDB client command. See [GDB documentation](https://sourceware.org/gdb/onlinedocs/gdb/Set-Catchpoints.html) 11 /// for further details. 12 pub trait CatchSyscalls: Target { 13 /// Enables catching syscalls from the inferior process. 14 /// 15 /// If `filter` is `None`, then all syscalls should be reported to GDB. If a 16 /// filter is provided, only the syscalls listed in the filter should be 17 /// reported to GDB. 18 /// 19 /// Note: filters are not combined, subsequent calls this method should 20 /// replace any existing syscall filtering. enable_catch_syscalls( &mut self, filter: Option<SyscallNumbers<'_, <Self::Arch as Arch>::Usize>>, ) -> TargetResult<(), Self>21 fn enable_catch_syscalls( 22 &mut self, 23 filter: Option<SyscallNumbers<'_, <Self::Arch as Arch>::Usize>>, 24 ) -> TargetResult<(), Self>; 25 26 /// Disables catching syscalls from the inferior process. disable_catch_syscalls(&mut self) -> TargetResult<(), Self>27 fn disable_catch_syscalls(&mut self) -> TargetResult<(), Self>; 28 } 29 30 define_ext!(CatchSyscallsOps, CatchSyscalls); 31 32 /// Describes where the syscall catchpoint was triggered at. 33 #[derive(Clone, Copy, Debug, PartialEq, Eq)] 34 pub enum CatchSyscallPosition { 35 /// Reached the entry location of the syscall. 36 Entry, 37 /// Reached the return location of the syscall. 38 Return, 39 } 40 41 /// Iterator of syscall numbers that should be reported to GDB. 42 pub struct SyscallNumbers<'a, U> { 43 pub(crate) inner: &'a mut dyn Iterator<Item = U>, 44 } 45 46 impl<U> Iterator for SyscallNumbers<'_, U> { 47 type Item = U; 48 next(&mut self) -> Option<Self::Item>49 fn next(&mut self) -> Option<Self::Item> { 50 self.inner.next() 51 } 52 } 53