[Lldb-commits] [lldb] r118018 - in /lldb/trunk: source/Commands/CommandObjectProcess.cpp tools/debugserver/source/MacOSX/MachProcess.cpp tools/debugserver/source/MacOSX/MachProcess.h

Caroline Tice ctice at apple.com
Tue Nov 2 09:16:53 PDT 2010


Author: ctice
Date: Tue Nov  2 11:16:53 2010
New Revision: 118018

URL: http://llvm.org/viewvc/llvm-project?rev=118018&view=rev
Log:
Fix problem where "process detach" was not working properly.  The
ptrace thread update that was replying to the SIGSTOP was also causing the
process to not really be sigstop'd any more so then the call to ptrace
detach was failing, and when debugserver exited the attached process
was being killed.  Now the ptrace thread update does not disturb the sigstop
state of the thread, so the detach works properly.


Modified:
    lldb/trunk/source/Commands/CommandObjectProcess.cpp
    lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.cpp
    lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.h

Modified: lldb/trunk/source/Commands/CommandObjectProcess.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectProcess.cpp?rev=118018&r1=118017&r2=118018&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectProcess.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectProcess.cpp Tue Nov  2 11:16:53 2010
@@ -836,6 +836,7 @@
             return false;
         }
 
+        result.AppendMessageWithFormat ("Detaching from process %i\n", process->GetID());
         Error error (process->Detach());
         if (error.Success())
         {

Modified: lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.cpp?rev=118018&r1=118017&r2=118018&view=diff
==============================================================================
--- lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.cpp (original)
+++ lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.cpp Tue Nov  2 11:16:53 2010
@@ -359,7 +359,7 @@
 }
 
 nub_state_t
-MachProcess::DoSIGSTOP (bool clear_bps_and_wps)
+MachProcess::DoSIGSTOP (bool clear_bps_and_wps, uint32_t *thread_idx_ptr)
 {
     nub_state_t state = GetState();
     DNBLogThreadedIf(LOG_PROCESS, "MachProcess::DoSIGSTOP() state = %s", DNBStateAsString (state));
@@ -375,7 +375,10 @@
 
         // If we already have a thread stopped due to a SIGSTOP, we don't have
         // to do anything...
-        if (m_thread_list.GetThreadIndexForThreadStoppedWithSignal (SIGSTOP) != UINT32_MAX)
+        uint32_t thread_idx = m_thread_list.GetThreadIndexForThreadStoppedWithSignal (SIGSTOP);
+        if (thread_idx_ptr)
+            *thread_idx_ptr = thread_idx;
+        if (thread_idx != UINT32_MAX)
             return GetState();
 
         // No threads were stopped with a SIGSTOP, we need to run and halt the
@@ -401,6 +404,9 @@
         DisableAllWatchpoints (true);
         clear_bps_and_wps = false;
     }
+    uint32_t thread_idx = m_thread_list.GetThreadIndexForThreadStoppedWithSignal (SIGSTOP);
+    if (thread_idx_ptr)
+        *thread_idx_ptr = thread_idx;
     return GetState();
 }
 
@@ -409,11 +415,22 @@
 {
     DNBLogThreadedIf(LOG_PROCESS, "MachProcess::Detach()");
 
-    nub_state_t state = DoSIGSTOP(true);
+    uint32_t thread_idx = UINT32_MAX;
+    nub_state_t state = DoSIGSTOP(true, &thread_idx);
     DNBLogThreadedIf(LOG_PROCESS, "MachProcess::Detach() DoSIGSTOP() returned %s", DNBStateAsString(state));
 
     {
-        DNBThreadResumeActions thread_actions (eStateRunning, 0);
+        DNBThreadResumeActions thread_actions;
+        DNBThreadResumeAction thread_action;
+        thread_action.tid = m_thread_list.ThreadIDAtIndex (thread_idx);
+        thread_action.state = eStateRunning;
+        thread_action.signal = -1;
+        thread_action.addr = INVALID_NUB_ADDRESS;
+        
+        thread_actions.Append (thread_action);
+        
+        thread_actions.SetDefaultThreadActionIfNeeded (eStateRunning, 0);
+        
         PTHREAD_MUTEX_LOCKER (locker, m_exception_messages_mutex);
 
         ReplyToAllExceptions (thread_actions);
@@ -425,9 +442,9 @@
     // Detach from our process
     errno = 0;
     nub_process_t pid = m_pid;
-    ::ptrace (PT_DETACH, pid, (caddr_t)1, 0);
+    int ret = ::ptrace (PT_DETACH, pid, (caddr_t)1, 0);
     DNBError err(errno, DNBError::POSIX);
-    if (DNBLogCheckLogBit(LOG_PROCESS) || err.Fail())
+    if (DNBLogCheckLogBit(LOG_PROCESS) || err.Fail() || (ret != 0))
         err.LogThreaded("::ptrace (PT_DETACH, %u, (caddr_t)1, 0)", pid);
 
     // Resume our task
@@ -1546,7 +1563,7 @@
 
             SetState (eStateAttaching);
             errno = 0;
-            int err = ptrace (PT_ATTACHEXC, m_pid, 0, 0);
+            int err = ::ptrace (PT_ATTACHEXC, m_pid, 0, 0);
             if (err == 0)
             {
                 m_flags |= eMachProcessFlagsAttached;
@@ -1802,7 +1819,7 @@
 
         StartSTDIOThread();
         SetState (eStateAttaching);
-        int err = ptrace (PT_ATTACHEXC, m_pid, 0, 0);
+        int err = ::ptrace (PT_ATTACHEXC, m_pid, 0, 0);
         if (err == 0)
         {
             m_flags |= eMachProcessFlagsAttached;

Modified: lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.h?rev=118018&r1=118017&r2=118018&view=diff
==============================================================================
--- lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.h (original)
+++ lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.h Tue Nov  2 11:16:53 2010
@@ -224,7 +224,7 @@
     nub_size_t              RemoveTrapsFromBuffer (nub_addr_t addr, nub_size_t size, uint8_t *buf) const;
 
     uint32_t                Flags () const { return m_flags; }
-    nub_state_t             DoSIGSTOP (bool clear_bps_and_wps);
+    nub_state_t             DoSIGSTOP (bool clear_bps_and_wps, uint32_t *thread_idx_ptr = NULL);
 
     pid_t                       m_pid;                      // Process ID of child process
     int                         m_child_stdin;





More information about the lldb-commits mailing list