1 //===-- GDBRemote.cpp -----------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "lldb/Utility/GDBRemote.h"
11 #include "lldb/Utility/Flags.h"
12 #include "lldb/Utility/Stream.h"
17 using namespace lldb_private
;
20 StreamGDBRemote::StreamGDBRemote() : StreamString() {}
22 StreamGDBRemote::StreamGDBRemote(uint32_t flags
, uint32_t addr_size
,
24 : StreamString(flags
, addr_size
, byte_order
) {}
26 StreamGDBRemote::~StreamGDBRemote() = default;
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
);
37 if (byte
== 0x23 || byte
== 0x24 || byte
== 0x7d || byte
== 0x2a) {
38 bytes_written
+= PutChar(0x7d);
41 bytes_written
+= PutChar(byte
);
48 llvm::StringRef
GDBRemotePacket::GetTypeStr() const {
50 case GDBRemotePacket::ePacketTypeSend
:
52 case GDBRemotePacket::ePacketTypeRecv
:
54 case GDBRemotePacket::ePacketTypeInvalid
:
57 llvm_unreachable("All enum cases should be handled");
60 void GDBRemotePacket::Dump(Stream
&strm
) const {
61 strm
.Printf("tid=0x%4.4" PRIx64
" <%4u> %s packet: %s\n", tid
,
62 bytes_transmitted
, GetTypeStr().data(), packet
.data
.c_str());