LLDB  mainline
GDBRemoteCommunicationHistory.h
Go to the documentation of this file.
1 //===-- GDBRemoteCommunicationHistory.h--------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef liblldb_GDBRemoteCommunicationHistory_h_
10 #define liblldb_GDBRemoteCommunicationHistory_h_
11 
12 #include <string>
13 #include <vector>
14 
15 #include "lldb/lldb-public.h"
16 #include "llvm/Support/YAMLTraits.h"
17 #include "llvm/Support/raw_ostream.h"
18 
19 namespace lldb_private {
20 namespace process_gdb_remote {
21 
22 /// The history keeps a circular buffer of GDB remote packets. The history is
23 /// used for logging and replaying GDB remote packets.
25 public:
26  friend llvm::yaml::MappingTraits<GDBRemoteCommunicationHistory>;
27 
29 
30  /// Entry in the ring buffer containing the packet data, its type, size and
31  /// index. Entries can be serialized to file.
32  struct Entry {
36 
37  void Clear() {
38  packet.data.clear();
41  packet_idx = 0;
43  }
44 
45  struct BinaryData {
46  std::string data;
47  };
48 
49  void Serialize(llvm::raw_ostream &strm) const;
50 
56  };
57 
59 
61 
62  // For single char packets for ack, nack and /x03
63  void AddPacket(char packet_char, PacketType type, uint32_t bytes_transmitted);
64 
65  void AddPacket(const std::string &src, uint32_t src_len, PacketType type,
67 
68  void Dump(Stream &strm) const;
69  void Dump(Log *log) const;
70  bool DidDumpToLog() const { return m_dumped_to_log; }
71 
72  void SetStream(llvm::raw_ostream *strm) { m_stream = strm; }
73 
74 private:
75  uint32_t GetFirstSavedPacketIndex() const {
76  if (m_total_packet_count < m_packets.size())
77  return 0;
78  else
79  return m_curr_idx + 1;
80  }
81 
82  uint32_t GetNumPacketsInHistory() const {
83  if (m_total_packet_count < m_packets.size())
84  return m_total_packet_count;
85  else
86  return (uint32_t)m_packets.size();
87  }
88 
89  uint32_t GetNextIndex() {
90  ++m_total_packet_count;
91  const uint32_t idx = m_curr_idx;
92  m_curr_idx = NormalizeIndex(idx + 1);
93  return idx;
94  }
95 
96  uint32_t NormalizeIndex(uint32_t i) const {
97  return m_packets.empty() ? 0 : i % m_packets.size();
98  }
99 
100  std::vector<Entry> m_packets;
101  uint32_t m_curr_idx;
102  uint32_t m_total_packet_count;
103  mutable bool m_dumped_to_log;
104  llvm::raw_ostream *m_stream = nullptr;
105 };
106 
107 } // namespace process_gdb_remote
108 } // namespace lldb_private
109 
112 
113 namespace llvm {
114 namespace yaml {
115 
116 template <>
117 struct ScalarEnumerationTraits<lldb_private::process_gdb_remote::
119  static void enumeration(IO &io,
122 };
123 
124 template <>
125 struct ScalarTraits<lldb_private::process_gdb_remote::
126  GDBRemoteCommunicationHistory::Entry::BinaryData> {
127  static void output(const lldb_private::process_gdb_remote::
128  GDBRemoteCommunicationHistory::Entry::BinaryData &,
129  void *, raw_ostream &);
130 
131  static StringRef
132  input(StringRef, void *,
134  BinaryData &);
135 
136  static QuotingType mustQuote(StringRef S) { return QuotingType::None; }
137 };
138 
139 template <>
140 struct MappingTraits<
141  lldb_private::process_gdb_remote::GDBRemoteCommunicationHistory::Entry> {
142  static void
143  mapping(IO &io,
145  &Entry);
146 
147  static StringRef validate(
148  IO &io,
150 };
151 
152 } // namespace yaml
153 } // namespace llvm
154 
155 #endif // liblldb_GDBRemoteCommunicationHistory_h_
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
Definition: Debugger.h:71
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
Entry in the ring buffer containing the packet data, its type, size and index.
uint64_t tid_t
Definition: lldb-types.h:86
The history keeps a circular buffer of GDB remote packets.
#define LLDB_INVALID_THREAD_ID
Definition: lldb-defines.h:93
LLVM_YAML_IS_DOCUMENT_LIST_VECTOR(lldb_private::process_gdb_remote::GDBRemoteCommunicationHistory::Entry) namespace llvm
void AddPacket(char packet_char, PacketType type, uint32_t bytes_transmitted)