Skip to content

Commit 77cbaee

Browse files
committed
Address Jim's feedback
1 parent 656beb2 commit 77cbaee

File tree

5 files changed

+33
-16
lines changed

5 files changed

+33
-16
lines changed

lldb/include/lldb/API/SBBreakpoint.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ class LLDB_API SBBreakpoint {
148148

149149
bool IsHardware() const;
150150

151-
void SetIsHardware(bool is_hardware);
151+
bool SetIsHardware(bool is_hardware);
152152

153153
// Can only be called from a ScriptedBreakpointResolver...
154154
SBError

lldb/include/lldb/Breakpoint/Breakpoint.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,8 @@ class Breakpoint : public std::enable_shared_from_this<Breakpoint>,
518518
lldb::break_id_t bp_loc_id);
519519

520520
bool IsHardware() const { return m_hardware; }
521-
void SetIsHardware(bool is_hardware);
521+
522+
bool SetIsHardware(bool is_hardware);
522523

523524
lldb::BreakpointResolverSP GetResolver() { return m_resolver_sp; }
524525

lldb/source/API/SBBreakpoint.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -781,15 +781,16 @@ bool SBBreakpoint::IsHardware() const {
781781
return false;
782782
}
783783

784-
void SBBreakpoint::SetIsHardware(bool is_hardware) {
784+
bool SBBreakpoint::SetIsHardware(bool is_hardware) {
785785
LLDB_INSTRUMENT_VA(this, is_hardware);
786786

787787
BreakpointSP bkpt_sp = GetSP();
788788
if (bkpt_sp) {
789789
std::lock_guard<std::recursive_mutex> guard(
790790
bkpt_sp->GetTarget().GetAPIMutex());
791-
bkpt_sp->SetIsHardware(is_hardware);
791+
return bkpt_sp->SetIsHardware(is_hardware);
792792
}
793+
return false;
793794
}
794795

795796
BreakpointSP SBBreakpoint::GetSP() const { return m_opaque_wp.lock(); }

lldb/source/Breakpoint/Breakpoint.cpp

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -251,25 +251,40 @@ const lldb::TargetSP Breakpoint::GetTargetSP() {
251251

252252
bool Breakpoint::IsInternal() const { return LLDB_BREAK_ID_IS_INTERNAL(m_bid); }
253253

254-
void Breakpoint::SetIsHardware(bool is_hardware) {
254+
bool Breakpoint::SetIsHardware(bool is_hardware) {
255255
if (is_hardware == m_hardware)
256-
return;
256+
return true;
257257

258-
// Remember all the breakpoint locations we've disabled.
258+
// Disable all non-hardware breakpoint locations.
259259
std::vector<BreakpointLocationSP> locations;
260-
for (BreakpointLocationSP location : m_locations.BreakpointLocations()) {
261-
if (location->IsEnabled()) {
262-
locations.push_back(location);
263-
location->SetEnabled(false);
264-
}
260+
for (BreakpointLocationSP location_sp : m_locations.BreakpointLocations()) {
261+
if (!location_sp || !location_sp->IsEnabled())
262+
continue;
263+
264+
lldb::BreakpointSiteSP breakpoint_site_sp =
265+
location_sp->GetBreakpointSite();
266+
if (!breakpoint_site_sp ||
267+
breakpoint_site_sp->GetType() == BreakpointSite::eHardware)
268+
continue;
269+
270+
locations.push_back(location_sp);
271+
location_sp->SetEnabled(false);
265272
}
266273

267274
// Toggle the hardware mode.
268275
m_hardware = is_hardware;
269276

270-
// Re-enable the breakpoint locations.
271-
for (BreakpointLocationSP location : locations)
272-
location->SetEnabled(true);
277+
// Re-enable all breakpoint locations.
278+
bool success = true;
279+
for (BreakpointLocationSP location_sp : locations) {
280+
location_sp->SetEnabled(true);
281+
282+
lldb::BreakpointSiteSP breakpoint_site_sp =
283+
location_sp->GetBreakpointSite();
284+
success &= breakpoint_site_sp &&
285+
breakpoint_site_sp->GetType() == BreakpointSite::eHardware;
286+
}
287+
return success;
273288
}
274289

275290
BreakpointLocationSP Breakpoint::AddLocation(const Address &addr,

lldb/test/API/functionalities/breakpoint/hardware_breakpoints/simple_hw_breakpoints/TestSimpleHWBreakpoints.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def test(self):
2222

2323
breakpoint = target.BreakpointCreateByLocation("main.c", 1)
2424
self.assertFalse(breakpoint.IsHardware())
25-
breakpoint.SetIsHardware(True)
25+
self.assertTrue(breakpoint.SetIsHardware(True))
2626
self.assertTrue(breakpoint.IsHardware())
2727

2828
self.runCmd("run", RUN_SUCCEEDED)

0 commit comments

Comments
 (0)