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"
10 #include "lldb/API/SBBroadcaster.h"
11 #include "lldb/API/SBStream.h"
13 
15 #include "lldb/Core/StreamFile.h"
17 #include "lldb/Target/Process.h"
19 #include "lldb/Utility/Event.h"
20 #include "lldb/Utility/Stream.h"
21 
22 using namespace lldb;
23 using namespace lldb_private;
24 
26 
27 SBEvent::SBEvent(uint32_t event_type, const char *cstr, uint32_t cstr_len)
28  : m_event_sp(new Event(event_type, new EventDataBytes(cstr, cstr_len))),
29  m_opaque_ptr(m_event_sp.get()) {
30  LLDB_INSTRUMENT_VA(this, event_type, cstr, cstr_len);
31 }
32 
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);
36 }
37 
38 SBEvent::SBEvent(Event *event_ptr) : m_opaque_ptr(event_ptr) {
39  LLDB_INSTRUMENT_VA(this, event_ptr);
40 }
41 
43  : m_event_sp(rhs.m_event_sp), m_opaque_ptr(rhs.m_opaque_ptr) {
44  LLDB_INSTRUMENT_VA(this, rhs);
45 }
46 
47 const SBEvent &SBEvent::operator=(const SBEvent &rhs) {
48  LLDB_INSTRUMENT_VA(this, rhs);
49 
50  if (this != &rhs) {
51  m_event_sp = rhs.m_event_sp;
53  }
54  return *this;
55 }
56 
57 SBEvent::~SBEvent() = default;
58 
59 const char *SBEvent::GetDataFlavor() {
60  LLDB_INSTRUMENT_VA(this);
61 
62  Event *lldb_event = get();
63  if (lldb_event) {
64  EventData *event_data = lldb_event->GetData();
65  if (event_data)
66  return lldb_event->GetData()->GetFlavor().AsCString();
67  }
68  return nullptr;
69 }
70 
72  LLDB_INSTRUMENT_VA(this);
73 
74  const Event *lldb_event = get();
75  uint32_t event_type = 0;
76  if (lldb_event)
77  event_type = lldb_event->GetType();
78 
79 
80  return event_type;
81 }
82 
84  LLDB_INSTRUMENT_VA(this);
85 
86  SBBroadcaster broadcaster;
87  const Event *lldb_event = get();
88  if (lldb_event)
89  broadcaster.reset(lldb_event->GetBroadcaster(), false);
90  return broadcaster;
91 }
92 
93 const char *SBEvent::GetBroadcasterClass() const {
94  LLDB_INSTRUMENT_VA(this);
95 
96  const Event *lldb_event = get();
97  if (lldb_event)
98  return lldb_event->GetBroadcaster()->GetBroadcasterClass().AsCString();
99  else
100  return "unknown class";
101 }
102 
104  LLDB_INSTRUMENT_VA(this, broadcaster);
105 
106  if (broadcaster)
107  return BroadcasterMatchesRef(*broadcaster);
108  return false;
109 }
110 
112  LLDB_INSTRUMENT_VA(this, broadcaster);
113 
114  Event *lldb_event = get();
115  bool success = false;
116  if (lldb_event)
117  success = lldb_event->BroadcasterIs(broadcaster.get());
118 
119 
120  return success;
121 }
122 
124  LLDB_INSTRUMENT_VA(this);
125 
126  Event *lldb_event = get();
127  if (lldb_event)
128  lldb_event->Clear();
129 }
130 
131 EventSP &SBEvent::GetSP() const { return m_event_sp; }
132 
133 Event *SBEvent::get() const {
134  // There is a dangerous accessor call GetSharedPtr which can be used, so if
135  // we have anything valid in m_event_sp, we must use that since if it gets
136  // used by a function that puts something in there, then it won't update
137  // m_opaque_ptr...
138  if (m_event_sp)
139  m_opaque_ptr = m_event_sp.get();
140 
141  return m_opaque_ptr;
142 }
143 
144 void SBEvent::reset(EventSP &event_sp) {
145  m_event_sp = event_sp;
146  m_opaque_ptr = m_event_sp.get();
147 }
148 
149 void SBEvent::reset(Event *event_ptr) {
150  m_opaque_ptr = event_ptr;
151  m_event_sp.reset();
152 }
153 
154 bool SBEvent::IsValid() const {
155  LLDB_INSTRUMENT_VA(this);
156  return this->operator bool();
157 }
158 SBEvent::operator bool() const {
159  LLDB_INSTRUMENT_VA(this);
160 
161  // Do NOT use m_opaque_ptr directly!!! Must use the SBEvent::get() accessor.
162  // See comments in SBEvent::get()....
163  return SBEvent::get() != nullptr;
164 }
165 
166 const char *SBEvent::GetCStringFromEvent(const SBEvent &event) {
167  LLDB_INSTRUMENT_VA(event);
168 
169  return static_cast<const char *>(
171 }
172 
173 bool SBEvent::GetDescription(SBStream &description) {
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 
186 bool 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 }
Instrumentation.h
lldb::SBEvent::get
lldb_private::Event * get() const
Definition: SBEvent.cpp:133
lldb::SBStream::ref
lldb_private::Stream & ref()
Definition: SBStream.cpp:176
lldb_private::EventData::GetFlavor
virtual ConstString GetFlavor() const =0
lldb_private::Event
Definition: Event.h:182
lldb_private::Event::Clear
void Clear()
Definition: Event.h:230
lldb::SBEvent::m_event_sp
lldb::EventSP m_event_sp
Definition: SBEvent.h:81
lldb_private::Broadcaster::GetBroadcasterClass
virtual ConstString & GetBroadcasterClass() const
This needs to be filled in if you are going to register the broadcaster with the broadcaster manager ...
Definition: Broadcaster.cpp:310
lldb_private::EventData
Definition: Event.h:36
lldb::SBEvent::GetDescription
bool GetDescription(lldb::SBStream &description)
Definition: SBEvent.cpp:173
lldb_private::ConstString::AsCString
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
Definition: ConstString.h:192
lldb::SBEvent
Definition: SBEvent.h:21
lldb_private::Stream
Definition: Stream.h:28
lldb::SBEvent::GetCStringFromEvent
static const char * GetCStringFromEvent(const lldb::SBEvent &event)
Definition: SBEvent.cpp:166
Process.h
lldb::SBEvent::operator=
const SBEvent & operator=(const lldb::SBEvent &rhs)
Definition: SBEvent.cpp:47
lldb::SBEvent::BroadcasterMatchesRef
bool BroadcasterMatchesRef(const lldb::SBBroadcaster &broadcaster)
Definition: SBEvent.cpp:111
lldb_private::Event::GetType
uint32_t GetType() const
Definition: Event.h:208
lldb_private::Event::GetData
EventData * GetData()
Definition: Event.h:202
lldb::SBEvent::m_opaque_ptr
lldb_private::Event * m_opaque_ptr
Definition: SBEvent.h:82
SBStream.h
bool
lldb_private::Event::Dump
void Dump(Stream *s) const
Definition: Event.cpp:47
lldb::SBBroadcaster::reset
void reset(lldb_private::Broadcaster *broadcaster, bool owns)
Definition: SBBroadcaster.cpp:118
lldb::SBEvent::GetSP
lldb::EventSP & GetSP() const
Definition: SBEvent.cpp:131
lldb::SBEvent::reset
void reset(lldb::EventSP &event_sp)
SBBroadcaster.h
lldb::SBEvent::SBEvent
SBEvent()
Definition: SBEvent.cpp:25
lldb_private::EventDataBytes
Definition: Event.h:58
Event.h
lldb::SBEvent::GetType
uint32_t GetType() const
Definition: SBEvent.cpp:71
StreamFile.h
uint32_t
lldb::SBBroadcaster::get
lldb_private::Broadcaster * get() const
Definition: SBBroadcaster.cpp:116
lldb_private::EventDataBytes::GetBytesFromEvent
static const void * GetBytesFromEvent(const Event *event_ptr)
Definition: Event.cpp:156
lldb::SBEvent::GetBroadcasterClass
const char * GetBroadcasterClass() const
Definition: SBEvent.cpp:93
lldb_private::Event::BroadcasterIs
bool BroadcasterIs(Broadcaster *broadcaster)
Definition: Event.h:221
lldb::SBEvent::GetBroadcaster
lldb::SBBroadcaster GetBroadcaster() const
Definition: SBEvent.cpp:83
lldb::SBEvent::BroadcasterMatchesPtr
bool BroadcasterMatchesPtr(const lldb::SBBroadcaster *broadcaster)
Definition: SBEvent.cpp:103
SBEvent.h
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb::SBEvent::GetDataFlavor
const char * GetDataFlavor()
Definition: SBEvent.cpp:59
lldb_private::Event::GetBroadcaster
Broadcaster * GetBroadcaster() const
Definition: Event.h:212
Breakpoint.h
lldb::SBEvent::IsValid
bool IsValid() const
Definition: SBEvent.cpp:154
LLDB_INSTRUMENT_VA
#define LLDB_INSTRUMENT_VA(...)
Definition: Instrumentation.h:98
CommandInterpreter.h
ConstString.h
lldb::SBBroadcaster
Definition: SBBroadcaster.h:16
Stream.h
lldb::SBEvent::~SBEvent
~SBEvent()
lldb_private::Stream::PutCString
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition: Stream.cpp:63
lldb::SBStream
Definition: SBStream.h:18
lldb::SBEvent::Clear
void Clear()
Definition: SBEvent.cpp:123
lldb
Definition: SBAddress.h:15