Implement ProcessMonitor::Kill for Linux
authorEd Maste <emaste@freebsd.org>
Tue, 1 Apr 2014 18:14:06 +0000 (18:14 +0000)
committerEd Maste <emaste@freebsd.org>
Tue, 1 Apr 2014 18:14:06 +0000 (18:14 +0000)
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

lldb/source/Plugins/Process/Linux/ProcessMonitor.cpp
lldb/source/Plugins/Process/Linux/ProcessMonitor.h
lldb/source/Plugins/Process/POSIX/ProcessPOSIX.cpp

index 3dec6de72476be67a54d6a5e051695b09c968e99..198a1eb595c17a17e4c8375167cdbb988b30998a 100644 (file)
@@ -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
index a087140f4077dcd2cc805053fe4cd7c830106d8d..3e289ff133797a1bfa1d191599b913d83a1087bf 100644 (file)
@@ -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);
index 571818134d44249045b7f3d1a21900ddc885f3be..47e113537146db081d3d2732b6acbe48aa63d272 100644 (file)
@@ -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;