Skip to content

Commit 0098759

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

File tree

7 files changed

+32
-23
lines changed

7 files changed

+32
-23
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/include/lldb/Breakpoint/BreakpointLocation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class BreakpointLocation
6969
// The next section deals with various breakpoint options.
7070

7171
/// If \a enabled is \b true, enable the breakpoint, if \b false disable it.
72-
void SetEnabled(bool enabled);
72+
bool SetEnabled(bool enabled);
7373

7474
/// Check the Enable/Disable state.
7575
///

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: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -251,25 +251,34 @@ 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+
success &= location_sp->SetEnabled(true);
281+
return success;
273282
}
274283

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

lldb/source/Breakpoint/BreakpointLocation.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,13 @@ bool BreakpointLocation::IsEnabled() const {
7474
return true;
7575
}
7676

77-
void BreakpointLocation::SetEnabled(bool enabled) {
77+
bool BreakpointLocation::SetEnabled(bool enabled) {
7878
GetLocationOptions().SetEnabled(enabled);
79-
if (enabled) {
80-
ResolveBreakpointSite();
81-
} else {
82-
ClearBreakpointSite();
83-
}
79+
const bool success =
80+
enabled ? ResolveBreakpointSite() : ClearBreakpointSite();
8481
SendBreakpointLocationChangedEvent(enabled ? eBreakpointEventTypeEnabled
8582
: eBreakpointEventTypeDisabled);
83+
return success;
8684
}
8785

8886
bool BreakpointLocation::IsAutoContinue() const {

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)