From 4e0999bc22656eb8e46775114a174ba4388e8ee6 Mon Sep 17 00:00:00 2001 From: Ed Maste Date: Tue, 1 Apr 2014 18:14:06 +0000 Subject: [PATCH] Implement ProcessMonitor::Kill for Linux On FreeBSD ptrace(PT_KILL) is used to terminate the traced process (as if PT_CONTINUE had been used with SIGKILL as the signal to be delivered), and is the desired behaviour for ProcessPOSIX::DoDestroy. On Linux, after ptrace(PTRACE_KILL) the traced process still exists and can be interrogated. It is only upon resume that it exits as though it received SIGKILL. As the Linux PTRACE_KILL behaviour is not used by LLDB, rename BringProcessIntoLimbo to Kill, and change the implementation to simply call kill() instead of using ptrace. Thanks to Todd F for testing (Ubuntu 12.04, gcc 4.8.2). Sponsored by: DARPA, AFRL Differential Revision: http://llvm-reviews.chandlerc.com/D3159 llvm-svn: 205337 --- .../Plugins/Process/Linux/ProcessMonitor.cpp | 32 ++----------------- .../Plugins/Process/Linux/ProcessMonitor.h | 6 ++-- .../Plugins/Process/POSIX/ProcessPOSIX.cpp | 4 --- 3 files changed, 4 insertions(+), 38 deletions(-) diff --git a/lldb/source/Plugins/Process/Linux/ProcessMonitor.cpp b/lldb/source/Plugins/Process/Linux/ProcessMonitor.cpp index 3dec6de72476..198a1eb595c1 100644 --- a/lldb/source/Plugins/Process/Linux/ProcessMonitor.cpp +++ b/lldb/source/Plugins/Process/Linux/ProcessMonitor.cpp @@ -903,31 +903,6 @@ EventMessageOperation::Execute(ProcessMonitor *monitor) m_result = true; } -//------------------------------------------------------------------------------ -/// @class KillOperation -/// @brief Implements ProcessMonitor::BringProcessIntoLimbo. -class KillOperation : public Operation -{ -public: - KillOperation(bool &result) : m_result(result) { } - - void Execute(ProcessMonitor *monitor); - -private: - bool &m_result; -}; - -void -KillOperation::Execute(ProcessMonitor *monitor) -{ - lldb::pid_t pid = monitor->GetPID(); - - if (PTRACE(PTRACE_KILL, pid, NULL, NULL, 0)) - m_result = false; - else - m_result = true; -} - //------------------------------------------------------------------------------ /// @class DetachOperation /// @brief Implements ProcessMonitor::Detach. @@ -2229,12 +2204,9 @@ ProcessMonitor::SingleStep(lldb::tid_t tid, uint32_t signo) } bool -ProcessMonitor::BringProcessIntoLimbo() +ProcessMonitor::Kill() { - bool result; - KillOperation op(result); - DoOperation(&op); - return result; + return kill(GetPID(), SIGKILL) == 0; } bool diff --git a/lldb/source/Plugins/Process/Linux/ProcessMonitor.h b/lldb/source/Plugins/Process/Linux/ProcessMonitor.h index a087140f4077..3e289ff13379 100644 --- a/lldb/source/Plugins/Process/Linux/ProcessMonitor.h +++ b/lldb/source/Plugins/Process/Linux/ProcessMonitor.h @@ -172,11 +172,9 @@ public: bool SingleStep(lldb::tid_t tid, uint32_t signo); - /// Sends the inferior process a PTRACE_KILL signal. The inferior will - /// still exists and can be interrogated. Once resumed it will exit as - /// though it received a SIGKILL. + /// Terminate the traced process. bool - BringProcessIntoLimbo(); + Kill(); lldb_private::Error Detach(lldb::tid_t tid); diff --git a/lldb/source/Plugins/Process/POSIX/ProcessPOSIX.cpp b/lldb/source/Plugins/Process/POSIX/ProcessPOSIX.cpp index 571818134d44..47e113537146 100644 --- a/lldb/source/Plugins/Process/POSIX/ProcessPOSIX.cpp +++ b/lldb/source/Plugins/Process/POSIX/ProcessPOSIX.cpp @@ -339,11 +339,7 @@ ProcessPOSIX::DoDestroy() { assert(m_monitor); m_exit_now = true; -#ifdef __linux__ - if ((m_monitor == NULL || kill(m_monitor->GetPID(), SIGKILL)) && error.Success()) -#else if (!m_monitor->Kill()) -#endif { error.SetErrorToErrno(); return error; -- 2.34.1