Fixed the GDBRemoteCommuncation to return a new GDBRemoteCommuncation::PacketResult enum for all packet sends/receives.

<rdar://problem/15600045>

Due to other recent changes, all connections to GDB servers that didn't support the "QStartNoAckMode" packet would cause us to fail to attach to the remote GDB server.

The problem was that SendPacket* and WaitForResponse* packets would return a size_t indicating the number of bytes sent/received. The other issue was WaitForResponse* packets would strip the leading '$' and the trailing "#CC" (checksum) bytes, so the unimplemented response packet of "$#00" would get stripped and the WaitForResponse* packets would return 0.

These new error codes give us flexibility to to more intelligent things in response to what is returned. 

llvm-svn: 196610
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
index 5966cca..77eb605 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
@@ -199,14 +199,14 @@
     return bytes_written;
 }
 
-size_t
+GDBRemoteCommunication::PacketResult
 GDBRemoteCommunication::SendPacket (const char *payload, size_t payload_length)
 {
     Mutex::Locker locker(m_sequence_mutex);
     return SendPacketNoLock (payload, payload_length);
 }
 
-size_t
+GDBRemoteCommunication::PacketResult
 GDBRemoteCommunication::SendPacketNoLock (const char *payload, size_t payload_length)
 {
     if (IsConnected())
@@ -239,32 +239,32 @@
         if (bytes_written == packet.GetSize())
         {
             if (GetSendAcks ())
-            {
-                if (GetAck () != '+')
-                {
-                    if (log)
-                        log->Printf("get ack failed...");
-                    return 0;
-                }
-            }
+                return GetAck ();
+            else
+                return PacketResult::Success;
         }
         else
         {
             if (log)
                 log->Printf ("error: failed to send packet: %.*s", (int)packet.GetSize(), packet.GetData());
         }
-        return bytes_written;
     }
-    return 0;
+    return PacketResult::ErrorSendFailed;
 }
 
-char
+GDBRemoteCommunication::PacketResult
 GDBRemoteCommunication::GetAck ()
 {
     StringExtractorGDBRemote packet;
-    if (WaitForPacketWithTimeoutMicroSecondsNoLock (packet, GetPacketTimeoutInMicroSeconds ()) == 1)
-        return packet.GetChar();
-    return 0;
+    PacketResult result = WaitForPacketWithTimeoutMicroSecondsNoLock (packet, GetPacketTimeoutInMicroSeconds ());
+    if (result == PacketResult::Success)
+    {
+        if (packet.GetResponseType() == StringExtractorGDBRemote::ResponseType::eAck)
+            return PacketResult::Success;
+        else
+            return PacketResult::ErrorSendAck;
+    }
+    return result;
 }
 
 bool
@@ -284,7 +284,7 @@
     return m_private_is_running.WaitForValueEqualTo (false, timeout_ptr, NULL);
 }
 
-size_t
+GDBRemoteCommunication::PacketResult
 GDBRemoteCommunication::WaitForPacketWithTimeoutMicroSecondsNoLock (StringExtractorGDBRemote &packet, uint32_t timeout_usec)
 {
     uint8_t buffer[8192];
@@ -294,9 +294,10 @@
 
     // Check for a packet from our cache first without trying any reading...
     if (CheckForPacket (NULL, 0, packet))
-        return packet.GetStringRef().size();
+        return PacketResult::Success;
 
     bool timed_out = false;
+    bool disconnected = false;
     while (IsConnected() && !timed_out)
     {
         lldb::ConnectionStatus status = eConnectionStatusNoConnection;
@@ -313,7 +314,7 @@
         if (bytes_read > 0)
         {
             if (CheckForPacket (buffer, bytes_read, packet))
-                return packet.GetStringRef().size();
+                return PacketResult::Success;
         }
         else
         {
@@ -330,13 +331,19 @@
             case eConnectionStatusNoConnection:
             case eConnectionStatusLostConnection:
             case eConnectionStatusError:
+                disconnected = true;
                 Disconnect();
                 break;
             }
         }
     }
-    packet.Clear ();    
-    return 0;
+    packet.Clear ();
+    if (disconnected)
+        return PacketResult::ErrorDisconnected;
+    if (timed_out)
+        return PacketResult::ErrorReplyTimeout;
+    else
+        return PacketResult::ErrorReplyFailed;
 }
 
 bool