Skip to content

Commit db68e92

Browse files
authored
[lldb][NFCI] Remove m_being_created from Breakpoint classes (#79716)
The purpose of m_being_created in these classes was to prevent broadcasting an event related to these Breakpoints during the creation of the breakpoint (i.e. in the constructor). In Breakpoint and Watchpoint, m_being_created had no effect. That is to say, removing it does not change behavior. However, BreakpointLocation does still use m_being_created. In the constructor, SetThreadID is called which does broadcast an event only if `m_being_created` is false. Instead of having this logic be roundabout, the constructor instead calls `SetThreadIDInternal`, which actually changes the thread ID. `SetThreadID` also will call `SetThreadIDInternal` in addition to broadcasting a changed event.
1 parent ff53d50 commit db68e92

File tree

6 files changed

+43
-41
lines changed

6 files changed

+43
-41
lines changed

lldb/include/lldb/Breakpoint/Breakpoint.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,6 @@ class Breakpoint : public std::enable_shared_from_this<Breakpoint>,
637637
Breakpoint(Target &new_target, const Breakpoint &bp_to_copy_from);
638638

639639
// For Breakpoint only
640-
bool m_being_created;
641640
bool
642641
m_hardware; // If this breakpoint is required to use a hardware breakpoint
643642
Target &m_target; // The target that holds this breakpoint.

lldb/include/lldb/Breakpoint/BreakpointLocation.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,17 @@ class BreakpointLocation
313313

314314
void UndoBumpHitCount();
315315

316+
/// Updates the thread ID internally.
317+
///
318+
/// This method was created to handle actually mutating the thread ID
319+
/// internally because SetThreadID broadcasts an event in addition to mutating
320+
/// state. The constructor calls this instead of SetThreadID to avoid the
321+
/// broadcast.
322+
///
323+
/// \param[in] thread_id
324+
/// The new thread ID.
325+
void SetThreadIDInternal(lldb::tid_t thread_id);
326+
316327
// Constructors and Destructors
317328
//
318329
// Only the Breakpoint can make breakpoint locations, and it owns them.
@@ -337,7 +348,6 @@ class BreakpointLocation
337348
bool check_for_resolver = true);
338349

339350
// Data members:
340-
bool m_being_created;
341351
bool m_should_resolve_indirect_functions;
342352
bool m_is_reexported;
343353
bool m_is_indirect;

lldb/include/lldb/Breakpoint/Watchpoint.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,11 +224,8 @@ class Watchpoint : public std::enable_shared_from_this<Watchpoint>,
224224
CompilerType m_type;
225225
Status m_error; // An error object describing errors associated with this
226226
// watchpoint.
227-
WatchpointOptions
228-
m_options; // Settable watchpoint options, which is a delegate to handle
229-
// the callback machinery.
230-
bool m_being_created;
231-
227+
WatchpointOptions m_options; // Settable watchpoint options, which is a
228+
// delegate to handle the callback machinery.
232229
std::unique_ptr<UserExpression> m_condition_up; // The condition to test.
233230

234231
void SetID(lldb::watch_id_t id) { m_id = id; }

lldb/source/Breakpoint/Breakpoint.cpp

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,14 @@ const char *Breakpoint::g_option_names[static_cast<uint32_t>(
4444
Breakpoint::Breakpoint(Target &target, SearchFilterSP &filter_sp,
4545
BreakpointResolverSP &resolver_sp, bool hardware,
4646
bool resolve_indirect_symbols)
47-
: m_being_created(true), m_hardware(hardware), m_target(target),
48-
m_filter_sp(filter_sp), m_resolver_sp(resolver_sp), m_options(true),
49-
m_locations(*this), m_resolve_indirect_symbols(resolve_indirect_symbols),
50-
m_hit_counter() {
51-
m_being_created = false;
52-
}
47+
: m_hardware(hardware), m_target(target), m_filter_sp(filter_sp),
48+
m_resolver_sp(resolver_sp), m_options(true), m_locations(*this),
49+
m_resolve_indirect_symbols(resolve_indirect_symbols), m_hit_counter() {}
5350

5451
Breakpoint::Breakpoint(Target &new_target, const Breakpoint &source_bp)
55-
: m_being_created(true), m_hardware(source_bp.m_hardware),
56-
m_target(new_target), m_name_list(source_bp.m_name_list),
57-
m_options(source_bp.m_options), m_locations(*this),
52+
: m_hardware(source_bp.m_hardware), m_target(new_target),
53+
m_name_list(source_bp.m_name_list), m_options(source_bp.m_options),
54+
m_locations(*this),
5855
m_resolve_indirect_symbols(source_bp.m_resolve_indirect_symbols),
5956
m_hit_counter() {}
6057

@@ -979,9 +976,8 @@ bool Breakpoint::EvaluatePrecondition(StoppointCallbackContext &context) {
979976

980977
void Breakpoint::SendBreakpointChangedEvent(
981978
lldb::BreakpointEventType eventKind) {
982-
if (!m_being_created && !IsInternal() &&
983-
GetTarget().EventTypeHasListeners(
984-
Target::eBroadcastBitBreakpointChanged)) {
979+
if (!IsInternal() && GetTarget().EventTypeHasListeners(
980+
Target::eBroadcastBitBreakpointChanged)) {
985981
std::shared_ptr<BreakpointEventData> data =
986982
std::make_shared<BreakpointEventData>(eventKind, shared_from_this());
987983

@@ -994,7 +990,7 @@ void Breakpoint::SendBreakpointChangedEvent(
994990
if (!breakpoint_data_sp)
995991
return;
996992

997-
if (!m_being_created && !IsInternal() &&
993+
if (!IsInternal() &&
998994
GetTarget().EventTypeHasListeners(Target::eBroadcastBitBreakpointChanged))
999995
GetTarget().BroadcastEvent(Target::eBroadcastBitBreakpointChanged,
1000996
breakpoint_data_sp);

lldb/source/Breakpoint/BreakpointLocation.cpp

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,17 @@ using namespace lldb_private;
3232
BreakpointLocation::BreakpointLocation(break_id_t loc_id, Breakpoint &owner,
3333
const Address &addr, lldb::tid_t tid,
3434
bool hardware, bool check_for_resolver)
35-
: m_being_created(true), m_should_resolve_indirect_functions(false),
36-
m_is_reexported(false), m_is_indirect(false), m_address(addr),
37-
m_owner(owner), m_condition_hash(0), m_loc_id(loc_id), m_hit_counter() {
35+
: m_should_resolve_indirect_functions(false), m_is_reexported(false),
36+
m_is_indirect(false), m_address(addr), m_owner(owner),
37+
m_condition_hash(0), m_loc_id(loc_id), m_hit_counter() {
3838
if (check_for_resolver) {
3939
Symbol *symbol = m_address.CalculateSymbolContextSymbol();
4040
if (symbol && symbol->IsIndirect()) {
4141
SetShouldResolveIndirectFunctions(true);
4242
}
4343
}
4444

45-
SetThreadID(tid);
46-
m_being_created = false;
45+
SetThreadIDInternal(tid);
4746
}
4847

4948
BreakpointLocation::~BreakpointLocation() { ClearBreakpointSite(); }
@@ -100,14 +99,7 @@ void BreakpointLocation::SetAutoContinue(bool auto_continue) {
10099
}
101100

102101
void BreakpointLocation::SetThreadID(lldb::tid_t thread_id) {
103-
if (thread_id != LLDB_INVALID_THREAD_ID)
104-
GetLocationOptions().SetThreadID(thread_id);
105-
else {
106-
// If we're resetting this to an invalid thread id, then don't make an
107-
// options pointer just to do that.
108-
if (m_options_up != nullptr)
109-
m_options_up->SetThreadID(thread_id);
110-
}
102+
SetThreadIDInternal(thread_id);
111103
SendBreakpointLocationChangedEvent(eBreakpointEventTypeThreadChanged);
112104
}
113105

@@ -646,9 +638,8 @@ void BreakpointLocation::Dump(Stream *s) const {
646638

647639
void BreakpointLocation::SendBreakpointLocationChangedEvent(
648640
lldb::BreakpointEventType eventKind) {
649-
if (!m_being_created && !m_owner.IsInternal() &&
650-
m_owner.GetTarget().EventTypeHasListeners(
651-
Target::eBroadcastBitBreakpointChanged)) {
641+
if (!m_owner.IsInternal() && m_owner.GetTarget().EventTypeHasListeners(
642+
Target::eBroadcastBitBreakpointChanged)) {
652643
auto data_sp = std::make_shared<Breakpoint::BreakpointEventData>(
653644
eventKind, m_owner.shared_from_this());
654645
data_sp->GetBreakpointLocationCollection().Add(shared_from_this());
@@ -665,3 +656,14 @@ void BreakpointLocation::SwapLocation(BreakpointLocationSP swap_from) {
665656
m_is_indirect = swap_from->m_is_indirect;
666657
m_user_expression_sp.reset();
667658
}
659+
660+
void BreakpointLocation::SetThreadIDInternal(lldb::tid_t thread_id) {
661+
if (thread_id != LLDB_INVALID_THREAD_ID)
662+
GetLocationOptions().SetThreadID(thread_id);
663+
else {
664+
// If we're resetting this to an invalid thread id, then don't make an
665+
// options pointer just to do that.
666+
if (m_options_up != nullptr)
667+
m_options_up->SetThreadID(thread_id);
668+
}
669+
}

lldb/source/Breakpoint/Watchpoint.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ Watchpoint::Watchpoint(Target &target, lldb::addr_t addr, uint32_t size,
3131
: StoppointSite(0, addr, size, hardware), m_target(target),
3232
m_enabled(false), m_is_hardware(hardware), m_is_watch_variable(false),
3333
m_is_ephemeral(false), m_disabled_count(0), m_watch_read(0),
34-
m_watch_write(0), m_watch_modify(0), m_ignore_count(0),
35-
m_being_created(true) {
34+
m_watch_write(0), m_watch_modify(0), m_ignore_count(0) {
3635

3736
if (type && type->IsValid())
3837
m_type = *type;
@@ -60,7 +59,6 @@ Watchpoint::Watchpoint(Target &target, lldb::addr_t addr, uint32_t size,
6059
m_target.GetProcessSP()->CalculateExecutionContext(exe_ctx);
6160
CaptureWatchedValue(exe_ctx);
6261
}
63-
m_being_created = false;
6462
}
6563

6664
Watchpoint::~Watchpoint() = default;
@@ -462,8 +460,8 @@ const char *Watchpoint::GetConditionText() const {
462460

463461
void Watchpoint::SendWatchpointChangedEvent(
464462
lldb::WatchpointEventType eventKind) {
465-
if (!m_being_created && GetTarget().EventTypeHasListeners(
466-
Target::eBroadcastBitWatchpointChanged)) {
463+
if (GetTarget().EventTypeHasListeners(
464+
Target::eBroadcastBitWatchpointChanged)) {
467465
auto data_sp =
468466
std::make_shared<WatchpointEventData>(eventKind, shared_from_this());
469467
GetTarget().BroadcastEvent(Target::eBroadcastBitWatchpointChanged, data_sp);

0 commit comments

Comments
 (0)