From 254849621d36b1404f9b393f74f040a912bc6909 Mon Sep 17 00:00:00 2001 From: xd009642 Date: Tue, 30 Jan 2018 17:37:42 +0000 Subject: Add step function to ptrace Added step function to ptrace, this follows the same form as the PTRACE_CONTINUE by advanced the tracee by a single step! --- src/sys/ptrace.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/sys/ptrace.rs b/src/sys/ptrace.rs index 8fb8f823..22c6f487 100644 --- a/src/sys/ptrace.rs +++ b/src/sys/ptrace.rs @@ -280,3 +280,17 @@ pub fn cont>>(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 +/// single specified by `sig`. +pub fn step>>(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(|_| ()) + } +} -- cgit v1.2.3 From b218cd5e9ccb63524e9a9a687f48772b826b4907 Mon Sep 17 00:00:00 2001 From: xd009642 Date: Wed, 31 Jan 2018 20:33:31 +0000 Subject: Added example and updated changelog. Added doc test for sys::ptrace::step and also updated the changelog. --- CHANGELOG.md | 2 ++ src/sys/ptrace.rs | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index dbe6110a..ffc1b560 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,8 @@ This project adheres to [Semantic Versioning](http://semver.org/). ## [0.10.0] 2018-01-26 ### Added +- Added specialized wrapper: `sys::ptrace::step` + ([#852](https://github.com/nix-rust/nix/pull/852)) - Added `AioCb::from_ptr` and `AioCb::from_mut_ptr` ([#820](https://github.com/nix-rust/nix/pull/820)) - Added specialized wrappers: `sys::ptrace::{traceme, syscall, cont, attach}`. Using the matching routines diff --git a/src/sys/ptrace.rs b/src/sys/ptrace.rs index 22c6f487..ae371b50 100644 --- a/src/sys/ptrace.rs +++ b/src/sys/ptrace.rs @@ -285,6 +285,19 @@ pub fn cont>>(pid: Pid, sig: T) -> Result<()> { /// /// Advances the execution of the process with PID `pid` by a single step optionally delivering a /// single specified by `sig`. +/// +/// # Example +/// ```rust +/// extern crate nix; +/// use nix::sys::ptrace::step; +/// use nix::unistd::Pid; +/// use nix::sys::signal::Signal; +/// fn main() { +/// let dummy_pid = Pid::from_raw(0); +/// +/// let _ = step(dummy_pid, Some(Signal::SIGSTOP)); +/// } +/// ``` pub fn step>>(pid: Pid, sig: T) -> Result<()> { let data = match sig.into() { Some(s) => s as i32 as *mut c_void, -- cgit v1.2.3 From d0218ee3958306ef6c6a1790a0dcbb12ad615007 Mon Sep 17 00:00:00 2001 From: xd009642 Date: Thu, 1 Feb 2018 17:45:20 +0000 Subject: Corrected typo --- src/sys/ptrace.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sys/ptrace.rs b/src/sys/ptrace.rs index ae371b50..be09974d 100644 --- a/src/sys/ptrace.rs +++ b/src/sys/ptrace.rs @@ -284,7 +284,7 @@ pub fn cont>>(pid: Pid, sig: T) -> Result<()> { /// `ptrace(PTRACE_SINGLESTEP, ...)` /// /// Advances the execution of the process with PID `pid` by a single step optionally delivering a -/// single specified by `sig`. +/// signal specified by `sig`. /// /// # Example /// ```rust -- cgit v1.2.3 From 445b488f830d75ca173af77440a2fe7626a4e6dc Mon Sep 17 00:00:00 2001 From: xd009642 Date: Sat, 3 Feb 2018 11:46:03 +0000 Subject: Updated example to be more meaningful Example now matches something more akin to an actual usecase. --- src/sys/ptrace.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/sys/ptrace.rs b/src/sys/ptrace.rs index be09974d..59ceb378 100644 --- a/src/sys/ptrace.rs +++ b/src/sys/ptrace.rs @@ -292,10 +292,17 @@ pub fn cont>>(pid: Pid, sig: T) -> Result<()> { /// use nix::sys::ptrace::step; /// use nix::unistd::Pid; /// use nix::sys::signal::Signal; +/// use nix::sys::wait::*; /// fn main() { -/// let dummy_pid = Pid::from_raw(0); -/// -/// let _ = step(dummy_pid, Some(Signal::SIGSTOP)); +/// // 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>>(pid: Pid, sig: T) -> Result<()> { -- cgit v1.2.3