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(const void *s, size_t src_len) {
28 int bytes_written = 0;
29 const uint8_t *src = static_cast<const uint8_t *>(s);
30 bool binary_is_set = m_flags.Test(eBinary);
31 m_flags.Clear(eBinary);
32 while (src_len) {
33 uint8_t byte = *src;
34 src++;
35 src_len--;
36 if (byte == 0x23 || byte == 0x24 || byte == 0x7d || byte == 0x2a) {
37 bytes_written += PutChar(0x7d);
38 byte ^= 0x20;
39 }
40 bytes_written += PutChar(byte);
41 };
42 if (binary_is_set)
43 m_flags.Set(eBinary);
44 return bytes_written;
45}
46
47llvm::StringRef GDBRemotePacket::GetTypeStr() const {
48 switch (type) {
50 return "send";
52 return "read";
54 return "invalid";
55 }
56 llvm_unreachable("All enum cases should be handled");
57}
58
59void GDBRemotePacket::Dump(Stream &strm) const {
60 strm.Printf("tid=0x%4.4" PRIx64 " <%4u> %s packet: %s\n", tid,
61 bytes_transmitted, GetTypeStr().data(), packet.data.c_str());
62}
int PutEscapedBytes(const void *s, size_t src_len)
Output a block of data to the stream performing GDB-remote escaping.
Definition GDBRemote.cpp:27
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:132
size_t PutChar(char ch)
Definition Stream.cpp:129
@ 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:408
A class that represents a running process on the host machine.
ByteOrder
Byte ordering definitions.
void Dump(Stream &strm) const
Definition GDBRemote.cpp:59
llvm::StringRef GetTypeStr() const
Definition GDBRemote.cpp:47