]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - contrib/llvm/tools/lldb/source/Core/StreamGDBRemote.cpp
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.git] / contrib / llvm / tools / lldb / source / Core / StreamGDBRemote.cpp
1 //===-- StreamGDBRemote.cpp -------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #include "lldb/Core/StreamGDBRemote.h"
11 #include <stdio.h>
12
13 using namespace lldb;
14 using namespace lldb_private;
15
16 StreamGDBRemote::StreamGDBRemote () :
17 StreamString ()
18 {
19 }
20
21 StreamGDBRemote::StreamGDBRemote(uint32_t flags, uint32_t addr_size, ByteOrder byte_order) :
22 StreamString (flags, addr_size, byte_order)
23 {
24 }
25
26 StreamGDBRemote::~StreamGDBRemote()
27 {
28 }
29
30
31 int
32 StreamGDBRemote::PutEscapedBytes (const void* s,
33                                   size_t src_len)
34 {
35     int bytes_written = 0;
36     const uint8_t *src = (const uint8_t *)s;
37     bool binary_is_set = m_flags.Test(eBinary);
38     m_flags.Clear(eBinary);
39     while (src_len)
40     {
41         uint8_t byte = *src;
42         src++; src_len--;
43         if (byte == 0x23 || byte == 0x24 || byte == 0x7d || byte == 0x2a)
44         {
45             bytes_written += PutChar(0x7d);
46             byte ^= 0x20;
47         }
48         bytes_written += PutChar(byte);
49     };
50     if (binary_is_set)
51         m_flags.Set(eBinary);
52     return bytes_written;
53 }
54