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"
20
21using namespace lldb;
22using namespace lldb_private;
23
25
26SBEvent::SBEvent(uint32_t event_type, const char *cstr, uint32_t cstr_len)
27 : m_event_sp(new Event(event_type, new EventDataBytes(cstr, cstr_len))),
28 m_opaque_ptr(m_event_sp.get()) {
29 LLDB_INSTRUMENT_VA(this, event_type, cstr, cstr_len);
30}
31
33 : m_event_sp(event_sp), m_opaque_ptr(event_sp.get()) {
34 LLDB_INSTRUMENT_VA(this, event_sp);
35}
36
37SBEvent::SBEvent(Event *event_ptr) : m_opaque_ptr(event_ptr) {
38 LLDB_INSTRUMENT_VA(this, event_ptr);
39}
40
42 : m_event_sp(rhs.m_event_sp), m_opaque_ptr(rhs.m_opaque_ptr) {
43 LLDB_INSTRUMENT_VA(this, rhs);
44}
45
47 LLDB_INSTRUMENT_VA(this, rhs);
48
49 if (this != &rhs) {
52 }
53 return *this;
54}
55
56SBEvent::~SBEvent() = default;
57
60
61 Event *lldb_event = get();
62 if (lldb_event) {
63 EventData *event_data = lldb_event->GetData();
64 if (event_data)
65 return ConstString(lldb_event->GetData()->GetFlavor()).GetCString();
66 }
67 return nullptr;
68}
69
70uint32_t SBEvent::GetType() const {
72
73 const Event *lldb_event = get();
74 uint32_t event_type = 0;
75 if (lldb_event)
76 event_type = lldb_event->GetType();
77
78
79 return event_type;
80}
81
84
85 SBBroadcaster broadcaster;
86 const Event *lldb_event = get();
87 if (lldb_event)
88 broadcaster.reset(lldb_event->GetBroadcaster(), false);
89 return broadcaster;
90}
91
92const char *SBEvent::GetBroadcasterClass() const {
94
95 const Event *lldb_event = get();
96 if (lldb_event)
97 return lldb_event->GetBroadcaster()->GetBroadcasterClass().AsCString();
98 else
99 return "unknown class";
100}
101
103 LLDB_INSTRUMENT_VA(this, broadcaster);
104
105 if (broadcaster)
106 return BroadcasterMatchesRef(*broadcaster);
107 return false;
108}
109
111 LLDB_INSTRUMENT_VA(this, broadcaster);
112
113 Event *lldb_event = get();
114 bool success = false;
115 if (lldb_event)
116 success = lldb_event->BroadcasterIs(broadcaster.get());
117
118
119 return success;
120}
121
123 LLDB_INSTRUMENT_VA(this);
124
125 Event *lldb_event = get();
126 if (lldb_event)
127 lldb_event->Clear();
128}
129
131
133 // There is a dangerous accessor call GetSharedPtr which can be used, so if
134 // we have anything valid in m_event_sp, we must use that since if it gets
135 // used by a function that puts something in there, then it won't update
136 // m_opaque_ptr...
137 if (m_event_sp)
138 m_opaque_ptr = m_event_sp.get();
139
140 return m_opaque_ptr;
141}
142
143void SBEvent::reset(EventSP &event_sp) {
144 m_event_sp = event_sp;
145 m_opaque_ptr = m_event_sp.get();
146}
147
148void SBEvent::reset(Event *event_ptr) {
149 m_opaque_ptr = event_ptr;
150 m_event_sp.reset();
151}
152
153bool SBEvent::IsValid() const {
154 LLDB_INSTRUMENT_VA(this);
155 return this->operator bool();
156}
157SBEvent::operator bool() const {
158 LLDB_INSTRUMENT_VA(this);
159
160 // Do NOT use m_opaque_ptr directly!!! Must use the SBEvent::get() accessor.
161 // See comments in SBEvent::get()....
162 return SBEvent::get() != nullptr;
163}
164
165const char *SBEvent::GetCStringFromEvent(const SBEvent &event) {
166 LLDB_INSTRUMENT_VA(event);
167
168 return ConstString(static_cast<const char *>(
170 .GetCString();
171}
172
174 LLDB_INSTRUMENT_VA(this, description);
175
176 Stream &strm = description.ref();
177
178 if (get()) {
179 m_opaque_ptr->Dump(&strm);
180 } else
181 strm.PutCString("No value");
182
183 return true;
184}
185
186bool SBEvent::GetDescription(SBStream &description) const {
187 LLDB_INSTRUMENT_VA(this, description);
188
189 Stream &strm = description.ref();
190
191 if (get()) {
192 m_opaque_ptr->Dump(&strm);
193 } else
194 strm.PutCString("No value");
195
196 return true;
197}
#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:92
uint32_t GetType() const
Definition: SBEvent.cpp:70
void Clear()
Definition: SBEvent.cpp:122
const char * GetDataFlavor()
Definition: SBEvent.cpp:58
bool GetDescription(lldb::SBStream &description)
Definition: SBEvent.cpp:173
lldb::EventSP m_event_sp
Definition: SBEvent.h:91
lldb_private::Event * get() const
Definition: SBEvent.cpp:132
bool BroadcasterMatchesPtr(const lldb::SBBroadcaster *broadcaster)
Definition: SBEvent.cpp:102
lldb::SBBroadcaster GetBroadcaster() const
Definition: SBEvent.cpp:82
bool BroadcasterMatchesRef(const lldb::SBBroadcaster &broadcaster)
Definition: SBEvent.cpp:110
const char * GetBroadcasterClass() const
Definition: SBEvent.cpp:92
void reset(lldb::EventSP &event_sp)
Definition: SBEvent.cpp:143
bool IsValid() const
Definition: SBEvent.cpp:153
static const char * GetCStringFromEvent(const lldb::SBEvent &event)
Definition: SBEvent.cpp:165
const SBEvent & operator=(const lldb::SBEvent &rhs)
Definition: SBEvent.cpp:46
lldb::EventSP & GetSP() const
Definition: SBEvent.cpp:130
lldb_private::Stream & ref()
Definition: SBStream.cpp:177
virtual ConstString & GetBroadcasterClass() const
This needs to be filled in if you are going to register the broadcaster with the broadcaster manager ...
A uniqued constant string class.
Definition: ConstString.h:40
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
Definition: ConstString.h:182
const char * GetCString() const
Get the string value as a C string.
Definition: ConstString.h:205
static const void * GetBytesFromEvent(const Event *event_ptr)
Definition: Event.cpp:164
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
void Dump(Stream *s) const
Definition: Event.cpp:50
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
A class that represents a running process on the host machine.
Definition: SBAttachInfo.h:14
Definition: SBAddress.h:15
std::shared_ptr< lldb_private::Event > EventSP
Definition: lldb-forward.h:333