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 "llvm/Support/WithColor.h"
13
14using namespace lldb_private;
15using namespace lldb;
16
17template <typename T>
18static const T *GetEventDataFromEventImpl(const Event *event_ptr) {
19 if (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());
23 return nullptr;
24}
25
27 return "ProgressEventData";
28}
29
30llvm::StringRef ProgressEventData::GetFlavor() const {
32}
33
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");
40 else
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);
46}
47
50 return GetEventDataFromEventImpl<ProgressEventData>(event_ptr);
51}
52
55 const ProgressEventData *progress_data =
57
58 if (!progress_data)
59 return {};
60
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());
70
71 return dictionary_sp;
72}
73
74llvm::StringRef DiagnosticEventData::GetPrefix() const {
75 switch (m_type) {
76 case Type::Info:
77 return "info";
78 case Type::Warning:
79 return "warning";
80 case Type::Error:
81 return "error";
82 }
83 llvm_unreachable("Fully covered switch above!");
84}
85
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)
91 << GetPrefix();
92 *s << ": " << GetMessage() << '\n';
93 s->Flush();
94}
95
97 return "DiagnosticEventData";
98}
99
100llvm::StringRef DiagnosticEventData::GetFlavor() const {
102}
103
106 return GetEventDataFromEventImpl<DiagnosticEventData>(event_ptr);
107}
108
111 const DiagnosticEventData *diagnostic_data =
113
114 if (!diagnostic_data)
115 return {};
116
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;
123}
124
126 return "SymbolChangeEventData";
127}
128
129llvm::StringRef SymbolChangeEventData::GetFlavor() const {
131}
132
135 return GetEventDataFromEventImpl<SymbolChangeEventData>(event_ptr);
136}
137
139 DebuggerSP debugger_sp(m_debugger_wp.lock());
140 if (!debugger_sp)
141 return;
142
143 for (TargetSP target_sp : debugger_sp->GetTargetList().Targets()) {
144 if (ModuleSP module_sp =
145 target_sp->GetImages().FindModule(m_module_spec.GetUUID())) {
146 {
147 std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
148 if (!module_sp->GetSymbolFileFileSpec())
149 module_sp->SetSymbolFileFileSpec(m_module_spec.GetSymbolFileSpec());
150 }
151 ModuleList module_list;
152 module_list.Append(module_sp);
153 target_sp->SymbolsDidLoad(module_list);
154 }
155 }
156}
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:199
A collection class for Module objects.
Definition: ModuleList.h:82
void Append(const lldb::ModuleSP &module_sp, bool notify=true)
Append a module to the module list.
Definition: ModuleList.cpp:220
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
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:357
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:107
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition: Stream.cpp:63
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
#define UINT64_MAX
Definition: lldb-defines.h:23
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:321
std::shared_ptr< lldb_private::Target > TargetSP
Definition: lldb-forward.h:423
std::shared_ptr< lldb_private::Module > ModuleSP
Definition: lldb-forward.h:354