LLDB
mainline
llvm-project
lldb
source
Plugins
Process
gdb-remote
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
9
#include "
GDBRemoteCommunicationHistory.h
"
10
11
// Other libraries and framework includes
12
#include "
lldb/Utility/ConstString.h
"
13
#include "
lldb/Utility/Log.h
"
14
15
using namespace
llvm
;
16
using namespace
lldb
;
17
using namespace
lldb_private
;
18
using namespace
lldb_private::process_gdb_remote
;
19
20
GDBRemoteCommunicationHistory::GDBRemoteCommunicationHistory
(uint32_t size)
21
:
m_packets
() {
22
if
(size)
23
m_packets
.resize(size);
24
}
25
26
GDBRemoteCommunicationHistory::~GDBRemoteCommunicationHistory
() =
default
;
27
28
void
GDBRemoteCommunicationHistory::AddPacket
(
char
packet_char,
29
GDBRemotePacket::Type
type,
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
43
void
GDBRemoteCommunicationHistory::AddPacket
(
const
std::string &src,
44
uint32_t src_len,
45
GDBRemotePacket::Type
type,
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
59
void
GDBRemoteCommunicationHistory::Dump
(
Stream
&strm)
const
{
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];
66
if
(entry.
type
==
GDBRemotePacket::ePacketTypeInvalid
||
67
entry.
packet
.
data
.empty())
68
break
;
69
strm.
Printf
(
"history[%u] "
, entry.
packet_idx
);
70
entry.
Dump
(strm);
71
}
72
}
73
74
void
GDBRemoteCommunicationHistory::Dump
(
Log
*log)
const
{
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];
85
if
(entry.
type
==
GDBRemotePacket::ePacketTypeInvalid
||
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
ConstString.h
GDBRemoteCommunicationHistory.h
Log.h
LLDB_LOGF
#define LLDB_LOGF(log,...)
Definition
Log.h:376
lldb_private::Log
Definition
Log.h:132
lldb_private::Stream
A stream class that can stream formatted output to a file.
Definition
Stream.h:28
lldb_private::Stream::Printf
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition
Stream.cpp:134
lldb_private::process_gdb_remote::GDBRemoteCommunicationHistory::Dump
void Dump(Stream &strm) const
Definition
GDBRemoteCommunicationHistory.cpp:59
lldb_private::process_gdb_remote::GDBRemoteCommunicationHistory::m_total_packet_count
uint32_t m_total_packet_count
Definition
GDBRemoteCommunicationHistory.h:69
lldb_private::process_gdb_remote::GDBRemoteCommunicationHistory::GDBRemoteCommunicationHistory
GDBRemoteCommunicationHistory(uint32_t size=0)
Definition
GDBRemoteCommunicationHistory.cpp:20
lldb_private::process_gdb_remote::GDBRemoteCommunicationHistory::GetNextIndex
uint32_t GetNextIndex()
Definition
GDBRemoteCommunicationHistory.h:56
lldb_private::process_gdb_remote::GDBRemoteCommunicationHistory::NormalizeIndex
uint32_t NormalizeIndex(uint32_t i) const
Definition
GDBRemoteCommunicationHistory.h:63
lldb_private::process_gdb_remote::GDBRemoteCommunicationHistory::GetNumPacketsInHistory
uint32_t GetNumPacketsInHistory() const
Definition
GDBRemoteCommunicationHistory.h:49
lldb_private::process_gdb_remote::GDBRemoteCommunicationHistory::GetFirstSavedPacketIndex
uint32_t GetFirstSavedPacketIndex() const
Definition
GDBRemoteCommunicationHistory.h:42
lldb_private::process_gdb_remote::GDBRemoteCommunicationHistory::m_dumped_to_log
bool m_dumped_to_log
Definition
GDBRemoteCommunicationHistory.h:70
lldb_private::process_gdb_remote::GDBRemoteCommunicationHistory::m_curr_idx
uint32_t m_curr_idx
Definition
GDBRemoteCommunicationHistory.h:68
lldb_private::process_gdb_remote::GDBRemoteCommunicationHistory::AddPacket
void AddPacket(char packet_char, GDBRemotePacket::Type type, uint32_t bytes_transmitted)
Definition
GDBRemoteCommunicationHistory.cpp:28
lldb_private::process_gdb_remote::GDBRemoteCommunicationHistory::m_packets
std::vector< GDBRemotePacket > m_packets
Definition
GDBRemoteCommunicationHistory.h:67
lldb_private::process_gdb_remote::GDBRemoteCommunicationHistory::~GDBRemoteCommunicationHistory
~GDBRemoteCommunicationHistory()
lldb_private::process_gdb_remote
Definition
GDBRemoteClientBase.h:22
lldb_private
A class that represents a running process on the host machine.
Definition
SBAddressRange.h:14
lldb
Definition
SBAddress.h:15
llvm
Definition
Debugger.h:58
lldb_private::GDBRemotePacket::BinaryData::data
std::string data
Definition
GDBRemote.h:65
lldb_private::GDBRemotePacket
GDB remote packet as used by the GDB remote communication history.
Definition
GDBRemote.h:50
lldb_private::GDBRemotePacket::packet_idx
uint32_t packet_idx
Definition
GDBRemote.h:73
lldb_private::GDBRemotePacket::Dump
void Dump(Stream &strm) const
Definition
GDBRemote.cpp:60
lldb_private::GDBRemotePacket::type
Type type
Definition
GDBRemote.h:71
lldb_private::GDBRemotePacket::bytes_transmitted
uint32_t bytes_transmitted
Definition
GDBRemote.h:72
lldb_private::GDBRemotePacket::tid
lldb::tid_t tid
Definition
GDBRemote.h:74
lldb_private::GDBRemotePacket::Type
Type
Definition
GDBRemote.h:52
lldb_private::GDBRemotePacket::ePacketTypeSend
@ ePacketTypeSend
Definition
GDBRemote.h:52
lldb_private::GDBRemotePacket::ePacketTypeInvalid
@ ePacketTypeInvalid
Definition
GDBRemote.h:52
lldb_private::GDBRemotePacket::packet
BinaryData packet
Definition
GDBRemote.h:70
Generated on
for LLDB by
1.14.0