Coverage Report

Created: 2023-11-11 10:31

/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationHistory.cpp
Line
Count
Source (jump to first uncovered line)
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
2.34k
    : m_packets() {
22
2.34k
  if (size)
23
2.34k
    m_packets.resize(size);
24
2.34k
}
25
26
2.24k
GDBRemoteCommunicationHistory::~GDBRemoteCommunicationHistory() = default;
27
28
void GDBRemoteCommunicationHistory::AddPacket(char packet_char,
29
                                              GDBRemotePacket::Type type,
30
4.57k
                                              uint32_t bytes_transmitted) {
31
4.57k
  const size_t size = m_packets.size();
32
4.57k
  if (size == 0)
33
0
    return;
34
35
4.57k
  const uint32_t idx = GetNextIndex();
36
4.57k
  m_packets[idx].packet.data.assign(1, packet_char);
37
4.57k
  m_packets[idx].type = type;
38
4.57k
  m_packets[idx].bytes_transmitted = bytes_transmitted;
39
4.57k
  m_packets[idx].packet_idx = m_total_packet_count;
40
4.57k
  m_packets[idx].tid = llvm::get_threadid();
41
4.57k
}
42
43
void GDBRemoteCommunicationHistory::AddPacket(const std::string &src,
44
                                              uint32_t src_len,
45
                                              GDBRemotePacket::Type type,
46
884k
                                              uint32_t bytes_transmitted) {
47
884k
  const size_t size = m_packets.size();
48
884k
  if (size == 0)
49
0
    return;
50
51
884k
  const uint32_t idx = GetNextIndex();
52
884k
  m_packets[idx].packet.data.assign(src, 0, src_len);
53
884k
  m_packets[idx].type = type;
54
884k
  m_packets[idx].bytes_transmitted = bytes_transmitted;
55
884k
  m_packets[idx].packet_idx = m_total_packet_count;
56
884k
  m_packets[idx].tid = llvm::get_threadid();
57
884k
}
58
59
0
void GDBRemoteCommunicationHistory::Dump(Stream &strm) const {
60
0
  const uint32_t size = GetNumPacketsInHistory();
61
0
  const uint32_t first_idx = GetFirstSavedPacketIndex();
62
0
  const uint32_t stop_idx = m_curr_idx + size;
63
0
  for (uint32_t i = first_idx; i < stop_idx; ++i) {
64
0
    const uint32_t idx = NormalizeIndex(i);
65
0
    const GDBRemotePacket &entry = m_packets[idx];
66
0
    if (entry.type == GDBRemotePacket::ePacketTypeInvalid ||
67
0
        entry.packet.data.empty())
68
0
      break;
69
0
    strm.Printf("history[%u] ", entry.packet_idx);
70
0
    entry.Dump(strm);
71
0
  }
72
0
}
73
74
57
void GDBRemoteCommunicationHistory::Dump(Log *log) const {
75
57
  if (!log || m_dumped_to_log)
76
0
    return;
77
78
57
  m_dumped_to_log = true;
79
57
  const uint32_t size = GetNumPacketsInHistory();
80
57
  const uint32_t first_idx = GetFirstSavedPacketIndex();
81
57
  const uint32_t stop_idx = m_curr_idx + size;
82
114
  for (uint32_t i = first_idx; i < stop_idx; 
++i57
) {
83
114
    const uint32_t idx = NormalizeIndex(i);
84
114
    const GDBRemotePacket &entry = m_packets[idx];
85
114
    if (entry.type == GDBRemotePacket::ePacketTypeInvalid ||
86
114
        
entry.packet.data.empty()57
)
87
57
      break;
88
57
    LLDB_LOGF(log, "history[%u] tid=0x%4.4" PRIx64 " <%4u> %s packet: %s",
89
57
              entry.packet_idx, entry.tid, entry.bytes_transmitted,
90
57
              (entry.type == GDBRemotePacket::ePacketTypeSend) ? "send"
91
57
                                                               : "read",
92
57
              entry.packet.data.c_str());
93
57
  }
94
57
}
95