]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm-project/lldb/source/Utility/StreamGDBRemote.cpp
Unbreak DRM KMS build by adding the needed compatibility field in the LinuxKPI.
[FreeBSD/FreeBSD.git] / contrib / llvm-project / lldb / source / Utility / StreamGDBRemote.cpp
1 //===-- StreamGDBRemote.cpp -------------------------------------*- 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 #include "lldb/Utility/StreamGDBRemote.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
19 StreamGDBRemote::StreamGDBRemote() : StreamString() {}
20
21 StreamGDBRemote::StreamGDBRemote(uint32_t flags, uint32_t addr_size,
22                                  ByteOrder byte_order)
23     : StreamString(flags, addr_size, byte_order) {}
24
25 StreamGDBRemote::~StreamGDBRemote() {}
26
27 int 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 }