Skip to content

Commit c3a2138

Browse files
jiminghamadrian-prantl
authored andcommitted
Fix "break delete --disabled" with no arguments.
The code that figured out which breakpoints to delete was supposed to set the result status if it found breakpoints, and then the code that actually deleted them checked that the result's status was set. The code for "break delete --disabled" failed to set the status if no "protected" breakpoints were provided. This was a confusing way to implement this, so I reworked it with early returns so it was less error prone, and added a test case for the no arguments case. Differential Revision: https://reviews.llvm.org/D106623 (cherry picked from commit 0018c71)
1 parent 8ac6869 commit c3a2138

File tree

2 files changed

+78
-52
lines changed

2 files changed

+78
-52
lines changed

lldb/source/Commands/CommandObjectBreakpoint.cpp

Lines changed: 59 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1463,6 +1463,7 @@ class CommandObjectBreakpointDelete : public CommandObjectParsed {
14631463
return false;
14641464
}
14651465

1466+
// Handle the delete all breakpoints case:
14661467
if (command.empty() && !m_options.m_delete_disabled) {
14671468
if (!m_options.m_force &&
14681469
!m_interpreter.Confirm(
@@ -1476,67 +1477,73 @@ class CommandObjectBreakpointDelete : public CommandObjectParsed {
14761477
(uint64_t)num_breakpoints, num_breakpoints > 1 ? "s" : "");
14771478
}
14781479
result.SetStatus(eReturnStatusSuccessFinishNoResult);
1479-
} else {
1480-
// Particular breakpoint selected; disable that breakpoint.
1481-
BreakpointIDList valid_bp_ids;
1482-
1483-
if (m_options.m_delete_disabled) {
1484-
BreakpointIDList excluded_bp_ids;
1480+
return result.Succeeded();
1481+
}
1482+
1483+
// Either we have some kind of breakpoint specification(s),
1484+
// or we are handling "break disable --deleted". Gather the list
1485+
// of breakpoints to delete here, the we'll delete them below.
1486+
BreakpointIDList valid_bp_ids;
1487+
1488+
if (m_options.m_delete_disabled) {
1489+
BreakpointIDList excluded_bp_ids;
14851490

1486-
if (!command.empty()) {
1487-
CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs(
1488-
command, &target, result, &excluded_bp_ids,
1489-
BreakpointName::Permissions::PermissionKinds::deletePerm);
1490-
}
1491-
for (auto breakpoint_sp : breakpoints.Breakpoints()) {
1492-
if (!breakpoint_sp->IsEnabled() && breakpoint_sp->AllowDelete()) {
1493-
BreakpointID bp_id(breakpoint_sp->GetID());
1494-
size_t pos = 0;
1495-
if (!excluded_bp_ids.FindBreakpointID(bp_id, &pos))
1496-
valid_bp_ids.AddBreakpointID(breakpoint_sp->GetID());
1497-
}
1498-
}
1499-
if (valid_bp_ids.GetSize() == 0) {
1500-
result.AppendError("No disabled breakpoints.");
1501-
return false;
1502-
}
1503-
} else {
1491+
if (!command.empty()) {
15041492
CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs(
1505-
command, &target, result, &valid_bp_ids,
1493+
command, &target, result, &excluded_bp_ids,
15061494
BreakpointName::Permissions::PermissionKinds::deletePerm);
1495+
if (!result.Succeeded())
1496+
return false;
15071497
}
1508-
1509-
if (result.Succeeded()) {
1510-
int delete_count = 0;
1511-
int disable_count = 0;
1512-
const size_t count = valid_bp_ids.GetSize();
1513-
for (size_t i = 0; i < count; ++i) {
1514-
BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex(i);
15151498

1516-
if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) {
1517-
if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) {
1518-
Breakpoint *breakpoint =
1519-
target.GetBreakpointByID(cur_bp_id.GetBreakpointID()).get();
1520-
BreakpointLocation *location =
1521-
breakpoint->FindLocationByID(cur_bp_id.GetLocationID()).get();
1522-
// It makes no sense to try to delete individual locations, so we
1523-
// disable them instead.
1524-
if (location) {
1525-
location->SetEnabled(false);
1526-
++disable_count;
1527-
}
1528-
} else {
1529-
target.RemoveBreakpointByID(cur_bp_id.GetBreakpointID());
1530-
++delete_count;
1531-
}
1499+
for (auto breakpoint_sp : breakpoints.Breakpoints()) {
1500+
if (!breakpoint_sp->IsEnabled() && breakpoint_sp->AllowDelete()) {
1501+
BreakpointID bp_id(breakpoint_sp->GetID());
1502+
size_t pos = 0;
1503+
if (!excluded_bp_ids.FindBreakpointID(bp_id, &pos))
1504+
valid_bp_ids.AddBreakpointID(breakpoint_sp->GetID());
1505+
}
1506+
}
1507+
if (valid_bp_ids.GetSize() == 0) {
1508+
result.AppendError("No disabled breakpoints.");
1509+
return false;
1510+
}
1511+
} else {
1512+
CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs(
1513+
command, &target, result, &valid_bp_ids,
1514+
BreakpointName::Permissions::PermissionKinds::deletePerm);
1515+
if (!result.Succeeded())
1516+
return false;
1517+
}
1518+
1519+
int delete_count = 0;
1520+
int disable_count = 0;
1521+
const size_t count = valid_bp_ids.GetSize();
1522+
for (size_t i = 0; i < count; ++i) {
1523+
BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex(i);
1524+
1525+
if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) {
1526+
if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) {
1527+
Breakpoint *breakpoint =
1528+
target.GetBreakpointByID(cur_bp_id.GetBreakpointID()).get();
1529+
BreakpointLocation *location =
1530+
breakpoint->FindLocationByID(cur_bp_id.GetLocationID()).get();
1531+
// It makes no sense to try to delete individual locations, so we
1532+
// disable them instead.
1533+
if (location) {
1534+
location->SetEnabled(false);
1535+
++disable_count;
15321536
}
1537+
} else {
1538+
target.RemoveBreakpointByID(cur_bp_id.GetBreakpointID());
1539+
++delete_count;
15331540
}
1534-
result.AppendMessageWithFormat(
1535-
"%d breakpoints deleted; %d breakpoint locations disabled.\n",
1536-
delete_count, disable_count);
1537-
result.SetStatus(eReturnStatusSuccessFinishNoResult);
15381541
}
15391542
}
1543+
result.AppendMessageWithFormat(
1544+
"%d breakpoints deleted; %d breakpoint locations disabled.\n",
1545+
delete_count, disable_count);
1546+
result.SetStatus(eReturnStatusSuccessFinishNoResult);
15401547
return result.Succeeded();
15411548
}
15421549

lldb/test/API/functionalities/breakpoint/breakpoint_command/TestBreakpointCommand.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,3 +313,22 @@ def test_breakpoint_delete_disabled(self):
313313

314314
bp_3 = target.FindBreakpointByID(bp_id_3)
315315
self.assertTrue(bp_3.IsValid(), "DeleteMeNot didn't protect disabled breakpoint 3")
316+
317+
# Reset the first breakpoint, disable it, and do this again with no protected name:
318+
bp_1 = target.BreakpointCreateByName("main")
319+
320+
bp_1.SetEnabled(False)
321+
322+
bp_id_1 = bp_1.GetID()
323+
324+
self.runCmd("breakpoint delete --disabled")
325+
326+
bp_1 = target.FindBreakpointByID(bp_id_1)
327+
self.assertFalse(bp_1.IsValid(), "Didn't delete disabled breakpoint 1")
328+
329+
bp_2 = target.FindBreakpointByID(bp_id_2)
330+
self.assertTrue(bp_2.IsValid(), "Deleted enabled breakpoint 2")
331+
332+
bp_3 = target.FindBreakpointByID(bp_id_3)
333+
self.assertFalse(bp_3.IsValid(), "Didn't delete disabled breakpoint 3")
334+

0 commit comments

Comments
 (0)