LLDB mainline
SBEvent.cpp
Go to the documentation of this file.
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//===----------------------------------------------------------------------===//
8
9#include "lldb/API/SBEvent.h"
11#include "lldb/API/SBStream.h"
13
16#include "lldb/Target/Process.h"
18#include "lldb/Utility/Event.h"
19#include "lldb/Utility/Stream.h"
21
22using namespace lldb;
23using namespace lldb_private;
24
26
27SBEvent::SBEvent(uint32_t event_type, const char *cstr, uint32_t cstr_len)
28 : m_event_sp(new Event(
29 event_type, new EventDataBytes(llvm::StringRef(cstr, cstr_len)))),
31 LLDB_INSTRUMENT_VA(this, event_type, cstr, cstr_len);
32}
33
35 : m_event_sp(event_sp), m_opaque_ptr(event_sp.get()) {
36 LLDB_INSTRUMENT_VA(this, event_sp);
37}
38
39SBEvent::SBEvent(Event *event_ptr) : m_opaque_ptr(event_ptr) {
40 LLDB_INSTRUMENT_VA(this, event_ptr);
41}
42
47
49 LLDB_INSTRUMENT_VA(this, rhs);
50
51 if (this != &rhs) {
54 }
55 return *this;
56}
57
58SBEvent::~SBEvent() = default;
59
62
63 Event *lldb_event = get();
64 if (lldb_event) {
65 EventData *event_data = lldb_event->GetData();
66 if (event_data)
68 lldb_event->GetData()->GetFlavor());
69 }
70 return nullptr;
71}
72
73uint32_t SBEvent::GetType() const {
75
76 const Event *lldb_event = get();
77 uint32_t event_type = 0;
78 if (lldb_event)
79 event_type = lldb_event->GetType();
80
81
82 return event_type;
83}
84
87
88 SBBroadcaster broadcaster;
89 const Event *lldb_event = get();
90 if (lldb_event)
91 broadcaster.reset(lldb_event->GetBroadcaster(), false);
92 return broadcaster;
93}
94
95const char *SBEvent::GetBroadcasterClass() const {
97
98 // An event has no broadcaster until it is broadcast.
99 if (const Event *lldb_event = get())
100 if (Broadcaster *broadcaster = lldb_event->GetBroadcaster())
102 broadcaster->GetBroadcasterClass());
103 return "unknown class";
104}
105
107 LLDB_INSTRUMENT_VA(this, broadcaster);
108
109 if (broadcaster)
110 return BroadcasterMatchesRef(*broadcaster);
111 return false;
112}
113
115 LLDB_INSTRUMENT_VA(this, broadcaster);
116
117 Event *lldb_event = get();
118 bool success = false;
119 if (lldb_event)
120 success = lldb_event->BroadcasterIs(broadcaster.get());
121
122
123 return success;
124}
125
127 LLDB_INSTRUMENT_VA(this);
128
129 Event *lldb_event = get();
130 if (lldb_event)
131 lldb_event->Clear();
132}
133
135
137 // There is a dangerous accessor call GetSharedPtr which can be used, so if
138 // we have anything valid in m_event_sp, we must use that since if it gets
139 // used by a function that puts something in there, then it won't update
140 // m_opaque_ptr...
141 if (m_event_sp)
142 m_opaque_ptr = m_event_sp.get();
143
144 return m_opaque_ptr;
145}
146
147void SBEvent::reset(EventSP &event_sp) {
148 m_event_sp = event_sp;
149 m_opaque_ptr = m_event_sp.get();
150}
151
152void SBEvent::reset(Event *event_ptr) {
153 m_opaque_ptr = event_ptr;
154 m_event_sp.reset();
155}
156
157bool SBEvent::IsValid() const {
158 LLDB_INSTRUMENT_VA(this);
159 return this->operator bool();
160}
161SBEvent::operator bool() const {
162 LLDB_INSTRUMENT_VA(this);
163
164 // Do NOT use m_opaque_ptr directly!!! Must use the SBEvent::get() accessor.
165 // See comments in SBEvent::get()....
166 return SBEvent::get() != nullptr;
167}
168
169const char *SBEvent::GetCStringFromEvent(const SBEvent &event) {
170 LLDB_INSTRUMENT_VA(event);
171
172 return StringPool::GetSystemPool().Intern(static_cast<const char *>(
174}
175
177 LLDB_INSTRUMENT_VA(this, description);
178
179 Stream &strm = description.ref();
180
181 if (get()) {
182 m_opaque_ptr->Dump(&strm);
183 } else
184 strm.PutCString("No value");
185
186 return true;
187}
188
189bool SBEvent::GetDescription(SBStream &description) const {
190 LLDB_INSTRUMENT_VA(this, description);
191
192 Stream &strm = description.ref();
193
194 if (get()) {
195 m_opaque_ptr->Dump(&strm);
196 } else
197 strm.PutCString("No value");
198
199 return true;
200}
#define LLDB_INSTRUMENT_VA(...)
void reset(lldb_private::Broadcaster *broadcaster, bool owns)
lldb_private::Broadcaster * get() const
lldb_private::Event * m_opaque_ptr
Definition SBEvent.h:94
uint32_t GetType() const
Definition SBEvent.cpp:73
const char * GetDataFlavor()
Definition SBEvent.cpp:60
bool GetDescription(lldb::SBStream &description)
Definition SBEvent.cpp:176
lldb::EventSP m_event_sp
Definition SBEvent.h:93
lldb_private::Event * get() const
Definition SBEvent.cpp:136
bool BroadcasterMatchesPtr(const lldb::SBBroadcaster *broadcaster)
Definition SBEvent.cpp:106
lldb::SBBroadcaster GetBroadcaster() const
Definition SBEvent.cpp:85
bool BroadcasterMatchesRef(const lldb::SBBroadcaster &broadcaster)
Definition SBEvent.cpp:114
const char * GetBroadcasterClass() const
Definition SBEvent.cpp:95
void reset(lldb::EventSP &event_sp)
Definition SBEvent.cpp:147
bool IsValid() const
Definition SBEvent.cpp:157
static const char * GetCStringFromEvent(const lldb::SBEvent &event)
Definition SBEvent.cpp:169
friend class SBBroadcaster
Definition SBEvent.h:69
const SBEvent & operator=(const lldb::SBEvent &rhs)
Definition SBEvent.cpp:48
lldb::EventSP & GetSP() const
Definition SBEvent.cpp:134
lldb_private::Stream & ref()
Definition SBStream.cpp:179
An event broadcasting class.
static const void * GetBytesFromEvent(const Event *event_ptr)
Definition Event.cpp:146
virtual llvm::StringRef GetFlavor() const =0
EventData * GetData()
Definition Event.h:199
bool BroadcasterIs(Broadcaster *broadcaster)
Definition Event.h:218
uint32_t GetType() const
Definition Event.h:205
Broadcaster * GetBroadcaster() const
Definition Event.h:209
A stream class that can stream formatted output to a file.
Definition Stream.h:28
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition Stream.cpp:63
const char * Intern(llvm::StringRef str) const
Definition StringPool.h:78
const char * InternNonEmpty(llvm::StringRef str) const
Like Intern, but an empty string yields nullptr.
Definition StringPool.h:81
static StringPoolRef GetSystemPool()
The system pool. Only valid between Initialize and Terminate.
A class that represents a running process on the host machine.
std::shared_ptr< lldb_private::Event > EventSP