Coverage Report

Created: 2023-09-30 09:22

/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/source/Core/DebuggerEvents.cpp
Line
Count
Source (jump to first uncovered line)
1
//===-- DebuggerEvents.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 "lldb/Core/DebuggerEvents.h"
10
#include "lldb/Core/Debugger.h"
11
#include "lldb/Core/Module.h"
12
#include "llvm/Support/WithColor.h"
13
14
using namespace lldb_private;
15
using namespace lldb;
16
17
template <typename T>
18
18.2k
static const T *GetEventDataFromEventImpl(const Event *event_ptr) {
19
18.2k
  if (event_ptr)
20
18.2k
    if (const EventData *event_data = event_ptr->GetData())
21
18.2k
      if (event_data->GetFlavor() == T::GetFlavorString())
22
18.2k
        return static_cast<const T *>(event_ptr->GetData());
23
0
  return nullptr;
24
18.2k
}
DebuggerEvents.cpp:lldb_private::ProgressEventData const* GetEventDataFromEventImpl<lldb_private::ProgressEventData>(lldb_private::Event const*)
Line
Count
Source
18
18.2k
static const T *GetEventDataFromEventImpl(const Event *event_ptr) {
19
18.2k
  if (event_ptr)
20
18.2k
    if (const EventData *event_data = event_ptr->GetData())
21
18.2k
      if (event_data->GetFlavor() == T::GetFlavorString())
22
18.2k
        return static_cast<const T *>(event_ptr->GetData());
23
0
  return nullptr;
24
18.2k
}
DebuggerEvents.cpp:lldb_private::DiagnosticEventData const* GetEventDataFromEventImpl<lldb_private::DiagnosticEventData>(lldb_private::Event const*)
Line
Count
Source
18
32
static const T *GetEventDataFromEventImpl(const Event *event_ptr) {
19
32
  if (event_ptr)
20
32
    if (const EventData *event_data = event_ptr->GetData())
21
32
      if (event_data->GetFlavor() == T::GetFlavorString())
22
32
        return static_cast<const T *>(event_ptr->GetData());
23
0
  return nullptr;
24
32
}
Unexecuted instantiation: DebuggerEvents.cpp:lldb_private::SymbolChangeEventData const* GetEventDataFromEventImpl<lldb_private::SymbolChangeEventData>(lldb_private::Event const*)
25
26
36.5k
llvm::StringRef ProgressEventData::GetFlavorString() {
27
36.5k
  return "ProgressEventData";
28
36.5k
}
29
30
18.2k
llvm::StringRef ProgressEventData::GetFlavor() const {
31
18.2k
  return ProgressEventData::GetFlavorString();
32
18.2k
}
33
34
0
void ProgressEventData::Dump(Stream *s) const {
35
0
  s->Printf(" id = %" PRIu64 ", title = \"%s\"", m_id, m_title.c_str());
36
0
  if (!m_details.empty())
37
0
    s->Printf(", details = \"%s\"", m_details.c_str());
38
0
  if (m_completed == 0 || m_completed == m_total)
39
0
    s->Printf(", type = %s", m_completed == 0 ? "start" : "end");
40
0
  else
41
0
    s->PutCString(", type = update");
42
  // If m_total is UINT64_MAX, there is no progress to report, just "start"
43
  // and "end". If it isn't we will show the completed and total amounts.
44
0
  if (m_total != UINT64_MAX)
45
0
    s->Printf(", progress = %" PRIu64 " of %" PRIu64, m_completed, m_total);
46
0
}
47
48
const ProgressEventData *
49
18.2k
ProgressEventData::GetEventDataFromEvent(const Event *event_ptr) {
50
18.2k
  return GetEventDataFromEventImpl<ProgressEventData>(event_ptr);
51
18.2k
}
52
53
StructuredData::DictionarySP
54
2
ProgressEventData::GetAsStructuredData(const Event *event_ptr) {
55
2
  const ProgressEventData *progress_data =
56
2
      ProgressEventData::GetEventDataFromEvent(event_ptr);
57
58
2
  if (!progress_data)
59
0
    return {};
60
61
2
  auto dictionary_sp = std::make_shared<StructuredData::Dictionary>();
62
2
  dictionary_sp->AddStringItem("title", progress_data->GetTitle());
63
2
  dictionary_sp->AddStringItem("details", progress_data->GetDetails());
64
2
  dictionary_sp->AddStringItem("message", progress_data->GetMessage());
65
2
  dictionary_sp->AddIntegerItem("progress_id", progress_data->GetID());
66
2
  dictionary_sp->AddIntegerItem("completed", progress_data->GetCompleted());
67
2
  dictionary_sp->AddIntegerItem("total", progress_data->GetTotal());
68
2
  dictionary_sp->AddBooleanItem("debugger_specific",
69
2
                                progress_data->IsDebuggerSpecific());
70
71
2
  return dictionary_sp;
72
2
}
73
74
106
llvm::StringRef DiagnosticEventData::GetPrefix() const {
75
106
  switch (m_type) {
76
0
  case Type::Info:
77
0
    return "info";
78
77
  case Type::Warning:
79
77
    return "warning";
80
29
  case Type::Error:
81
29
    return "error";
82
106
  }
83
0
  llvm_unreachable("Fully covered switch above!");
84
0
}
85
86
98
void DiagnosticEventData::Dump(Stream *s) const {
87
98
  llvm::HighlightColor color = m_type == Type::Warning
88
98
                                   ? 
llvm::HighlightColor::Warning73
89
98
                                   : 
llvm::HighlightColor::Error25
;
90
98
  llvm::WithColor(s->AsRawOstream(), color, llvm::ColorMode::Enable)
91
98
      << GetPrefix();
92
98
  *s << ": " << GetMessage() << '\n';
93
98
  s->Flush();
94
98
}
95
96
64
llvm::StringRef DiagnosticEventData::GetFlavorString() {
97
64
  return "DiagnosticEventData";
98
64
}
99
100
32
llvm::StringRef DiagnosticEventData::GetFlavor() const {
101
32
  return DiagnosticEventData::GetFlavorString();
102
32
}
103
104
const DiagnosticEventData *
105
32
DiagnosticEventData::GetEventDataFromEvent(const Event *event_ptr) {
106
32
  return GetEventDataFromEventImpl<DiagnosticEventData>(event_ptr);
107
32
}
108
109
StructuredData::DictionarySP
110
2
DiagnosticEventData::GetAsStructuredData(const Event *event_ptr) {
111
2
  const DiagnosticEventData *diagnostic_data =
112
2
      DiagnosticEventData::GetEventDataFromEvent(event_ptr);
113
114
2
  if (!diagnostic_data)
115
0
    return {};
116
117
2
  auto dictionary_sp = std::make_shared<StructuredData::Dictionary>();
118
2
  dictionary_sp->AddStringItem("message", diagnostic_data->GetMessage());
119
2
  dictionary_sp->AddStringItem("type", diagnostic_data->GetPrefix());
120
2
  dictionary_sp->AddBooleanItem("debugger_specific",
121
2
                                diagnostic_data->IsDebuggerSpecific());
122
2
  return dictionary_sp;
123
2
}
124
125
0
llvm::StringRef SymbolChangeEventData::GetFlavorString() {
126
0
  return "SymbolChangeEventData";
127
0
}
128
129
0
llvm::StringRef SymbolChangeEventData::GetFlavor() const {
130
0
  return SymbolChangeEventData::GetFlavorString();
131
0
}
132
133
const SymbolChangeEventData *
134
0
SymbolChangeEventData::GetEventDataFromEvent(const Event *event_ptr) {
135
0
  return GetEventDataFromEventImpl<SymbolChangeEventData>(event_ptr);
136
0
}
137
138
0
void SymbolChangeEventData::DoOnRemoval(Event *event_ptr) {
139
0
  DebuggerSP debugger_sp(m_debugger_wp.lock());
140
0
  if (!debugger_sp)
141
0
    return;
142
143
0
  for (TargetSP target_sp : debugger_sp->GetTargetList().Targets()) {
144
0
    if (ModuleSP module_sp =
145
0
            target_sp->GetImages().FindModule(m_module_spec.GetUUID())) {
146
0
      {
147
0
        std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
148
0
        if (!module_sp->GetSymbolFileFileSpec())
149
0
          module_sp->SetSymbolFileFileSpec(m_module_spec.GetSymbolFileSpec());
150
0
      }
151
0
      ModuleList module_list;
152
0
      module_list.Append(module_sp);
153
0
      target_sp->SymbolsDidLoad(module_list);
154
0
    }
155
0
  }
156
0
}