summaryrefslogtreecommitdiff
path: root/src/sys
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2018-02-07 16:21:27 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2018-02-07 16:21:27 +0000
commit0a128f04b8ad64069a909bfb7184428021f2c082 (patch)
tree607a94ad3cc91d5f0c7025c6487574034ef5d852 /src/sys
parent90e82ed3d1bb03921f2b4c447f1a93fa1a4b33fc (diff)
parent445b488f830d75ca173af77440a2fe7626a4e6dc (diff)
downloadnix-0a128f04b8ad64069a909bfb7184428021f2c082.zip
Merge #852
852: Add step function to ptrace r=Susurrus a=xd009642 Added step function to ptrace, this follows the same form as the PTRACE_CONTINUE by advanced the tracee by a single step! Found when I was updating to nix 0.10.0 that this function had been missed out. Minor addition as `SINGLESTEP` works the same as `CONTINUE`
Diffstat (limited to 'src/sys')
-rw-r--r--src/sys/ptrace.rs34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/sys/ptrace.rs b/src/sys/ptrace.rs
index 90c12e43..4fb4f5b5 100644
--- a/src/sys/ptrace.rs
+++ b/src/sys/ptrace.rs
@@ -280,3 +280,37 @@ pub fn cont<T: Into<Option<Signal>>>(pid: Pid, sig: T) -> Result<()> {
}
}
+/// Move the stopped tracee process forward by a single step as with
+/// `ptrace(PTRACE_SINGLESTEP, ...)`
+///
+/// Advances the execution of the process with PID `pid` by a single step optionally delivering a
+/// signal specified by `sig`.
+///
+/// # Example
+/// ```rust
+/// extern crate nix;
+/// use nix::sys::ptrace::step;
+/// use nix::unistd::Pid;
+/// use nix::sys::signal::Signal;
+/// use nix::sys::wait::*;
+/// fn main() {
+/// // If a process changes state to the stopped state because of a SIGUSR1
+/// // signal, this will step the process forward and forward the user
+/// // signal to the stopped process
+/// match waitpid(Pid::from_raw(-1), None) {
+/// Ok(WaitStatus::Stopped(pid, Signal::SIGUSR1)) => {
+/// let _ = step(pid, Signal::SIGUSR1);
+/// }
+/// _ => {},
+/// }
+/// }
+/// ```
+pub fn step<T: Into<Option<Signal>>>(pid: Pid, sig: T) -> Result<()> {
+ let data = match sig.into() {
+ Some(s) => s as i32 as *mut c_void,
+ None => ptr::null_mut(),
+ };
+ unsafe {
+ ptrace_other(Request::PTRACE_SINGLESTEP, pid, ptr::null_mut(), data).map(|_| ())
+ }
+}