Skip to content

Commit e04bbb2

Browse files
author
Piyush Jaiswal
committed
Refactor Breakpoint event notification
1 parent 81a9d75 commit e04bbb2

File tree

5 files changed

+39
-17
lines changed

5 files changed

+39
-17
lines changed

lldb/include/lldb/Target/Target.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,6 +1346,21 @@ class Target : public std::enable_shared_from_this<Target>,
13461346
const lldb_private::RegisterFlags &flags,
13471347
uint32_t byte_size);
13481348

1349+
/// Sends a breakpoint notification event if any listener is registered.
1350+
/// \param[in] bp
1351+
/// The breakpoint that was hit.
1352+
/// \param[in] eventKind
1353+
/// The kind of event that occurred.
1354+
void NotifyBreakpointChanged(Breakpoint &bp,
1355+
lldb::BreakpointEventType eventKind);
1356+
/// Sends a breakpoint notification event if any listener is registered.
1357+
/// \param[in] bp
1358+
/// The breakpoint that was hit.
1359+
/// \param[in] data
1360+
/// The data associated with the event.
1361+
void NotifyBreakpointChanged(Breakpoint &bp,
1362+
const lldb::EventDataSP &breakpoint_data_sp);
1363+
13491364
llvm::Expected<lldb::DisassemblerSP>
13501365
ReadInstructions(const Address &start_addr, uint32_t count,
13511366
const char *flavor_string = nullptr);

lldb/source/Breakpoint/Breakpoint.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,12 +1099,11 @@ bool Breakpoint::EvaluatePrecondition(StoppointCallbackContext &context) {
10991099

11001100
void Breakpoint::SendBreakpointChangedEvent(
11011101
lldb::BreakpointEventType eventKind) {
1102-
if (!IsInternal() && GetTarget().EventTypeHasListeners(
1103-
Target::eBroadcastBitBreakpointChanged)) {
1102+
if (!IsInternal()) {
11041103
std::shared_ptr<BreakpointEventData> data =
11051104
std::make_shared<BreakpointEventData>(eventKind, shared_from_this());
11061105

1107-
GetTarget().BroadcastEvent(Target::eBroadcastBitBreakpointChanged, data);
1106+
GetTarget().NotifyBreakpointChanged(*this, eventKind);
11081107
}
11091108
}
11101109

@@ -1113,10 +1112,8 @@ void Breakpoint::SendBreakpointChangedEvent(
11131112
if (!breakpoint_data_sp)
11141113
return;
11151114

1116-
if (!IsInternal() &&
1117-
GetTarget().EventTypeHasListeners(Target::eBroadcastBitBreakpointChanged))
1118-
GetTarget().BroadcastEvent(Target::eBroadcastBitBreakpointChanged,
1119-
breakpoint_data_sp);
1115+
if (!IsInternal())
1116+
GetTarget().NotifyBreakpointChanged(*this, breakpoint_data_sp);
11201117
}
11211118

11221119
const char *Breakpoint::BreakpointEventTypeAsCString(BreakpointEventType type) {

lldb/source/Breakpoint/BreakpointList.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,7 @@ using namespace lldb_private;
1717

1818
static void NotifyChange(const BreakpointSP &bp, BreakpointEventType event) {
1919
Target &target = bp->GetTarget();
20-
if (target.EventTypeHasListeners(Target::eBroadcastBitBreakpointChanged)) {
21-
auto event_data_sp =
22-
std::make_shared<Breakpoint::BreakpointEventData>(event, bp);
23-
target.BroadcastEvent(Target::eBroadcastBitBreakpointChanged,
24-
event_data_sp);
25-
}
20+
target.NotifyBreakpointChanged(*bp, event);
2621
}
2722

2823
BreakpointList::BreakpointList(bool is_internal)

lldb/source/Breakpoint/BreakpointLocation.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -749,13 +749,11 @@ void BreakpointLocation::Dump(Stream *s) const {
749749

750750
void BreakpointLocation::SendBreakpointLocationChangedEvent(
751751
lldb::BreakpointEventType eventKind) {
752-
if (!m_owner.IsInternal() && m_owner.GetTarget().EventTypeHasListeners(
753-
Target::eBroadcastBitBreakpointChanged)) {
752+
if (!m_owner.IsInternal()) {
754753
auto data_sp = std::make_shared<Breakpoint::BreakpointEventData>(
755754
eventKind, m_owner.shared_from_this());
756755
data_sp->GetBreakpointLocationCollection().Add(shared_from_this());
757-
m_owner.GetTarget().BroadcastEvent(Target::eBroadcastBitBreakpointChanged,
758-
data_sp);
756+
m_owner.GetTarget().NotifyBreakpointChanged(m_owner, data_sp);
759757
}
760758
}
761759

lldb/source/Target/Target.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "lldb/Target/Target.h"
10+
#include "lldb/Breakpoint/Breakpoint.h"
1011
#include "lldb/Breakpoint/BreakpointIDList.h"
1112
#include "lldb/Breakpoint/BreakpointPrecondition.h"
1213
#include "lldb/Breakpoint/BreakpointResolver.h"
@@ -5244,3 +5245,19 @@ void Target::ClearSectionLoadList() { GetSectionLoadList().Clear(); }
52445245
void Target::DumpSectionLoadList(Stream &s) {
52455246
GetSectionLoadList().Dump(s, this);
52465247
}
5248+
5249+
void Target::NotifyBreakpointChanged(Breakpoint &bp,
5250+
lldb::BreakpointEventType eventKind) {
5251+
if (EventTypeHasListeners(Target::eBroadcastBitBreakpointChanged)) {
5252+
std::shared_ptr<Breakpoint::BreakpointEventData> data =
5253+
std::make_shared<Breakpoint::BreakpointEventData>(
5254+
eventKind, bp.shared_from_this());
5255+
BroadcastEvent(Target::eBroadcastBitBreakpointChanged, data);
5256+
}
5257+
}
5258+
5259+
void Target::NotifyBreakpointChanged(
5260+
Breakpoint &bp, const lldb::EventDataSP &breakpoint_data_sp) {
5261+
if (EventTypeHasListeners(Target::eBroadcastBitBreakpointChanged))
5262+
BroadcastEvent(Target::eBroadcastBitBreakpointChanged, breakpoint_data_sp);
5263+
}

0 commit comments

Comments
 (0)