LLDB mainline
GDBRemote.cpp
Go to the documentation of this file.
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
10
11#include "lldb/Utility/Flags.h"
12#include "lldb/Utility/Stream.h"
13
14#include <cstdio>
15
16using namespace lldb;
17using namespace lldb_private;
18using namespace llvm;
19
21
23 : StreamString(flags, byte_order) {}
24
26
27int StreamGDBRemote::PutEscapedBytes(llvm::StringRef str) {
28 return PutEscapedBytes(str.data(), str.size());
29}
30
31int StreamGDBRemote::PutEscapedBytes(const void *s, size_t src_len) {
32 int bytes_written = 0;
33 const uint8_t *src = static_cast<const uint8_t *>(s);
34 bool binary_is_set = m_flags.Test(eBinary);
35 m_flags.Clear(eBinary);
36 while (src_len) {
37 uint8_t byte = *src;
38 src++;
39 src_len--;
40 if (byte == 0x23 || byte == 0x24 || byte == 0x7d || byte == 0x2a) {
41 bytes_written += PutChar(0x7d);
42 byte ^= 0x20;
43 }
44 bytes_written += PutChar(byte);
45 };
46 if (binary_is_set)
47 m_flags.Set(eBinary);
48 return bytes_written;
49}
50
51llvm::StringRef GDBRemotePacket::GetTypeStr() const {
52 switch (type) {
54 return "send";
56 return "read";
58 return "invalid";
59 }
60 llvm_unreachable("All enum cases should be handled");
61}
62
63void GDBRemotePacket::Dump(Stream &strm) const {
64 strm.Printf("tid=0x%4.4" PRIx64 " <%4u> %s packet: %s\n", tid,
65 bytes_transmitted, GetTypeStr().data(), packet.data.c_str());
66}
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
StreamString(bool colors=false)
A stream class that can stream formatted output to a file.
Definition Stream.h:28
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition Stream.cpp:134
size_t PutChar(char ch)
Definition Stream.cpp:131
@ eBinary
Get and put data as binary instead of as the default string mode.
Definition Stream.h:32
Flags m_flags
Dump flags.
Definition Stream.h:411
A class that represents a running process on the host machine.
ByteOrder
Byte ordering definitions.
void Dump(Stream &strm) const
Definition GDBRemote.cpp:63
llvm::StringRef GetTypeStr() const
Definition GDBRemote.cpp:51