[Lldb-commits] [lldb] r371907 - [Reproducer] Move GDB Remote Packet into Utility. (NFC)

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Fri Sep 13 16:14:10 PDT 2019


Author: jdevlieghere
Date: Fri Sep 13 16:14:10 2019
New Revision: 371907

URL: http://llvm.org/viewvc/llvm-project?rev=371907&view=rev
Log:
[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

Added:
    lldb/trunk/include/lldb/Utility/GDBRemote.h
    lldb/trunk/source/Utility/GDBRemote.cpp
Removed:
    lldb/trunk/include/lldb/Utility/StreamGDBRemote.h
    lldb/trunk/source/Utility/StreamGDBRemote.cpp
Modified:
    lldb/trunk/include/lldb/Utility/Reproducer.h
    lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
    lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
    lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationHistory.cpp
    lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationHistory.h
    lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationReplayServer.cpp
    lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationReplayServer.h
    lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
    lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
    lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
    lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
    lldb/trunk/source/Utility/CMakeLists.txt
    lldb/trunk/unittests/Process/gdb-remote/GDBRemoteClientBaseTest.cpp

Added: lldb/trunk/include/lldb/Utility/GDBRemote.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Utility/GDBRemote.h?rev=371907&view=auto
==============================================================================
--- lldb/trunk/include/lldb/Utility/GDBRemote.h (added)
+++ lldb/trunk/include/lldb/Utility/GDBRemote.h Fri Sep 13 16:14:10 2019
@@ -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_

Modified: lldb/trunk/include/lldb/Utility/Reproducer.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Utility/Reproducer.h?rev=371907&r1=371906&r2=371907&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Utility/Reproducer.h (original)
+++ lldb/trunk/include/lldb/Utility/Reproducer.h Fri Sep 13 16:14:10 2019
@@ -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"

Removed: lldb/trunk/include/lldb/Utility/StreamGDBRemote.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Utility/StreamGDBRemote.h?rev=371906&view=auto
==============================================================================
--- lldb/trunk/include/lldb/Utility/StreamGDBRemote.h (original)
+++ lldb/trunk/include/lldb/Utility/StreamGDBRemote.h (removed)
@@ -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_

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=371907&r1=371906&r2=371907&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp Fri Sep 13 16:14:10 2019
@@ -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::SendRawPacketNoL
     }
 
     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(c
       }
 
       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

Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h?rev=371907&r1=371906&r2=371907&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h Fri Sep 13 16:14:10 2019
@@ -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"

Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationHistory.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationHistory.cpp?rev=371907&r1=371906&r2=371907&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationHistory.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationHistory.cpp Fri Sep 13 16:14:10 2019
@@ -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::GDBRemote
 
 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::AddP
 }
 
 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
   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
   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 {};
-}

Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationHistory.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationHistory.h?rev=371907&r1=371906&r2=371907&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationHistory.h (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationHistory.h Fri Sep 13 16:14:10 2019
@@ -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_

Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationReplayServer.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationReplayServer.cpp?rev=371907&r1=371906&r2=371907&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationReplayServer.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationReplayServer.cpp Fri Sep 13 16:14:10 2019
@@ -128,7 +128,7 @@ GDBRemoteCommunicationReplayServer::GetP
   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::GetP
     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::GetP
       // 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::GetP
   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());

Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationReplayServer.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationReplayServer.h?rev=371907&r1=371906&r2=371907&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationReplayServer.h (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationReplayServer.h Fri Sep 13 16:14:10 2019
@@ -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;

Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp?rev=371907&r1=371906&r2=371907&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp Fri Sep 13 16:14:10 2019
@@ -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"

Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp?rev=371907&r1=371906&r2=371907&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp Fri Sep 13 16:14:10 2019
@@ -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>

Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp?rev=371907&r1=371906&r2=371907&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp Fri Sep 13 16:14:10 2019
@@ -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"

Modified: lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h?rev=371907&r1=371906&r2=371907&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h Fri Sep 13 16:14:10 2019
@@ -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"

Modified: lldb/trunk/source/Utility/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Utility/CMakeLists.txt?rev=371907&r1=371906&r2=371907&view=diff
==============================================================================
--- lldb/trunk/source/Utility/CMakeLists.txt (original)
+++ lldb/trunk/source/Utility/CMakeLists.txt Fri Sep 13 16:14:10 2019
@@ -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

Added: lldb/trunk/source/Utility/GDBRemote.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Utility/GDBRemote.cpp?rev=371907&view=auto
==============================================================================
--- lldb/trunk/source/Utility/GDBRemote.cpp (added)
+++ lldb/trunk/source/Utility/GDBRemote.cpp Fri Sep 13 16:14:10 2019
@@ -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 {};
+}

Removed: lldb/trunk/source/Utility/StreamGDBRemote.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Utility/StreamGDBRemote.cpp?rev=371906&view=auto
==============================================================================
--- lldb/trunk/source/Utility/StreamGDBRemote.cpp (original)
+++ lldb/trunk/source/Utility/StreamGDBRemote.cpp (removed)
@@ -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;
-}

Modified: lldb/trunk/unittests/Process/gdb-remote/GDBRemoteClientBaseTest.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Process/gdb-remote/GDBRemoteClientBaseTest.cpp?rev=371907&r1=371906&r2=371907&view=diff
==============================================================================
--- lldb/trunk/unittests/Process/gdb-remote/GDBRemoteClientBaseTest.cpp (original)
+++ lldb/trunk/unittests/Process/gdb-remote/GDBRemoteClientBaseTest.cpp Fri Sep 13 16:14:10 2019
@@ -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"
 




More information about the lldb-commits mailing list