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
13#include "lldb/Utility/Log.h"
14
15using namespace llvm;
16using namespace lldb;
17using namespace lldb_private;
19
21 : m_packets() {
22 if (size)
23 m_packets.resize(size);
24}
25
27
30 uint32_t bytes_transmitted) {
31 const size_t size = m_packets.size();
32 if (size == 0)
33 return;
34
35 const uint32_t idx = GetNextIndex();
36 m_packets[idx].packet.data.assign(1, packet_char);
37 m_packets[idx].type = type;
38 m_packets[idx].bytes_transmitted = bytes_transmitted;
39 m_packets[idx].packet_idx = m_total_packet_count;
40 m_packets[idx].tid = llvm::get_threadid();
41}
42
43void GDBRemoteCommunicationHistory::AddPacket(const std::string &src,
44 uint32_t src_len,
46 uint32_t bytes_transmitted) {
47 const size_t size = m_packets.size();
48 if (size == 0)
49 return;
50
51 const uint32_t idx = GetNextIndex();
52 m_packets[idx].packet.data.assign(src, 0, src_len);
53 m_packets[idx].type = type;
54 m_packets[idx].bytes_transmitted = bytes_transmitted;
55 m_packets[idx].packet_idx = m_total_packet_count;
56 m_packets[idx].tid = llvm::get_threadid();
57}
58
60 const uint32_t size = GetNumPacketsInHistory();
61 const uint32_t first_idx = GetFirstSavedPacketIndex();
62 const uint32_t stop_idx = m_curr_idx + size;
63 for (uint32_t i = first_idx; i < stop_idx; ++i) {
64 const uint32_t idx = NormalizeIndex(i);
65 const GDBRemotePacket &entry = m_packets[idx];
67 entry.packet.data.empty())
68 break;
69 strm.Printf("history[%u] ", entry.packet_idx);
70 entry.Dump(strm);
71 }
72}
73
75 if (!log || m_dumped_to_log)
76 return;
77
78 m_dumped_to_log = true;
79 const uint32_t size = GetNumPacketsInHistory();
80 const uint32_t first_idx = GetFirstSavedPacketIndex();
81 const uint32_t stop_idx = m_curr_idx + size;
82 for (uint32_t i = first_idx; i < stop_idx; ++i) {
83 const uint32_t idx = NormalizeIndex(i);
84 const GDBRemotePacket &entry = m_packets[idx];
86 entry.packet.data.empty())
87 break;
88 LLDB_LOGF(log, "history[%u] tid=0x%4.4" PRIx64 " <%4u> %s packet: %s",
89 entry.packet_idx, entry.tid, entry.bytes_transmitted,
90 (entry.type == GDBRemotePacket::ePacketTypeSend) ? "send"
91 : "read",
92 entry.packet.data.c_str());
93 }
94}
95
#define LLDB_LOGF(log,...)
Definition: Log.h:366
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:134
void AddPacket(char packet_char, GDBRemotePacket::Type type, uint32_t bytes_transmitted)
A class that represents a running process on the host machine.
Definition: SBAddress.h:15
Definition: Debugger.h:54
GDB remote packet as used by the GDB remote communication history.
Definition: GDBRemote.h:50
void Dump(Stream &strm) const
Definition: GDBRemote.cpp:60