Skip to content

[lldb] Add --exists flag to settings set #4044

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 1 commit into from
Mar 9, 2022
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
12 changes: 8 additions & 4 deletions lldb/source/Commands/CommandObjectSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ insert-before or insert-after.");
case 'g':
m_global = true;
break;
case 'e':
m_exists = true;
break;
default:
llvm_unreachable("Unimplemented option");
}
Expand All @@ -113,6 +116,7 @@ insert-before or insert-after.");
void OptionParsingStarting(ExecutionContext *execution_context) override {
m_global = false;
m_force = false;
m_exists = false;
}

llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
Expand All @@ -121,7 +125,8 @@ insert-before or insert-after.");

// Instance variables to hold the values for command options.
bool m_global = false;
bool m_force;
bool m_force = false;
bool m_exists = false;
};

void
Expand Down Expand Up @@ -220,13 +225,12 @@ insert-before or insert-after.");
var_name, var_value);
}

if (error.Fail()) {
if (error.Fail() && !m_options.m_exists) {
result.AppendError(error.AsCString());
return false;
} else {
result.SetStatus(eReturnStatusSuccessFinishResult);
}

result.SetStatus(eReturnStatusSuccessFinishResult);
return result.Succeeded();
}

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 @@ -23,6 +23,9 @@ let Command = "settings set" in {
Desc<"Apply the new value to the global default value.">;
def setset_force : Option<"force", "f">,
Desc<"Force an empty value to be accepted as the default.">;
def setset_exists : Option<"exists", "e">,
Desc<"Set the setting if it exists, but do not cause the command to raise "
"an error if it does not exist.">;
}

let Command = "settings write" in {
Expand Down
10 changes: 10 additions & 0 deletions lldb/test/API/commands/settings/TestSettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -779,3 +779,13 @@ def test_experimental_settings(self):
# finally, confirm that trying to set a setting that does not exist still fails.
# (SHOWING a setting that does not exist does not currently yield an error.)
self.expect('settings set target.setting-which-does-not-exist true', error=True)

def test_settings_set_exists(self):
cmdinterp = self.dbg.GetCommandInterpreter()

# An unknown option should succeed.
self.expect('settings set -e foo bar')
self.expect('settings set --exists foo bar')

# A known option should fail if its argument is invalid.
self.expect("settings set auto-confirm bogus", error=True)