LLDB  mainline
GDBRemoteCommunicationHistory.cpp
Go to the documentation of this file.
1 //===-- GDBRemoteCommunicationHistory.cpp ---------------------------------===//
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 
10 
11 // Other libraries and framework includes
12 #include "lldb/Core/StreamFile.h"
14 #include "lldb/Utility/Log.h"
15 
16 using namespace llvm;
17 using namespace lldb;
18 using namespace lldb_private;
19 using namespace lldb_private::process_gdb_remote;
20 
21 GDBRemoteCommunicationHistory::GDBRemoteCommunicationHistory(uint32_t size)
22  : m_packets() {
23  if (size)
24  m_packets.resize(size);
25 }
26 
28 
31  uint32_t bytes_transmitted) {
32  const size_t size = m_packets.size();
33  if (size == 0)
34  return;
35 
36  const uint32_t idx = GetNextIndex();
37  m_packets[idx].packet.data.assign(1, packet_char);
38  m_packets[idx].type = type;
39  m_packets[idx].bytes_transmitted = bytes_transmitted;
40  m_packets[idx].packet_idx = m_total_packet_count;
41  m_packets[idx].tid = llvm::get_threadid();
42  if (m_recorder)
44 }
45 
47  uint32_t src_len,
49  uint32_t bytes_transmitted) {
50  const size_t size = m_packets.size();
51  if (size == 0)
52  return;
53 
54  const uint32_t idx = GetNextIndex();
55  m_packets[idx].packet.data.assign(src, 0, src_len);
56  m_packets[idx].type = type;
57  m_packets[idx].bytes_transmitted = bytes_transmitted;
58  m_packets[idx].packet_idx = m_total_packet_count;
59  m_packets[idx].tid = llvm::get_threadid();
60  if (m_recorder)
62 }
63 
65  const uint32_t size = GetNumPacketsInHistory();
66  const uint32_t first_idx = GetFirstSavedPacketIndex();
67  const uint32_t stop_idx = m_curr_idx + size;
68  for (uint32_t i = first_idx; i < stop_idx; ++i) {
69  const uint32_t idx = NormalizeIndex(i);
70  const GDBRemotePacket &entry = m_packets[idx];
72  entry.packet.data.empty())
73  break;
74  strm.Printf("history[%u] ", entry.packet_idx);
75  entry.Dump(strm);
76  }
77 }
78 
80  if (!log || m_dumped_to_log)
81  return;
82 
83  m_dumped_to_log = true;
84  const uint32_t size = GetNumPacketsInHistory();
85  const uint32_t first_idx = GetFirstSavedPacketIndex();
86  const uint32_t stop_idx = m_curr_idx + size;
87  for (uint32_t i = first_idx; i < stop_idx; ++i) {
88  const uint32_t idx = NormalizeIndex(i);
89  const GDBRemotePacket &entry = m_packets[idx];
91  entry.packet.data.empty())
92  break;
93  LLDB_LOGF(log, "history[%u] tid=0x%4.4" PRIx64 " <%4u> %s packet: %s",
94  entry.packet_idx, entry.tid, entry.bytes_transmitted,
95  (entry.type == GDBRemotePacket::ePacketTypeSend) ? "send"
96  : "read",
97  entry.packet.data.c_str());
98  }
99 }
100 
llvm
Definition: Debugger.h:49
lldb_private::GDBRemotePacket::packet
BinaryData packet
Definition: GDBRemote.h:74
lldb_private::GDBRemotePacket::Dump
void Dump(Stream &strm) const
Definition: GDBRemote.cpp:61
lldb_private::process_gdb_remote::GDBRemoteCommunicationHistory::m_curr_idx
uint32_t m_curr_idx
Definition: GDBRemoteCommunicationHistory.h:77
LLDB_LOGF
#define LLDB_LOGF(log,...)
Definition: Log.h:249
lldb_private::repro::PacketRecorder::Record
void Record(const GDBRemotePacket &packet)
Definition: GDBRemote.cpp:141
lldb_private::GDBRemotePacket::packet_idx
uint32_t packet_idx
Definition: GDBRemote.h:77
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
Log.h
lldb_private::GDBRemotePacket::type
Type type
Definition: GDBRemote.h:75
lldb_private::process_gdb_remote::GDBRemoteCommunicationHistory::GetNumPacketsInHistory
uint32_t GetNumPacketsInHistory() const
Definition: GDBRemoteCommunicationHistory.h:58
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
Definition: GDBRemoteClientBase.h:17
GDBRemoteCommunicationHistory.h
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
StreamFile.h
lldb_private::process_gdb_remote::GDBRemoteCommunicationHistory::m_dumped_to_log
bool m_dumped_to_log
Definition: GDBRemoteCommunicationHistory.h:79
lldb_private::GDBRemotePacket::ePacketTypeSend
@ ePacketTypeSend
Definition: GDBRemote.h:56
uint32_t
lldb_private::process_gdb_remote::GDBRemoteCommunicationHistory::NormalizeIndex
uint32_t NormalizeIndex(uint32_t i) const
Definition: GDBRemoteCommunicationHistory.h:72
lldb_private::GDBRemotePacket
GDB remote packet as used by the reproducer and the GDB remote communication history.
Definition: GDBRemote.h:52
lldb_private::GDBRemotePacket::tid
lldb::tid_t tid
Definition: GDBRemote.h:78
lldb_private::GDBRemotePacket::bytes_transmitted
uint32_t bytes_transmitted
Definition: GDBRemote.h:76
lldb_private::GDBRemotePacket::ePacketTypeInvalid
@ ePacketTypeInvalid
Definition: GDBRemote.h:56
lldb_private::Stream::Printf
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:107
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
ConstString.h
lldb_private::GDBRemotePacket::BinaryData::data
std::string data
Definition: GDBRemote.h:69
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::m_recorder
repro::PacketRecorder * m_recorder
Definition: GDBRemoteCommunicationHistory.h:80
lldb
Definition: SBAddress.h:15