[Lldb-commits] [lldb] r345207 - [Settings] Add -force flag to "settings set"
Jonas Devlieghere via lldb-commits
lldb-commits at lists.llvm.org
Wed Oct 24 15:04:20 PDT 2018
Author: jdevlieghere
Date: Wed Oct 24 15:04:20 2018
New Revision: 345207
URL: http://llvm.org/viewvc/llvm-project?rev=345207&view=rev
Log:
[Settings] Add -force flag to "settings set"
The -force option allows you to pass an empty value to settings set to
reset the value to its default. This means that the following operations
are equivalent:
settings set -f <setting>
settings clear <setting>
The motivation for this change is the ability to export and import
settings from LLDB. Because of the way the dumpers work, we don't know
whether a value is going to be the default or not. Hence we cannot use
settings clear and use settings set -f, potentially providing an empty
value.
Differential revision: https://reviews.llvm.org/D52772
Added:
lldb/trunk/lit/Settings/TestSettingsSet.test
Modified:
lldb/trunk/source/Commands/CommandObjectSettings.cpp
Added: lldb/trunk/lit/Settings/TestSettingsSet.test
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/Settings/TestSettingsSet.test?rev=345207&view=auto
==============================================================================
--- lldb/trunk/lit/Settings/TestSettingsSet.test (added)
+++ lldb/trunk/lit/Settings/TestSettingsSet.test Wed Oct 24 15:04:20 2018
@@ -0,0 +1,15 @@
+# This tests setting setting values.
+
+# Check that setting an empty value with -f(orce) clears the value.
+# RUN: %lldb -b -s %s 2>&1 | FileCheck %s
+
+settings set tab-size 16
+settings show tab-size
+# CHECK: tab-size (unsigned) = 16
+
+settings set -f tab-size
+settings show tab-size
+# CHECK: tab-size (unsigned) = 4
+
+settings set tab-size
+# CHECK: error: 'settings set' takes more arguments
Modified: lldb/trunk/source/Commands/CommandObjectSettings.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectSettings.cpp?rev=345207&r1=345206&r2=345207&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectSettings.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectSettings.cpp Wed Oct 24 15:04:20 2018
@@ -30,7 +30,8 @@ using namespace lldb_private;
static constexpr OptionDefinition g_settings_set_options[] = {
// clang-format off
- { LLDB_OPT_SET_2, false, "global", 'g', OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone, "Apply the new value to the global default value." }
+ { LLDB_OPT_SET_2, false, "global", 'g', OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone, "Apply the new value to the global default value." },
+ { LLDB_OPT_SET_2, false, "force", 'f', OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone, "Force an empty value to be accepted as the default." }
// clang-format on
};
@@ -108,6 +109,9 @@ insert-before or insert-after.");
const int short_option = m_getopt_table[option_idx].val;
switch (short_option) {
+ case 'f':
+ m_force = true;
+ break;
case 'g':
m_global = true;
break;
@@ -122,6 +126,7 @@ insert-before or insert-after.");
void OptionParsingStarting(ExecutionContext *execution_context) override {
m_global = false;
+ m_force = false;
}
llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
@@ -129,8 +134,8 @@ insert-before or insert-after.");
}
// Instance variables to hold the values for command options.
-
bool m_global;
+ bool m_force;
};
int HandleArgumentCompletion(
@@ -184,8 +189,10 @@ protected:
if (!ParseOptions(cmd_args, result))
return false;
+ const size_t min_argc = m_options.m_force ? 1 : 2;
const size_t argc = cmd_args.GetArgumentCount();
- if ((argc < 2) && (!m_options.m_global)) {
+
+ if ((argc < min_argc) && (!m_options.m_global)) {
result.AppendError("'settings set' takes more arguments");
result.SetStatus(eReturnStatusFailed);
return false;
@@ -199,6 +206,19 @@ protected:
return false;
}
+ // A missing value corresponds to clearing the setting when "force" is
+ // specified.
+ if (argc == 1 && m_options.m_force) {
+ Status error(m_interpreter.GetDebugger().SetPropertyValue(
+ &m_exe_ctx, eVarSetOperationClear, var_name, llvm::StringRef()));
+ if (error.Fail()) {
+ result.AppendError(error.AsCString());
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+ return result.Succeeded();
+ }
+
// Split the raw command into var_name and value pair.
llvm::StringRef raw_str(command);
std::string var_value_string = raw_str.split(var_name).second.str();
More information about the lldb-commits
mailing list