LLDB  mainline
Broadcaster.h
Go to the documentation of this file.
1 //===-- Broadcaster.h -------------------------------------------*- C++ -*-===//
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 #ifndef LLDB_UTILITY_BROADCASTER_H
10 #define LLDB_UTILITY_BROADCASTER_H
11 
13 #include "lldb/lldb-defines.h"
14 #include "lldb/lldb-forward.h"
15 
16 #include "llvm/ADT/SmallVector.h"
17 
18 #include <cstdint>
19 #include <map>
20 #include <memory>
21 #include <mutex>
22 #include <set>
23 #include <string>
24 #include <utility>
25 #include <vector>
26 
27 namespace lldb_private {
28 class Broadcaster;
29 class EventData;
30 class Listener;
31 class Stream;
32 } // namespace lldb_private
33 
34 namespace lldb_private {
35 
36 /// lldb::BroadcastEventSpec
37 ///
38 /// This class is used to specify a kind of event to register for. The
39 /// Debugger maintains a list of BroadcastEventSpec's and when it is made
41 public:
42  BroadcastEventSpec(const ConstString &broadcaster_class, uint32_t event_bits)
43  : m_broadcaster_class(broadcaster_class), m_event_bits(event_bits) {}
44 
45  ~BroadcastEventSpec() = default;
46 
48 
49  uint32_t GetEventBits() const { return m_event_bits; }
50 
51  /// Tell whether this BroadcastEventSpec is contained in in_spec. That is:
52  /// (a) the two spec's share the same broadcaster class (b) the event bits of
53  /// this spec are wholly contained in those of in_spec.
54  bool IsContainedIn(const BroadcastEventSpec &in_spec) const {
56  return false;
57  uint32_t in_bits = in_spec.GetEventBits();
58  if (in_bits == m_event_bits)
59  return true;
60 
61  if ((m_event_bits & in_bits) != 0 && (m_event_bits & ~in_bits) == 0)
62  return true;
63 
64  return false;
65  }
66 
67  bool operator<(const BroadcastEventSpec &rhs) const;
68 
69 private:
72 };
73 
75  : public std::enable_shared_from_this<BroadcasterManager> {
76 public:
77  friend class Listener;
78 
79 protected:
81 
82 public:
83  /// Listeners hold onto weak pointers to their broadcaster managers. So they
84  /// must be made into shared pointers, which you do with
85  /// MakeBroadcasterManager.
86  static lldb::BroadcasterManagerSP MakeBroadcasterManager();
87 
88  ~BroadcasterManager() = default;
89 
90  uint32_t RegisterListenerForEvents(const lldb::ListenerSP &listener_sp,
91  const BroadcastEventSpec &event_spec);
92 
93  bool UnregisterListenerForEvents(const lldb::ListenerSP &listener_sp,
94  const BroadcastEventSpec &event_spec);
95 
96  lldb::ListenerSP
97  GetListenerForEventSpec(const BroadcastEventSpec &event_spec) const;
98 
99  void SignUpListenersForBroadcaster(Broadcaster &broadcaster);
100 
101  void RemoveListener(const lldb::ListenerSP &listener_sp);
102 
103  void RemoveListener(Listener *listener);
104 
105  void Clear();
106 
107 private:
108  typedef std::pair<BroadcastEventSpec, lldb::ListenerSP> event_listener_key;
109  typedef std::map<BroadcastEventSpec, lldb::ListenerSP> collection;
110  typedef std::set<lldb::ListenerSP> listener_collection;
113 
114  mutable std::recursive_mutex m_manager_mutex;
115 
116  // A couple of comparator classes for find_if:
117 
119  public:
120  BroadcasterClassMatches(const ConstString &broadcaster_class)
121  : m_broadcaster_class(broadcaster_class) {}
122 
123  ~BroadcasterClassMatches() = default;
124 
125  bool operator()(const event_listener_key &input) const {
126  return (input.first.GetBroadcasterClass() == m_broadcaster_class);
127  }
128 
129  private:
131  };
132 
134  public:
136  : m_broadcaster_spec(broadcaster_spec) {}
137 
138  ~BroadcastEventSpecMatches() = default;
139 
140  bool operator()(const event_listener_key &input) const {
141  return (input.first.IsContainedIn(m_broadcaster_spec));
142  }
143 
144  private:
146  };
147 
149  public:
151  const BroadcastEventSpec &broadcaster_spec,
152  const lldb::ListenerSP &listener_sp)
153  : m_broadcaster_spec(broadcaster_spec), m_listener_sp(listener_sp) {}
154 
155  ~ListenerMatchesAndSharedBits() = default;
156 
157  bool operator()(const event_listener_key &input) const {
158  return (input.first.GetBroadcasterClass() ==
160  (input.first.GetEventBits() &
162  input.second == m_listener_sp);
163  }
164 
165  private:
167  const lldb::ListenerSP m_listener_sp;
168  };
169 
171  public:
172  explicit ListenerMatches(const lldb::ListenerSP &in_listener_sp)
173  : m_listener_sp(in_listener_sp) {}
174 
175  ~ListenerMatches() = default;
176 
177  bool operator()(const event_listener_key &input) const {
178  if (input.second == m_listener_sp)
179  return true;
180 
181  return false;
182  }
183 
184  private:
185  const lldb::ListenerSP m_listener_sp;
186  };
187 
189  public:
190  ListenerMatchesPointer(const Listener *in_listener)
191  : m_listener(in_listener) {}
192 
193  ~ListenerMatchesPointer() = default;
194 
195  bool operator()(const event_listener_key &input) const {
196  if (input.second.get() == m_listener)
197  return true;
198 
199  return false;
200  }
201 
202  bool operator()(const lldb::ListenerSP &input) const {
203  if (input.get() == m_listener)
204  return true;
205 
206  return false;
207  }
208 
209  private:
211  };
212 };
213 
214 /// \class Broadcaster Broadcaster.h "lldb/Utility/Broadcaster.h" An event
215 /// broadcasting class.
216 ///
217 /// The Broadcaster class is designed to be subclassed by objects that wish to
218 /// vend events in a multi-threaded environment. Broadcaster objects can each
219 /// vend 32 events. Each event is represented by a bit in a 32 bit value and
220 /// these bits can be set:
221 /// \see Broadcaster::SetEventBits(uint32_t)
222 /// or cleared:
223 /// \see Broadcaster::ResetEventBits(uint32_t)
224 /// When an event gets set the Broadcaster object will notify the Listener
225 /// object that is listening for the event (if there is one).
226 ///
227 /// Subclasses should provide broadcast bit definitions for any events they
228 /// vend, typically using an enumeration:
229 /// \code
230 /// class Foo : public Broadcaster
231 /// {
232 /// public:
233 /// // Broadcaster event bits definitions.
234 /// enum
235 /// {
236 /// eBroadcastBitOne = (1 << 0),
237 /// eBroadcastBitTwo = (1 << 1),
238 /// eBroadcastBitThree = (1 << 2),
239 /// ...
240 /// };
241 /// \endcode
242 class Broadcaster {
243  friend class Listener;
244  friend class Event;
245 
246 public:
247  /// Construct with a broadcaster with a name.
248  ///
249  /// \param[in] name
250  /// A NULL terminated C string that contains the name of the
251  /// broadcaster object.
252  Broadcaster(lldb::BroadcasterManagerSP manager_sp, const char *name);
253 
254  /// Destructor.
255  ///
256  /// The destructor is virtual since this class gets subclassed.
257  virtual ~Broadcaster();
258 
259  void CheckInWithManager();
260 
261  /// Broadcast an event which has no associated data.
262  void BroadcastEvent(lldb::EventSP &event_sp) {
263  m_broadcaster_sp->BroadcastEvent(event_sp);
264  }
265 
266  void BroadcastEventIfUnique(lldb::EventSP &event_sp) {
267  m_broadcaster_sp->BroadcastEventIfUnique(event_sp);
268  }
269 
270  void BroadcastEvent(uint32_t event_type,
271  const lldb::EventDataSP &event_data_sp) {
272  m_broadcaster_sp->BroadcastEvent(event_type, event_data_sp);
273  }
274 
275  void BroadcastEvent(uint32_t event_type, EventData *event_data = nullptr) {
276  m_broadcaster_sp->BroadcastEvent(event_type, event_data);
277  }
278 
280  EventData *event_data = nullptr) {
281  m_broadcaster_sp->BroadcastEventIfUnique(event_type, event_data);
282  }
283 
284  void Clear() { m_broadcaster_sp->Clear(); }
285 
286  virtual void AddInitialEventsToListener(const lldb::ListenerSP &listener_sp,
287  uint32_t requested_events);
288 
289  /// Listen for any events specified by \a event_mask.
290  ///
291  /// Only one listener can listen to each event bit in a given Broadcaster.
292  /// Once a listener has acquired an event bit, no other broadcaster will
293  /// have access to it until it is relinquished by the first listener that
294  /// gets it. The actual event bits that get acquired by \a listener may be
295  /// different from what is requested in \a event_mask, and to track this the
296  /// actual event bits that are acquired get returned.
297  ///
298  /// \param[in] listener_sp
299  /// The Listener object that wants to monitor the events that
300  /// get broadcast by this object.
301  ///
302  /// \param[in] event_mask
303  /// A bit mask that indicates which events the listener is
304  /// asking to monitor.
305  ///
306  /// \return
307  /// The actual event bits that were acquired by \a listener.
308  uint32_t AddListener(const lldb::ListenerSP &listener_sp,
309  uint32_t event_mask) {
310  return m_broadcaster_sp->AddListener(listener_sp, event_mask);
311  }
312 
313  /// Get the NULL terminated C string name of this Broadcaster object.
314  ///
315  /// \return
316  /// The NULL terminated C string name of this Broadcaster.
318 
319  /// Get the event name(s) for one or more event bits.
320  ///
321  /// \param[in] event_mask
322  /// A bit mask that indicates which events to get names for.
323  ///
324  /// \return
325  /// The NULL terminated C string name of this Broadcaster.
326  bool GetEventNames(Stream &s, const uint32_t event_mask,
327  bool prefix_with_broadcaster_name) const {
328  return m_broadcaster_sp->GetEventNames(s, event_mask,
329  prefix_with_broadcaster_name);
330  }
331 
332  /// Set the name for an event bit.
333  ///
334  /// \param[in] event_mask
335  /// A bit mask that indicates which events the listener is
336  /// asking to monitor.
337  void SetEventName(uint32_t event_mask, const char *name) {
338  m_broadcaster_sp->SetEventName(event_mask, name);
339  }
340 
341  const char *GetEventName(uint32_t event_mask) const {
342  return m_broadcaster_sp->GetEventName(event_mask);
343  }
344 
345  bool EventTypeHasListeners(uint32_t event_type) {
346  return m_broadcaster_sp->EventTypeHasListeners(event_type);
347  }
348 
349  /// Removes a Listener from this broadcasters list and frees the event bits
350  /// specified by \a event_mask that were previously acquired by \a listener
351  /// (assuming \a listener was listening to this object) for other listener
352  /// objects to use.
353  ///
354  /// \param[in] listener_sp
355  /// A Listener object that previously called AddListener.
356  ///
357  /// \param[in] event_mask
358  /// The event bits \a listener wishes to relinquish.
359  ///
360  /// \return
361  /// \b True if the listener was listening to this broadcaster
362  /// and was removed, \b false otherwise.
363  ///
364  /// \see uint32_t Broadcaster::AddListener (Listener*, uint32_t)
365  bool RemoveListener(const lldb::ListenerSP &listener_sp,
366  uint32_t event_mask = UINT32_MAX) {
367  return m_broadcaster_sp->RemoveListener(listener_sp, event_mask);
368  }
369 
370  /// Provides a simple mechanism to temporarily redirect events from
371  /// broadcaster. When you call this function passing in a listener and
372  /// event type mask, all events from the broadcaster matching the mask will
373  /// now go to the hijacking listener. Only one hijack can occur at a time.
374  /// If we need more than this we will have to implement a Listener stack.
375  ///
376  /// \param[in] listener_sp
377  /// A Listener object. You do not need to call StartListeningForEvents
378  /// for this broadcaster (that would fail anyway since the event bits
379  /// would most likely be taken by the listener(s) you are usurping.
380  ///
381  /// \param[in] event_mask
382  /// The event bits \a listener wishes to hijack.
383  ///
384  /// \return
385  /// \b True if the event mask could be hijacked, \b false otherwise.
386  ///
387  /// \see uint32_t Broadcaster::AddListener (Listener*, uint32_t)
388  bool HijackBroadcaster(const lldb::ListenerSP &listener_sp,
389  uint32_t event_mask = UINT32_MAX) {
390  return m_broadcaster_sp->HijackBroadcaster(listener_sp, event_mask);
391  }
392 
393  bool IsHijackedForEvent(uint32_t event_mask) {
394  return m_broadcaster_sp->IsHijackedForEvent(event_mask);
395  }
396 
397  /// Restore the state of the Broadcaster from a previous hijack attempt.
398  void RestoreBroadcaster() { m_broadcaster_sp->RestoreBroadcaster(); }
399 
400  /// This needs to be filled in if you are going to register the broadcaster
401  /// with the broadcaster manager and do broadcaster class matching.
402  /// FIXME: Probably should make a ManagedBroadcaster subclass with all the
403  /// bits needed to work with the BroadcasterManager, so that it is clearer
404  /// how to add one.
405  virtual ConstString &GetBroadcasterClass() const;
406 
407  lldb::BroadcasterManagerSP GetManager();
408 
409 protected:
410  /// BroadcasterImpl contains the actual Broadcaster implementation. The
411  /// Broadcaster makes a BroadcasterImpl which lives as long as it does. The
412  /// Listeners & the Events hold a weak pointer to the BroadcasterImpl, so
413  /// that they can survive if a Broadcaster they were listening to is
414  /// destroyed w/o their being able to unregister from it (which can happen if
415  /// the Broadcasters & Listeners are being destroyed on separate threads
416  /// simultaneously. The Broadcaster itself can't be shared out as a weak
417  /// pointer, because some things that are broadcasters (e.g. the Target and
418  /// the Process) are shared in their own right.
419  ///
420  /// For the most part, the Broadcaster functions dispatch to the
421  /// BroadcasterImpl, and are documented in the public Broadcaster API above.
423  friend class Listener;
424  friend class Broadcaster;
425 
426  public:
427  BroadcasterImpl(Broadcaster &broadcaster);
428 
429  ~BroadcasterImpl() = default;
430 
431  void BroadcastEvent(lldb::EventSP &event_sp);
432 
433  void BroadcastEventIfUnique(lldb::EventSP &event_sp);
434 
435  void BroadcastEvent(uint32_t event_type, EventData *event_data = nullptr);
436 
437  void BroadcastEvent(uint32_t event_type,
438  const lldb::EventDataSP &event_data_sp);
439 
440  void BroadcastEventIfUnique(uint32_t event_type,
441  EventData *event_data = nullptr);
442 
443  void Clear();
444 
445  uint32_t AddListener(const lldb::ListenerSP &listener_sp,
446  uint32_t event_mask);
447 
448  const char *GetBroadcasterName() const {
450  }
451 
453 
454  bool GetEventNames(Stream &s, const uint32_t event_mask,
455  bool prefix_with_broadcaster_name) const;
456 
457  void SetEventName(uint32_t event_mask, const char *name) {
458  m_event_names[event_mask] = name;
459  }
460 
461  const char *GetEventName(uint32_t event_mask) const {
462  const auto pos = m_event_names.find(event_mask);
463  if (pos != m_event_names.end())
464  return pos->second.c_str();
465  return nullptr;
466  }
467 
468  bool EventTypeHasListeners(uint32_t event_type);
469 
470  bool RemoveListener(lldb_private::Listener *listener,
471  uint32_t event_mask = UINT32_MAX);
472 
473  bool RemoveListener(const lldb::ListenerSP &listener_sp,
474  uint32_t event_mask = UINT32_MAX);
475 
476  bool HijackBroadcaster(const lldb::ListenerSP &listener_sp,
477  uint32_t event_mask = UINT32_MAX);
478 
479  bool IsHijackedForEvent(uint32_t event_mask);
480 
481  void RestoreBroadcaster();
482 
483  protected:
484  void PrivateBroadcastEvent(lldb::EventSP &event_sp, bool unique);
485 
486  const char *GetHijackingListenerName();
487 
488  typedef llvm::SmallVector<std::pair<lldb::ListenerWP, uint32_t>, 4>
490  typedef std::map<uint32_t, std::string> event_names_map;
491 
492  llvm::SmallVector<std::pair<lldb::ListenerSP, uint32_t &>, 4>
493  GetListeners();
494 
495  /// The broadcaster that this implements.
497 
498  /// Optionally define event names for readability and logging for each
499  /// event bit.
501 
502  /// A list of Listener / event_mask pairs that are listening to this
503  /// broadcaster.
505 
506  /// A mutex that protects \a m_listeners.
507  std::recursive_mutex m_listeners_mutex;
508 
509  /// A simple mechanism to intercept events from a broadcaster
510  std::vector<lldb::ListenerSP> m_hijacking_listeners;
511 
512  /// At some point we may want to have a stack or Listener collections, but
513  /// for now this is just for private hijacking.
514  std::vector<uint32_t> m_hijacking_masks;
515 
516  private:
517  BroadcasterImpl(const BroadcasterImpl &) = delete;
518  const BroadcasterImpl &operator=(const BroadcasterImpl &) = delete;
519  };
520 
521  typedef std::shared_ptr<BroadcasterImpl> BroadcasterImplSP;
522  typedef std::weak_ptr<BroadcasterImpl> BroadcasterImplWP;
523 
525 
526  const char *GetHijackingListenerName() {
527  return m_broadcaster_sp->GetHijackingListenerName();
528  }
529 
530 private:
532  lldb::BroadcasterManagerSP m_manager_sp;
533 
534  /// The name of this broadcaster object.
536 
537  Broadcaster(const Broadcaster &) = delete;
538  const Broadcaster &operator=(const Broadcaster &) = delete;
539 };
540 
541 } // namespace lldb_private
542 
543 #endif // LLDB_UTILITY_BROADCASTER_H
lldb_private::Broadcaster::CheckInWithManager
void CheckInWithManager()
Definition: Broadcaster.cpp:48
lldb_private::BroadcasterManager::collection
std::map< BroadcastEventSpec, lldb::ListenerSP > collection
Definition: Broadcaster.h:109
lldb_private::BroadcasterManager::BroadcasterClassMatches
Definition: Broadcaster.h:118
lldb_private::BroadcastEventSpec::GetEventBits
uint32_t GetEventBits() const
Definition: Broadcaster.h:49
lldb_private::BroadcasterManager::SignUpListenersForBroadcaster
void SignUpListenersForBroadcaster(Broadcaster &broadcaster)
Definition: Broadcaster.cpp:440
lldb_private::Broadcaster::GetManager
lldb::BroadcasterManagerSP GetManager()
lldb_private::BroadcasterManager::BroadcasterClassMatches::BroadcasterClassMatches
BroadcasterClassMatches(const ConstString &broadcaster_class)
Definition: Broadcaster.h:120
lldb_private::Broadcaster::BroadcasterImpl::HijackBroadcaster
bool HijackBroadcaster(const lldb::ListenerSP &listener_sp, uint32_t event_mask=UINT32_MAX)
Definition: Broadcaster.cpp:260
lldb_private::Broadcaster::BroadcasterImpl::m_hijacking_masks
std::vector< uint32_t > m_hijacking_masks
At some point we may want to have a stack or Listener collections, but for now this is just for priva...
Definition: Broadcaster.h:514
lldb_private::Event
Definition: Event.h:180
lldb_private::BroadcasterManager::BroadcastEventSpecMatches::~BroadcastEventSpecMatches
~BroadcastEventSpecMatches()=default
lldb_private::Broadcaster::AddInitialEventsToListener
virtual void AddInitialEventsToListener(const lldb::ListenerSP &listener_sp, uint32_t requested_events)
Definition: Broadcaster.cpp:112
lldb_private::BroadcasterManager::ListenerMatchesAndSharedBits::~ListenerMatchesAndSharedBits
~ListenerMatchesAndSharedBits()=default
lldb_private::Broadcaster::BroadcasterImpl::GetBroadcaster
Broadcaster * GetBroadcaster()
Definition: Broadcaster.cpp:82
lldb_private::Broadcaster::BroadcastEvent
void BroadcastEvent(uint32_t event_type, EventData *event_data=nullptr)
Definition: Broadcaster.h:275
lldb_private::Broadcaster::BroadcasterImpl::event_names_map
std::map< uint32_t, std::string > event_names_map
Definition: Broadcaster.h:490
lldb_private::BroadcasterManager::ListenerMatches::m_listener_sp
const lldb::ListenerSP m_listener_sp
Definition: Broadcaster.h:185
lldb_private::Broadcaster::BroadcasterImpl::BroadcastEvent
void BroadcastEvent(lldb::EventSP &event_sp)
lldb_private::BroadcasterManager::ListenerMatchesPointer::~ListenerMatchesPointer
~ListenerMatchesPointer()=default
lldb-defines.h
lldb_private::Broadcaster::m_broadcaster_sp
BroadcasterImplSP m_broadcaster_sp
Definition: Broadcaster.h:531
lldb_private::BroadcasterManager::ListenerMatchesAndSharedBits::operator()
bool operator()(const event_listener_key &input) const
Definition: Broadcaster.h:157
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:308
lldb_private::Broadcaster::BroadcasterImpl::BroadcastEventIfUnique
void BroadcastEventIfUnique(lldb::EventSP &event_sp)
lldb_private::Broadcaster::BroadcasterImpl::GetHijackingListenerName
const char * GetHijackingListenerName()
Definition: Broadcaster.cpp:283
lldb_private::EventData
Definition: Event.h:36
lldb_private::Broadcaster::SetEventName
void SetEventName(uint32_t event_mask, const char *name)
Set the name for an event bit.
Definition: Broadcaster.h:337
lldb_private::BroadcasterManager::ListenerMatchesPointer::m_listener
const Listener * m_listener
Definition: Broadcaster.h:210
lldb_private::Broadcaster::~Broadcaster
virtual ~Broadcaster()
Destructor.
Definition: Broadcaster.cpp:40
lldb_private::BroadcasterManager::BroadcastEventSpecMatches::BroadcastEventSpecMatches
BroadcastEventSpecMatches(const BroadcastEventSpec &broadcaster_spec)
Definition: Broadcaster.h:135
lldb_private::BroadcasterManager::MakeBroadcasterManager
static lldb::BroadcasterManagerSP MakeBroadcasterManager()
Listeners hold onto weak pointers to their broadcaster managers.
Definition: Broadcaster.cpp:322
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:193
lldb_private::BroadcasterManager::~BroadcasterManager
~BroadcasterManager()=default
lldb_private::BroadcasterManager::event_listener_key
std::pair< BroadcastEventSpec, lldb::ListenerSP > event_listener_key
Definition: Broadcaster.h:108
lldb_private::Broadcaster::BroadcasterImplWP
std::weak_ptr< BroadcasterImpl > BroadcasterImplWP
Definition: Broadcaster.h:522
lldb_private::BroadcastEventSpec::IsContainedIn
bool IsContainedIn(const BroadcastEventSpec &in_spec) const
Tell whether this BroadcastEventSpec is contained in in_spec.
Definition: Broadcaster.h:54
lldb_private::Stream
Definition: Stream.h:28
lldb_private::BroadcastEventSpec::GetBroadcasterClass
ConstString GetBroadcasterClass() const
Definition: Broadcaster.h:47
lldb_private::BroadcasterManager::BroadcasterClassMatches::~BroadcasterClassMatches
~BroadcasterClassMatches()=default
lldb_private::BroadcasterManager::ListenerMatches::ListenerMatches
ListenerMatches(const lldb::ListenerSP &in_listener_sp)
Definition: Broadcaster.h:172
lldb_private::BroadcasterManager::RegisterListenerForEvents
uint32_t RegisterListenerForEvents(const lldb::ListenerSP &listener_sp, const BroadcastEventSpec &event_spec)
Definition: Broadcaster.cpp:326
lldb_private::BroadcasterManager::BroadcasterClassMatches::operator()
bool operator()(const event_listener_key &input) const
Definition: Broadcaster.h:125
lldb_private::Broadcaster::BroadcasterImpl::Clear
void Clear()
Definition: Broadcaster.cpp:71
lldb_private::Broadcaster::m_manager_sp
lldb::BroadcasterManagerSP m_manager_sp
Definition: Broadcaster.h:532
lldb_private::Broadcaster::BroadcasterImpl::EventTypeHasListeners
bool EventTypeHasListeners(uint32_t event_type)
Definition: Broadcaster.cpp:150
lldb_private::BroadcastEventSpec::operator<
bool operator<(const BroadcastEventSpec &rhs) const
Definition: Broadcaster.cpp:313
lldb_private::BroadcasterManager::BroadcasterManager
BroadcasterManager()
Definition: Broadcaster.cpp:320
lldb_private::Broadcaster::BroadcasterImpl::m_listeners_mutex
std::recursive_mutex m_listeners_mutex
A mutex that protects m_listeners.
Definition: Broadcaster.h:507
lldb_private::BroadcasterManager::ListenerMatchesAndSharedBits::m_listener_sp
const lldb::ListenerSP m_listener_sp
Definition: Broadcaster.h:167
lldb_private::BroadcasterManager::Clear
void Clear()
Definition: Broadcaster.cpp:456
lldb_private::Broadcaster::BroadcasterImpl::RemoveListener
bool RemoveListener(lldb_private::Listener *listener, uint32_t event_mask=UINT32_MAX)
Definition: Broadcaster.cpp:163
lldb_private::BroadcasterManager::BroadcasterClassMatches::m_broadcaster_class
ConstString m_broadcaster_class
Definition: Broadcaster.h:130
lldb_private::Broadcaster::RestoreBroadcaster
void RestoreBroadcaster()
Restore the state of the Broadcaster from a previous hijack attempt.
Definition: Broadcaster.h:398
lldb_private::Broadcaster::BroadcasterImpl::GetEventName
const char * GetEventName(uint32_t event_mask) const
Definition: Broadcaster.h:461
lldb_private::BroadcasterManager::UnregisterListenerForEvents
bool UnregisterListenerForEvents(const lldb::ListenerSP &listener_sp, const BroadcastEventSpec &event_spec)
Definition: Broadcaster.cpp:351
lldb_private::Broadcaster::m_broadcaster_name
const ConstString m_broadcaster_name
The name of this broadcaster object.
Definition: Broadcaster.h:535
lldb_private::BroadcasterManager::ListenerMatchesPointer::operator()
bool operator()(const event_listener_key &input) const
Definition: Broadcaster.h:195
lldb_private::Broadcaster::BroadcasterImpl::AddListener
uint32_t AddListener(const lldb::ListenerSP &listener_sp, uint32_t event_mask)
Definition: Broadcaster.cpp:116
lldb_private::BroadcasterManager::m_listeners
listener_collection m_listeners
Definition: Broadcaster.h:112
lldb_private::Broadcaster::BroadcastEventIfUnique
void BroadcastEventIfUnique(lldb::EventSP &event_sp)
Definition: Broadcaster.h:266
lldb_private::BroadcasterManager::ListenerMatchesPointer
Definition: Broadcaster.h:188
lldb_private::Broadcaster::BroadcasterImpl::RestoreBroadcaster
void RestoreBroadcaster()
Definition: Broadcaster.cpp:290
lldb_private::ConstString
Definition: ConstString.h:40
lldb_private::BroadcasterManager::BroadcastEventSpecMatches
Definition: Broadcaster.h:133
lldb_private::BroadcasterManager::RemoveListener
void RemoveListener(const lldb::ListenerSP &listener_sp)
Definition: Broadcaster.cpp:423
lldb_private::Broadcaster::BroadcasterImpl::m_hijacking_listeners
std::vector< lldb::ListenerSP > m_hijacking_listeners
A simple mechanism to intercept events from a broadcaster.
Definition: Broadcaster.h:510
lldb_private::Broadcaster::BroadcasterImpl::m_event_names
event_names_map m_event_names
Optionally define event names for readability and logging for each event bit.
Definition: Broadcaster.h:500
lldb_private::Broadcaster::AddListener
uint32_t AddListener(const lldb::ListenerSP &listener_sp, uint32_t event_mask)
Listen for any events specified by event_mask.
Definition: Broadcaster.h:308
lldb_private::Broadcaster::BroadcasterImpl::operator=
const BroadcasterImpl & operator=(const BroadcasterImpl &)=delete
lldb_private::BroadcasterManager::ListenerMatchesAndSharedBits::ListenerMatchesAndSharedBits
ListenerMatchesAndSharedBits(const BroadcastEventSpec &broadcaster_spec, const lldb::ListenerSP &listener_sp)
Definition: Broadcaster.h:150
lldb_private::Broadcaster::EventTypeHasListeners
bool EventTypeHasListeners(uint32_t event_type)
Definition: Broadcaster.h:345
lldb_private::BroadcasterManager::ListenerMatches
Definition: Broadcaster.h:170
lldb_private::BroadcastEventSpec::m_broadcaster_class
ConstString m_broadcaster_class
Definition: Broadcaster.h:70
lldb_private::Broadcaster::BroadcasterImpl
BroadcasterImpl contains the actual Broadcaster implementation.
Definition: Broadcaster.h:422
lldb_private::Broadcaster::RemoveListener
bool RemoveListener(const lldb::ListenerSP &listener_sp, uint32_t event_mask=UINT32_MAX)
Removes a Listener from this broadcasters list and frees the event bits specified by event_mask that ...
Definition: Broadcaster.h:365
lldb_private::Listener
Definition: Listener.h:36
lldb_private::Broadcaster::HijackBroadcaster
bool HijackBroadcaster(const lldb::ListenerSP &listener_sp, uint32_t event_mask=UINT32_MAX)
Provides a simple mechanism to temporarily redirect events from broadcaster.
Definition: Broadcaster.h:388
lldb_private::Broadcaster::BroadcasterImpl::SetEventName
void SetEventName(uint32_t event_mask, const char *name)
Definition: Broadcaster.h:457
lldb_private::Broadcaster::BroadcasterImplSP
std::shared_ptr< BroadcasterImpl > BroadcasterImplSP
Definition: Broadcaster.h:521
lldb_private::BroadcasterManager::GetListenerForEventSpec
lldb::ListenerSP GetListenerForEventSpec(const BroadcastEventSpec &event_spec) const
Definition: Broadcaster.cpp:390
lldb_private::Broadcaster::operator=
const Broadcaster & operator=(const Broadcaster &)=delete
lldb_private::Broadcaster::BroadcastEvent
void BroadcastEvent(lldb::EventSP &event_sp)
Broadcast an event which has no associated data.
Definition: Broadcaster.h:262
lldb_private::Broadcaster::Broadcaster
Broadcaster(lldb::BroadcasterManagerSP manager_sp, const char *name)
Construct with a broadcaster with a name.
lldb_private::BroadcasterManager::ListenerMatchesAndSharedBits
Definition: Broadcaster.h:148
uint32_t
lldb_private::BroadcasterManager::listener_collection
std::set< lldb::ListenerSP > listener_collection
Definition: Broadcaster.h:110
lldb_private::BroadcasterManager
Definition: Broadcaster.h:74
lldb_private::Broadcaster::Clear
void Clear()
Definition: Broadcaster.h:284
lldb_private::Broadcaster::IsHijackedForEvent
bool IsHijackedForEvent(uint32_t event_mask)
Definition: Broadcaster.h:393
lldb_private::BroadcasterManager::ListenerMatchesPointer::operator()
bool operator()(const lldb::ListenerSP &input) const
Definition: Broadcaster.h:202
lldb_private::BroadcasterManager::ListenerMatchesAndSharedBits::m_broadcaster_spec
BroadcastEventSpec m_broadcaster_spec
Definition: Broadcaster.h:166
lldb_private::BroadcastEventSpec
lldb::BroadcastEventSpec
Definition: Broadcaster.h:40
lldb_private::Broadcaster::BroadcasterImpl::BroadcasterImpl
BroadcasterImpl(Broadcaster &broadcaster)
Definition: Broadcaster.cpp:36
lldb_private::Broadcaster::BroadcasterImpl::GetListeners
llvm::SmallVector< std::pair< lldb::ListenerSP, uint32_t & >, 4 > GetListeners()
Definition: Broadcaster.cpp:55
UINT32_MAX
#define UINT32_MAX
Definition: lldb-defines.h:31
lldb_private::Broadcaster::GetEventName
const char * GetEventName(uint32_t event_mask) const
Definition: Broadcaster.h:341
lldb_private::Broadcaster::BroadcastEventIfUnique
void BroadcastEventIfUnique(uint32_t event_type, EventData *event_data=nullptr)
Definition: Broadcaster.h:279
lldb_private::Broadcaster::BroadcasterImpl::PrivateBroadcastEvent
void PrivateBroadcastEvent(lldb::EventSP &event_sp, bool unique)
Definition: Broadcaster.cpp:191
lldb_private::Broadcaster::BroadcasterImpl::IsHijackedForEvent
bool IsHijackedForEvent(uint32_t event_mask)
Definition: Broadcaster.cpp:275
lldb_private::BroadcastEventSpec::~BroadcastEventSpec
~BroadcastEventSpec()=default
lldb-forward.h
lldb_private::BroadcasterManager::ListenerMatches::~ListenerMatches
~ListenerMatches()=default
lldb_private::Broadcaster::GetBroadcasterName
ConstString GetBroadcasterName()
Get the NULL terminated C string name of this Broadcaster object.
Definition: Broadcaster.h:317
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
ConstString.h
lldb_private::BroadcasterManager::BroadcastEventSpecMatches::m_broadcaster_spec
BroadcastEventSpec m_broadcaster_spec
Definition: Broadcaster.h:145
lldb_private::Broadcaster::BroadcasterImpl::GetBroadcasterName
const char * GetBroadcasterName() const
Definition: Broadcaster.h:448
lldb_private::Broadcaster::BroadcastEvent
void BroadcastEvent(uint32_t event_type, const lldb::EventDataSP &event_data_sp)
Definition: Broadcaster.h:270
lldb_private::BroadcasterManager::ListenerMatchesPointer::ListenerMatchesPointer
ListenerMatchesPointer(const Listener *in_listener)
Definition: Broadcaster.h:190
lldb_private::Broadcaster::BroadcasterImpl::~BroadcasterImpl
~BroadcasterImpl()=default
lldb_private::BroadcasterManager::ListenerMatches::operator()
bool operator()(const event_listener_key &input) const
Definition: Broadcaster.h:177
lldb_private::BroadcastEventSpec::BroadcastEventSpec
BroadcastEventSpec(const ConstString &broadcaster_class, uint32_t event_bits)
Definition: Broadcaster.h:42
lldb_private::Broadcaster
Definition: Broadcaster.h:242
lldb_private::BroadcasterManager::BroadcastEventSpecMatches::operator()
bool operator()(const event_listener_key &input) const
Definition: Broadcaster.h:140
lldb_private::Broadcaster::BroadcasterImpl::m_listeners
collection m_listeners
A list of Listener / event_mask pairs that are listening to this broadcaster.
Definition: Broadcaster.h:504
lldb_private::BroadcastEventSpec::m_event_bits
uint32_t m_event_bits
Definition: Broadcaster.h:71
lldb_private::Broadcaster::BroadcasterImpl::m_broadcaster
Broadcaster & m_broadcaster
The broadcaster that this implements.
Definition: Broadcaster.h:496
lldb_private::Broadcaster::BroadcasterImpl::collection
llvm::SmallVector< std::pair< lldb::ListenerWP, uint32_t >, 4 > collection
Definition: Broadcaster.h:489
lldb_private::Broadcaster::BroadcasterImpl::GetEventNames
bool GetEventNames(Stream &s, const uint32_t event_mask, bool prefix_with_broadcaster_name) const
Definition: Broadcaster.cpp:86
lldb_private::Broadcaster::GetEventNames
bool GetEventNames(Stream &s, const uint32_t event_mask, bool prefix_with_broadcaster_name) const
Get the event name(s) for one or more event bits.
Definition: Broadcaster.h:326
lldb_private::BroadcasterManager::m_event_map
collection m_event_map
Definition: Broadcaster.h:111
lldb_private::Broadcaster::GetHijackingListenerName
const char * GetHijackingListenerName()
Definition: Broadcaster.h:526
lldb_private::BroadcasterManager::m_manager_mutex
std::recursive_mutex m_manager_mutex
Definition: Broadcaster.h:114
lldb_private::Broadcaster::GetBroadcasterImpl
BroadcasterImplSP GetBroadcasterImpl()
Definition: Broadcaster.h:524