LLDB  mainline
GDBRemote.h
Go to the documentation of this file.
1 //===-- GDBRemote.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 LLDB_UTILITY_GDBREMOTE_H
10 #define LLDB_UTILITY_GDBREMOTE_H
11 
12 #include "lldb/Utility/FileSpec.h"
15 #include "lldb/lldb-enumerations.h"
16 #include "lldb/lldb-public.h"
17 #include "llvm/Support/YAMLTraits.h"
18 #include "llvm/Support/raw_ostream.h"
19 
20 #include <cstddef>
21 #include <cstdint>
22 #include <string>
23 #include <vector>
24 
25 namespace lldb_private {
26 
27 class StreamGDBRemote : public StreamString {
28 public:
30 
31  StreamGDBRemote(uint32_t flags, uint32_t addr_size,
32  lldb::ByteOrder byte_order);
33 
34  ~StreamGDBRemote() override;
35 
36  /// Output a block of data to the stream performing GDB-remote escaping.
37  ///
38  /// \param[in] s
39  /// A block of data.
40  ///
41  /// \param[in] src_len
42  /// The amount of data to write.
43  ///
44  /// \return
45  /// Number of bytes written.
46  // TODO: Convert this function to take ArrayRef<uint8_t>
47  int PutEscapedBytes(const void *s, size_t src_len);
48 };
49 
50 /// GDB remote packet as used by the reproducer and the GDB remote
51 /// communication history. Packets can be serialized to file.
53 
54  friend llvm::yaml::MappingTraits<GDBRemotePacket>;
55 
57 
61 
62  void Clear() {
63  packet.data.clear();
66  packet_idx = 0;
68  }
69 
70  struct BinaryData {
72  };
73 
74  void Dump(Stream &strm) const;
75 
81 
82 private:
83  llvm::StringRef GetTypeStr() const;
84 };
85 
86 namespace repro {
88 public:
89  PacketRecorder(const FileSpec &filename, std::error_code &ec)
90  : AbstractRecorder(filename, ec) {}
91 
92  static llvm::Expected<std::unique_ptr<PacketRecorder>>
93  Create(const FileSpec &filename);
94 
95  void Record(const GDBRemotePacket &packet);
96 };
97 
98 class GDBRemoteProvider : public repro::Provider<GDBRemoteProvider> {
99 public:
100  struct Info {
101  static const char *name;
102  static const char *file;
103  };
104 
105  GDBRemoteProvider(const FileSpec &directory) : Provider(directory) {}
106 
107  llvm::raw_ostream *GetHistoryStream();
109 
110  void SetCallback(std::function<void()> callback) {
111  m_callback = std::move(callback);
112  }
113 
114  void Keep() override;
115  void Discard() override;
116 
117  static char ID;
118 
119 private:
120  std::function<void()> m_callback;
121  std::unique_ptr<llvm::raw_fd_ostream> m_stream_up;
122  std::vector<std::unique_ptr<PacketRecorder>> m_packet_recorders;
123 };
124 
125 } // namespace repro
126 } // namespace lldb_private
127 
128 LLVM_YAML_IS_DOCUMENT_LIST_VECTOR(lldb_private::GDBRemotePacket)
129 LLVM_YAML_IS_DOCUMENT_LIST_VECTOR(std::vector<lldb_private::GDBRemotePacket>)
130 
131 namespace llvm {
132 namespace yaml {
133 
134 template <>
135 struct ScalarEnumerationTraits<lldb_private::GDBRemotePacket::Type> {
136  static void enumeration(IO &io, lldb_private::GDBRemotePacket::Type &value);
137 };
138 
139 template <> struct ScalarTraits<lldb_private::GDBRemotePacket::BinaryData> {
140  static void output(const lldb_private::GDBRemotePacket::BinaryData &, void *,
141  raw_ostream &);
142 
143  static StringRef input(StringRef, void *,
145 
146  static QuotingType mustQuote(StringRef S) { return QuotingType::None; }
147 };
148 
149 template <> struct MappingTraits<lldb_private::GDBRemotePacket> {
150  static void mapping(IO &io, lldb_private::GDBRemotePacket &Packet);
151 
152  static StringRef validate(IO &io, lldb_private::GDBRemotePacket &);
153 };
154 
155 } // namespace yaml
156 } // namespace llvm
157 
158 #endif // LLDB_UTILITY_GDBREMOTE_H
lldb-public.h
lldb_private::repro::GDBRemoteProvider::GetHistoryStream
llvm::raw_ostream * GetHistoryStream()
Definition: GDBRemote.cpp:149
llvm
Definition: Debugger.h:49
lldb_private::repro::GDBRemoteProvider::Info::file
static const char * file
Definition: GDBRemote.h:102
lldb_private::GDBRemotePacket::packet
BinaryData packet
Definition: GDBRemote.h:76
lldb_private::GDBRemotePacket::Dump
void Dump(Stream &strm) const
Definition: GDBRemote.cpp:61
lldb_private::repro::GDBRemoteProvider::Keep
void Keep() override
The Keep method is called when it is decided that we need to keep the data in order to provide a repr...
Definition: GDBRemote.cpp:99
lldb_private::repro::PacketRecorder::Record
void Record(const GDBRemotePacket &packet)
Definition: GDBRemote.cpp:141
lldb_private::GDBRemotePacket::packet_idx
uint32_t packet_idx
Definition: GDBRemote.h:79
lldb_private::repro::Provider
Definition: Reproducer.h:75
lldb_private::Stream
Definition: Stream.h:28
lldb_private::GDBRemotePacket::Type
Type
Definition: GDBRemote.h:56
lldb_private::repro::GDBRemoteProvider::GetNewPacketRecorder
PacketRecorder * GetNewPacketRecorder()
Definition: GDBRemote.cpp:125
ReproducerProvider.h
lldb_private::FileSpec
Definition: FileSpec.h:56
lldb_private::repro::GDBRemoteProvider::ID
static char ID
Definition: GDBRemote.h:117
StreamString.h
lldb_private::StreamString
Definition: StreamString.h:23
lldb_private::GDBRemotePacket::type
Type type
Definition: GDBRemote.h:77
lldb-enumerations.h
lldb_private::GDBRemotePacket::GetTypeStr
llvm::StringRef GetTypeStr() const
Definition: GDBRemote.cpp:49
lldb_private::repro::GDBRemoteProvider::m_packet_recorders
std::vector< std::unique_ptr< PacketRecorder > > m_packet_recorders
Definition: GDBRemote.h:122
lldb_private::repro::AbstractRecorder
The recorder is a small object handed out by a provider to record data.
Definition: ReproducerProvider.h:31
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:38
lldb_private::GDBRemotePacket::Clear
void Clear()
Definition: GDBRemote.h:62
lldb_private::repro::GDBRemoteProvider::m_callback
std::function< void()> m_callback
Definition: GDBRemote.h:120
lldb_private::GDBRemotePacket::ePacketTypeRecv
@ ePacketTypeRecv
Definition: GDBRemote.h:56
lldb_private::repro::GDBRemoteProvider::m_stream_up
std::unique_ptr< llvm::raw_fd_ostream > m_stream_up
Definition: GDBRemote.h:121
lldb_private::GDBRemotePacket::ePacketTypeSend
@ ePacketTypeSend
Definition: GDBRemote.h:56
uint32_t
lldb_private::repro::GDBRemoteProvider::GDBRemoteProvider
GDBRemoteProvider(const FileSpec &directory)
Definition: GDBRemote.h:105
lldb_private::GDBRemotePacket::GDBRemotePacket
GDBRemotePacket()
Definition: GDBRemote.h:58
lldb_private::StreamGDBRemote::StreamGDBRemote
StreamGDBRemote()
Definition: GDBRemote.cpp:21
lldb_private::GDBRemotePacket
GDB remote packet as used by the reproducer and the GDB remote communication history.
Definition: GDBRemote.h:52
lldb_private::GDBRemotePacket::tid
lldb::tid_t tid
Definition: GDBRemote.h:80
lldb_private::repro::GDBRemoteProvider::Info
Definition: GDBRemote.h:100
lldb_private::StreamGDBRemote
Definition: GDBRemote.h:27
lldb_private::GDBRemotePacket::bytes_transmitted
uint32_t bytes_transmitted
Definition: GDBRemote.h:78
llvm::yaml::ScalarTraits< lldb_private::GDBRemotePacket::BinaryData >::mustQuote
static QuotingType mustQuote(StringRef S)
Definition: GDBRemote.h:146
lldb_private::StreamGDBRemote::~StreamGDBRemote
~StreamGDBRemote() override
Definition: GDBRemote.cpp:27
lldb_private::repro::PacketRecorder::PacketRecorder
PacketRecorder(const FileSpec &filename, std::error_code &ec)
Definition: GDBRemote.h:89
lldb_private::GDBRemotePacket::ePacketTypeInvalid
@ ePacketTypeInvalid
Definition: GDBRemote.h:56
lldb_private::repro::PacketRecorder
Definition: GDBRemote.h:87
lldb_private::GDBRemotePacket::BinaryData
Definition: GDBRemote.h:70
lldb_private::repro::PacketRecorder::Create
static llvm::Expected< std::unique_ptr< PacketRecorder > > Create(const FileSpec &filename)
Definition: GDBRemote.cpp:117
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::StreamGDBRemote::PutEscapedBytes
int PutEscapedBytes(const void *s, size_t src_len)
Output a block of data to the stream performing GDB-remote escaping.
Definition: GDBRemote.cpp:29
FileSpec.h
lldb_private::repro::GDBRemoteProvider
Definition: GDBRemote.h:98
lldb_private::GDBRemotePacket::BinaryData::data
std::string data
Definition: GDBRemote.h:71
LLDB_INVALID_THREAD_ID
#define LLDB_INVALID_THREAD_ID
Definition: lldb-defines.h:93
lldb_private::repro::GDBRemoteProvider::Info::name
static const char * name
Definition: GDBRemote.h:101
lldb_private::repro::GDBRemoteProvider::SetCallback
void SetCallback(std::function< void()> callback)
Definition: GDBRemote.h:110
lldb::tid_t
uint64_t tid_t
Definition: lldb-types.h:86
lldb::ByteOrder
ByteOrder
Byte ordering definitions.
Definition: lldb-enumerations.h:138
lldb_private::repro::GDBRemoteProvider::Discard
void Discard() override
The Discard method is called when it is decided that we do not need to keep any information and will ...
Definition: GDBRemote.cpp:114