Author: jingham
Date: Fri Mar 28 15:00:07 2014
New Revision: 205043

URL: http://llvm.org/viewvc/llvm-project?rev=205043&view=rev
Log:
Wait for the reply from the 'D' detach packet before tearing down the debugger. 
 Avoids a race
condition where we could end up killing debugserver (and thus the target) 
before it had a chance
to detach.
Also fix debugserver to send the OK AFTER it detaches to avoid the same race 
condition.

<rdar://problem/16202713>

Modified:
    
lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
    lldb/trunk/tools/debugserver/source/RNBRemote.cpp

Modified: 
lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp?rev=205043&r1=205042&r2=205043&view=diff
==============================================================================
--- 
lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp 
(original)
+++ 
lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp 
Fri Mar 28 15:00:07 2014
@@ -1756,14 +1756,16 @@ GDBRemoteCommunicationClient::Detach (bo
         }
         else
         {
-            PacketResult packet_result = SendPacket ("D1", 2);
+            StringExtractorGDBRemote response;
+            PacketResult packet_result = SendPacketAndWaitForResponse ("D1", 
1, response, false);
             if (packet_result != PacketResult::Success)
                 error.SetErrorString ("Sending extended disconnect packet 
failed.");
         }
     }
     else
     {
-        PacketResult packet_result = SendPacket ("D", 1);
+        StringExtractorGDBRemote response;
+        PacketResult packet_result = SendPacketAndWaitForResponse ("D", 1, 
response, false);
         if (packet_result != PacketResult::Success)
             error.SetErrorString ("Sending disconnect packet failed.");
     }

Modified: lldb/trunk/tools/debugserver/source/RNBRemote.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/RNBRemote.cpp?rev=205043&r1=205042&r2=205043&view=diff
==============================================================================
--- lldb/trunk/tools/debugserver/source/RNBRemote.cpp (original)
+++ lldb/trunk/tools/debugserver/source/RNBRemote.cpp Fri Mar 28 15:00:07 2014
@@ -3605,9 +3605,17 @@ RNBRemote::HandlePacket_C (const char *p
 rnb_err_t
 RNBRemote::HandlePacket_D (const char *p)
 {
-    SendPacket ("OK");
     if (m_ctx.HasValidProcessID())
-        DNBProcessDetach(m_ctx.ProcessID());
+    {
+        if (DNBProcessDetach(m_ctx.ProcessID()))
+            SendPacket ("OK");
+        else
+            SendPacket ("E");
+    }
+    else
+    {
+        SendPacket ("E");
+    }
     return rnb_success;
 }
 


_______________________________________________
lldb-commits mailing list
lldb-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits

Reply via email to