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 ByteOrder byte_order)
24 : StreamString(flags, addr_size, byte_order) {}
25
27
28int 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);
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)
45 return bytes_written;
46}
47
48llvm::StringRef GDBRemotePacket::GetTypeStr() const {
49 switch (type) {
51 return "send";
53 return "read";
55 return "invalid";
56 }
57 llvm_unreachable("All enum cases should be handled");
58}
59
60void 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());
63}
ValueType Clear(ValueType mask=~static_cast< ValueType >(0))
Clear one or more flags.
Definition: Flags.h:61
bool Test(ValueType bit) const
Test a single flag bit.
Definition: Flags.h:96
ValueType Set(ValueType mask)
Set one or more flags by logical OR'ing mask with the current flags.
Definition: Flags.h:73
int PutEscapedBytes(const void *s, size_t src_len)
Output a block of data to the stream performing GDB-remote escaping.
Definition: GDBRemote.cpp:28
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:107
size_t PutChar(char ch)
Definition: Stream.cpp:104
@ 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:363
A class that represents a running process on the host machine.
Definition: SBAddress.h:15
ByteOrder
Byte ordering definitions.
Definition: Debugger.h:51
void Dump(Stream &strm) const
Definition: GDBRemote.cpp:60
llvm::StringRef GetTypeStr() const
Definition: GDBRemote.cpp:48