[Reproducer] Move GDB Remote Packet into Utility. (NFC)
To support dumping the reproducer's GDB remote packets, we need the
(de)serialization logic to live in Utility rather than the GDB remote
plugin. This patch renames StreamGDBRemote to GDBRemote and moves the
relevant packet code there.
Its uses in the GDBRemoteCommunicationHistory and the
GDBRemoteCommunicationReplayServer are updated as well.
Differential revision: https://reviews.llvm.org/D67523
llvm-svn: 371907
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationHistory.h b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationHistory.h
index 85f112b..c006fbd 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationHistory.h
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationHistory.h
@@ -12,6 +12,7 @@
#include <string>
#include <vector>
+#include "lldb/Utility/GDBRemote.h"
#include "lldb/lldb-public.h"
#include "llvm/Support/YAMLTraits.h"
#include "llvm/Support/raw_ostream.h"
@@ -25,46 +26,17 @@
public:
friend llvm::yaml::MappingTraits<GDBRemoteCommunicationHistory>;
- enum PacketType { ePacketTypeInvalid = 0, ePacketTypeSend, ePacketTypeRecv };
-
- /// Entry in the ring buffer containing the packet data, its type, size and
- /// index. Entries can be serialized to file.
- struct Entry {
- Entry()
- : packet(), type(ePacketTypeInvalid), bytes_transmitted(0),
- packet_idx(0), tid(LLDB_INVALID_THREAD_ID) {}
-
- void Clear() {
- packet.data.clear();
- type = ePacketTypeInvalid;
- bytes_transmitted = 0;
- packet_idx = 0;
- tid = LLDB_INVALID_THREAD_ID;
- }
-
- struct BinaryData {
- std::string data;
- };
-
- void Serialize(llvm::raw_ostream &strm) const;
-
- BinaryData packet;
- PacketType type;
- uint32_t bytes_transmitted;
- uint32_t packet_idx;
- lldb::tid_t tid;
- };
-
GDBRemoteCommunicationHistory(uint32_t size = 0);
~GDBRemoteCommunicationHistory();
// For single char packets for ack, nack and /x03
- void AddPacket(char packet_char, PacketType type, uint32_t bytes_transmitted);
-
- void AddPacket(const std::string &src, uint32_t src_len, PacketType type,
+ void AddPacket(char packet_char, GDBRemotePacket::Type type,
uint32_t bytes_transmitted);
+ void AddPacket(const std::string &src, uint32_t src_len,
+ GDBRemotePacket::Type type, uint32_t bytes_transmitted);
+
void Dump(Stream &strm) const;
void Dump(Log *log) const;
bool DidDumpToLog() const { return m_dumped_to_log; }
@@ -97,7 +69,7 @@
return m_packets.empty() ? 0 : i % m_packets.size();
}
- std::vector<Entry> m_packets;
+ std::vector<GDBRemotePacket> m_packets;
uint32_t m_curr_idx;
uint32_t m_total_packet_count;
mutable bool m_dumped_to_log;
@@ -107,49 +79,4 @@
} // namespace process_gdb_remote
} // namespace lldb_private
-LLVM_YAML_IS_DOCUMENT_LIST_VECTOR(
- lldb_private::process_gdb_remote::GDBRemoteCommunicationHistory::Entry)
-
-namespace llvm {
-namespace yaml {
-
-template <>
-struct ScalarEnumerationTraits<lldb_private::process_gdb_remote::
- GDBRemoteCommunicationHistory::PacketType> {
- static void enumeration(IO &io,
- lldb_private::process_gdb_remote::
- GDBRemoteCommunicationHistory::PacketType &value);
-};
-
-template <>
-struct ScalarTraits<lldb_private::process_gdb_remote::
- GDBRemoteCommunicationHistory::Entry::BinaryData> {
- static void output(const lldb_private::process_gdb_remote::
- GDBRemoteCommunicationHistory::Entry::BinaryData &,
- void *, raw_ostream &);
-
- static StringRef
- input(StringRef, void *,
- lldb_private::process_gdb_remote::GDBRemoteCommunicationHistory::Entry::
- BinaryData &);
-
- static QuotingType mustQuote(StringRef S) { return QuotingType::None; }
-};
-
-template <>
-struct MappingTraits<
- lldb_private::process_gdb_remote::GDBRemoteCommunicationHistory::Entry> {
- static void
- mapping(IO &io,
- lldb_private::process_gdb_remote::GDBRemoteCommunicationHistory::Entry
- &Entry);
-
- static StringRef validate(
- IO &io,
- lldb_private::process_gdb_remote::GDBRemoteCommunicationHistory::Entry &);
-};
-
-} // namespace yaml
-} // namespace llvm
-
#endif // liblldb_GDBRemoteCommunicationHistory_h_