Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 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 | |
Zachary Turner | fb1a0a0 | 2017-03-06 18:34:25 +0000 | [diff] [blame] | 10 | #include "lldb/Utility/StreamGDBRemote.h" |
Zachary Turner | 4479ac1 | 2017-04-06 18:12:24 +0000 | [diff] [blame] | 11 | |
| 12 | #include "lldb/Utility/Flags.h" // for Flags |
| 13 | #include "lldb/Utility/Stream.h" // for Stream::::eBinary |
| 14 | |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 15 | #include <stdio.h> |
| 16 | |
| 17 | using namespace lldb; |
| 18 | using namespace lldb_private; |
| 19 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 20 | StreamGDBRemote::StreamGDBRemote() : StreamString() {} |
| 21 | |
| 22 | StreamGDBRemote::StreamGDBRemote(uint32_t flags, uint32_t addr_size, |
| 23 | ByteOrder byte_order) |
| 24 | : StreamString(flags, addr_size, byte_order) {} |
| 25 | |
| 26 | StreamGDBRemote::~StreamGDBRemote() {} |
| 27 | |
| 28 | int StreamGDBRemote::PutEscapedBytes(const void *s, size_t src_len) { |
| 29 | int bytes_written = 0; |
| 30 | const uint8_t *src = (const uint8_t *)s; |
| 31 | bool binary_is_set = m_flags.Test(eBinary); |
| 32 | m_flags.Clear(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) |
| 44 | m_flags.Set(eBinary); |
| 45 | return bytes_written; |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 46 | } |