Path: blob/main/contrib/llvm-project/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationHistory.h
39644 views
//===-- GDBRemoteCommunicationHistory.h--------------------------*- C++ -*-===//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#ifndef LLDB_SOURCE_PLUGINS_PROCESS_GDB_REMOTE_GDBREMOTECOMMUNICATIONHISTORY_H9#define LLDB_SOURCE_PLUGINS_PROCESS_GDB_REMOTE_GDBREMOTECOMMUNICATIONHISTORY_H1011#include <string>12#include <vector>1314#include "lldb/Utility/GDBRemote.h"15#include "lldb/lldb-public.h"16#include "llvm/Support/raw_ostream.h"1718namespace lldb_private {19namespace process_gdb_remote {2021/// The history keeps a circular buffer of GDB remote packets. The history is22/// used for logging and replaying GDB remote packets.23class GDBRemoteCommunicationHistory {24public:25GDBRemoteCommunicationHistory(uint32_t size = 0);2627~GDBRemoteCommunicationHistory();2829// For single char packets for ack, nack and /x0330void AddPacket(char packet_char, GDBRemotePacket::Type type,31uint32_t bytes_transmitted);3233void AddPacket(const std::string &src, uint32_t src_len,34GDBRemotePacket::Type type, uint32_t bytes_transmitted);3536void Dump(Stream &strm) const;37void Dump(Log *log) const;38bool DidDumpToLog() const { return m_dumped_to_log; }3940private:41uint32_t GetFirstSavedPacketIndex() const {42if (m_total_packet_count < m_packets.size())43return 0;44else45return m_curr_idx + 1;46}4748uint32_t GetNumPacketsInHistory() const {49if (m_total_packet_count < m_packets.size())50return m_total_packet_count;51else52return (uint32_t)m_packets.size();53}5455uint32_t GetNextIndex() {56++m_total_packet_count;57const uint32_t idx = m_curr_idx;58m_curr_idx = NormalizeIndex(idx + 1);59return idx;60}6162uint32_t NormalizeIndex(uint32_t i) const {63return m_packets.empty() ? 0 : i % m_packets.size();64}6566std::vector<GDBRemotePacket> m_packets;67uint32_t m_curr_idx = 0;68uint32_t m_total_packet_count = 0;69mutable bool m_dumped_to_log = false;70};7172} // namespace process_gdb_remote73} // namespace lldb_private7475#endif // LLDB_SOURCE_PLUGINS_PROCESS_GDB_REMOTE_GDBREMOTECOMMUNICATIONHISTORY_H767778