LLDB mainline
DebuggerEvents.cpp
Go to the documentation of this file.
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
10#include "lldb/Core/Debugger.h"
11#include "lldb/Core/Module.h"
12#include "lldb/Core/Progress.h"
13#include "llvm/Support/WithColor.h"
14
15using namespace lldb_private;
16using namespace lldb;
17
18template <typename T>
19static const T *GetEventDataFromEventImpl(const Event *event_ptr) {
20 if (event_ptr)
21 if (const EventData *event_data = event_ptr->GetData())
22 if (event_data->GetFlavor() == T::GetFlavorString())
23 return static_cast<const T *>(event_ptr->GetData());
24 return nullptr;
25}
26
28 return "ProgressEventData";
29}
30
31llvm::StringRef ProgressEventData::GetFlavor() const {
33}
34
36 s->Printf(" id = %" PRIu64 ", title = \"%s\"", m_id, m_title.c_str());
37 if (!m_details.empty())
38 s->Printf(", details = \"%s\"", m_details.c_str());
39 if (m_completed == 0 || m_completed == m_total)
40 s->Printf(", type = %s", m_completed == 0 ? "start" : "end");
41 else
42 s->PutCString(", type = update");
43 // If m_total is UINT64_MAX, there is no progress to report, just "start"
44 // and "end". If it isn't we will show the completed and total amounts.
46 s->Printf(", progress = %" PRIu64 " of %" PRIu64, m_completed, m_total);
47}
48
51 return GetEventDataFromEventImpl<ProgressEventData>(event_ptr);
52}
53
56 const ProgressEventData *progress_data =
58
59 if (!progress_data)
60 return {};
61
62 auto dictionary_sp = std::make_shared<StructuredData::Dictionary>();
63 dictionary_sp->AddStringItem("title", progress_data->GetTitle());
64 dictionary_sp->AddStringItem("details", progress_data->GetDetails());
65 dictionary_sp->AddStringItem("message", progress_data->GetMessage());
66 dictionary_sp->AddIntegerItem("progress_id", progress_data->GetID());
67 dictionary_sp->AddIntegerItem("completed", progress_data->GetCompleted());
68 dictionary_sp->AddIntegerItem("total", progress_data->GetTotal());
69 dictionary_sp->AddBooleanItem("debugger_specific",
70 progress_data->IsDebuggerSpecific());
71
72 return dictionary_sp;
73}
74
75llvm::StringRef DiagnosticEventData::GetPrefix() const {
76 switch (m_type) {
77 case Type::Info:
78 return "info";
79 case Type::Warning:
80 return "warning";
81 case Type::Error:
82 return "error";
83 }
84 llvm_unreachable("Fully covered switch above!");
85}
86
88 llvm::HighlightColor color = m_type == Type::Warning
89 ? llvm::HighlightColor::Warning
90 : llvm::HighlightColor::Error;
91 llvm::WithColor(s->AsRawOstream(), color, llvm::ColorMode::Enable)
92 << GetPrefix();
93 *s << ": " << GetMessage() << '\n';
94 s->Flush();
95}
96
98 return "DiagnosticEventData";
99}
100
101llvm::StringRef DiagnosticEventData::GetFlavor() const {
103}
104
107 return GetEventDataFromEventImpl<DiagnosticEventData>(event_ptr);
108}
109
112 const DiagnosticEventData *diagnostic_data =
114
115 if (!diagnostic_data)
116 return {};
117
118 auto dictionary_sp = std::make_shared<StructuredData::Dictionary>();
119 dictionary_sp->AddStringItem("message", diagnostic_data->GetMessage());
120 dictionary_sp->AddStringItem("type", diagnostic_data->GetPrefix());
121 dictionary_sp->AddBooleanItem("debugger_specific",
122 diagnostic_data->IsDebuggerSpecific());
123 return dictionary_sp;
124}
125
127 return "SymbolChangeEventData";
128}
129
130llvm::StringRef SymbolChangeEventData::GetFlavor() const {
132}
133
136 return GetEventDataFromEventImpl<SymbolChangeEventData>(event_ptr);
137}
138
140 DebuggerSP debugger_sp(m_debugger_wp.lock());
141 if (!debugger_sp)
142 return;
143
144 for (TargetSP target_sp : debugger_sp->GetTargetList().Targets()) {
145 if (ModuleSP module_sp =
146 target_sp->GetImages().FindModule(m_module_spec.GetUUID())) {
147 {
148 std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
149 if (!module_sp->GetSymbolFileFileSpec())
150 module_sp->SetSymbolFileFileSpec(m_module_spec.GetSymbolFileSpec());
151 }
152 ModuleList module_list;
153 module_list.Append(module_sp);
154 target_sp->SymbolsDidLoad(module_list);
155 }
156 }
157}
static const T * GetEventDataFromEventImpl(const Event *event_ptr)
void Dump(Stream *s) const override
static llvm::StringRef GetFlavorString()
const std::string & GetMessage() const
llvm::StringRef GetPrefix() const
static StructuredData::DictionarySP GetAsStructuredData(const Event *event_ptr)
static const DiagnosticEventData * GetEventDataFromEvent(const Event *event_ptr)
llvm::StringRef GetFlavor() const override
EventData * GetData()
Definition: Event.h:189
A collection class for Module objects.
Definition: ModuleList.h:103
void Append(const lldb::ModuleSP &module_sp, bool notify=true)
Append a module to the module list.
Definition: ModuleList.cpp:247
FileSpec & GetSymbolFileSpec()
Definition: ModuleSpec.h:77
void Dump(Stream *s) const override
llvm::StringRef GetFlavor() const override
static const ProgressEventData * GetEventDataFromEvent(const Event *event_ptr)
static StructuredData::DictionarySP GetAsStructuredData(const Event *event_ptr)
std::string m_details
Details associated with this progress event update.
static llvm::StringRef GetFlavorString()
const uint64_t m_id
Unique ID used to associate progress events.
const std::string & GetTitle() const
std::string m_title
The title of this progress event.
std::string GetMessage() const
const std::string & GetDetails() const
static constexpr uint64_t kNonDeterministicTotal
Used to indicate a non-deterministic progress report.
Definition: Progress.h:98
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
llvm::raw_ostream & AsRawOstream()
Returns a raw_ostream that forwards the data to this Stream object.
Definition: Stream.h:401
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:134
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition: Stream.cpp:65
virtual void Flush()=0
Flush the stream.
std::shared_ptr< Dictionary > DictionarySP
static const SymbolChangeEventData * GetEventDataFromEvent(const Event *event_ptr)
llvm::StringRef GetFlavor() const override
static llvm::StringRef GetFlavorString()
void DoOnRemoval(Event *event_ptr) override
A class that represents a running process on the host machine.
Definition: SBAttachInfo.h:14
Definition: SBAddress.h:15
std::shared_ptr< lldb_private::Debugger > DebuggerSP
Definition: lldb-forward.h:331
std::shared_ptr< lldb_private::Target > TargetSP
Definition: lldb-forward.h:436
std::shared_ptr< lldb_private::Module > ModuleSP
Definition: lldb-forward.h:365