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 static ConstString g_flavor("ProgressEventData");
28 return g_flavor;
29}
30
33}
34
36 s->Printf(" id = %" PRIu64 ", message = \"%s\"", m_id, m_message.c_str());
37 if (m_completed == 0 || m_completed == m_total)
38 s->Printf(", type = %s", m_completed == 0 ? "start" : "end");
39 else
40 s->PutCString(", type = update");
41 // If m_total is UINT64_MAX, there is no progress to report, just "start"
42 // and "end". If it isn't we will show the completed and total amounts.
43 if (m_total != UINT64_MAX)
44 s->Printf(", progress = %" PRIu64 " of %" PRIu64, m_completed, m_total);
45}
46
49 return GetEventDataFromEventImpl<ProgressEventData>(event_ptr);
50}
51
52llvm::StringRef DiagnosticEventData::GetPrefix() const {
53 switch (m_type) {
54 case Type::Info:
55 return "info";
56 case Type::Warning:
57 return "warning";
58 case Type::Error:
59 return "error";
60 }
61 llvm_unreachable("Fully covered switch above!");
62}
63
65 llvm::HighlightColor color = m_type == Type::Warning
66 ? llvm::HighlightColor::Warning
67 : llvm::HighlightColor::Error;
68 llvm::WithColor(s->AsRawOstream(), color, llvm::ColorMode::Enable)
69 << GetPrefix();
70 *s << ": " << GetMessage() << '\n';
71 s->Flush();
72}
73
75 static ConstString g_flavor("DiagnosticEventData");
76 return g_flavor;
77}
78
81}
82
85 return GetEventDataFromEventImpl<DiagnosticEventData>(event_ptr);
86}
87
89 static ConstString g_flavor("SymbolChangeEventData");
90 return g_flavor;
91}
92
95}
96
99 return GetEventDataFromEventImpl<SymbolChangeEventData>(event_ptr);
100}
101
103 DebuggerSP debugger_sp(m_debugger_wp.lock());
104 if (!debugger_sp)
105 return;
106
107 for (TargetSP target_sp : debugger_sp->GetTargetList().Targets()) {
108 if (ModuleSP module_sp =
109 target_sp->GetImages().FindModule(m_module_spec.GetUUID())) {
110 {
111 std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
112 if (!module_sp->GetSymbolFileFileSpec())
113 module_sp->SetSymbolFileFileSpec(m_module_spec.GetSymbolFileSpec());
114 }
115 ModuleList module_list;
116 module_list.Append(module_sp);
117 target_sp->SymbolsDidLoad(module_list);
118 }
119 }
120}
static const T * GetEventDataFromEventImpl(const Event *event_ptr)
A uniqued constant string class.
Definition: ConstString.h:39
void Dump(Stream *s) const override
static ConstString GetFlavorString()
const std::string & GetMessage() const
llvm::StringRef GetPrefix() const
static const DiagnosticEventData * GetEventDataFromEvent(const Event *event_ptr)
ConstString GetFlavor() const override
EventData * GetData()
Definition: Event.h:202
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.
FileSpec & GetSymbolFileSpec()
Definition: ModuleSpec.h:77
void Dump(Stream *s) const override
static const ProgressEventData * GetEventDataFromEvent(const Event *event_ptr)
ConstString GetFlavor() const override
static ConstString GetFlavorString()
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.
ConstString GetFlavor() const override
static const SymbolChangeEventData * GetEventDataFromEvent(const Event *event_ptr)
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: SBAddress.h:15