1 //===-- DebuggerEvents.cpp ------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "lldb/Core/DebuggerEvents.h"
10 #include "lldb/Core/Debugger.h"
11 #include "lldb/Core/Module.h"
12 #include "llvm/Support/WithColor.h"
14 using namespace lldb_private
;
18 static const T
*GetEventDataFromEventImpl(const Event
*event_ptr
) {
20 if (const EventData
*event_data
= event_ptr
->GetData())
21 if (event_data
->GetFlavor() == T::GetFlavorString())
22 return static_cast<const T
*>(event_ptr
->GetData());
26 llvm::StringRef
ProgressEventData::GetFlavorString() {
27 return "ProgressEventData";
30 llvm::StringRef
ProgressEventData::GetFlavor() const {
31 return ProgressEventData::GetFlavorString();
34 void ProgressEventData::Dump(Stream
*s
) const {
35 s
->Printf(" id = %" PRIu64
", title = \"%s\"", m_id
, m_title
.c_str());
36 if (!m_details
.empty())
37 s
->Printf(", details = \"%s\"", m_details
.c_str());
38 if (m_completed
== 0 || m_completed
== m_total
)
39 s
->Printf(", type = %s", m_completed
== 0 ? "start" : "end");
41 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 if (m_total
!= UINT64_MAX
)
45 s
->Printf(", progress = %" PRIu64
" of %" PRIu64
, m_completed
, m_total
);
48 const ProgressEventData
*
49 ProgressEventData::GetEventDataFromEvent(const Event
*event_ptr
) {
50 return GetEventDataFromEventImpl
<ProgressEventData
>(event_ptr
);
53 StructuredData::DictionarySP
54 ProgressEventData::GetAsStructuredData(const Event
*event_ptr
) {
55 const ProgressEventData
*progress_data
=
56 ProgressEventData::GetEventDataFromEvent(event_ptr
);
61 auto dictionary_sp
= std::make_shared
<StructuredData::Dictionary
>();
62 dictionary_sp
->AddStringItem("title", progress_data
->GetTitle());
63 dictionary_sp
->AddStringItem("details", progress_data
->GetDetails());
64 dictionary_sp
->AddStringItem("message", progress_data
->GetMessage());
65 dictionary_sp
->AddIntegerItem("progress_id", progress_data
->GetID());
66 dictionary_sp
->AddIntegerItem("completed", progress_data
->GetCompleted());
67 dictionary_sp
->AddIntegerItem("total", progress_data
->GetTotal());
68 dictionary_sp
->AddBooleanItem("debugger_specific",
69 progress_data
->IsDebuggerSpecific());
74 llvm::StringRef
DiagnosticEventData::GetPrefix() const {
83 llvm_unreachable("Fully covered switch above!");
86 void DiagnosticEventData::Dump(Stream
*s
) const {
87 llvm::HighlightColor color
= m_type
== Type::Warning
88 ? llvm::HighlightColor::Warning
89 : llvm::HighlightColor::Error
;
90 llvm::WithColor(s
->AsRawOstream(), color
, llvm::ColorMode::Enable
)
92 *s
<< ": " << GetMessage() << '\n';
96 llvm::StringRef
DiagnosticEventData::GetFlavorString() {
97 return "DiagnosticEventData";
100 llvm::StringRef
DiagnosticEventData::GetFlavor() const {
101 return DiagnosticEventData::GetFlavorString();
104 const DiagnosticEventData
*
105 DiagnosticEventData::GetEventDataFromEvent(const Event
*event_ptr
) {
106 return GetEventDataFromEventImpl
<DiagnosticEventData
>(event_ptr
);
109 StructuredData::DictionarySP
110 DiagnosticEventData::GetAsStructuredData(const Event
*event_ptr
) {
111 const DiagnosticEventData
*diagnostic_data
=
112 DiagnosticEventData::GetEventDataFromEvent(event_ptr
);
114 if (!diagnostic_data
)
117 auto dictionary_sp
= std::make_shared
<StructuredData::Dictionary
>();
118 dictionary_sp
->AddStringItem("message", diagnostic_data
->GetMessage());
119 dictionary_sp
->AddStringItem("type", diagnostic_data
->GetPrefix());
120 dictionary_sp
->AddBooleanItem("debugger_specific",
121 diagnostic_data
->IsDebuggerSpecific());
122 return dictionary_sp
;
125 llvm::StringRef
SymbolChangeEventData::GetFlavorString() {
126 return "SymbolChangeEventData";
129 llvm::StringRef
SymbolChangeEventData::GetFlavor() const {
130 return SymbolChangeEventData::GetFlavorString();
133 const SymbolChangeEventData
*
134 SymbolChangeEventData::GetEventDataFromEvent(const Event
*event_ptr
) {
135 return GetEventDataFromEventImpl
<SymbolChangeEventData
>(event_ptr
);
138 void SymbolChangeEventData::DoOnRemoval(Event
*event_ptr
) {
139 DebuggerSP
debugger_sp(m_debugger_wp
.lock());
143 for (TargetSP target_sp
: debugger_sp
->GetTargetList().Targets()) {
144 if (ModuleSP module_sp
=
145 target_sp
->GetImages().FindModule(m_module_spec
.GetUUID())) {
147 std::lock_guard
<std::recursive_mutex
> guard(module_sp
->GetMutex());
148 if (!module_sp
->GetSymbolFileFileSpec())
149 module_sp
->SetSymbolFileFileSpec(m_module_spec
.GetSymbolFileSpec());
151 ModuleList module_list
;
152 module_list
.Append(module_sp
);
153 target_sp
->SymbolsDidLoad(module_list
);