Skip to content

Commit 5f22d33

Browse files
authored
[lldb][NFCI] Change BreakpointIDList::FindBreakpointID to BreakpointIDList::Contains (llvm#79517)
`FindBreakpointID` take a BreakpointID and a pointer to a size_t (so you can get position information). It returns a bool to indicate whether the id was found in the list or not. There are 2 callers of this currently and neither one actually uses the position information, so I removed it. After that, I renamed it to Contains to more accurately reflect the intent. Additionally, I changed the argument type from a reference to a value (because BreakpointID is just a wrapper around 2 integers, copies are cheap).
1 parent 7f518ee commit 5f22d33

File tree

5 files changed

+12
-20
lines changed

5 files changed

+12
-20
lines changed

lldb/include/lldb/Breakpoint/BreakpointID.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ class BreakpointID {
2626

2727
virtual ~BreakpointID();
2828

29+
bool operator==(BreakpointID rhs) const {
30+
return m_break_id == rhs.m_break_id && m_location_id == rhs.m_location_id;
31+
}
32+
2933
lldb::break_id_t GetBreakpointID() const { return m_break_id; }
3034

3135
lldb::break_id_t GetLocationID() const { return m_location_id; }

lldb/include/lldb/Breakpoint/BreakpointIDList.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ class BreakpointIDList {
4242

4343
bool AddBreakpointID(BreakpointID bp_id);
4444

45-
// TODO: This should take a const BreakpointID.
46-
bool FindBreakpointID(BreakpointID &bp_id, size_t *position) const;
45+
bool Contains(BreakpointID bp_id) const;
4746

4847
// Returns a pair consisting of the beginning and end of a breakpoint
4948
// ID range expression. If the input string is not a valid specification,

lldb/source/Breakpoint/BreakpointIDList.cpp

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#include "lldb/Utility/Args.h"
1616
#include "lldb/Utility/StreamString.h"
1717

18+
#include "llvm/ADT/STLExtras.h"
19+
1820
using namespace lldb;
1921
using namespace lldb_private;
2022

@@ -48,18 +50,8 @@ bool BreakpointIDList::AddBreakpointID(BreakpointID bp_id) {
4850
// return true.
4951
}
5052

51-
bool BreakpointIDList::FindBreakpointID(BreakpointID &bp_id,
52-
size_t *position) const {
53-
for (size_t i = 0; i < m_breakpoint_ids.size(); ++i) {
54-
BreakpointID tmp_id = m_breakpoint_ids[i];
55-
if (tmp_id.GetBreakpointID() == bp_id.GetBreakpointID() &&
56-
tmp_id.GetLocationID() == bp_id.GetLocationID()) {
57-
*position = i;
58-
return true;
59-
}
60-
}
61-
62-
return false;
53+
bool BreakpointIDList::Contains(BreakpointID bp_id) const {
54+
return llvm::is_contained(m_breakpoint_ids, bp_id);
6355
}
6456

6557
// This function takes OLD_ARGS, which is usually the result of breaking the

lldb/source/Commands/CommandObjectBreakpoint.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1485,9 +1485,8 @@ class CommandObjectBreakpointDelete : public CommandObjectParsed {
14851485
for (auto breakpoint_sp : breakpoints.Breakpoints()) {
14861486
if (!breakpoint_sp->IsEnabled() && breakpoint_sp->AllowDelete()) {
14871487
BreakpointID bp_id(breakpoint_sp->GetID());
1488-
size_t pos = 0;
1489-
if (!excluded_bp_ids.FindBreakpointID(bp_id, &pos))
1490-
valid_bp_ids.AddBreakpointID(breakpoint_sp->GetID());
1488+
if (!excluded_bp_ids.Contains(bp_id))
1489+
valid_bp_ids.AddBreakpointID(bp_id);
14911490
}
14921491
}
14931492
if (valid_bp_ids.GetSize() == 0) {

lldb/source/Commands/CommandObjectProcess.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -646,9 +646,7 @@ class CommandObjectProcessContinue : public CommandObjectParsed {
646646
for (size_t loc_idx = 0; loc_idx < num_locations; loc_idx++) {
647647
BreakpointLocationSP loc_sp = bp_sp->GetLocationAtIndex(loc_idx);
648648
tmp_id.SetBreakpointLocationID(loc_idx);
649-
size_t position = 0;
650-
if (!with_locs.FindBreakpointID(tmp_id, &position)
651-
&& loc_sp->IsEnabled()) {
649+
if (!with_locs.Contains(tmp_id) && loc_sp->IsEnabled()) {
652650
locs_disabled.push_back(tmp_id);
653651
loc_sp->SetEnabled(false);
654652
}

0 commit comments

Comments
 (0)