[lldb][dwarf] Compute fully qualified names on simplified template names with DWARFT...
[llvm-project.git] / lldb / source / API / SBEvent.cpp
blobaa9c0ff097d45666d76085c3778e9587c21a1d4f
1 //===-- SBEvent.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 //===----------------------------------------------------------------------===//
9 #include "lldb/API/SBEvent.h"
10 #include "lldb/API/SBBroadcaster.h"
11 #include "lldb/API/SBStream.h"
12 #include "lldb/Utility/Instrumentation.h"
14 #include "lldb/Breakpoint/Breakpoint.h"
15 #include "lldb/Interpreter/CommandInterpreter.h"
16 #include "lldb/Target/Process.h"
17 #include "lldb/Utility/ConstString.h"
18 #include "lldb/Utility/Event.h"
19 #include "lldb/Utility/Stream.h"
21 using namespace lldb;
22 using namespace lldb_private;
24 SBEvent::SBEvent() { LLDB_INSTRUMENT_VA(this); }
26 SBEvent::SBEvent(uint32_t event_type, const char *cstr, uint32_t cstr_len)
27 : m_event_sp(new Event(
28 event_type, new EventDataBytes(llvm::StringRef(cstr, cstr_len)))),
29 m_opaque_ptr(m_event_sp.get()) {
30 LLDB_INSTRUMENT_VA(this, event_type, cstr, cstr_len);
33 SBEvent::SBEvent(EventSP &event_sp)
34 : m_event_sp(event_sp), m_opaque_ptr(event_sp.get()) {
35 LLDB_INSTRUMENT_VA(this, event_sp);
38 SBEvent::SBEvent(Event *event_ptr) : m_opaque_ptr(event_ptr) {
39 LLDB_INSTRUMENT_VA(this, event_ptr);
42 SBEvent::SBEvent(const SBEvent &rhs)
43 : m_event_sp(rhs.m_event_sp), m_opaque_ptr(rhs.m_opaque_ptr) {
44 LLDB_INSTRUMENT_VA(this, rhs);
47 const SBEvent &SBEvent::operator=(const SBEvent &rhs) {
48 LLDB_INSTRUMENT_VA(this, rhs);
50 if (this != &rhs) {
51 m_event_sp = rhs.m_event_sp;
52 m_opaque_ptr = rhs.m_opaque_ptr;
54 return *this;
57 SBEvent::~SBEvent() = default;
59 const char *SBEvent::GetDataFlavor() {
60 LLDB_INSTRUMENT_VA(this);
62 Event *lldb_event = get();
63 if (lldb_event) {
64 EventData *event_data = lldb_event->GetData();
65 if (event_data)
66 return ConstString(lldb_event->GetData()->GetFlavor()).GetCString();
68 return nullptr;
71 uint32_t SBEvent::GetType() const {
72 LLDB_INSTRUMENT_VA(this);
74 const Event *lldb_event = get();
75 uint32_t event_type = 0;
76 if (lldb_event)
77 event_type = lldb_event->GetType();
80 return event_type;
83 SBBroadcaster SBEvent::GetBroadcaster() const {
84 LLDB_INSTRUMENT_VA(this);
86 SBBroadcaster broadcaster;
87 const Event *lldb_event = get();
88 if (lldb_event)
89 broadcaster.reset(lldb_event->GetBroadcaster(), false);
90 return broadcaster;
93 const char *SBEvent::GetBroadcasterClass() const {
94 LLDB_INSTRUMENT_VA(this);
96 const Event *lldb_event = get();
97 if (lldb_event)
98 return ConstString(lldb_event->GetBroadcaster()->GetBroadcasterClass())
99 .AsCString();
100 else
101 return "unknown class";
104 bool SBEvent::BroadcasterMatchesPtr(const SBBroadcaster *broadcaster) {
105 LLDB_INSTRUMENT_VA(this, broadcaster);
107 if (broadcaster)
108 return BroadcasterMatchesRef(*broadcaster);
109 return false;
112 bool SBEvent::BroadcasterMatchesRef(const SBBroadcaster &broadcaster) {
113 LLDB_INSTRUMENT_VA(this, broadcaster);
115 Event *lldb_event = get();
116 bool success = false;
117 if (lldb_event)
118 success = lldb_event->BroadcasterIs(broadcaster.get());
121 return success;
124 void SBEvent::Clear() {
125 LLDB_INSTRUMENT_VA(this);
127 Event *lldb_event = get();
128 if (lldb_event)
129 lldb_event->Clear();
132 EventSP &SBEvent::GetSP() const { return m_event_sp; }
134 Event *SBEvent::get() const {
135 // There is a dangerous accessor call GetSharedPtr which can be used, so if
136 // we have anything valid in m_event_sp, we must use that since if it gets
137 // used by a function that puts something in there, then it won't update
138 // m_opaque_ptr...
139 if (m_event_sp)
140 m_opaque_ptr = m_event_sp.get();
142 return m_opaque_ptr;
145 void SBEvent::reset(EventSP &event_sp) {
146 m_event_sp = event_sp;
147 m_opaque_ptr = m_event_sp.get();
150 void SBEvent::reset(Event *event_ptr) {
151 m_opaque_ptr = event_ptr;
152 m_event_sp.reset();
155 bool SBEvent::IsValid() const {
156 LLDB_INSTRUMENT_VA(this);
157 return this->operator bool();
159 SBEvent::operator bool() const {
160 LLDB_INSTRUMENT_VA(this);
162 // Do NOT use m_opaque_ptr directly!!! Must use the SBEvent::get() accessor.
163 // See comments in SBEvent::get()....
164 return SBEvent::get() != nullptr;
167 const char *SBEvent::GetCStringFromEvent(const SBEvent &event) {
168 LLDB_INSTRUMENT_VA(event);
170 return ConstString(static_cast<const char *>(
171 EventDataBytes::GetBytesFromEvent(event.get())))
172 .GetCString();
175 bool SBEvent::GetDescription(SBStream &description) {
176 LLDB_INSTRUMENT_VA(this, description);
178 Stream &strm = description.ref();
180 if (get()) {
181 m_opaque_ptr->Dump(&strm);
182 } else
183 strm.PutCString("No value");
185 return true;
188 bool SBEvent::GetDescription(SBStream &description) const {
189 LLDB_INSTRUMENT_VA(this, description);
191 Stream &strm = description.ref();
193 if (get()) {
194 m_opaque_ptr->Dump(&strm);
195 } else
196 strm.PutCString("No value");
198 return true;