[lldb] Refactor LLDB Breakpoint Event Notifications to centralize and eliminate code duplication (#164739)

### Summary

This PR refactors breakpoint event notification in LLDB to centralize
and eliminate code duplication. It creates a unified method in the
`Target` class for sending breakpoint change events. The new methods
check if listeners exist before broadcasting events

### Test

<img width="1532" height="76" alt="Screenshot 2025-10-23 at 12 49 31 PM"
src="https://github.com/user-attachments/assets/6d6a6da6-9684-463c-aeeb-90663cdbd077"
/>

---------

Co-authored-by: Piyush Jaiswal <piyushjais@meta.com>
This commit is contained in:
Piyush Jaiswal
2025-10-31 13:06:36 -07:00
committed by GitHub
parent fe8ab75b40
commit 6bac76bf27
5 changed files with 32 additions and 23 deletions

View File

@@ -1346,6 +1346,13 @@ public:
const lldb_private::RegisterFlags &flags,
uint32_t byte_size);
/// Sends a breakpoint notification event.
void NotifyBreakpointChanged(Breakpoint &bp,
lldb::BreakpointEventType event_kind);
/// Sends a breakpoint notification event.
void NotifyBreakpointChanged(Breakpoint &bp,
const lldb::EventDataSP &breakpoint_data_sp);
llvm::Expected<lldb::DisassemblerSP>
ReadInstructions(const Address &start_addr, uint32_t count,
const char *flavor_string = nullptr);

View File

@@ -1098,14 +1098,9 @@ bool Breakpoint::EvaluatePrecondition(StoppointCallbackContext &context) {
}
void Breakpoint::SendBreakpointChangedEvent(
lldb::BreakpointEventType eventKind) {
if (!IsInternal() && GetTarget().EventTypeHasListeners(
Target::eBroadcastBitBreakpointChanged)) {
std::shared_ptr<BreakpointEventData> data =
std::make_shared<BreakpointEventData>(eventKind, shared_from_this());
GetTarget().BroadcastEvent(Target::eBroadcastBitBreakpointChanged, data);
}
lldb::BreakpointEventType event_kind) {
if (!IsInternal())
GetTarget().NotifyBreakpointChanged(*this, event_kind);
}
void Breakpoint::SendBreakpointChangedEvent(
@@ -1113,10 +1108,8 @@ void Breakpoint::SendBreakpointChangedEvent(
if (!breakpoint_data_sp)
return;
if (!IsInternal() &&
GetTarget().EventTypeHasListeners(Target::eBroadcastBitBreakpointChanged))
GetTarget().BroadcastEvent(Target::eBroadcastBitBreakpointChanged,
breakpoint_data_sp);
if (!IsInternal())
GetTarget().NotifyBreakpointChanged(*this, breakpoint_data_sp);
}
const char *Breakpoint::BreakpointEventTypeAsCString(BreakpointEventType type) {

View File

@@ -16,13 +16,7 @@ using namespace lldb;
using namespace lldb_private;
static void NotifyChange(const BreakpointSP &bp, BreakpointEventType event) {
Target &target = bp->GetTarget();
if (target.EventTypeHasListeners(Target::eBroadcastBitBreakpointChanged)) {
auto event_data_sp =
std::make_shared<Breakpoint::BreakpointEventData>(event, bp);
target.BroadcastEvent(Target::eBroadcastBitBreakpointChanged,
event_data_sp);
}
bp->GetTarget().NotifyBreakpointChanged(*bp, event);
}
BreakpointList::BreakpointList(bool is_internal)

View File

@@ -749,13 +749,11 @@ void BreakpointLocation::Dump(Stream *s) const {
void BreakpointLocation::SendBreakpointLocationChangedEvent(
lldb::BreakpointEventType eventKind) {
if (!m_owner.IsInternal() && m_owner.GetTarget().EventTypeHasListeners(
Target::eBroadcastBitBreakpointChanged)) {
if (!m_owner.IsInternal()) {
auto data_sp = std::make_shared<Breakpoint::BreakpointEventData>(
eventKind, m_owner.shared_from_this());
data_sp->GetBreakpointLocationCollection().Add(shared_from_this());
m_owner.GetTarget().BroadcastEvent(Target::eBroadcastBitBreakpointChanged,
data_sp);
m_owner.GetTarget().NotifyBreakpointChanged(m_owner, data_sp);
}
}

View File

@@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
#include "lldb/Target/Target.h"
#include "lldb/Breakpoint/Breakpoint.h"
#include "lldb/Breakpoint/BreakpointIDList.h"
#include "lldb/Breakpoint/BreakpointPrecondition.h"
#include "lldb/Breakpoint/BreakpointResolver.h"
@@ -5271,3 +5272,19 @@ void Target::ClearSectionLoadList() { GetSectionLoadList().Clear(); }
void Target::DumpSectionLoadList(Stream &s) {
GetSectionLoadList().Dump(s, this);
}
void Target::NotifyBreakpointChanged(Breakpoint &bp,
lldb::BreakpointEventType eventKind) {
if (EventTypeHasListeners(Target::eBroadcastBitBreakpointChanged)) {
std::shared_ptr<Breakpoint::BreakpointEventData> data_sp =
std::make_shared<Breakpoint::BreakpointEventData>(
eventKind, bp.shared_from_this());
BroadcastEvent(Target::eBroadcastBitBreakpointChanged, data_sp);
}
}
void Target::NotifyBreakpointChanged(
Breakpoint &bp, const lldb::EventDataSP &breakpoint_data_sp) {
if (EventTypeHasListeners(Target::eBroadcastBitBreakpointChanged))
BroadcastEvent(Target::eBroadcastBitBreakpointChanged, breakpoint_data_sp);
}