[Lldb-commits] [PATCH] Fix debuggee termination from ProcessPOSIX::DoDestroy
Ed Maste
emaste at freebsd.org
Mon Mar 24 10:06:42 PDT 2014
Hi tfiala,
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. BringProcessIntoLimbo already provided this functionality, so rename the function to Kill.
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 BringProcessIntoLimbo behaviour is not used by LLDB anyway, rename the function to Kill, and change the Linux implementation to simply call kill() instead of using ptrace.
This fixes quitting LLDB while stopped at a breakpoint in the debuggee. Previously the debuggee remained stopped in ptrace (with the signal either pending or lost). After a timeout of a second or two LLDB exited, which caused the debuggee to resume and dump core from an unhandled SIGTRAP.
llvm.org/pr18894
http://llvm-reviews.chandlerc.com/D3159
Files:
source/Plugins/Process/FreeBSD/ProcessMonitor.cpp
source/Plugins/Process/FreeBSD/ProcessMonitor.h
source/Plugins/Process/Linux/ProcessMonitor.cpp
source/Plugins/Process/Linux/ProcessMonitor.h
source/Plugins/Process/POSIX/ProcessPOSIX.cpp
Index: source/Plugins/Process/FreeBSD/ProcessMonitor.cpp
===================================================================
--- source/Plugins/Process/FreeBSD/ProcessMonitor.cpp
+++ source/Plugins/Process/FreeBSD/ProcessMonitor.cpp
@@ -702,7 +702,7 @@
//------------------------------------------------------------------------------
/// @class KillOperation
-/// @brief Implements ProcessMonitor::BringProcessIntoLimbo.
+/// @brief Implements ProcessMonitor::Kill.
class KillOperation : public Operation
{
public:
@@ -1648,7 +1648,7 @@
}
bool
-ProcessMonitor::BringProcessIntoLimbo()
+ProcessMonitor::Kill()
{
bool result;
KillOperation op(result);
Index: source/Plugins/Process/FreeBSD/ProcessMonitor.h
===================================================================
--- source/Plugins/Process/FreeBSD/ProcessMonitor.h
+++ source/Plugins/Process/FreeBSD/ProcessMonitor.h
@@ -194,11 +194,9 @@
bool
SingleStep(lldb::tid_t unused, 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: source/Plugins/Process/Linux/ProcessMonitor.cpp
===================================================================
--- source/Plugins/Process/Linux/ProcessMonitor.cpp
+++ source/Plugins/Process/Linux/ProcessMonitor.cpp
@@ -904,31 +904,6 @@
}
//------------------------------------------------------------------------------
-/// @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.
class DetachOperation : public Operation
@@ -2229,12 +2204,9 @@
}
bool
-ProcessMonitor::BringProcessIntoLimbo()
+ProcessMonitor::Kill
{
- bool result;
- KillOperation op(result);
- DoOperation(&op);
- return result;
+ return kill(m_monitor->GetPID(), SIGKILL) == 0;
}
bool
Index: source/Plugins/Process/Linux/ProcessMonitor.h
===================================================================
--- source/Plugins/Process/Linux/ProcessMonitor.h
+++ source/Plugins/Process/Linux/ProcessMonitor.h
@@ -172,11 +172,9 @@
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: source/Plugins/Process/POSIX/ProcessPOSIX.cpp
===================================================================
--- source/Plugins/Process/POSIX/ProcessPOSIX.cpp
+++ source/Plugins/Process/POSIX/ProcessPOSIX.cpp
@@ -337,11 +337,9 @@
if (!HasExited())
{
- // Drive the exit event to completion (do not keep the inferior in
- // limbo).
+ assert (m_monitor);
m_exit_now = true;
-
- if ((m_monitor == NULL || kill(m_monitor->GetPID(), SIGKILL)) && error.Success())
+ if (m_monitor->Kill())
{
error.SetErrorToErrno();
return error;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D3159.1.patch
Type: text/x-patch
Size: 3892 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20140324/b54263e6/attachment.bin>
More information about the lldb-commits
mailing list