Path: blob/main/contrib/llvm-project/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationHistory.cpp
39642 views
//===-- GDBRemoteCommunicationHistory.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 "GDBRemoteCommunicationHistory.h"910// Other libraries and framework includes11#include "lldb/Utility/ConstString.h"12#include "lldb/Utility/Log.h"1314using namespace llvm;15using namespace lldb;16using namespace lldb_private;17using namespace lldb_private::process_gdb_remote;1819GDBRemoteCommunicationHistory::GDBRemoteCommunicationHistory(uint32_t size)20: m_packets() {21if (size)22m_packets.resize(size);23}2425GDBRemoteCommunicationHistory::~GDBRemoteCommunicationHistory() = default;2627void GDBRemoteCommunicationHistory::AddPacket(char packet_char,28GDBRemotePacket::Type type,29uint32_t bytes_transmitted) {30const size_t size = m_packets.size();31if (size == 0)32return;3334const uint32_t idx = GetNextIndex();35m_packets[idx].packet.data.assign(1, packet_char);36m_packets[idx].type = type;37m_packets[idx].bytes_transmitted = bytes_transmitted;38m_packets[idx].packet_idx = m_total_packet_count;39m_packets[idx].tid = llvm::get_threadid();40}4142void GDBRemoteCommunicationHistory::AddPacket(const std::string &src,43uint32_t src_len,44GDBRemotePacket::Type type,45uint32_t bytes_transmitted) {46const size_t size = m_packets.size();47if (size == 0)48return;4950const uint32_t idx = GetNextIndex();51m_packets[idx].packet.data.assign(src, 0, src_len);52m_packets[idx].type = type;53m_packets[idx].bytes_transmitted = bytes_transmitted;54m_packets[idx].packet_idx = m_total_packet_count;55m_packets[idx].tid = llvm::get_threadid();56}5758void GDBRemoteCommunicationHistory::Dump(Stream &strm) const {59const uint32_t size = GetNumPacketsInHistory();60const uint32_t first_idx = GetFirstSavedPacketIndex();61const uint32_t stop_idx = m_curr_idx + size;62for (uint32_t i = first_idx; i < stop_idx; ++i) {63const uint32_t idx = NormalizeIndex(i);64const GDBRemotePacket &entry = m_packets[idx];65if (entry.type == GDBRemotePacket::ePacketTypeInvalid ||66entry.packet.data.empty())67break;68strm.Printf("history[%u] ", entry.packet_idx);69entry.Dump(strm);70}71}7273void GDBRemoteCommunicationHistory::Dump(Log *log) const {74if (!log || m_dumped_to_log)75return;7677m_dumped_to_log = true;78const uint32_t size = GetNumPacketsInHistory();79const uint32_t first_idx = GetFirstSavedPacketIndex();80const uint32_t stop_idx = m_curr_idx + size;81for (uint32_t i = first_idx; i < stop_idx; ++i) {82const uint32_t idx = NormalizeIndex(i);83const GDBRemotePacket &entry = m_packets[idx];84if (entry.type == GDBRemotePacket::ePacketTypeInvalid ||85entry.packet.data.empty())86break;87LLDB_LOGF(log, "history[%u] tid=0x%4.4" PRIx64 " <%4u> %s packet: %s",88entry.packet_idx, entry.tid, entry.bytes_transmitted,89(entry.type == GDBRemotePacket::ePacketTypeSend) ? "send"90: "read",91entry.packet.data.c_str());92}93}94959697