Skip to content

Commit 0018c71

Browse files
committed
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
1 parent 71909de commit 0018c71

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
@@ -1458,6 +1458,7 @@ class CommandObjectBreakpointDelete : public CommandObjectParsed {
14581458
return false;
14591459
}
14601460

1461+
// Handle the delete all breakpoints case:
14611462
if (command.empty() && !m_options.m_delete_disabled) {
14621463
if (!m_options.m_force &&
14631464
!m_interpreter.Confirm(
@@ -1471,67 +1472,73 @@ class CommandObjectBreakpointDelete : public CommandObjectParsed {
14711472
(uint64_t)num_breakpoints, num_breakpoints > 1 ? "s" : "");
14721473
}
14731474
result.SetStatus(eReturnStatusSuccessFinishNoResult);
1474-
} else {
1475-
// Particular breakpoint selected; disable that breakpoint.
1476-
BreakpointIDList valid_bp_ids;
1477-
1478-
if (m_options.m_delete_disabled) {
1479-
BreakpointIDList excluded_bp_ids;
1475+
return result.Succeeded();
1476+
}
1477+
1478+
// Either we have some kind of breakpoint specification(s),
1479+
// or we are handling "break disable --deleted". Gather the list
1480+
// of breakpoints to delete here, the we'll delete them below.
1481+
BreakpointIDList valid_bp_ids;
1482+
1483+
if (m_options.m_delete_disabled) {
1484+
BreakpointIDList excluded_bp_ids;
14801485

1481-
if (!command.empty()) {
1482-
CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs(
1483-
command, &target, result, &excluded_bp_ids,
1484-
BreakpointName::Permissions::PermissionKinds::deletePerm);
1485-
}
1486-
for (auto breakpoint_sp : breakpoints.Breakpoints()) {
1487-
if (!breakpoint_sp->IsEnabled() && breakpoint_sp->AllowDelete()) {
1488-
BreakpointID bp_id(breakpoint_sp->GetID());
1489-
size_t pos = 0;
1490-
if (!excluded_bp_ids.FindBreakpointID(bp_id, &pos))
1491-
valid_bp_ids.AddBreakpointID(breakpoint_sp->GetID());
1492-
}
1493-
}
1494-
if (valid_bp_ids.GetSize() == 0) {
1495-
result.AppendError("No disabled breakpoints.");
1496-
return false;
1497-
}
1498-
} else {
1486+
if (!command.empty()) {
14991487
CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs(
1500-
command, &target, result, &valid_bp_ids,
1488+
command, &target, result, &excluded_bp_ids,
15011489
BreakpointName::Permissions::PermissionKinds::deletePerm);
1490+
if (!result.Succeeded())
1491+
return false;
15021492
}
1503-
1504-
if (result.Succeeded()) {
1505-
int delete_count = 0;
1506-
int disable_count = 0;
1507-
const size_t count = valid_bp_ids.GetSize();
1508-
for (size_t i = 0; i < count; ++i) {
1509-
BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex(i);
15101493

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

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)