Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ff5225b

Browse files
committedSep 13, 2019
[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 llvm-svn: 371907
1 parent ae530c5 commit ff5225b

17 files changed

+237
-246
lines changed
 

‎lldb/include/lldb/Utility/GDBRemote.h

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
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 liblldb_GDBRemote_h_
10+
#define liblldb_GDBRemote_h_
11+
12+
#include "lldb/Utility/StreamString.h"
13+
#include "lldb/lldb-enumerations.h"
14+
#include "lldb/lldb-public.h"
15+
#include "llvm/Support/YAMLTraits.h"
16+
#include "llvm/Support/raw_ostream.h"
17+
18+
#include <stddef.h>
19+
#include <stdint.h>
20+
#include <string>
21+
#include <vector>
22+
23+
namespace lldb_private {
24+
25+
class StreamGDBRemote : public StreamString {
26+
public:
27+
StreamGDBRemote();
28+
29+
StreamGDBRemote(uint32_t flags, uint32_t addr_size,
30+
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+
48+
/// GDB remote packet as used by the reproducer and the GDB remote
49+
/// communication history. Packets can be serialized to file.
50+
struct GDBRemotePacket {
51+
52+
friend llvm::yaml::MappingTraits<GDBRemotePacket>;
53+
54+
enum Type { ePacketTypeInvalid = 0, ePacketTypeSend, ePacketTypeRecv };
55+
56+
GDBRemotePacket()
57+
: packet(), type(ePacketTypeInvalid), bytes_transmitted(0), packet_idx(0),
58+
tid(LLDB_INVALID_THREAD_ID) {}
59+
60+
void Clear() {
61+
packet.data.clear();
62+
type = ePacketTypeInvalid;
63+
bytes_transmitted = 0;
64+
packet_idx = 0;
65+
tid = LLDB_INVALID_THREAD_ID;
66+
}
67+
68+
struct BinaryData {
69+
std::string data;
70+
};
71+
72+
void Serialize(llvm::raw_ostream &strm) const;
73+
74+
BinaryData packet;
75+
Type type;
76+
uint32_t bytes_transmitted;
77+
uint32_t packet_idx;
78+
lldb::tid_t tid;
79+
};
80+
81+
} // namespace lldb_private
82+
83+
LLVM_YAML_IS_DOCUMENT_LIST_VECTOR(lldb_private::GDBRemotePacket)
84+
LLVM_YAML_IS_DOCUMENT_LIST_VECTOR(std::vector<lldb_private::GDBRemotePacket>)
85+
86+
namespace llvm {
87+
namespace yaml {
88+
89+
template <>
90+
struct ScalarEnumerationTraits<lldb_private::GDBRemotePacket::Type> {
91+
static void enumeration(IO &io, lldb_private::GDBRemotePacket::Type &value);
92+
};
93+
94+
template <> struct ScalarTraits<lldb_private::GDBRemotePacket::BinaryData> {
95+
static void output(const lldb_private::GDBRemotePacket::BinaryData &, void *,
96+
raw_ostream &);
97+
98+
static StringRef input(StringRef, void *,
99+
lldb_private::GDBRemotePacket::BinaryData &);
100+
101+
static QuotingType mustQuote(StringRef S) { return QuotingType::None; }
102+
};
103+
104+
template <> struct MappingTraits<lldb_private::GDBRemotePacket> {
105+
static void mapping(IO &io, lldb_private::GDBRemotePacket &Packet);
106+
107+
static StringRef validate(IO &io, lldb_private::GDBRemotePacket &);
108+
};
109+
110+
} // namespace yaml
111+
} // namespace llvm
112+
113+
#endif // liblldb_GDBRemote_h_

‎lldb/include/lldb/Utility/Reproducer.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#define LLDB_UTILITY_REPRODUCER_H
1111

1212
#include "lldb/Utility/FileSpec.h"
13-
1413
#include "llvm/ADT/DenseMap.h"
1514
#include "llvm/Support/Error.h"
1615
#include "llvm/Support/FileCollector.h"

‎lldb/include/lldb/Utility/StreamGDBRemote.h

Lines changed: 0 additions & 45 deletions
This file was deleted.

‎lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,7 @@ size_t GDBRemoteCommunication::SendAck() {
103103
char ch = '+';
104104
const size_t bytes_written = Write(&ch, 1, status, nullptr);
105105
LLDB_LOGF(log, "<%4" PRIu64 "> send packet: %c", (uint64_t)bytes_written, ch);
106-
m_history.AddPacket(ch, GDBRemoteCommunicationHistory::ePacketTypeSend,
107-
bytes_written);
106+
m_history.AddPacket(ch, GDBRemotePacket::ePacketTypeSend, bytes_written);
108107
return bytes_written;
109108
}
110109

@@ -114,8 +113,7 @@ size_t GDBRemoteCommunication::SendNack() {
114113
char ch = '-';
115114
const size_t bytes_written = Write(&ch, 1, status, nullptr);
116115
LLDB_LOGF(log, "<%4" PRIu64 "> send packet: %c", (uint64_t)bytes_written, ch);
117-
m_history.AddPacket(ch, GDBRemoteCommunicationHistory::ePacketTypeSend,
118-
bytes_written);
116+
m_history.AddPacket(ch, GDBRemotePacket::ePacketTypeSend, bytes_written);
119117
return bytes_written;
120118
}
121119

@@ -178,8 +176,7 @@ GDBRemoteCommunication::SendRawPacketNoLock(llvm::StringRef packet,
178176
}
179177

180178
m_history.AddPacket(packet.str(), packet_length,
181-
GDBRemoteCommunicationHistory::ePacketTypeSend,
182-
bytes_written);
179+
GDBRemotePacket::ePacketTypeSend, bytes_written);
183180

184181
if (bytes_written == packet_length) {
185182
if (!skip_ack && GetSendAcks())
@@ -809,8 +806,7 @@ GDBRemoteCommunication::CheckForPacket(const uint8_t *src, size_t src_len,
809806
}
810807

811808
m_history.AddPacket(m_bytes, total_length,
812-
GDBRemoteCommunicationHistory::ePacketTypeRecv,
813-
total_length);
809+
GDBRemotePacket::ePacketTypeRecv, total_length);
814810

815811
// Copy the packet from m_bytes to packet_str expanding the run-length
816812
// encoding in the process. Reserve enough byte for the most common case

‎lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include <vector>
1919

2020
#include "lldb/Utility/ArchSpec.h"
21-
#include "lldb/Utility/StreamGDBRemote.h"
21+
#include "lldb/Utility/GDBRemote.h"
2222
#include "lldb/Utility/StructuredData.h"
2323
#if defined(_WIN32)
2424
#include "lldb/Host/windows/PosixApi.h"

‎lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationHistory.cpp

Lines changed: 14 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,6 @@ using namespace lldb;
1818
using namespace lldb_private;
1919
using namespace lldb_private::process_gdb_remote;
2020

21-
void GDBRemoteCommunicationHistory::Entry::Serialize(raw_ostream &strm) const {
22-
yaml::Output yout(strm);
23-
yout << const_cast<GDBRemoteCommunicationHistory::Entry &>(*this);
24-
strm.flush();
25-
}
26-
2721
GDBRemoteCommunicationHistory::GDBRemoteCommunicationHistory(uint32_t size)
2822
: m_packets(), m_curr_idx(0), m_total_packet_count(0),
2923
m_dumped_to_log(false) {
@@ -33,7 +27,8 @@ GDBRemoteCommunicationHistory::GDBRemoteCommunicationHistory(uint32_t size)
3327

3428
GDBRemoteCommunicationHistory::~GDBRemoteCommunicationHistory() {}
3529

36-
void GDBRemoteCommunicationHistory::AddPacket(char packet_char, PacketType type,
30+
void GDBRemoteCommunicationHistory::AddPacket(char packet_char,
31+
GDBRemotePacket::Type type,
3732
uint32_t bytes_transmitted) {
3833
const size_t size = m_packets.size();
3934
if (size == 0)
@@ -50,7 +45,8 @@ void GDBRemoteCommunicationHistory::AddPacket(char packet_char, PacketType type,
5045
}
5146

5247
void GDBRemoteCommunicationHistory::AddPacket(const std::string &src,
53-
uint32_t src_len, PacketType type,
48+
uint32_t src_len,
49+
GDBRemotePacket::Type type,
5450
uint32_t bytes_transmitted) {
5551
const size_t size = m_packets.size();
5652
if (size == 0)
@@ -72,12 +68,14 @@ void GDBRemoteCommunicationHistory::Dump(Stream &strm) const {
7268
const uint32_t stop_idx = m_curr_idx + size;
7369
for (uint32_t i = first_idx; i < stop_idx; ++i) {
7470
const uint32_t idx = NormalizeIndex(i);
75-
const Entry &entry = m_packets[idx];
76-
if (entry.type == ePacketTypeInvalid || entry.packet.data.empty())
71+
const GDBRemotePacket &entry = m_packets[idx];
72+
if (entry.type == GDBRemotePacket::ePacketTypeInvalid ||
73+
entry.packet.data.empty())
7774
break;
7875
strm.Printf("history[%u] tid=0x%4.4" PRIx64 " <%4u> %s packet: %s\n",
7976
entry.packet_idx, entry.tid, entry.bytes_transmitted,
80-
(entry.type == ePacketTypeSend) ? "send" : "read",
77+
(entry.type == GDBRemotePacket::ePacketTypeSend) ? "send"
78+
: "read",
8179
entry.packet.data.c_str());
8280
}
8381
}
@@ -92,51 +90,15 @@ void GDBRemoteCommunicationHistory::Dump(Log *log) const {
9290
const uint32_t stop_idx = m_curr_idx + size;
9391
for (uint32_t i = first_idx; i < stop_idx; ++i) {
9492
const uint32_t idx = NormalizeIndex(i);
95-
const Entry &entry = m_packets[idx];
96-
if (entry.type == ePacketTypeInvalid || entry.packet.data.empty())
93+
const GDBRemotePacket &entry = m_packets[idx];
94+
if (entry.type == GDBRemotePacket::ePacketTypeInvalid ||
95+
entry.packet.data.empty())
9796
break;
9897
LLDB_LOGF(log, "history[%u] tid=0x%4.4" PRIx64 " <%4u> %s packet: %s",
9998
entry.packet_idx, entry.tid, entry.bytes_transmitted,
100-
(entry.type == ePacketTypeSend) ? "send" : "read",
99+
(entry.type == GDBRemotePacket::ePacketTypeSend) ? "send"
100+
: "read",
101101
entry.packet.data.c_str());
102102
}
103103
}
104104

105-
void yaml::ScalarEnumerationTraits<GDBRemoteCommunicationHistory::PacketType>::
106-
enumeration(IO &io, GDBRemoteCommunicationHistory::PacketType &value) {
107-
io.enumCase(value, "Invalid",
108-
GDBRemoteCommunicationHistory::ePacketTypeInvalid);
109-
io.enumCase(value, "Send", GDBRemoteCommunicationHistory::ePacketTypeSend);
110-
io.enumCase(value, "Recv", GDBRemoteCommunicationHistory::ePacketTypeRecv);
111-
}
112-
113-
void yaml::ScalarTraits<GDBRemoteCommunicationHistory::Entry::BinaryData>::
114-
output(const GDBRemoteCommunicationHistory::Entry::BinaryData &Val, void *,
115-
raw_ostream &Out) {
116-
Out << toHex(Val.data);
117-
}
118-
119-
StringRef
120-
yaml::ScalarTraits<GDBRemoteCommunicationHistory::Entry::BinaryData>::input(
121-
StringRef Scalar, void *,
122-
GDBRemoteCommunicationHistory::Entry::BinaryData &Val) {
123-
Val.data = fromHex(Scalar);
124-
return {};
125-
}
126-
127-
void yaml::MappingTraits<GDBRemoteCommunicationHistory::Entry>::mapping(
128-
IO &io, GDBRemoteCommunicationHistory::Entry &Entry) {
129-
io.mapRequired("packet", Entry.packet);
130-
io.mapRequired("type", Entry.type);
131-
io.mapRequired("bytes", Entry.bytes_transmitted);
132-
io.mapRequired("index", Entry.packet_idx);
133-
io.mapRequired("tid", Entry.tid);
134-
}
135-
136-
StringRef yaml::MappingTraits<GDBRemoteCommunicationHistory::Entry>::validate(
137-
IO &io, GDBRemoteCommunicationHistory::Entry &Entry) {
138-
if (Entry.bytes_transmitted != Entry.packet.data.size())
139-
return "BinaryData size doesn't match bytes transmitted";
140-
141-
return {};
142-
}

‎lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationHistory.h

Lines changed: 6 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <string>
1313
#include <vector>
1414

15+
#include "lldb/Utility/GDBRemote.h"
1516
#include "lldb/lldb-public.h"
1617
#include "llvm/Support/YAMLTraits.h"
1718
#include "llvm/Support/raw_ostream.h"
@@ -25,46 +26,17 @@ class GDBRemoteCommunicationHistory {
2526
public:
2627
friend llvm::yaml::MappingTraits<GDBRemoteCommunicationHistory>;
2728

28-
enum PacketType { ePacketTypeInvalid = 0, ePacketTypeSend, ePacketTypeRecv };
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 {
33-
Entry()
34-
: packet(), type(ePacketTypeInvalid), bytes_transmitted(0),
35-
packet_idx(0), tid(LLDB_INVALID_THREAD_ID) {}
36-
37-
void Clear() {
38-
packet.data.clear();
39-
type = ePacketTypeInvalid;
40-
bytes_transmitted = 0;
41-
packet_idx = 0;
42-
tid = LLDB_INVALID_THREAD_ID;
43-
}
44-
45-
struct BinaryData {
46-
std::string data;
47-
};
48-
49-
void Serialize(llvm::raw_ostream &strm) const;
50-
51-
BinaryData packet;
52-
PacketType type;
53-
uint32_t bytes_transmitted;
54-
uint32_t packet_idx;
55-
lldb::tid_t tid;
56-
};
57-
5829
GDBRemoteCommunicationHistory(uint32_t size = 0);
5930

6031
~GDBRemoteCommunicationHistory();
6132

6233
// 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,
34+
void AddPacket(char packet_char, GDBRemotePacket::Type type,
6635
uint32_t bytes_transmitted);
6736

37+
void AddPacket(const std::string &src, uint32_t src_len,
38+
GDBRemotePacket::Type type, uint32_t bytes_transmitted);
39+
6840
void Dump(Stream &strm) const;
6941
void Dump(Log *log) const;
7042
bool DidDumpToLog() const { return m_dumped_to_log; }
@@ -97,7 +69,7 @@ class GDBRemoteCommunicationHistory {
9769
return m_packets.empty() ? 0 : i % m_packets.size();
9870
}
9971

100-
std::vector<Entry> m_packets;
72+
std::vector<GDBRemotePacket> m_packets;
10173
uint32_t m_curr_idx;
10274
uint32_t m_total_packet_count;
10375
mutable bool m_dumped_to_log;
@@ -107,49 +79,4 @@ class GDBRemoteCommunicationHistory {
10779
} // namespace process_gdb_remote
10880
} // namespace lldb_private
10981

110-
LLVM_YAML_IS_DOCUMENT_LIST_VECTOR(
111-
lldb_private::process_gdb_remote::GDBRemoteCommunicationHistory::Entry)
112-
113-
namespace llvm {
114-
namespace yaml {
115-
116-
template <>
117-
struct ScalarEnumerationTraits<lldb_private::process_gdb_remote::
118-
GDBRemoteCommunicationHistory::PacketType> {
119-
static void enumeration(IO &io,
120-
lldb_private::process_gdb_remote::
121-
GDBRemoteCommunicationHistory::PacketType &value);
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 *,
133-
lldb_private::process_gdb_remote::GDBRemoteCommunicationHistory::Entry::
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,
144-
lldb_private::process_gdb_remote::GDBRemoteCommunicationHistory::Entry
145-
&Entry);
146-
147-
static StringRef validate(
148-
IO &io,
149-
lldb_private::process_gdb_remote::GDBRemoteCommunicationHistory::Entry &);
150-
};
151-
152-
} // namespace yaml
153-
} // namespace llvm
154-
15582
#endif // liblldb_GDBRemoteCommunicationHistory_h_

‎lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationReplayServer.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,15 @@ GDBRemoteCommunicationReplayServer::GetPacketAndSendResponse(
128128
Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS));
129129
while (!m_packet_history.empty()) {
130130
// Pop last packet from the history.
131-
GDBRemoteCommunicationHistory::Entry entry = m_packet_history.back();
131+
GDBRemotePacket entry = m_packet_history.back();
132132
m_packet_history.pop_back();
133133

134134
// We've handled the handshake implicitly before. Skip the packet and move
135135
// on.
136136
if (entry.packet.data == "+")
137137
continue;
138138

139-
if (entry.type == GDBRemoteCommunicationHistory::ePacketTypeSend) {
139+
if (entry.type == GDBRemotePacket::ePacketTypeSend) {
140140
if (unexpected(entry.packet.data, packet.GetStringRef())) {
141141
LLDB_LOG(log,
142142
"GDBRemoteCommunicationReplayServer expected packet: '{0}'",
@@ -150,14 +150,14 @@ GDBRemoteCommunicationReplayServer::GetPacketAndSendResponse(
150150
// Ignore QEnvironment packets as they're handled earlier.
151151
if (entry.packet.data.find("QEnvironment") == 1) {
152152
assert(m_packet_history.back().type ==
153-
GDBRemoteCommunicationHistory::ePacketTypeRecv);
153+
GDBRemotePacket::ePacketTypeRecv);
154154
m_packet_history.pop_back();
155155
}
156156

157157
continue;
158158
}
159159

160-
if (entry.type == GDBRemoteCommunicationHistory::ePacketTypeInvalid) {
160+
if (entry.type == GDBRemotePacket::ePacketTypeInvalid) {
161161
LLDB_LOG(
162162
log,
163163
"GDBRemoteCommunicationReplayServer skipped invalid packet: '{0}'",
@@ -176,10 +176,6 @@ GDBRemoteCommunicationReplayServer::GetPacketAndSendResponse(
176176
return packet_result;
177177
}
178178

179-
LLVM_YAML_IS_DOCUMENT_LIST_VECTOR(
180-
std::vector<
181-
lldb_private::process_gdb_remote::GDBRemoteCommunicationHistory::Entry>)
182-
183179
llvm::Error
184180
GDBRemoteCommunicationReplayServer::LoadReplayHistory(const FileSpec &path) {
185181
auto error_or_file = MemoryBuffer::getFile(path.GetPath());

‎lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationReplayServer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class GDBRemoteCommunicationReplayServer : public GDBRemoteCommunication {
6262
static lldb::thread_result_t AsyncThread(void *arg);
6363

6464
/// Replay history with the oldest packet at the end.
65-
std::vector<GDBRemoteCommunicationHistory::Entry> m_packet_history;
65+
std::vector<GDBRemotePacket> m_packet_history;
6666

6767
/// Server thread.
6868
Broadcaster m_async_broadcaster;

‎lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@
2929
#include "lldb/Symbol/ObjectFile.h"
3030
#include "lldb/Target/Platform.h"
3131
#include "lldb/Utility/Endian.h"
32+
#include "lldb/Utility/GDBRemote.h"
3233
#include "lldb/Utility/JSON.h"
3334
#include "lldb/Utility/Log.h"
34-
#include "lldb/Utility/StreamGDBRemote.h"
3535
#include "lldb/Utility/StreamString.h"
3636
#include "lldb/Utility/StructuredData.h"
3737
#include "llvm/ADT/Triple.h"

‎lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include "lldb/Host/Config.h"
1212

1313
#include "GDBRemoteCommunicationServerLLGS.h"
14-
#include "lldb/Utility/StreamGDBRemote.h"
14+
#include "lldb/Utility/GDBRemote.h"
1515

1616
#include <chrono>
1717
#include <cstring>

‎lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727
#include "lldb/Host/HostInfo.h"
2828
#include "lldb/Target/Platform.h"
2929
#include "lldb/Target/UnixSignals.h"
30+
#include "lldb/Utility/GDBRemote.h"
3031
#include "lldb/Utility/JSON.h"
3132
#include "lldb/Utility/Log.h"
32-
#include "lldb/Utility/StreamGDBRemote.h"
3333
#include "lldb/Utility/StreamString.h"
3434
#include "lldb/Utility/StructuredData.h"
3535
#include "lldb/Utility/UriParser.h"

‎lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
#include "lldb/Utility/ArchSpec.h"
2525
#include "lldb/Utility/Broadcaster.h"
2626
#include "lldb/Utility/ConstString.h"
27+
#include "lldb/Utility/GDBRemote.h"
2728
#include "lldb/Utility/Status.h"
28-
#include "lldb/Utility/StreamGDBRemote.h"
2929
#include "lldb/Utility/StreamString.h"
3030
#include "lldb/Utility/StringExtractor.h"
3131
#include "lldb/Utility/StringList.h"

‎lldb/source/Utility/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ add_lldb_library(lldbUtility
2525
Environment.cpp
2626
Event.cpp
2727
FileSpec.cpp
28+
GDBRemote.cpp
2829
IOObject.cpp
2930
JSON.cpp
3031
LLDBAssert.cpp
@@ -44,7 +45,6 @@ add_lldb_library(lldbUtility
4445
Status.cpp
4546
Stream.cpp
4647
StreamCallback.cpp
47-
StreamGDBRemote.cpp
4848
StreamString.cpp
4949
StringExtractor.cpp
5050
StringExtractorGDBRemote.cpp

‎lldb/source/Utility/GDBRemote.cpp

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
//===-- GDBRemote.cpp -----------------------------------------------------===//
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+
#include "lldb/Utility/GDBRemote.h"
10+
11+
#include "lldb/Utility/Flags.h"
12+
#include "lldb/Utility/Stream.h"
13+
14+
#include <stdio.h>
15+
16+
using namespace lldb;
17+
using namespace lldb_private;
18+
using namespace llvm;
19+
20+
StreamGDBRemote::StreamGDBRemote() : StreamString() {}
21+
22+
StreamGDBRemote::StreamGDBRemote(uint32_t flags, uint32_t addr_size,
23+
ByteOrder byte_order)
24+
: StreamString(flags, addr_size, byte_order) {}
25+
26+
StreamGDBRemote::~StreamGDBRemote() {}
27+
28+
int StreamGDBRemote::PutEscapedBytes(const void *s, size_t src_len) {
29+
int bytes_written = 0;
30+
const uint8_t *src = static_cast<const uint8_t *>(s);
31+
bool binary_is_set = m_flags.Test(eBinary);
32+
m_flags.Clear(eBinary);
33+
while (src_len) {
34+
uint8_t byte = *src;
35+
src++;
36+
src_len--;
37+
if (byte == 0x23 || byte == 0x24 || byte == 0x7d || byte == 0x2a) {
38+
bytes_written += PutChar(0x7d);
39+
byte ^= 0x20;
40+
}
41+
bytes_written += PutChar(byte);
42+
};
43+
if (binary_is_set)
44+
m_flags.Set(eBinary);
45+
return bytes_written;
46+
}
47+
48+
void GDBRemotePacket::Serialize(raw_ostream &strm) const {
49+
yaml::Output yout(strm);
50+
yout << const_cast<GDBRemotePacket &>(*this);
51+
strm.flush();
52+
}
53+
54+
void yaml::ScalarEnumerationTraits<GDBRemotePacket::Type>::enumeration(
55+
IO &io, GDBRemotePacket::Type &value) {
56+
io.enumCase(value, "Invalid", GDBRemotePacket::ePacketTypeInvalid);
57+
io.enumCase(value, "Send", GDBRemotePacket::ePacketTypeSend);
58+
io.enumCase(value, "Recv", GDBRemotePacket::ePacketTypeRecv);
59+
}
60+
61+
void yaml::ScalarTraits<GDBRemotePacket::BinaryData>::output(
62+
const GDBRemotePacket::BinaryData &Val, void *, raw_ostream &Out) {
63+
Out << toHex(Val.data);
64+
}
65+
66+
StringRef yaml::ScalarTraits<GDBRemotePacket::BinaryData>::input(
67+
StringRef Scalar, void *, GDBRemotePacket::BinaryData &Val) {
68+
Val.data = fromHex(Scalar);
69+
return {};
70+
}
71+
72+
void yaml::MappingTraits<GDBRemotePacket>::mapping(IO &io,
73+
GDBRemotePacket &Packet) {
74+
io.mapRequired("packet", Packet.packet);
75+
io.mapRequired("type", Packet.type);
76+
io.mapRequired("bytes", Packet.bytes_transmitted);
77+
io.mapRequired("index", Packet.packet_idx);
78+
io.mapRequired("tid", Packet.tid);
79+
}
80+
81+
StringRef
82+
yaml::MappingTraits<GDBRemotePacket>::validate(IO &io,
83+
GDBRemotePacket &Packet) {
84+
if (Packet.bytes_transmitted != Packet.packet.data.size())
85+
return "BinaryData size doesn't match bytes transmitted";
86+
87+
return {};
88+
}

‎lldb/source/Utility/StreamGDBRemote.cpp

Lines changed: 0 additions & 45 deletions
This file was deleted.

‎lldb/unittests/Process/gdb-remote/GDBRemoteClientBaseTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include "Plugins/Process/Utility/LinuxSignals.h"
1313
#include "Plugins/Process/gdb-remote/GDBRemoteClientBase.h"
1414
#include "Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h"
15-
#include "lldb/Utility/StreamGDBRemote.h"
15+
#include "lldb/Utility/GDBRemote.h"
1616
#include "llvm/ADT/STLExtras.h"
1717
#include "llvm/Testing/Support/Error.h"
1818

0 commit comments

Comments
 (0)
Please sign in to comment.