From 4e053ff1d188bae61f6f7d20c591a462b32a9992 Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Mon, 16 Sep 2019 20:02:57 +0000 Subject: [PATCH] [NFC] Move dumping into GDBRemotePacket 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 | 4 ++++ .../GDBRemoteCommunicationHistory.cpp | 7 ++----- lldb/source/Utility/GDBRemote.cpp | 17 +++++++++++++++++ 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/lldb/include/lldb/Utility/GDBRemote.h b/lldb/include/lldb/Utility/GDBRemote.h index 2ec76781e748..b4adeb368524 100644 --- a/lldb/include/lldb/Utility/GDBRemote.h +++ b/lldb/include/lldb/Utility/GDBRemote.h @@ -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 diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationHistory.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationHistory.cpp index 898a6ec6851c..d2cc32f63f20 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationHistory.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationHistory.cpp @@ -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); } } diff --git a/lldb/source/Utility/GDBRemote.cpp b/lldb/source/Utility/GDBRemote.cpp index f0982922a892..85c4bc69a8d1 100644 --- a/lldb/source/Utility/GDBRemote.cpp +++ b/lldb/source/Utility/GDBRemote.cpp @@ -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::enumeration( IO &io, GDBRemotePacket::Type &value) { io.enumCase(value, "Invalid", GDBRemotePacket::ePacketTypeInvalid); -- 2.34.1