Skip to content

Add breakpoint delete --disabled: deletes all disabled breakpoints. #1845

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 40 additions & 8 deletions lldb/source/Commands/CommandObjectBreakpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1407,7 +1407,8 @@ class CommandObjectBreakpointDelete : public CommandObjectParsed {

class CommandOptions : public Options {
public:
CommandOptions() : Options(), m_use_dummy(false), m_force(false) {}
CommandOptions() : Options(), m_use_dummy(false), m_force(false),
m_delete_disabled(false) {}

~CommandOptions() override = default;

Expand All @@ -1424,6 +1425,10 @@ class CommandObjectBreakpointDelete : public CommandObjectParsed {
case 'D':
m_use_dummy = true;
break;

case 'd':
m_delete_disabled = true;
break;

default:
llvm_unreachable("Unimplemented option");
Expand All @@ -1435,6 +1440,7 @@ class CommandObjectBreakpointDelete : public CommandObjectParsed {
void OptionParsingStarting(ExecutionContext *execution_context) override {
m_use_dummy = false;
m_force = false;
m_delete_disabled = false;
}

llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
Expand All @@ -1444,16 +1450,18 @@ class CommandObjectBreakpointDelete : public CommandObjectParsed {
// Instance variables to hold the values for command options.
bool m_use_dummy;
bool m_force;
bool m_delete_disabled;
};

protected:
bool DoExecute(Args &command, CommandReturnObject &result) override {
Target &target = GetSelectedOrDummyTarget(m_options.m_use_dummy);

result.Clear();

std::unique_lock<std::recursive_mutex> lock;
target.GetBreakpointList().GetListMutex(lock);

const BreakpointList &breakpoints = target.GetBreakpointList();
BreakpointList &breakpoints = target.GetBreakpointList();

size_t num_breakpoints = breakpoints.GetSize();

Expand All @@ -1463,7 +1471,7 @@ class CommandObjectBreakpointDelete : public CommandObjectParsed {
return false;
}

if (command.empty()) {
if (command.empty() && !m_options.m_delete_disabled) {
if (!m_options.m_force &&
!m_interpreter.Confirm(
"About to delete all breakpoints, do you want to do that?",
Expand All @@ -1479,10 +1487,34 @@ class CommandObjectBreakpointDelete : public CommandObjectParsed {
} else {
// Particular breakpoint selected; disable that breakpoint.
BreakpointIDList valid_bp_ids;
CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs(
command, &target, result, &valid_bp_ids,
BreakpointName::Permissions::PermissionKinds::deletePerm);


if (m_options.m_delete_disabled) {
BreakpointIDList excluded_bp_ids;

if (!command.empty()) {
CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs(
command, &target, result, &excluded_bp_ids,
BreakpointName::Permissions::PermissionKinds::deletePerm);
}
for (auto breakpoint_sp : breakpoints.Breakpoints()) {
if (!breakpoint_sp->IsEnabled() && breakpoint_sp->AllowDelete()) {
BreakpointID bp_id(breakpoint_sp->GetID());
size_t pos = 0;
if (!excluded_bp_ids.FindBreakpointID(bp_id, &pos))
valid_bp_ids.AddBreakpointID(breakpoint_sp->GetID());
}
}
if (valid_bp_ids.GetSize() == 0) {
result.AppendError("No disabled breakpoints.");
result.SetStatus(eReturnStatusFailed);
return false;
}
} else {
CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs(
command, &target, result, &valid_bp_ids,
BreakpointName::Permissions::PermissionKinds::deletePerm);
}

if (result.Succeeded()) {
int delete_count = 0;
int disable_count = 0;
Expand Down
3 changes: 3 additions & 0 deletions lldb/source/Commands/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ let Command = "breakpoint delete" in {
def breakpoint_delete_dummy_breakpoints : Option<"dummy-breakpoints", "D">,
Group<1>, Desc<"Delete Dummy breakpoints - i.e. breakpoints set before a "
"file is provided, which prime new targets.">;
def breakpoint_delete_disabled : Option<"disabled", "d">, Group<1>,
Desc<"Delete all breakpoints which are currently disabled. When using the disabled option "
"any breakpoints listed on the command line are EXCLUDED from deletion.">;
}

let Command = "breakpoint name" in {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,3 +287,33 @@ def breakpoint_commands_on_creation(self):
self.assertEqual(com_list.GetStringAtIndex(0), "bt", "First bt")
self.assertEqual(com_list.GetStringAtIndex(1), "thread list", "Next thread list")
self.assertEqual(com_list.GetStringAtIndex(2), "continue", "Last continue")

def test_breakpoint_delete_disabled(self):
"""Test 'break delete --disabled' works"""
self.build()
exe = self.getBuildArtifact("a.out")
target = self.dbg.CreateTarget(exe)
self.assertTrue(target.IsValid(), "Created an invalid target.")

bp_1 = target.BreakpointCreateByName("main")
bp_2 = target.BreakpointCreateByName("not_here")
bp_3 = target.BreakpointCreateByName("main")
bp_3.AddName("DeleteMeNot")

bp_1.SetEnabled(False)
bp_3.SetEnabled(False)

bp_id_1 = bp_1.GetID()
bp_id_2 = bp_2.GetID()
bp_id_3 = bp_3.GetID()

self.runCmd("breakpoint delete --disabled DeleteMeNot")

bp_1 = target.FindBreakpointByID(bp_id_1)
self.assertFalse(bp_1.IsValid(), "Didn't delete disabled breakpoint 1")

bp_2 = target.FindBreakpointByID(bp_id_2)
self.assertTrue(bp_2.IsValid(), "Deleted enabled breakpoint 2")

bp_3 = target.FindBreakpointByID(bp_id_3)
self.assertTrue(bp_3.IsValid(), "DeleteMeNot didn't protect disabled breakpoint 3")