[Lldb-commits] [lldb] r175198 - <rdar://problem/13064893>

Greg Clayton gclayton at apple.com
Thu Feb 14 11:11:23 PST 2013


Author: gclayton
Date: Thu Feb 14 13:11:23 2013
New Revision: 175198

URL: http://llvm.org/viewvc/llvm-project?rev=175198&view=rev
Log:
<rdar://problem/13064893>

Poor network connections aren't handled well; commands fail instead of retrying.


Modified:
    lldb/trunk/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.cpp
    lldb/trunk/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.h

Modified: lldb/trunk/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.cpp?rev=175198&r1=175197&r2=175198&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.cpp (original)
+++ lldb/trunk/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.cpp Thu Feb 14 13:11:23 2013
@@ -97,8 +97,7 @@ CommunicationKDP::MakeRequestPacketHeade
 
 bool
 CommunicationKDP::SendRequestAndGetReply (const CommandType command,
-                                          const uint8_t request_sequence_id,
-                                          const PacketStreamType &request_packet, 
+                                          const PacketStreamType &request_packet,
                                           DataExtractor &reply_packet)
 {
     if (IsRunning())
@@ -118,20 +117,26 @@ CommunicationKDP::SendRequestAndGetReply
     // NOTE: this only works for packets that are in native endian byte order
     assert (request_packet.GetSize() == *((uint16_t *)(request_packet.GetData() + 2)));
 #endif
-    if (SendRequestPacketNoLock(request_packet))
+    lldb::offset_t offset = 1;
+    const uint32_t num_retries = 3;
+    for (uint32_t i=0; i<num_retries; ++i)
     {
-        if (WaitForPacketWithTimeoutMicroSecondsNoLock (reply_packet, GetPacketTimeoutInMicroSeconds ()))
+        if (SendRequestPacketNoLock(request_packet))
         {
-            lldb::offset_t offset = 0;
-            const uint8_t reply_command = reply_packet.GetU8 (&offset);
-            const uint8_t reply_sequence_id = reply_packet.GetU8 (&offset);
-            if ((reply_command & eCommandTypeMask) == command)
+            const uint8_t request_sequence_id = (uint8_t)request_packet.GetData()[1];
+            if (WaitForPacketWithTimeoutMicroSecondsNoLock (reply_packet, GetPacketTimeoutInMicroSeconds ()))
             {
-                if (request_sequence_id == reply_sequence_id)
+                offset = 0;
+                const uint8_t reply_command = reply_packet.GetU8 (&offset);
+                const uint8_t reply_sequence_id = reply_packet.GetU8 (&offset);
+                if ((reply_command & eCommandTypeMask) == command)
                 {
-                    if (command == KDP_RESUMECPUS)
-                        m_is_running.SetValue(true, eBroadcastAlways);
-                    return true;
+                    if (request_sequence_id == reply_sequence_id)
+                    {
+                        if (command == KDP_RESUMECPUS)
+                            m_is_running.SetValue(true, eBroadcastAlways);
+                        return true;
+                    }
                 }
             }
         }
@@ -365,7 +370,6 @@ CommunicationKDP::SendRequestConnect (ui
     const CommandType command = KDP_CONNECT;
     // Length is 82 uint16_t and the length of the greeting C string with the terminating NULL
     const uint32_t command_length = 8 + 2 + 2 + ::strlen(greeting) + 1;
-    const uint32_t request_sequence_id = m_request_sequence_id;
     MakeRequestPacketHeader (command, request_packet, command_length);
     // Always send connect ports as little endian
     request_packet.SetByteOrder (eByteOrderLittle);
@@ -374,7 +378,7 @@ CommunicationKDP::SendRequestConnect (ui
     request_packet.SetByteOrder (m_byte_order);
     request_packet.PutCString (greeting);
     DataExtractor reply_packet;
-    return SendRequestAndGetReply (command, request_sequence_id, request_packet, reply_packet);
+    return SendRequestAndGetReply (command, request_packet, reply_packet);
 }
 
 void
@@ -395,14 +399,13 @@ CommunicationKDP::SendRequestReattach (u
     const CommandType command = KDP_REATTACH;
     // Length is 8 bytes for the header plus 2 bytes for the reply UDP port
     const uint32_t command_length = 8 + 2;
-    const uint32_t request_sequence_id = m_request_sequence_id;
     MakeRequestPacketHeader (command, request_packet, command_length);
     // Always send connect ports as little endian
     request_packet.SetByteOrder (eByteOrderLittle);
     request_packet.PutHex16(reply_port);
     request_packet.SetByteOrder (m_byte_order);
     DataExtractor reply_packet;
-    if (SendRequestAndGetReply (command, request_sequence_id, request_packet, reply_packet))
+    if (SendRequestAndGetReply (command, request_packet, reply_packet))
     {
         // Reset the sequence ID to zero for reattach
         ClearKDPSettings ();
@@ -435,10 +438,9 @@ CommunicationKDP::SendRequestVersion ()
     PacketStreamType request_packet (Stream::eBinary, m_addr_byte_size, m_byte_order);
     const CommandType command = KDP_VERSION;
     const uint32_t command_length = 8;
-    const uint32_t request_sequence_id = m_request_sequence_id;
     MakeRequestPacketHeader (command, request_packet, command_length);
     DataExtractor reply_packet;
-    if (SendRequestAndGetReply (command, request_sequence_id, request_packet, reply_packet))
+    if (SendRequestAndGetReply (command, request_packet, reply_packet))
     {
         lldb::offset_t offset = 8;
         m_kdp_version_version = reply_packet.GetU32 (&offset);
@@ -463,10 +465,9 @@ CommunicationKDP::SendRequestImagePath (
     PacketStreamType request_packet (Stream::eBinary, m_addr_byte_size, m_byte_order);
     const CommandType command = KDP_IMAGEPATH;
     const uint32_t command_length = 8;
-    const uint32_t request_sequence_id = m_request_sequence_id;
     MakeRequestPacketHeader (command, request_packet, command_length);
     DataExtractor reply_packet;
-    if (SendRequestAndGetReply (command, request_sequence_id, request_packet, reply_packet))
+    if (SendRequestAndGetReply (command, request_packet, reply_packet))
     {
         const char *path = reply_packet.PeekCStr(8);
         if (path && path[0])
@@ -563,10 +564,9 @@ CommunicationKDP::SendRequestHostInfo ()
     PacketStreamType request_packet (Stream::eBinary, m_addr_byte_size, m_byte_order);
     const CommandType command = KDP_HOSTINFO;
     const uint32_t command_length = 8;
-    const uint32_t request_sequence_id = m_request_sequence_id;
     MakeRequestPacketHeader (command, request_packet, command_length);
     DataExtractor reply_packet;
-    if (SendRequestAndGetReply (command, request_sequence_id, request_packet, reply_packet))
+    if (SendRequestAndGetReply (command, request_packet, reply_packet))
     {
         lldb::offset_t offset = 8;
         m_kdp_hostinfo_cpu_mask     = reply_packet.GetU32 (&offset);
@@ -599,10 +599,9 @@ CommunicationKDP::SendRequestKernelVersi
     PacketStreamType request_packet (Stream::eBinary, m_addr_byte_size, m_byte_order);
     const CommandType command = KDP_KERNELVERSION;
     const uint32_t command_length = 8;
-    const uint32_t request_sequence_id = m_request_sequence_id;
     MakeRequestPacketHeader (command, request_packet, command_length);
     DataExtractor reply_packet;
-    if (SendRequestAndGetReply (command, request_sequence_id, request_packet, reply_packet))
+    if (SendRequestAndGetReply (command, request_packet, reply_packet))
     {
         const char *kernel_version_cstr = reply_packet.PeekCStr(8);
         if (kernel_version_cstr && kernel_version_cstr[0])
@@ -618,10 +617,9 @@ CommunicationKDP::SendRequestDisconnect
     PacketStreamType request_packet (Stream::eBinary, m_addr_byte_size, m_byte_order);
     const CommandType command = KDP_DISCONNECT;
     const uint32_t command_length = 8;
-    const uint32_t request_sequence_id = m_request_sequence_id;
     MakeRequestPacketHeader (command, request_packet, command_length);
     DataExtractor reply_packet;
-    if (SendRequestAndGetReply (command, request_sequence_id, request_packet, reply_packet))
+    if (SendRequestAndGetReply (command, request_packet, reply_packet))
     {
         // Are we supposed to get a reply for disconnect?
     }
@@ -641,12 +639,11 @@ CommunicationKDP::SendRequestReadMemory
     const CommandType command = use_64 ? KDP_READMEM64 : KDP_READMEM;
     // Size is header + address size + uint32_t length
     const uint32_t command_length = 8 + command_addr_byte_size + 4;
-    const uint32_t request_sequence_id = m_request_sequence_id;
     MakeRequestPacketHeader (command, request_packet, command_length);
     request_packet.PutMaxHex64 (addr, command_addr_byte_size);
     request_packet.PutHex32 (dst_len);
     DataExtractor reply_packet;
-    if (SendRequestAndGetReply (command, request_sequence_id, request_packet, reply_packet))
+    if (SendRequestAndGetReply (command, request_packet, reply_packet))
     {
         lldb::offset_t offset = 8;
         uint32_t kdp_error = reply_packet.GetU32 (&offset);
@@ -687,14 +684,13 @@ CommunicationKDP::SendRequestWriteMemory
     const CommandType command = use_64 ? KDP_WRITEMEM64 : KDP_WRITEMEM;
     // Size is header + address size + uint32_t length
     const uint32_t command_length = 8 + command_addr_byte_size + 4 + src_len;
-    const uint32_t request_sequence_id = m_request_sequence_id;
     MakeRequestPacketHeader (command, request_packet, command_length);
     request_packet.PutMaxHex64 (addr, command_addr_byte_size);
     request_packet.PutHex32 (src_len);
     request_packet.PutRawBytes(src, src_len);
 
     DataExtractor reply_packet;
-    if (SendRequestAndGetReply (command, request_sequence_id, request_packet, reply_packet))
+    if (SendRequestAndGetReply (command, request_packet, reply_packet))
     {
         lldb::offset_t offset = 8;
         uint32_t kdp_error = reply_packet.GetU32 (&offset);
@@ -724,11 +720,10 @@ CommunicationKDP::SendRawRequest (uint8_
     // Size is header + address size + uint32_t length
     const uint32_t command_length = 8 + src_len;
     const CommandType command = (CommandType)command_byte;
-    const uint32_t request_sequence_id = m_request_sequence_id;
     MakeRequestPacketHeader (command, request_packet, command_length);
     request_packet.PutRawBytes(src, src_len);
     
-    if (SendRequestAndGetReply (command, request_sequence_id, request_packet, reply_packet))
+    if (SendRequestAndGetReply (command, request_packet, reply_packet))
     {
         lldb::offset_t offset = 8;
         uint32_t kdp_error = reply_packet.GetU32 (&offset);
@@ -1145,12 +1140,11 @@ CommunicationKDP::SendRequestReadRegiste
     const CommandType command = KDP_READREGS;
     // Size is header + 4 byte cpu and 4 byte flavor
     const uint32_t command_length = 8 + 4 + 4;
-    const uint32_t request_sequence_id = m_request_sequence_id;
     MakeRequestPacketHeader (command, request_packet, command_length);
     request_packet.PutHex32 (cpu);
     request_packet.PutHex32 (flavor);
     DataExtractor reply_packet;
-    if (SendRequestAndGetReply (command, request_sequence_id, request_packet, reply_packet))
+    if (SendRequestAndGetReply (command, request_packet, reply_packet))
     {
         lldb::offset_t offset = 8;
         uint32_t kdp_error = reply_packet.GetU32 (&offset);
@@ -1192,13 +1186,12 @@ CommunicationKDP::SendRequestWriteRegist
     const CommandType command = KDP_WRITEREGS;
     // Size is header + 4 byte cpu and 4 byte flavor
     const uint32_t command_length = 8 + 4 + 4 + src_len;
-    const uint32_t request_sequence_id = m_request_sequence_id;
     MakeRequestPacketHeader (command, request_packet, command_length);
     request_packet.PutHex32 (cpu);
     request_packet.PutHex32 (flavor);
     request_packet.Write(src, src_len);
     DataExtractor reply_packet;
-    if (SendRequestAndGetReply (command, request_sequence_id, request_packet, reply_packet))
+    if (SendRequestAndGetReply (command, request_packet, reply_packet))
     {
         lldb::offset_t offset = 8;
         uint32_t kdp_error = reply_packet.GetU32 (&offset);
@@ -1220,12 +1213,11 @@ CommunicationKDP::SendRequestResume ()
     PacketStreamType request_packet (Stream::eBinary, m_addr_byte_size, m_byte_order);
     const CommandType command = KDP_RESUMECPUS;
     const uint32_t command_length = 12;
-    const uint32_t request_sequence_id = m_request_sequence_id;
     MakeRequestPacketHeader (command, request_packet, command_length);
     request_packet.PutHex32(GetCPUMask());
 
     DataExtractor reply_packet;
-    if (SendRequestAndGetReply (command, request_sequence_id, request_packet, reply_packet))
+    if (SendRequestAndGetReply (command, request_packet, reply_packet))
         return true;
     return false;
 }
@@ -1240,12 +1232,11 @@ CommunicationKDP::SendRequestBreakpoint
                                       (use_64 ? KDP_BREAKPOINT_REMOVE64 : KDP_BREAKPOINT_REMOVE);
 
     const uint32_t command_length = 8 + command_addr_byte_size;
-    const uint32_t request_sequence_id = m_request_sequence_id;
     MakeRequestPacketHeader (command, request_packet, command_length);
     request_packet.PutMaxHex64 (addr, command_addr_byte_size);
     
     DataExtractor reply_packet;
-    if (SendRequestAndGetReply (command, request_sequence_id, request_packet, reply_packet))
+    if (SendRequestAndGetReply (command, request_packet, reply_packet))
     {
         lldb::offset_t offset = 8;
         uint32_t kdp_error = reply_packet.GetU32 (&offset);        
@@ -1261,10 +1252,9 @@ CommunicationKDP::SendRequestSuspend ()
     PacketStreamType request_packet (Stream::eBinary, m_addr_byte_size, m_byte_order);
     const CommandType command = KDP_SUSPEND;
     const uint32_t command_length = 8;
-    const uint32_t request_sequence_id = m_request_sequence_id;
     MakeRequestPacketHeader (command, request_packet, command_length);
     DataExtractor reply_packet;
-    if (SendRequestAndGetReply (command, request_sequence_id, request_packet, reply_packet))
+    if (SendRequestAndGetReply (command, request_packet, reply_packet))
         return true;
     return false;
 }

Modified: lldb/trunk/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.h?rev=175198&r1=175197&r2=175198&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.h (original)
+++ lldb/trunk/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.h Thu Feb 14 13:11:23 2013
@@ -315,7 +315,6 @@ protected:
     
     bool
     SendRequestAndGetReply (const CommandType command,
-                            const uint8_t request_sequence_id,
                             const PacketStreamType &request_packet, 
                             lldb_private::DataExtractor &reply_packet);
     //------------------------------------------------------------------





More information about the lldb-commits mailing list