Skip to content

Commit 143f138

Browse files
Merge pull request #3751 from adrian-prantl/83503919
Cherry-pick fix for relative breakpoints
2 parents ae8b261 + c0fcec0 commit 143f138

File tree

3 files changed

+89
-57
lines changed

3 files changed

+89
-57
lines changed

lldb/source/Breakpoint/BreakpointResolverFileLine.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ void BreakpointResolverFileLine::FilterContexts(SymbolContextList &sc_list,
188188
// is 0, then we can't do this calculation. That can happen if
189189
// GetStartLineSourceInfo gets an error, or if the first line number in
190190
// the function really is 0 - which happens for some languages.
191-
191+
192192
// But only do this calculation if the line number we found in the SC
193193
// was different from the one requested in the source file. If we actually
194194
// found an exact match it must be valid.
@@ -229,18 +229,25 @@ Searcher::CallbackReturn BreakpointResolverFileLine::SearchCallback(
229229
const uint32_t line = m_location_spec.GetLine().getValueOr(0);
230230
const llvm::Optional<uint16_t> column = m_location_spec.GetColumn();
231231

232+
// We'll create a new SourceLocationSpec that can take into account the
233+
// relative path case, and we'll use it to resolve the symbol context
234+
// of the CUs.
232235
FileSpec search_file_spec = m_location_spec.GetFileSpec();
233236
const bool is_relative = search_file_spec.IsRelative();
234237
if (is_relative)
235238
search_file_spec.GetDirectory().Clear();
239+
SourceLocationSpec search_location_spec(
240+
search_file_spec, m_location_spec.GetLine().getValueOr(0),
241+
m_location_spec.GetColumn(), m_location_spec.GetCheckInlines(),
242+
m_location_spec.GetExactMatch());
236243

237244
const size_t num_comp_units = context.module_sp->GetNumCompileUnits();
238245
for (size_t i = 0; i < num_comp_units; i++) {
239246
CompUnitSP cu_sp(context.module_sp->GetCompileUnitAtIndex(i));
240247
if (cu_sp) {
241248
if (filter.CompUnitPasses(*cu_sp))
242-
cu_sp->ResolveSymbolContext(m_location_spec, eSymbolContextEverything,
243-
sc_list);
249+
cu_sp->ResolveSymbolContext(search_location_spec,
250+
eSymbolContextEverything, sc_list);
244251
}
245252
}
246253

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: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class BreakpointCommandTestCase(TestBase):
1818

1919
@expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24528")
2020
@skipIfReproducer # side_effect bypasses reproducer
21-
def not_test_breakpoint_command_sequence(self):
21+
def test_breakpoint_command_sequence(self):
2222
"""Test a sequence of breakpoint command add, list, and delete."""
2323
self.build()
2424
self.breakpoint_command_sequence()
@@ -302,7 +302,7 @@ def test_breakpoint_delete_disabled(self):
302302
bp_id_1 = bp_1.GetID()
303303
bp_id_2 = bp_2.GetID()
304304
bp_id_3 = bp_3.GetID()
305-
305+
306306
self.runCmd("breakpoint delete --disabled DeleteMeNot")
307307

308308
bp_1 = target.FindBreakpointByID(bp_id_1)
@@ -313,3 +313,21 @@ 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")

0 commit comments

Comments
 (0)