Path: blob/main/contrib/llvm-project/lldb/source/Utility/GDBRemote.cpp
39587 views
//===-- GDBRemote.cpp -----------------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "lldb/Utility/GDBRemote.h"910#include "lldb/Utility/Flags.h"11#include "lldb/Utility/Stream.h"1213#include <cstdio>1415using namespace lldb;16using namespace lldb_private;17using namespace llvm;1819StreamGDBRemote::StreamGDBRemote() : StreamString() {}2021StreamGDBRemote::StreamGDBRemote(uint32_t flags, uint32_t addr_size,22ByteOrder byte_order)23: StreamString(flags, addr_size, byte_order) {}2425StreamGDBRemote::~StreamGDBRemote() = default;2627int StreamGDBRemote::PutEscapedBytes(const void *s, size_t src_len) {28int bytes_written = 0;29const uint8_t *src = static_cast<const uint8_t *>(s);30bool binary_is_set = m_flags.Test(eBinary);31m_flags.Clear(eBinary);32while (src_len) {33uint8_t byte = *src;34src++;35src_len--;36if (byte == 0x23 || byte == 0x24 || byte == 0x7d || byte == 0x2a) {37bytes_written += PutChar(0x7d);38byte ^= 0x20;39}40bytes_written += PutChar(byte);41};42if (binary_is_set)43m_flags.Set(eBinary);44return bytes_written;45}4647llvm::StringRef GDBRemotePacket::GetTypeStr() const {48switch (type) {49case GDBRemotePacket::ePacketTypeSend:50return "send";51case GDBRemotePacket::ePacketTypeRecv:52return "read";53case GDBRemotePacket::ePacketTypeInvalid:54return "invalid";55}56llvm_unreachable("All enum cases should be handled");57}5859void GDBRemotePacket::Dump(Stream &strm) const {60strm.Printf("tid=0x%4.4" PRIx64 " <%4u> %s packet: %s\n", tid,61bytes_transmitted, GetTypeStr().data(), packet.data.c_str());62}636465