[Reproducer] Move GDB Remote Packet into Utility. (NFC)
authorJonas Devlieghere <jonas@devlieghere.com>
Fri, 13 Sep 2019 23:14:10 +0000 (23:14 +0000)
committerJonas Devlieghere <jonas@devlieghere.com>
Fri, 13 Sep 2019 23:14:10 +0000 (23:14 +0000)
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

17 files changed:
lldb/include/lldb/Utility/GDBRemote.h [new file with mode: 0644]
lldb/include/lldb/Utility/Reproducer.h
lldb/include/lldb/Utility/StreamGDBRemote.h [deleted file]
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationHistory.cpp
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationHistory.h
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationReplayServer.cpp
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationReplayServer.h
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
lldb/source/Utility/CMakeLists.txt
lldb/source/Utility/GDBRemote.cpp [new file with mode: 0644]
lldb/source/Utility/StreamGDBRemote.cpp [deleted file]
lldb/unittests/Process/gdb-remote/GDBRemoteClientBaseTest.cpp

diff --git a/lldb/include/lldb/Utility/GDBRemote.h b/lldb/include/lldb/Utility/GDBRemote.h
new file mode 100644 (file)
index 0000000..2ec7678
--- /dev/null
@@ -0,0 +1,113 @@
+//===-- GDBRemote.h ----------------------------------------------*- C++-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef liblldb_GDBRemote_h_
+#define liblldb_GDBRemote_h_
+
+#include "lldb/Utility/StreamString.h"
+#include "lldb/lldb-enumerations.h"
+#include "lldb/lldb-public.h"
+#include "llvm/Support/YAMLTraits.h"
+#include "llvm/Support/raw_ostream.h"
+
+#include <stddef.h>
+#include <stdint.h>
+#include <string>
+#include <vector>
+
+namespace lldb_private {
+
+class StreamGDBRemote : public StreamString {
+public:
+  StreamGDBRemote();
+
+  StreamGDBRemote(uint32_t flags, uint32_t addr_size,
+                  lldb::ByteOrder byte_order);
+
+  ~StreamGDBRemote() override;
+
+  /// Output a block of data to the stream performing GDB-remote escaping.
+  ///
+  /// \param[in] s
+  ///     A block of data.
+  ///
+  /// \param[in] src_len
+  ///     The amount of data to write.
+  ///
+  /// \return
+  ///     Number of bytes written.
+  // TODO: Convert this function to take ArrayRef<uint8_t>
+  int PutEscapedBytes(const void *s, size_t src_len);
+};
+
+/// GDB remote packet as used by the reproducer and the GDB remote
+/// communication history. Packets can be serialized to file.
+struct GDBRemotePacket {
+
+  friend llvm::yaml::MappingTraits<GDBRemotePacket>;
+
+  enum Type { ePacketTypeInvalid = 0, ePacketTypeSend, ePacketTypeRecv };
+
+  GDBRemotePacket()
+      : 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;
+  Type type;
+  uint32_t bytes_transmitted;
+  uint32_t packet_idx;
+  lldb::tid_t tid;
+};
+
+} // namespace lldb_private
+
+LLVM_YAML_IS_DOCUMENT_LIST_VECTOR(lldb_private::GDBRemotePacket)
+LLVM_YAML_IS_DOCUMENT_LIST_VECTOR(std::vector<lldb_private::GDBRemotePacket>)
+
+namespace llvm {
+namespace yaml {
+
+template <>
+struct ScalarEnumerationTraits<lldb_private::GDBRemotePacket::Type> {
+  static void enumeration(IO &io, lldb_private::GDBRemotePacket::Type &value);
+};
+
+template <> struct ScalarTraits<lldb_private::GDBRemotePacket::BinaryData> {
+  static void output(const lldb_private::GDBRemotePacket::BinaryData &, void *,
+                     raw_ostream &);
+
+  static StringRef input(StringRef, void *,
+                         lldb_private::GDBRemotePacket::BinaryData &);
+
+  static QuotingType mustQuote(StringRef S) { return QuotingType::None; }
+};
+
+template <> struct MappingTraits<lldb_private::GDBRemotePacket> {
+  static void mapping(IO &io, lldb_private::GDBRemotePacket &Packet);
+
+  static StringRef validate(IO &io, lldb_private::GDBRemotePacket &);
+};
+
+} // namespace yaml
+} // namespace llvm
+
+#endif // liblldb_GDBRemote_h_
index 76bdfa83037a9b5f0aa7cd689f53a620f04657b0..556f39034ab20668e08c5592d007e1cb55baabbe 100644 (file)
@@ -10,7 +10,6 @@
 #define LLDB_UTILITY_REPRODUCER_H
 
 #include "lldb/Utility/FileSpec.h"
-
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/FileCollector.h"
diff --git a/lldb/include/lldb/Utility/StreamGDBRemote.h b/lldb/include/lldb/Utility/StreamGDBRemote.h
deleted file mode 100644 (file)
index dd0ea31..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-//===-- StreamGDBRemote.h ----------------------------------------*- C++-*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef liblldb_StreamGDBRemote_h_
-#define liblldb_StreamGDBRemote_h_
-
-#include "lldb/Utility/StreamString.h"
-#include "lldb/lldb-enumerations.h"
-
-#include <stddef.h>
-#include <stdint.h>
-
-namespace lldb_private {
-
-class StreamGDBRemote : public StreamString {
-public:
-  StreamGDBRemote();
-
-  StreamGDBRemote(uint32_t flags, uint32_t addr_size,
-                  lldb::ByteOrder byte_order);
-
-  ~StreamGDBRemote() override;
-
-  /// Output a block of data to the stream performing GDB-remote escaping.
-  ///
-  /// \param[in] s
-  ///     A block of data.
-  ///
-  /// \param[in] src_len
-  ///     The amount of data to write.
-  ///
-  /// \return
-  ///     Number of bytes written.
-  // TODO: Convert this function to take ArrayRef<uint8_t>
-  int PutEscapedBytes(const void *s, size_t src_len);
-};
-
-} // namespace lldb_private
-
-#endif // liblldb_StreamGDBRemote_h_
index bb467df8bb6e3f6b4b492f888c3bef0229cfddcc..144ae103faa4ba9a02268eb6154e3980fac3b2f0 100644 (file)
@@ -103,8 +103,7 @@ size_t GDBRemoteCommunication::SendAck() {
   char ch = '+';
   const size_t bytes_written = Write(&ch, 1, status, nullptr);
   LLDB_LOGF(log, "<%4" PRIu64 "> send packet: %c", (uint64_t)bytes_written, ch);
-  m_history.AddPacket(ch, GDBRemoteCommunicationHistory::ePacketTypeSend,
-                      bytes_written);
+  m_history.AddPacket(ch, GDBRemotePacket::ePacketTypeSend, bytes_written);
   return bytes_written;
 }
 
@@ -114,8 +113,7 @@ size_t GDBRemoteCommunication::SendNack() {
   char ch = '-';
   const size_t bytes_written = Write(&ch, 1, status, nullptr);
   LLDB_LOGF(log, "<%4" PRIu64 "> send packet: %c", (uint64_t)bytes_written, ch);
-  m_history.AddPacket(ch, GDBRemoteCommunicationHistory::ePacketTypeSend,
-                      bytes_written);
+  m_history.AddPacket(ch, GDBRemotePacket::ePacketTypeSend, bytes_written);
   return bytes_written;
 }
 
@@ -178,8 +176,7 @@ GDBRemoteCommunication::SendRawPacketNoLock(llvm::StringRef packet,
     }
 
     m_history.AddPacket(packet.str(), packet_length,
-                        GDBRemoteCommunicationHistory::ePacketTypeSend,
-                        bytes_written);
+                        GDBRemotePacket::ePacketTypeSend, bytes_written);
 
     if (bytes_written == packet_length) {
       if (!skip_ack && GetSendAcks())
@@ -809,8 +806,7 @@ GDBRemoteCommunication::CheckForPacket(const uint8_t *src, size_t src_len,
       }
 
       m_history.AddPacket(m_bytes, total_length,
-                          GDBRemoteCommunicationHistory::ePacketTypeRecv,
-                          total_length);
+                          GDBRemotePacket::ePacketTypeRecv, total_length);
 
       // Copy the packet from m_bytes to packet_str expanding the run-length
       // encoding in the process. Reserve enough byte for the most common case
index daee68059520b75c6479cd19531ddb19f5ae7642..898942bb54594c593600efb0302709d07db96218 100644 (file)
@@ -18,7 +18,7 @@
 #include <vector>
 
 #include "lldb/Utility/ArchSpec.h"
-#include "lldb/Utility/StreamGDBRemote.h"
+#include "lldb/Utility/GDBRemote.h"
 #include "lldb/Utility/StructuredData.h"
 #if defined(_WIN32)
 #include "lldb/Host/windows/PosixApi.h"
index f9f67fcbcaa9208461cd5eaad51fe072e030864b..898a6ec6851c7b41ae760846524d9b09102d3b41 100644 (file)
@@ -18,12 +18,6 @@ using namespace lldb;
 using namespace lldb_private;
 using namespace lldb_private::process_gdb_remote;
 
-void GDBRemoteCommunicationHistory::Entry::Serialize(raw_ostream &strm) const {
-  yaml::Output yout(strm);
-  yout << const_cast<GDBRemoteCommunicationHistory::Entry &>(*this);
-  strm.flush();
-}
-
 GDBRemoteCommunicationHistory::GDBRemoteCommunicationHistory(uint32_t size)
     : m_packets(), m_curr_idx(0), m_total_packet_count(0),
       m_dumped_to_log(false) {
@@ -33,7 +27,8 @@ GDBRemoteCommunicationHistory::GDBRemoteCommunicationHistory(uint32_t size)
 
 GDBRemoteCommunicationHistory::~GDBRemoteCommunicationHistory() {}
 
-void GDBRemoteCommunicationHistory::AddPacket(char packet_char, PacketType type,
+void GDBRemoteCommunicationHistory::AddPacket(char packet_char,
+                                              GDBRemotePacket::Type type,
                                               uint32_t bytes_transmitted) {
   const size_t size = m_packets.size();
   if (size == 0)
@@ -50,7 +45,8 @@ void GDBRemoteCommunicationHistory::AddPacket(char packet_char, PacketType type,
 }
 
 void GDBRemoteCommunicationHistory::AddPacket(const std::string &src,
-                                              uint32_t src_len, PacketType type,
+                                              uint32_t src_len,
+                                              GDBRemotePacket::Type type,
                                               uint32_t bytes_transmitted) {
   const size_t size = m_packets.size();
   if (size == 0)
@@ -72,12 +68,14 @@ void GDBRemoteCommunicationHistory::Dump(Stream &strm) const {
   const uint32_t stop_idx = m_curr_idx + size;
   for (uint32_t i = first_idx; i < stop_idx; ++i) {
     const uint32_t idx = NormalizeIndex(i);
-    const Entry &entry = m_packets[idx];
-    if (entry.type == ePacketTypeInvalid || entry.packet.data.empty())
+    const GDBRemotePacket &entry = m_packets[idx];
+    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 == ePacketTypeSend) ? "send" : "read",
+                (entry.type == GDBRemotePacket::ePacketTypeSend) ? "send"
+                                                                 : "read",
                 entry.packet.data.c_str());
   }
 }
@@ -92,51 +90,15 @@ void GDBRemoteCommunicationHistory::Dump(Log *log) const {
   const uint32_t stop_idx = m_curr_idx + size;
   for (uint32_t i = first_idx; i < stop_idx; ++i) {
     const uint32_t idx = NormalizeIndex(i);
-    const Entry &entry = m_packets[idx];
-    if (entry.type == ePacketTypeInvalid || entry.packet.data.empty())
+    const GDBRemotePacket &entry = m_packets[idx];
+    if (entry.type == GDBRemotePacket::ePacketTypeInvalid ||
+        entry.packet.data.empty())
       break;
     LLDB_LOGF(log, "history[%u] tid=0x%4.4" PRIx64 " <%4u> %s packet: %s",
               entry.packet_idx, entry.tid, entry.bytes_transmitted,
-              (entry.type == ePacketTypeSend) ? "send" : "read",
+              (entry.type == GDBRemotePacket::ePacketTypeSend) ? "send"
+                                                               : "read",
               entry.packet.data.c_str());
   }
 }
 
-void yaml::ScalarEnumerationTraits<GDBRemoteCommunicationHistory::PacketType>::
-    enumeration(IO &io, GDBRemoteCommunicationHistory::PacketType &value) {
-  io.enumCase(value, "Invalid",
-              GDBRemoteCommunicationHistory::ePacketTypeInvalid);
-  io.enumCase(value, "Send", GDBRemoteCommunicationHistory::ePacketTypeSend);
-  io.enumCase(value, "Recv", GDBRemoteCommunicationHistory::ePacketTypeRecv);
-}
-
-void yaml::ScalarTraits<GDBRemoteCommunicationHistory::Entry::BinaryData>::
-    output(const GDBRemoteCommunicationHistory::Entry::BinaryData &Val, void *,
-           raw_ostream &Out) {
-  Out << toHex(Val.data);
-}
-
-StringRef
-yaml::ScalarTraits<GDBRemoteCommunicationHistory::Entry::BinaryData>::input(
-    StringRef Scalar, void *,
-    GDBRemoteCommunicationHistory::Entry::BinaryData &Val) {
-  Val.data = fromHex(Scalar);
-  return {};
-}
-
-void yaml::MappingTraits<GDBRemoteCommunicationHistory::Entry>::mapping(
-    IO &io, GDBRemoteCommunicationHistory::Entry &Entry) {
-  io.mapRequired("packet", Entry.packet);
-  io.mapRequired("type", Entry.type);
-  io.mapRequired("bytes", Entry.bytes_transmitted);
-  io.mapRequired("index", Entry.packet_idx);
-  io.mapRequired("tid", Entry.tid);
-}
-
-StringRef yaml::MappingTraits<GDBRemoteCommunicationHistory::Entry>::validate(
-    IO &io, GDBRemoteCommunicationHistory::Entry &Entry) {
-  if (Entry.bytes_transmitted != Entry.packet.data.size())
-    return "BinaryData size doesn't match bytes transmitted";
-
-  return {};
-}
index 85f112b506236445b244675556e3c6cbdfe3139c..c006fbd34a4b94ea5c72f908827b2a843ee8c984 100644 (file)
@@ -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 @@ class GDBRemoteCommunicationHistory {
 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 @@ private:
     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 @@ private:
 } // 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_
index 39304a6ff94e8b88fcb5baac0cea07a8cc27bf0a..2d26c550dc76a5dc63605306e6f33158bc9bab04 100644 (file)
@@ -128,7 +128,7 @@ GDBRemoteCommunicationReplayServer::GetPacketAndSendResponse(
   Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS));
   while (!m_packet_history.empty()) {
     // Pop last packet from the history.
-    GDBRemoteCommunicationHistory::Entry entry = m_packet_history.back();
+    GDBRemotePacket entry = m_packet_history.back();
     m_packet_history.pop_back();
 
     // We've handled the handshake implicitly before. Skip the packet and move
@@ -136,7 +136,7 @@ GDBRemoteCommunicationReplayServer::GetPacketAndSendResponse(
     if (entry.packet.data == "+")
       continue;
 
-    if (entry.type == GDBRemoteCommunicationHistory::ePacketTypeSend) {
+    if (entry.type == GDBRemotePacket::ePacketTypeSend) {
       if (unexpected(entry.packet.data, packet.GetStringRef())) {
         LLDB_LOG(log,
                  "GDBRemoteCommunicationReplayServer expected packet: '{0}'",
@@ -150,14 +150,14 @@ GDBRemoteCommunicationReplayServer::GetPacketAndSendResponse(
       // Ignore QEnvironment packets as they're handled earlier.
       if (entry.packet.data.find("QEnvironment") == 1) {
         assert(m_packet_history.back().type ==
-               GDBRemoteCommunicationHistory::ePacketTypeRecv);
+               GDBRemotePacket::ePacketTypeRecv);
         m_packet_history.pop_back();
       }
 
       continue;
     }
 
-    if (entry.type == GDBRemoteCommunicationHistory::ePacketTypeInvalid) {
+    if (entry.type == GDBRemotePacket::ePacketTypeInvalid) {
       LLDB_LOG(
           log,
           "GDBRemoteCommunicationReplayServer skipped invalid packet: '{0}'",
@@ -176,10 +176,6 @@ GDBRemoteCommunicationReplayServer::GetPacketAndSendResponse(
   return packet_result;
 }
 
-LLVM_YAML_IS_DOCUMENT_LIST_VECTOR(
-    std::vector<
-        lldb_private::process_gdb_remote::GDBRemoteCommunicationHistory::Entry>)
-
 llvm::Error
 GDBRemoteCommunicationReplayServer::LoadReplayHistory(const FileSpec &path) {
   auto error_or_file = MemoryBuffer::getFile(path.GetPath());
index 26d65e265463b20f9a267aa64daa1e4f496c0cca..0b5e910f7c6a67543089391fe3d8fdf5684b29c7 100644 (file)
@@ -62,7 +62,7 @@ protected:
   static lldb::thread_result_t AsyncThread(void *arg);
 
   /// Replay history with the oldest packet at the end.
-  std::vector<GDBRemoteCommunicationHistory::Entry> m_packet_history;
+  std::vector<GDBRemotePacket> m_packet_history;
 
   /// Server thread.
   Broadcaster m_async_broadcaster;
index d0ae5191efd6f4f43926b8bed19ac2e942cb29ec..4284bc616cf53c8dd41921e39eb5e3b5090fbf5f 100644 (file)
@@ -29,9 +29,9 @@
 #include "lldb/Symbol/ObjectFile.h"
 #include "lldb/Target/Platform.h"
 #include "lldb/Utility/Endian.h"
+#include "lldb/Utility/GDBRemote.h"
 #include "lldb/Utility/JSON.h"
 #include "lldb/Utility/Log.h"
-#include "lldb/Utility/StreamGDBRemote.h"
 #include "lldb/Utility/StreamString.h"
 #include "lldb/Utility/StructuredData.h"
 #include "llvm/ADT/Triple.h"
index bf7860ad1a5db50da5aa43f2659c198419f42597..ac579efd31bdc3ade62e21466b5cc2afc463db49 100644 (file)
@@ -11,7 +11,7 @@
 #include "lldb/Host/Config.h"
 
 #include "GDBRemoteCommunicationServerLLGS.h"
-#include "lldb/Utility/StreamGDBRemote.h"
+#include "lldb/Utility/GDBRemote.h"
 
 #include <chrono>
 #include <cstring>
index 677f348dec209229d8fbcfdf3bee1bf8278d20bf..83370bd2e98f0041b80f6068f7059fb0eaf2fa6c 100644 (file)
@@ -27,9 +27,9 @@
 #include "lldb/Host/HostInfo.h"
 #include "lldb/Target/Platform.h"
 #include "lldb/Target/UnixSignals.h"
+#include "lldb/Utility/GDBRemote.h"
 #include "lldb/Utility/JSON.h"
 #include "lldb/Utility/Log.h"
-#include "lldb/Utility/StreamGDBRemote.h"
 #include "lldb/Utility/StreamString.h"
 #include "lldb/Utility/StructuredData.h"
 #include "lldb/Utility/UriParser.h"
index 84004c195660f8d9be37132bf04593baeb1d44f9..0e3e3b39d9c8e1c3718a74c82fba2bd505d4069d 100644 (file)
@@ -24,8 +24,8 @@
 #include "lldb/Utility/ArchSpec.h"
 #include "lldb/Utility/Broadcaster.h"
 #include "lldb/Utility/ConstString.h"
+#include "lldb/Utility/GDBRemote.h"
 #include "lldb/Utility/Status.h"
-#include "lldb/Utility/StreamGDBRemote.h"
 #include "lldb/Utility/StreamString.h"
 #include "lldb/Utility/StringExtractor.h"
 #include "lldb/Utility/StringList.h"
index e5cee780d4f734cb4fa221a42e42a247b8b51956..d86963fde9a4a46327fd9fa8ad441fdcfce69a4f 100644 (file)
@@ -25,6 +25,7 @@ add_lldb_library(lldbUtility
   Environment.cpp
   Event.cpp
   FileSpec.cpp
+  GDBRemote.cpp
   IOObject.cpp
   JSON.cpp
   LLDBAssert.cpp
@@ -44,7 +45,6 @@ add_lldb_library(lldbUtility
   Status.cpp
   Stream.cpp
   StreamCallback.cpp
-  StreamGDBRemote.cpp
   StreamString.cpp
   StringExtractor.cpp
   StringExtractorGDBRemote.cpp
diff --git a/lldb/source/Utility/GDBRemote.cpp b/lldb/source/Utility/GDBRemote.cpp
new file mode 100644 (file)
index 0000000..f098292
--- /dev/null
@@ -0,0 +1,88 @@
+//===-- GDBRemote.cpp -----------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "lldb/Utility/GDBRemote.h"
+
+#include "lldb/Utility/Flags.h"
+#include "lldb/Utility/Stream.h"
+
+#include <stdio.h>
+
+using namespace lldb;
+using namespace lldb_private;
+using namespace llvm;
+
+StreamGDBRemote::StreamGDBRemote() : StreamString() {}
+
+StreamGDBRemote::StreamGDBRemote(uint32_t flags, uint32_t addr_size,
+                                 ByteOrder byte_order)
+    : StreamString(flags, addr_size, byte_order) {}
+
+StreamGDBRemote::~StreamGDBRemote() {}
+
+int StreamGDBRemote::PutEscapedBytes(const void *s, size_t src_len) {
+  int bytes_written = 0;
+  const uint8_t *src = static_cast<const uint8_t *>(s);
+  bool binary_is_set = m_flags.Test(eBinary);
+  m_flags.Clear(eBinary);
+  while (src_len) {
+    uint8_t byte = *src;
+    src++;
+    src_len--;
+    if (byte == 0x23 || byte == 0x24 || byte == 0x7d || byte == 0x2a) {
+      bytes_written += PutChar(0x7d);
+      byte ^= 0x20;
+    }
+    bytes_written += PutChar(byte);
+  };
+  if (binary_is_set)
+    m_flags.Set(eBinary);
+  return bytes_written;
+}
+
+void GDBRemotePacket::Serialize(raw_ostream &strm) const {
+  yaml::Output yout(strm);
+  yout << const_cast<GDBRemotePacket &>(*this);
+  strm.flush();
+}
+
+void yaml::ScalarEnumerationTraits<GDBRemotePacket::Type>::enumeration(
+    IO &io, GDBRemotePacket::Type &value) {
+  io.enumCase(value, "Invalid", GDBRemotePacket::ePacketTypeInvalid);
+  io.enumCase(value, "Send", GDBRemotePacket::ePacketTypeSend);
+  io.enumCase(value, "Recv", GDBRemotePacket::ePacketTypeRecv);
+}
+
+void yaml::ScalarTraits<GDBRemotePacket::BinaryData>::output(
+    const GDBRemotePacket::BinaryData &Val, void *, raw_ostream &Out) {
+  Out << toHex(Val.data);
+}
+
+StringRef yaml::ScalarTraits<GDBRemotePacket::BinaryData>::input(
+    StringRef Scalar, void *, GDBRemotePacket::BinaryData &Val) {
+  Val.data = fromHex(Scalar);
+  return {};
+}
+
+void yaml::MappingTraits<GDBRemotePacket>::mapping(IO &io,
+                                                   GDBRemotePacket &Packet) {
+  io.mapRequired("packet", Packet.packet);
+  io.mapRequired("type", Packet.type);
+  io.mapRequired("bytes", Packet.bytes_transmitted);
+  io.mapRequired("index", Packet.packet_idx);
+  io.mapRequired("tid", Packet.tid);
+}
+
+StringRef
+yaml::MappingTraits<GDBRemotePacket>::validate(IO &io,
+                                               GDBRemotePacket &Packet) {
+  if (Packet.bytes_transmitted != Packet.packet.data.size())
+    return "BinaryData size doesn't match bytes transmitted";
+
+  return {};
+}
diff --git a/lldb/source/Utility/StreamGDBRemote.cpp b/lldb/source/Utility/StreamGDBRemote.cpp
deleted file mode 100644 (file)
index c710bbe..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-//===-- StreamGDBRemote.cpp -------------------------------------*- C++ -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#include "lldb/Utility/StreamGDBRemote.h"
-
-#include "lldb/Utility/Flags.h"
-#include "lldb/Utility/Stream.h"
-
-#include <stdio.h>
-
-using namespace lldb;
-using namespace lldb_private;
-
-StreamGDBRemote::StreamGDBRemote() : StreamString() {}
-
-StreamGDBRemote::StreamGDBRemote(uint32_t flags, uint32_t addr_size,
-                                 ByteOrder byte_order)
-    : StreamString(flags, addr_size, byte_order) {}
-
-StreamGDBRemote::~StreamGDBRemote() {}
-
-int StreamGDBRemote::PutEscapedBytes(const void *s, size_t src_len) {
-  int bytes_written = 0;
-  const uint8_t *src = static_cast<const uint8_t *>(s);
-  bool binary_is_set = m_flags.Test(eBinary);
-  m_flags.Clear(eBinary);
-  while (src_len) {
-    uint8_t byte = *src;
-    src++;
-    src_len--;
-    if (byte == 0x23 || byte == 0x24 || byte == 0x7d || byte == 0x2a) {
-      bytes_written += PutChar(0x7d);
-      byte ^= 0x20;
-    }
-    bytes_written += PutChar(byte);
-  };
-  if (binary_is_set)
-    m_flags.Set(eBinary);
-  return bytes_written;
-}
index afba5c64266d53aa9331d704c7cd7dde1eaeeec9..d56e9cf81bc7558cf7108bf7ceaaee49018893be 100644 (file)
@@ -12,7 +12,7 @@
 #include "Plugins/Process/Utility/LinuxSignals.h"
 #include "Plugins/Process/gdb-remote/GDBRemoteClientBase.h"
 #include "Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h"
-#include "lldb/Utility/StreamGDBRemote.h"
+#include "lldb/Utility/GDBRemote.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/Testing/Support/Error.h"