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 
59 
60  void Clear() {
61  packet.data.clear();
64  packet_idx = 0;
66  }
67 
68  struct BinaryData {
70  };
71 
72  void Dump(Stream &strm) const;
73 
79 
80 private:
81  llvm::StringRef GetTypeStr() const;
82 };
83 
84 namespace repro {
86 public:
87  PacketRecorder(const FileSpec &filename, std::error_code &ec)
88  : AbstractRecorder(filename, ec) {}
89 
90  static llvm::Expected<std::unique_ptr<PacketRecorder>>
91  Create(const FileSpec &filename);
92 
93  void Record(const GDBRemotePacket &packet);
94 };
95 
96 class GDBRemoteProvider : public repro::Provider<GDBRemoteProvider> {
97 public:
98  struct Info {
99  static const char *name;
100  static const char *file;
101  };
102 
103  GDBRemoteProvider(const FileSpec &directory) : Provider(directory) {}
104 
105  llvm::raw_ostream *GetHistoryStream();
107 
108  void SetCallback(std::function<void()> callback) {
109  m_callback = std::move(callback);
110  }
111 
112  void Keep() override;
113  void Discard() override;
114 
115  static char ID;
116 
117 private:
118  std::function<void()> m_callback;
119  std::unique_ptr<llvm::raw_fd_ostream> m_stream_up;
120  std::vector<std::unique_ptr<PacketRecorder>> m_packet_recorders;
121 };
122 
123 } // namespace repro
124 } // namespace lldb_private
125 
126 LLVM_YAML_IS_DOCUMENT_LIST_VECTOR(lldb_private::GDBRemotePacket)
127 LLVM_YAML_IS_DOCUMENT_LIST_VECTOR(std::vector<lldb_private::GDBRemotePacket>)
128 
129 namespace llvm {
130 namespace yaml {
131 
132 template <>
133 struct ScalarEnumerationTraits<lldb_private::GDBRemotePacket::Type> {
134  static void enumeration(IO &io, lldb_private::GDBRemotePacket::Type &value);
135 };
136 
137 template <> struct ScalarTraits<lldb_private::GDBRemotePacket::BinaryData> {
138  static void output(const lldb_private::GDBRemotePacket::BinaryData &, void *,
139  raw_ostream &);
140 
141  static StringRef input(StringRef, void *,
143 
144  static QuotingType mustQuote(StringRef S) { return QuotingType::None; }
145 };
146 
147 template <> struct MappingTraits<lldb_private::GDBRemotePacket> {
148  static void mapping(IO &io, lldb_private::GDBRemotePacket &Packet);
149 
150  static StringRef validate(IO &io, lldb_private::GDBRemotePacket &);
151 };
152 
153 } // namespace yaml
154 } // namespace llvm
155 
156 #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:100
lldb_private::GDBRemotePacket::packet
BinaryData packet
Definition: GDBRemote.h:74
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:77
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:115
StreamString.h
lldb_private::StreamString
Definition: StreamString.h:23
lldb_private::GDBRemotePacket::type
Type type
Definition: GDBRemote.h:75
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:120
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:40
lldb_private::GDBRemotePacket::Clear
void Clear()
Definition: GDBRemote.h:60
lldb_private::repro::GDBRemoteProvider::m_callback
std::function< void()> m_callback
Definition: GDBRemote.h:118
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:119
lldb_private::GDBRemotePacket::ePacketTypeSend
@ ePacketTypeSend
Definition: GDBRemote.h:56
uint32_t
lldb_private::repro::GDBRemoteProvider::GDBRemoteProvider
GDBRemoteProvider(const FileSpec &directory)
Definition: GDBRemote.h:103
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:78
lldb_private::repro::GDBRemoteProvider::Info
Definition: GDBRemote.h:98
lldb_private::StreamGDBRemote
Definition: GDBRemote.h:27
lldb_private::GDBRemotePacket::bytes_transmitted
uint32_t bytes_transmitted
Definition: GDBRemote.h:76
llvm::yaml::ScalarTraits< lldb_private::GDBRemotePacket::BinaryData >::mustQuote
static QuotingType mustQuote(StringRef S)
Definition: GDBRemote.h:144
lldb_private::StreamGDBRemote::~StreamGDBRemote
~StreamGDBRemote() override
lldb_private::repro::PacketRecorder::PacketRecorder
PacketRecorder(const FileSpec &filename, std::error_code &ec)
Definition: GDBRemote.h:87
lldb_private::GDBRemotePacket::ePacketTypeInvalid
@ ePacketTypeInvalid
Definition: GDBRemote.h:56
lldb_private::repro::PacketRecorder
Definition: GDBRemote.h:85
lldb_private::GDBRemotePacket::BinaryData
Definition: GDBRemote.h:68
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:96
lldb_private::GDBRemotePacket::BinaryData::data
std::string data
Definition: GDBRemote.h:69
LLDB_INVALID_THREAD_ID
#define LLDB_INVALID_THREAD_ID
Definition: lldb-defines.h:94
lldb_private::repro::GDBRemoteProvider::Info::name
static const char * name
Definition: GDBRemote.h:99
lldb_private::repro::GDBRemoteProvider::SetCallback
void SetCallback(std::function< void()> callback)
Definition: GDBRemote.h:108
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