[Lldb-commits] [lldb] 8a0fa4d - [lldb] Add --exists flag to `settings set`
Jonas Devlieghere via lldb-commits
lldb-commits at lists.llvm.org
Tue Mar 8 22:59:41 PST 2022
Author: Jonas Devlieghere
Date: 2022-03-08T22:59:26-08:00
New Revision: 8a0fa4db39d862b99eb5d440a211c5c0228e13ce
URL: https://github.com/llvm/llvm-project/commit/8a0fa4db39d862b99eb5d440a211c5c0228e13ce
DIFF: https://github.com/llvm/llvm-project/commit/8a0fa4db39d862b99eb5d440a211c5c0228e13ce.diff
LOG: [lldb] Add --exists flag to `settings set`
Add a --exists/-e flag to `settings set` that sets the setting if it
exists, but doesn't print an error otherwise. This is useful for example
when setting options in your ~/.lldbinit that might not exist in older
versions of lldb.
Differential revision: https://reviews.llvm.org/D121155
Added:
Modified:
lldb/source/Commands/CommandObjectSettings.cpp
lldb/source/Commands/Options.td
lldb/test/API/commands/settings/TestSettings.py
Removed:
################################################################################
diff --git a/lldb/source/Commands/CommandObjectSettings.cpp b/lldb/source/Commands/CommandObjectSettings.cpp
index 391e728d9d8a4..db6a7bc164359 100644
--- a/lldb/source/Commands/CommandObjectSettings.cpp
+++ b/lldb/source/Commands/CommandObjectSettings.cpp
@@ -102,6 +102,9 @@ insert-before or insert-after.");
case 'g':
m_global = true;
break;
+ case 'e':
+ m_exists = true;
+ break;
default:
llvm_unreachable("Unimplemented option");
}
@@ -112,6 +115,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 {
@@ -120,7 +124,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
@@ -219,13 +224,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();
}
diff --git a/lldb/source/Commands/Options.td b/lldb/source/Commands/Options.td
index a1548cb6b443f..ff8dd271a9640 100644
--- a/lldb/source/Commands/Options.td
+++ b/lldb/source/Commands/Options.td
@@ -22,6 +22,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 {
@@ -957,7 +960,7 @@ let Command = "target modules lookup" in {
def target_modules_lookup_type : Option<"type", "t">, Group<6>, Arg<"Name">,
Required, Desc<"Lookup a type by name in the debug symbols in one or more "
"target modules.">;
- def target_modules_lookup_variables_ranges : Option<"show-variable-ranges",
+ def target_modules_lookup_variables_ranges : Option<"show-variable-ranges",
"\\x01">, GroupRange<1, 6>, Desc<"Dump valid ranges of variables (must be "
"used in conjunction with --verbose">;
def target_modules_lookup_verbose : Option<"verbose", "v">,
diff --git a/lldb/test/API/commands/settings/TestSettings.py b/lldb/test/API/commands/settings/TestSettings.py
index 83c5b10f51abd..9ba5a5dfbcab2 100644
--- a/lldb/test/API/commands/settings/TestSettings.py
+++ b/lldb/test/API/commands/settings/TestSettings.py
@@ -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)
More information about the lldb-commits
mailing list