LLDB  mainline
GDBRemoteCommunicationHistory.h
Go to the documentation of this file.
1 //===-- GDBRemoteCommunicationHistory.h--------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLDB_SOURCE_PLUGINS_PROCESS_GDB_REMOTE_GDBREMOTECOMMUNICATIONHISTORY_H
10 #define LLDB_SOURCE_PLUGINS_PROCESS_GDB_REMOTE_GDBREMOTECOMMUNICATIONHISTORY_H
11 
12 #include <string>
13 #include <vector>
14 
15 #include "lldb/Utility/GDBRemote.h"
17 #include "lldb/lldb-public.h"
18 #include "llvm/Support/YAMLTraits.h"
19 #include "llvm/Support/raw_ostream.h"
20 
21 namespace lldb_private {
22 namespace repro {
23 class PacketRecorder;
24 }
25 namespace process_gdb_remote {
26 
27 /// The history keeps a circular buffer of GDB remote packets. The history is
28 /// used for logging and replaying GDB remote packets.
30 public:
31  friend llvm::yaml::MappingTraits<GDBRemoteCommunicationHistory>;
32 
34 
36 
37  // For single char packets for ack, nack and /x03
38  void AddPacket(char packet_char, GDBRemotePacket::Type type,
39  uint32_t bytes_transmitted);
40 
41  void AddPacket(const std::string &src, uint32_t src_len,
42  GDBRemotePacket::Type type, uint32_t bytes_transmitted);
43 
44  void Dump(Stream &strm) const;
45  void Dump(Log *log) const;
46  bool DidDumpToLog() const { return m_dumped_to_log; }
47 
48  void SetRecorder(repro::PacketRecorder *recorder) { m_recorder = recorder; }
49 
50 private:
52  if (m_total_packet_count < m_packets.size())
53  return 0;
54  else
55  return m_curr_idx + 1;
56  }
57 
59  if (m_total_packet_count < m_packets.size())
60  return m_total_packet_count;
61  else
62  return (uint32_t)m_packets.size();
63  }
64 
67  const uint32_t idx = m_curr_idx;
68  m_curr_idx = NormalizeIndex(idx + 1);
69  return idx;
70  }
71 
73  return m_packets.empty() ? 0 : i % m_packets.size();
74  }
75 
76  std::vector<GDBRemotePacket> m_packets;
79  mutable bool m_dumped_to_log = false;
81 };
82 
83 } // namespace process_gdb_remote
84 } // namespace lldb_private
85 
86 #endif // LLDB_SOURCE_PLUGINS_PROCESS_GDB_REMOTE_GDBREMOTECOMMUNICATIONHISTORY_H
lldb-public.h
lldb_private::process_gdb_remote::GDBRemoteCommunicationHistory::m_curr_idx
uint32_t m_curr_idx
Definition: GDBRemoteCommunicationHistory.h:77
Reproducer.h
lldb_private::process_gdb_remote::GDBRemoteCommunicationHistory::~GDBRemoteCommunicationHistory
~GDBRemoteCommunicationHistory()
lldb_private::Stream
Definition: Stream.h:28
lldb_private::GDBRemotePacket::Type
Type
Definition: GDBRemote.h:56
lldb_private::process_gdb_remote::GDBRemoteCommunicationHistory::Dump
void Dump(Stream &strm) const
Definition: GDBRemoteCommunicationHistory.cpp:64
lldb_private::process_gdb_remote::GDBRemoteCommunicationHistory::m_total_packet_count
uint32_t m_total_packet_count
Definition: GDBRemoteCommunicationHistory.h:78
GDBRemote.h
lldb_private::process_gdb_remote::GDBRemoteCommunicationHistory::GetNumPacketsInHistory
uint32_t GetNumPacketsInHistory() const
Definition: GDBRemoteCommunicationHistory.h:58
lldb_private::process_gdb_remote::GDBRemoteCommunicationHistory::SetRecorder
void SetRecorder(repro::PacketRecorder *recorder)
Definition: GDBRemoteCommunicationHistory.h:48
lldb_private::process_gdb_remote::GDBRemoteCommunicationHistory::GetNextIndex
uint32_t GetNextIndex()
Definition: GDBRemoteCommunicationHistory.h:65
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:40
lldb_private::process_gdb_remote::GDBRemoteCommunicationHistory::GDBRemoteCommunicationHistory
GDBRemoteCommunicationHistory(uint32_t size=0)
Definition: GDBRemoteCommunicationHistory.cpp:21
lldb_private::process_gdb_remote::GDBRemoteCommunicationHistory::AddPacket
void AddPacket(char packet_char, GDBRemotePacket::Type type, uint32_t bytes_transmitted)
Definition: GDBRemoteCommunicationHistory.cpp:29
lldb_private::process_gdb_remote::GDBRemoteCommunicationHistory::m_packets
std::vector< GDBRemotePacket > m_packets
Definition: GDBRemoteCommunicationHistory.h:76
lldb_private::process_gdb_remote::GDBRemoteCommunicationHistory::m_dumped_to_log
bool m_dumped_to_log
Definition: GDBRemoteCommunicationHistory.h:79
uint32_t
lldb_private::process_gdb_remote::GDBRemoteCommunicationHistory::NormalizeIndex
uint32_t NormalizeIndex(uint32_t i) const
Definition: GDBRemoteCommunicationHistory.h:72
lldb_private::repro::PacketRecorder
Definition: GDBRemote.h:85
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::Log
Definition: Log.h:49
lldb_private::process_gdb_remote::GDBRemoteCommunicationHistory::GetFirstSavedPacketIndex
uint32_t GetFirstSavedPacketIndex() const
Definition: GDBRemoteCommunicationHistory.h:51
lldb_private::process_gdb_remote::GDBRemoteCommunicationHistory
The history keeps a circular buffer of GDB remote packets.
Definition: GDBRemoteCommunicationHistory.h:29
lldb_private::process_gdb_remote::GDBRemoteCommunicationHistory::DidDumpToLog
bool DidDumpToLog() const
Definition: GDBRemoteCommunicationHistory.h:46
lldb_private::process_gdb_remote::GDBRemoteCommunicationHistory::m_recorder
repro::PacketRecorder * m_recorder
Definition: GDBRemoteCommunicationHistory.h:80