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
14#include "lldb/Utility/Log.h"
15
16using namespace llvm;
17using namespace lldb;
18using namespace lldb_private;
20
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}
43
44void GDBRemoteCommunicationHistory::AddPacket(const std::string &src,
45 uint32_t src_len,
47 uint32_t bytes_transmitted) {
48 const size_t size = m_packets.size();
49 if (size == 0)
50 return;
51
52 const uint32_t idx = GetNextIndex();
53 m_packets[idx].packet.data.assign(src, 0, src_len);
54 m_packets[idx].type = type;
55 m_packets[idx].bytes_transmitted = bytes_transmitted;
56 m_packets[idx].packet_idx = m_total_packet_count;
57 m_packets[idx].tid = llvm::get_threadid();
58}
59
61 const uint32_t size = GetNumPacketsInHistory();
62 const uint32_t first_idx = GetFirstSavedPacketIndex();
63 const uint32_t stop_idx = m_curr_idx + size;
64 for (uint32_t i = first_idx; i < stop_idx; ++i) {
65 const uint32_t idx = NormalizeIndex(i);
66 const GDBRemotePacket &entry = m_packets[idx];
68 entry.packet.data.empty())
69 break;
70 strm.Printf("history[%u] ", entry.packet_idx);
71 entry.Dump(strm);
72 }
73}
74
76 if (!log || m_dumped_to_log)
77 return;
78
79 m_dumped_to_log = true;
80 const uint32_t size = GetNumPacketsInHistory();
81 const uint32_t first_idx = GetFirstSavedPacketIndex();
82 const uint32_t stop_idx = m_curr_idx + size;
83 for (uint32_t i = first_idx; i < stop_idx; ++i) {
84 const uint32_t idx = NormalizeIndex(i);
85 const GDBRemotePacket &entry = m_packets[idx];
87 entry.packet.data.empty())
88 break;
89 LLDB_LOGF(log, "history[%u] tid=0x%4.4" PRIx64 " <%4u> %s packet: %s",
90 entry.packet_idx, entry.tid, entry.bytes_transmitted,
91 (entry.type == GDBRemotePacket::ePacketTypeSend) ? "send"
92 : "read",
93 entry.packet.data.c_str());
94 }
95}
96
#define LLDB_LOGF(log,...)
Definition: Log.h:344
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:107
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:51
GDB remote packet as used by the GDB remote communication history.
Definition: GDBRemote.h:50
void Dump(Stream &strm) const
Definition: GDBRemote.cpp:60