[Lldb-commits] [lldb] r218000 - Add better logging for the "$vFile:pwrite:" packet so we can show binary data instead of nothing or unprintable characters. This can easily be extended for other packets that have binary data.

Greg Clayton gclayton at apple.com
Wed Sep 17 17:17:36 PDT 2014


Author: gclayton
Date: Wed Sep 17 19:17:36 2014
New Revision: 218000

URL: http://llvm.org/viewvc/llvm-project?rev=218000&view=rev
Log:
Add better logging for the "$vFile:pwrite:" packet so we can show binary data instead of nothing or unprintable characters. This can easily be extended for other packets that have binary data.

Modified:
    lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp

Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp?rev=218000&r1=217999&r2=218000&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp Wed Sep 17 19:17:36 2014
@@ -227,9 +227,23 @@ GDBRemoteCommunication::SendPacketNoLock
 
         Log *log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PACKETS));
         ConnectionStatus status = eConnectionStatusSuccess;
-        size_t bytes_written = Write (packet.GetData(), packet.GetSize(), status, NULL);
+        const char *packet_data = packet.GetData();
+        const size_t packet_length = packet.GetSize();
+        size_t bytes_written = Write (packet_data, packet_length, status, NULL);
         if (log)
         {
+            size_t binary_start_offset = 0;
+            if (strncmp(packet_data, "$vFile:pwrite:", strlen("$vFile:pwrite:")) == 0)
+            {
+                const char *first_comma = strchr(packet_data, ',');
+                if (first_comma)
+                {
+                    const char *second_comma = strchr(first_comma + 1, ',');
+                    if (second_comma)
+                        binary_start_offset = second_comma - packet_data + 1;
+                }
+            }
+
             // If logging was just enabled and we have history, then dump out what
             // we have to the log so we get the historical context. The Dump() call that
             // logs all of the packet will set a boolean so that we don't dump this more
@@ -237,13 +251,27 @@ GDBRemoteCommunication::SendPacketNoLock
             if (!m_history.DidDumpToLog ())
                 m_history.Dump (log);
 
-            log->Printf("<%4" PRIu64 "> send packet: %.*s", (uint64_t)bytes_written, (int)packet.GetSize(), packet.GetData());
+            if (binary_start_offset)
+            {
+                StreamString strm;
+                // Print non binary data header
+                strm.Printf("<%4" PRIu64 "> send packet: %.*s", (uint64_t)bytes_written, (int)binary_start_offset, packet_data);
+                const uint8_t *p;
+                // Print binary data exactly as sent
+                for (p = (uint8_t*)packet_data + binary_start_offset; *p != '#'; ++p)
+                    strm.Printf("\\x%2.2x", *p);
+                // Print the checksum
+                strm.Printf("%*s", (int)3, p);
+                log->PutCString(strm.GetString().c_str());
+            }
+            else
+                log->Printf("<%4" PRIu64 "> send packet: %.*s", (uint64_t)bytes_written, (int)packet_length, packet_data);
         }
 
-        m_history.AddPacket (packet.GetString(), packet.GetSize(), History::ePacketTypeSend, bytes_written);
+        m_history.AddPacket (packet.GetString(), packet_length, History::ePacketTypeSend, bytes_written);
 
 
-        if (bytes_written == packet.GetSize())
+        if (bytes_written == packet_length)
         {
             if (GetSendAcks ())
                 return GetAck ();
@@ -253,7 +281,7 @@ GDBRemoteCommunication::SendPacketNoLock
         else
         {
             if (log)
-                log->Printf ("error: failed to send packet: %.*s", (int)packet.GetSize(), packet.GetData());
+                log->Printf ("error: failed to send packet: %.*s", (int)packet_length, packet_data);
         }
     }
     return PacketResult::ErrorSendFailed;





More information about the lldb-commits mailing list