diff options
author | Dave Lee <davelee.com@gmail.com> | 2025-08-21 13:41:38 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-08-21 13:41:38 -0700 |
commit | 545cda649e940c58440530cbd2130f479aea77a9 (patch) | |
tree | 88b59ced81dcdca5bc3638e42ff08a7dfa03c6f4 /lldb/source/Commands/CommandObjectSettings.cpp | |
parent | ba5d487ac49619d94576909e2fe7ffbd3f8a6427 (diff) | |
download | llvm-545cda649e940c58440530cbd2130f479aea77a9.zip llvm-545cda649e940c58440530cbd2130f479aea77a9.tar.gz llvm-545cda649e940c58440530cbd2130f479aea77a9.tar.bz2 |
[lldb] Add flag to "settings show" to include default values (#153233)
Adds a `--defaults`/`-d` flag to `settings show`. This mode will _optionally_ show a
setting's default value. In other words, this does not always print a default value for
every setting.
A default value is not shown when the current value _is_ the default.
Note: some setting types do not print empty or invalid values. For these setting types,
if the default value is empty or invalid, the same elision logic is applied to printing
the default value.
Diffstat (limited to 'lldb/source/Commands/CommandObjectSettings.cpp')
-rw-r--r-- | lldb/source/Commands/CommandObjectSettings.cpp | 47 |
1 files changed, 42 insertions, 5 deletions
diff --git a/lldb/source/Commands/CommandObjectSettings.cpp b/lldb/source/Commands/CommandObjectSettings.cpp index 7bbb0dd..126f57c 100644 --- a/lldb/source/Commands/CommandObjectSettings.cpp +++ b/lldb/source/Commands/CommandObjectSettings.cpp @@ -237,28 +237,62 @@ private: }; // CommandObjectSettingsShow -- Show current values +#define LLDB_OPTIONS_settings_show +#include "CommandOptions.inc" class CommandObjectSettingsShow : public CommandObjectParsed { public: CommandObjectSettingsShow(CommandInterpreter &interpreter) : CommandObjectParsed(interpreter, "settings show", "Show matching debugger settings and their current " - "values. Defaults to showing all settings.", - nullptr) { + "values. Defaults to showing all settings.") { AddSimpleArgumentList(eArgTypeSettingVariableName, eArgRepeatOptional); } ~CommandObjectSettingsShow() override = default; + Options *GetOptions() override { return &m_options; } + + class CommandOptions : public Options { + public: + ~CommandOptions() override = default; + + Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, + ExecutionContext *execution_context) override { + const int short_option = m_getopt_table[option_idx].val; + switch (short_option) { + case 'd': + m_include_defaults = true; + break; + default: + llvm_unreachable("Unimplemented option"); + } + return {}; + } + + void OptionParsingStarting(ExecutionContext *execution_context) override { + m_include_defaults = false; + } + + llvm::ArrayRef<OptionDefinition> GetDefinitions() override { + return g_settings_show_options; + } + + bool m_include_defaults = false; + }; + protected: void DoExecute(Args &args, CommandReturnObject &result) override { result.SetStatus(eReturnStatusSuccessFinishResult); + uint32_t dump_mask = OptionValue::eDumpGroupValue; + if (m_options.m_include_defaults) + dump_mask |= OptionValue::eDumpOptionDefaultValue; + if (!args.empty()) { for (const auto &arg : args) { Status error(GetDebugger().DumpPropertyValue( - &m_exe_ctx, result.GetOutputStream(), arg.ref(), - OptionValue::eDumpGroupValue)); + &m_exe_ctx, result.GetOutputStream(), arg.ref(), dump_mask)); if (error.Success()) { result.GetOutputStream().EOL(); } else { @@ -267,9 +301,12 @@ protected: } } else { GetDebugger().DumpAllPropertyValues(&m_exe_ctx, result.GetOutputStream(), - OptionValue::eDumpGroupValue); + dump_mask); } } + +private: + CommandOptions m_options; }; // CommandObjectSettingsWrite -- Write settings to file |