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
15#include "lldb/lldb-public.h"
16#include "llvm/Support/JSON.h"
17#include "llvm/Support/raw_ostream.h"
18
19#include <cstddef>
20#include <cstdint>
21#include <string>
22#include <vector>
23
24namespace lldb_private {
25
27public:
29
30 StreamGDBRemote(uint32_t flags, lldb::ByteOrder byte_order);
31
32 ~StreamGDBRemote() override;
33
34 /// Output a block of data to the stream performing GDB-remote escaping.
35 ///
36 /// \param[in] s
37 /// A block of data.
38 ///
39 /// \param[in] src_len
40 /// The amount of data to write.
41 ///
42 /// \return
43 /// Number of bytes written.
44 // TODO: Convert this function to take ArrayRef<uint8_t>
45 int PutEscapedBytes(const void *s, size_t src_len);
46
47 /// Equivalent to PutEscapedBytes(str.data(), str.size());
48 int PutEscapedBytes(llvm::StringRef str);
49
50 template <class T> int PutAsJSON(const T &obj, bool hex_ascii) {
51 std::string json_string;
52 llvm::raw_string_ostream os(json_string);
53 os << llvm::json::Value(toJSON(obj));
54 if (hex_ascii)
55 return PutStringAsRawHex8(json_string);
56 return PutEscapedBytes(json_string.c_str(), json_string.size());
57 }
58
59 template <class T>
60 int PutAsJSONArray(const std::vector<T> &array, bool hex_ascii) {
61 llvm::json::Array json_array;
62 for (const auto &obj : array)
63 json_array.push_back(toJSON(obj));
64 std::string json_string;
65 llvm::raw_string_ostream os(json_string);
66 os << llvm::json::Value(std::move(json_array));
67 if (hex_ascii)
68 return PutStringAsRawHex8(json_string);
69 return PutEscapedBytes(json_string.data(), json_string.size());
70 }
71};
72
73/// GDB remote packet as used by the GDB remote communication history. Packets
74/// can be serialized to file.
76
78
79 GDBRemotePacket() = default;
80
81 void Clear() {
82 packet.data.clear();
85 packet_idx = 0;
87 }
88
89 struct BinaryData {
90 std::string data;
91 };
92
93 void Dump(Stream &strm) const;
94
97 uint32_t bytes_transmitted = 0;
98 uint32_t packet_idx = 0;
100
101private:
102 llvm::StringRef GetTypeStr() const;
103};
104
105} // namespace lldb_private
106
107#endif // LLDB_UTILITY_GDBREMOTE_H
int PutAsJSON(const T &obj, bool hex_ascii)
Definition GDBRemote.h:50
int PutEscapedBytes(const void *s, size_t src_len)
Output a block of data to the stream performing GDB-remote escaping.
Definition GDBRemote.cpp:31
int PutAsJSONArray(const std::vector< T > &array, bool hex_ascii)
Definition GDBRemote.h:60
StreamString(bool colors=false)
A stream class that can stream formatted output to a file.
Definition Stream.h:28
size_t PutStringAsRawHex8(llvm::StringRef s)
Definition Stream.cpp:418
#define LLDB_INVALID_THREAD_ID
A class that represents a running process on the host machine.
llvm::json::Value toJSON(const AcceleratorActions &data)
ByteOrder
Byte ordering definitions.
uint64_t tid_t
Definition lldb-types.h:84
void Dump(Stream &strm) const
Definition GDBRemote.cpp:63
llvm::StringRef GetTypeStr() const
Definition GDBRemote.cpp:51