[NFC] Move dumping into GDBRemotePacket
authorJonas Devlieghere <jonas@devlieghere.com>
Mon, 16 Sep 2019 20:02:57 +0000 (20:02 +0000)
committerJonas Devlieghere <jonas@devlieghere.com>
Mon, 16 Sep 2019 20:02:57 +0000 (20:02 +0000)
This moves the dumping logic from the GDBRemoteCommunicationHistory
class into the GDBRemotePacket so that it can be reused from the
reproducer command object.

llvm-svn: 372028

lldb/include/lldb/Utility/GDBRemote.h
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationHistory.cpp
lldb/source/Utility/GDBRemote.cpp

index 2ec7678..b4adeb3 100644 (file)
@@ -70,12 +70,16 @@ struct GDBRemotePacket {
   };
 
   void Serialize(llvm::raw_ostream &strm) const;
+  void Dump(Stream &strm) const;
 
   BinaryData packet;
   Type type;
   uint32_t bytes_transmitted;
   uint32_t packet_idx;
   lldb::tid_t tid;
+
+private:
+  llvm::StringRef GetTypeStr() const;
 };
 
 } // namespace lldb_private
index 898a6ec..d2cc32f 100644 (file)
@@ -72,11 +72,8 @@ void GDBRemoteCommunicationHistory::Dump(Stream &strm) const {
     if (entry.type == GDBRemotePacket::ePacketTypeInvalid ||
         entry.packet.data.empty())
       break;
-    strm.Printf("history[%u] tid=0x%4.4" PRIx64 " <%4u> %s packet: %s\n",
-                entry.packet_idx, entry.tid, entry.bytes_transmitted,
-                (entry.type == GDBRemotePacket::ePacketTypeSend) ? "send"
-                                                                 : "read",
-                entry.packet.data.c_str());
+    strm.Printf("history[%u] ", entry.packet_idx);
+    entry.Dump(strm);
   }
 }
 
index f098292..85c4bc6 100644 (file)
@@ -51,6 +51,23 @@ void GDBRemotePacket::Serialize(raw_ostream &strm) const {
   strm.flush();
 }
 
+llvm::StringRef GDBRemotePacket::GetTypeStr() const {
+  switch (type) {
+  case GDBRemotePacket::ePacketTypeSend:
+    return "send";
+  case GDBRemotePacket::ePacketTypeRecv:
+    return "read";
+  case GDBRemotePacket::ePacketTypeInvalid:
+    return "invalid";
+  }
+  llvm_unreachable("All enum cases should be handled");
+}
+
+void GDBRemotePacket::Dump(Stream &strm) const {
+  strm.Printf("tid=0x%4.4" PRIx64 " <%4u> %s packet: %s\n", tid,
+              bytes_transmitted, GetTypeStr().data(), packet.data.c_str());
+}
+
 void yaml::ScalarEnumerationTraits<GDBRemotePacket::Type>::enumeration(
     IO &io, GDBRemotePacket::Type &value) {
   io.enumCase(value, "Invalid", GDBRemotePacket::ePacketTypeInvalid);