[Lldb-commits] [lldb] [lldb] Add flag to "settings show" to include default values (PR #153233)
Dave Lee via lldb-commits
lldb-commits at lists.llvm.org
Sat Aug 16 13:52:44 PDT 2025
https://github.com/kastiglione updated https://github.com/llvm/llvm-project/pull/153233
>From 88b491d4a1a13e1f64efdf8e1bb71c3b58c4b0b5 Mon Sep 17 00:00:00 2001
From: Dave Lee <davelee.com at gmail.com>
Date: Tue, 12 Aug 2025 10:45:04 -0700
Subject: [PATCH 01/10] [lldb] Show setting default in new verbose mode
---
lldb/include/lldb/Interpreter/OptionValue.h | 10 ++++
.../lldb/Interpreter/OptionValueEnumeration.h | 1 +
lldb/include/lldb/Utility/ArchSpec.h | 1 +
.../source/Commands/CommandObjectSettings.cpp | 47 +++++++++++++++++--
lldb/source/Commands/Options.td | 5 ++
lldb/source/Interpreter/OptionValueArch.cpp | 7 +++
.../source/Interpreter/OptionValueBoolean.cpp | 6 +++
lldb/source/Interpreter/OptionValueChar.cpp | 18 +++++--
.../Interpreter/OptionValueEnumeration.cpp | 24 +++++++---
.../Interpreter/OptionValueFileSpec.cpp | 8 +++-
lldb/source/Interpreter/OptionValueFormat.cpp | 6 +++
.../Interpreter/OptionValueFormatEntity.cpp | 21 +++++----
.../Interpreter/OptionValueLanguage.cpp | 9 +++-
lldb/source/Interpreter/OptionValueRegex.cpp | 7 +++
lldb/source/Interpreter/OptionValueSInt64.cpp | 6 +++
lldb/source/Interpreter/OptionValueString.cpp | 40 ++++++++++------
lldb/source/Interpreter/OptionValueUInt64.cpp | 6 +++
lldb/source/Utility/ArchSpec.cpp | 4 ++
18 files changed, 183 insertions(+), 43 deletions(-)
diff --git a/lldb/include/lldb/Interpreter/OptionValue.h b/lldb/include/lldb/Interpreter/OptionValue.h
index f293a3a33bfa0..cbf117f2f8326 100644
--- a/lldb/include/lldb/Interpreter/OptionValue.h
+++ b/lldb/include/lldb/Interpreter/OptionValue.h
@@ -17,6 +17,7 @@
#include "lldb/Utility/FileSpec.h"
#include "lldb/Utility/FileSpecList.h"
#include "lldb/Utility/Status.h"
+#include "lldb/Utility/Stream.h"
#include "lldb/Utility/StringList.h"
#include "lldb/Utility/UUID.h"
#include "lldb/lldb-defines.h"
@@ -61,6 +62,7 @@ class OptionValue {
eDumpOptionDescription = (1u << 3),
eDumpOptionRaw = (1u << 4),
eDumpOptionCommand = (1u << 5),
+ eDumpOptionDefaultValue = (1u << 6),
eDumpGroupValue = (eDumpOptionName | eDumpOptionType | eDumpOptionValue),
eDumpGroupHelp =
(eDumpOptionName | eDumpOptionType | eDumpOptionDescription),
@@ -338,6 +340,14 @@ class OptionValue {
// DeepCopy to it. Inherit from Cloneable to avoid doing this manually.
virtual lldb::OptionValueSP Clone() const = 0;
+ struct DefaultValueFormat {
+ DefaultValueFormat(Stream &stream) : stream(stream) {
+ stream.PutCString(" (default: ");
+ }
+ ~DefaultValueFormat() { stream.PutChar(')'); }
+ Stream &stream;
+ };
+
lldb::OptionValueWP m_parent_wp;
std::function<void()> m_callback;
bool m_value_was_set = false; // This can be used to see if a value has been
diff --git a/lldb/include/lldb/Interpreter/OptionValueEnumeration.h b/lldb/include/lldb/Interpreter/OptionValueEnumeration.h
index a3a13ca7b15eb..91ab454b2065e 100644
--- a/lldb/include/lldb/Interpreter/OptionValueEnumeration.h
+++ b/lldb/include/lldb/Interpreter/OptionValueEnumeration.h
@@ -72,6 +72,7 @@ class OptionValueEnumeration
protected:
void SetEnumerations(const OptionEnumValues &enumerators);
+ void DumpEnum(Stream &strm, enum_type value);
enum_type m_current_value;
enum_type m_default_value;
diff --git a/lldb/include/lldb/Utility/ArchSpec.h b/lldb/include/lldb/Utility/ArchSpec.h
index 7e9bc23a75acb..96bd5e3597b68 100644
--- a/lldb/include/lldb/Utility/ArchSpec.h
+++ b/lldb/include/lldb/Utility/ArchSpec.h
@@ -564,6 +564,7 @@ class ArchSpec {
/// \return true if \a lhs is less than \a rhs
bool operator<(const ArchSpec &lhs, const ArchSpec &rhs);
bool operator==(const ArchSpec &lhs, const ArchSpec &rhs);
+bool operator!=(const ArchSpec &lhs, const ArchSpec &rhs);
bool ParseMachCPUDashSubtypeTriple(llvm::StringRef triple_str, ArchSpec &arch);
diff --git a/lldb/source/Commands/CommandObjectSettings.cpp b/lldb/source/Commands/CommandObjectSettings.cpp
index 7bbb0dd567ab1..e638df75b8c9a 100644
--- a/lldb/source/Commands/CommandObjectSettings.cpp
+++ b/lldb/source/Commands/CommandObjectSettings.cpp
@@ -237,28 +237,62 @@ insert-before or insert-after.");
};
// 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 'v':
+ m_verbose = true;
+ break;
+ default:
+ llvm_unreachable("Unimplemented option");
+ }
+ return {};
+ }
+
+ void OptionParsingStarting(ExecutionContext *execution_context) override {
+ m_verbose = false;
+ }
+
+ llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
+ return g_settings_show_options;
+ }
+
+ bool m_verbose = false;
+ };
+
protected:
void DoExecute(Args &args, CommandReturnObject &result) override {
result.SetStatus(eReturnStatusSuccessFinishResult);
+ uint32_t dump_mask = OptionValue::eDumpGroupValue;
+ if (m_options.m_verbose)
+ 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 @@ class CommandObjectSettingsShow : public CommandObjectParsed {
}
} else {
GetDebugger().DumpAllPropertyValues(&m_exe_ctx, result.GetOutputStream(),
- OptionValue::eDumpGroupValue);
+ dump_mask);
}
}
+
+private:
+ CommandOptions m_options;
};
// CommandObjectSettingsWrite -- Write settings to file
diff --git a/lldb/source/Commands/Options.td b/lldb/source/Commands/Options.td
index 61acc40585976..596f959b76d4a 100644
--- a/lldb/source/Commands/Options.td
+++ b/lldb/source/Commands/Options.td
@@ -56,6 +56,11 @@ let Command = "settings clear" in {
Desc<"Clear all settings.">;
}
+let Command = "settings show" in {
+ def setshow_verbose : Option<"verbose", "v">,
+ Desc<"Enable verbose output.">;
+}
+
let Command = "breakpoint list" in {
// FIXME: We need to add an "internal" command, and then add this sort of
// thing to it. But I need to see it for now, and don't want to wait.
diff --git a/lldb/source/Interpreter/OptionValueArch.cpp b/lldb/source/Interpreter/OptionValueArch.cpp
index ea15ccaaefe2b..62c53ee05f0ce 100644
--- a/lldb/source/Interpreter/OptionValueArch.cpp
+++ b/lldb/source/Interpreter/OptionValueArch.cpp
@@ -11,6 +11,7 @@
#include "lldb/DataFormatters/FormatManager.h"
#include "lldb/Interpreter/CommandCompletions.h"
#include "lldb/Interpreter/CommandInterpreter.h"
+#include "lldb/Interpreter/OptionValue.h"
#include "lldb/Utility/Args.h"
#include "lldb/Utility/State.h"
@@ -30,6 +31,12 @@ void OptionValueArch::DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
if (arch_name)
strm.PutCString(arch_name);
}
+
+ if (dump_mask & eDumpOptionDefaultValue &&
+ m_current_value != m_default_value && m_default_value.IsValid()) {
+ DefaultValueFormat label{strm};
+ strm.PutCString(m_default_value.GetArchitectureName());
+ }
}
}
diff --git a/lldb/source/Interpreter/OptionValueBoolean.cpp b/lldb/source/Interpreter/OptionValueBoolean.cpp
index d4fda762fea6b..1617e151f6bb2 100644
--- a/lldb/source/Interpreter/OptionValueBoolean.cpp
+++ b/lldb/source/Interpreter/OptionValueBoolean.cpp
@@ -10,6 +10,7 @@
#include "lldb/Host/PosixApi.h"
#include "lldb/Interpreter/OptionArgParser.h"
+#include "lldb/Interpreter/OptionValue.h"
#include "lldb/Utility/Stream.h"
#include "lldb/Utility/StringList.h"
#include "llvm/ADT/STLExtras.h"
@@ -27,6 +28,11 @@ void OptionValueBoolean::DumpValue(const ExecutionContext *exe_ctx,
if (dump_mask & eDumpOptionType)
strm.PutCString(" = ");
strm.PutCString(m_current_value ? "true" : "false");
+ if (dump_mask & eDumpOptionDefaultValue &&
+ m_current_value != m_default_value) {
+ DefaultValueFormat label{strm};
+ strm.PutCString(m_default_value ? "true" : "false");
+ }
}
}
diff --git a/lldb/source/Interpreter/OptionValueChar.cpp b/lldb/source/Interpreter/OptionValueChar.cpp
index 2aadcff158388..4efef2532bbb1 100644
--- a/lldb/source/Interpreter/OptionValueChar.cpp
+++ b/lldb/source/Interpreter/OptionValueChar.cpp
@@ -9,6 +9,7 @@
#include "lldb/Interpreter/OptionValueChar.h"
#include "lldb/Interpreter/OptionArgParser.h"
+#include "lldb/Interpreter/OptionValue.h"
#include "lldb/Utility/Stream.h"
#include "lldb/Utility/StringList.h"
#include "llvm/ADT/STLExtras.h"
@@ -16,6 +17,13 @@
using namespace lldb;
using namespace lldb_private;
+static void DumpChar(Stream &strm, char value) {
+ if (value != '\0')
+ strm.PutChar(value);
+ else
+ strm.PutCString("(null)");
+}
+
void OptionValueChar::DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
uint32_t dump_mask) {
if (dump_mask & eDumpOptionType)
@@ -24,10 +32,12 @@ void OptionValueChar::DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
if (dump_mask & eDumpOptionValue) {
if (dump_mask & eDumpOptionType)
strm.PutCString(" = ");
- if (m_current_value != '\0')
- strm.PutChar(m_current_value);
- else
- strm.PutCString("(null)");
+ DumpChar(strm, m_current_value);
+ if (dump_mask & eDumpOptionDefaultValue &&
+ m_current_value != m_default_value) {
+ DefaultValueFormat label{strm};
+ DumpChar(strm, m_default_value);
+ }
}
}
diff --git a/lldb/source/Interpreter/OptionValueEnumeration.cpp b/lldb/source/Interpreter/OptionValueEnumeration.cpp
index cf646233c80da..671ceb79fab67 100644
--- a/lldb/source/Interpreter/OptionValueEnumeration.cpp
+++ b/lldb/source/Interpreter/OptionValueEnumeration.cpp
@@ -8,6 +8,7 @@
#include "lldb/Interpreter/OptionValueEnumeration.h"
+#include "lldb/Interpreter/OptionValue.h"
#include "lldb/Utility/StringList.h"
using namespace lldb;
@@ -19,6 +20,17 @@ OptionValueEnumeration::OptionValueEnumeration(
SetEnumerations(enumerators);
}
+void OptionValueEnumeration::DumpEnum(Stream &strm, enum_type value) {
+ const size_t count = m_enumerations.GetSize();
+ for (size_t i = 0; i < count; ++i)
+ if (m_enumerations.GetValueAtIndexUnchecked(i).value == value) {
+ strm.PutCString(m_enumerations.GetCStringAtIndex(i));
+ return;
+ }
+
+ strm.Printf("%" PRIu64, (uint64_t)value);
+}
+
void OptionValueEnumeration::DumpValue(const ExecutionContext *exe_ctx,
Stream &strm, uint32_t dump_mask) {
if (dump_mask & eDumpOptionType)
@@ -26,14 +38,12 @@ void OptionValueEnumeration::DumpValue(const ExecutionContext *exe_ctx,
if (dump_mask & eDumpOptionValue) {
if (dump_mask & eDumpOptionType)
strm.PutCString(" = ");
- const size_t count = m_enumerations.GetSize();
- for (size_t i = 0; i < count; ++i) {
- if (m_enumerations.GetValueAtIndexUnchecked(i).value == m_current_value) {
- strm.PutCString(m_enumerations.GetCStringAtIndex(i).GetStringRef());
- return;
- }
+ DumpEnum(strm, m_current_value);
+ if (dump_mask & eDumpOptionDefaultValue &&
+ m_current_value != m_default_value) {
+ DefaultValueFormat label{strm};
+ DumpEnum(strm, m_default_value);
}
- strm.Printf("%" PRIu64, (uint64_t)m_current_value);
}
}
diff --git a/lldb/source/Interpreter/OptionValueFileSpec.cpp b/lldb/source/Interpreter/OptionValueFileSpec.cpp
index 6fa6af4ace02a..0f186bdb6ebfa 100644
--- a/lldb/source/Interpreter/OptionValueFileSpec.cpp
+++ b/lldb/source/Interpreter/OptionValueFileSpec.cpp
@@ -12,6 +12,7 @@
#include "lldb/Host/FileSystem.h"
#include "lldb/Interpreter/CommandCompletions.h"
#include "lldb/Interpreter/CommandInterpreter.h"
+#include "lldb/Interpreter/OptionValue.h"
#include "lldb/Utility/Args.h"
#include "lldb/Utility/State.h"
@@ -41,7 +42,12 @@ void OptionValueFileSpec::DumpValue(const ExecutionContext *exe_ctx,
strm.PutCString(" = ");
if (m_current_value) {
- strm << '"' << m_current_value.GetPath().c_str() << '"';
+ strm.QuotedCString(m_current_value.GetPath().data());
+ }
+ if (dump_mask & eDumpOptionDefaultValue &&
+ m_current_value != m_default_value && m_default_value) {
+ DefaultValueFormat label{strm};
+ strm.QuotedCString(m_default_value.GetPath().data());
}
}
}
diff --git a/lldb/source/Interpreter/OptionValueFormat.cpp b/lldb/source/Interpreter/OptionValueFormat.cpp
index bc4e77923d10e..f642595a56d97 100644
--- a/lldb/source/Interpreter/OptionValueFormat.cpp
+++ b/lldb/source/Interpreter/OptionValueFormat.cpp
@@ -10,6 +10,7 @@
#include "lldb/DataFormatters/FormatManager.h"
#include "lldb/Interpreter/OptionArgParser.h"
+#include "lldb/Interpreter/OptionValue.h"
#include "lldb/Utility/Stream.h"
using namespace lldb;
@@ -23,6 +24,11 @@ void OptionValueFormat::DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
if (dump_mask & eDumpOptionType)
strm.PutCString(" = ");
strm.PutCString(FormatManager::GetFormatAsCString(m_current_value));
+ if (dump_mask & eDumpOptionDefaultValue &&
+ m_current_value != m_default_value) {
+ DefaultValueFormat label{strm};
+ strm.PutCString(FormatManager::GetFormatAsCString(m_default_value));
+ }
}
}
diff --git a/lldb/source/Interpreter/OptionValueFormatEntity.cpp b/lldb/source/Interpreter/OptionValueFormatEntity.cpp
index d8b830115005c..96529fd13c3b0 100644
--- a/lldb/source/Interpreter/OptionValueFormatEntity.cpp
+++ b/lldb/source/Interpreter/OptionValueFormatEntity.cpp
@@ -10,6 +10,7 @@
#include "lldb/Core/Module.h"
#include "lldb/Interpreter/CommandInterpreter.h"
+#include "lldb/Interpreter/OptionValue.h"
#include "lldb/Utility/Stream.h"
#include "lldb/Utility/StringList.h"
using namespace lldb;
@@ -33,10 +34,8 @@ void OptionValueFormatEntity::Clear() {
m_value_was_set = false;
}
-static void EscapeBackticks(llvm::StringRef str, std::string &dst) {
- dst.clear();
- dst.reserve(str.size());
-
+static std::string EscapeBackticks(llvm::StringRef str) {
+ std::string dst;
for (size_t i = 0, e = str.size(); i != e; ++i) {
char c = str[i];
if (c == '`') {
@@ -45,6 +44,7 @@ static void EscapeBackticks(llvm::StringRef str, std::string &dst) {
}
dst += c;
}
+ return dst;
}
void OptionValueFormatEntity::DumpValue(const ExecutionContext *exe_ctx,
@@ -54,17 +54,18 @@ void OptionValueFormatEntity::DumpValue(const ExecutionContext *exe_ctx,
if (dump_mask & eDumpOptionValue) {
if (dump_mask & eDumpOptionType)
strm.PutCString(" = ");
- std::string escaped;
- EscapeBackticks(m_current_format, escaped);
- strm << '"' << escaped << '"';
+ strm.QuotedCString(EscapeBackticks(m_current_format).data());
+ if (dump_mask & eDumpOptionDefaultValue &&
+ m_current_format != m_default_format) {
+ DefaultValueFormat label{strm};
+ strm.QuotedCString(EscapeBackticks(m_default_format).data());
+ }
}
}
llvm::json::Value
OptionValueFormatEntity::ToJSON(const ExecutionContext *exe_ctx) const {
- std::string escaped;
- EscapeBackticks(m_current_format, escaped);
- return escaped;
+ return EscapeBackticks(m_current_format);
}
Status OptionValueFormatEntity::SetValueFromString(llvm::StringRef value_str,
diff --git a/lldb/source/Interpreter/OptionValueLanguage.cpp b/lldb/source/Interpreter/OptionValueLanguage.cpp
index 0fdaacb02594e..55023704ba887 100644
--- a/lldb/source/Interpreter/OptionValueLanguage.cpp
+++ b/lldb/source/Interpreter/OptionValueLanguage.cpp
@@ -9,8 +9,9 @@
#include "lldb/Interpreter/OptionValueLanguage.h"
#include "lldb/DataFormatters/FormatManager.h"
-#include "lldb/Target/Language.h"
+#include "lldb/Interpreter/OptionValue.h"
#include "lldb/Symbol/TypeSystem.h"
+#include "lldb/Target/Language.h"
#include "lldb/Utility/Args.h"
#include "lldb/Utility/Stream.h"
@@ -26,6 +27,12 @@ void OptionValueLanguage::DumpValue(const ExecutionContext *exe_ctx,
strm.PutCString(" = ");
if (m_current_value != eLanguageTypeUnknown)
strm.PutCString(Language::GetNameForLanguageType(m_current_value));
+ if (dump_mask & eDumpOptionDefaultValue &&
+ m_current_value != m_default_value &&
+ m_default_value != eLanguageTypeUnknown) {
+ DefaultValueFormat label{strm};
+ strm.PutCString(Language::GetNameForLanguageType(m_default_value));
+ }
}
}
diff --git a/lldb/source/Interpreter/OptionValueRegex.cpp b/lldb/source/Interpreter/OptionValueRegex.cpp
index 91ec41df6ee50..8d2e02c26177b 100644
--- a/lldb/source/Interpreter/OptionValueRegex.cpp
+++ b/lldb/source/Interpreter/OptionValueRegex.cpp
@@ -8,6 +8,7 @@
#include "lldb/Interpreter/OptionValueRegex.h"
+#include "lldb/Interpreter/OptionValue.h"
#include "lldb/Utility/Stream.h"
using namespace lldb;
@@ -24,6 +25,12 @@ void OptionValueRegex::DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
llvm::StringRef regex_text = m_regex.GetText();
strm.Printf("%s", regex_text.str().c_str());
}
+ if (dump_mask & eDumpOptionDefaultValue &&
+ m_regex.GetText() != m_default_regex_str &&
+ !m_default_regex_str.empty()) {
+ DefaultValueFormat label{strm};
+ strm.PutCString(m_default_regex_str);
+ }
}
}
diff --git a/lldb/source/Interpreter/OptionValueSInt64.cpp b/lldb/source/Interpreter/OptionValueSInt64.cpp
index df7aee99e212c..ec5a6d200ede0 100644
--- a/lldb/source/Interpreter/OptionValueSInt64.cpp
+++ b/lldb/source/Interpreter/OptionValueSInt64.cpp
@@ -8,6 +8,7 @@
#include "lldb/Interpreter/OptionValueSInt64.h"
+#include "lldb/Interpreter/OptionValue.h"
#include "lldb/Utility/Stream.h"
using namespace lldb;
@@ -26,6 +27,11 @@ void OptionValueSInt64::DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
if (dump_mask & eDumpOptionType)
strm.PutCString(" = ");
strm.Printf("%" PRIi64, m_current_value);
+ if (dump_mask & eDumpOptionDefaultValue &&
+ m_current_value != m_default_value) {
+ DefaultValueFormat label{strm};
+ strm.Printf("%" PRIi64, m_default_value);
+ }
}
}
diff --git a/lldb/source/Interpreter/OptionValueString.cpp b/lldb/source/Interpreter/OptionValueString.cpp
index ae30661a56d05..62ca6f9890026 100644
--- a/lldb/source/Interpreter/OptionValueString.cpp
+++ b/lldb/source/Interpreter/OptionValueString.cpp
@@ -9,12 +9,28 @@
#include "lldb/Interpreter/OptionValueString.h"
#include "lldb/Host/OptionParser.h"
+#include "lldb/Interpreter/OptionValue.h"
#include "lldb/Utility/Args.h"
#include "lldb/Utility/Stream.h"
using namespace lldb;
using namespace lldb_private;
+static void DumpValue(Stream &strm, const std::string &str, bool escape,
+ bool raw) {
+ if (escape) {
+ std::string escaped_str;
+ Args::ExpandEscapedCharacters(str.data(), escaped_str);
+ ::DumpValue(strm, escaped_str, false, raw);
+ return;
+ }
+
+ if (raw)
+ strm.PutCString(str);
+ else
+ strm.QuotedCString(str.data());
+}
+
void OptionValueString::DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
uint32_t dump_mask) {
if (dump_mask & eDumpOptionType)
@@ -22,21 +38,15 @@ void OptionValueString::DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
if (dump_mask & eDumpOptionValue) {
if (dump_mask & eDumpOptionType)
strm.PutCString(" = ");
- if (!m_current_value.empty() || m_value_was_set) {
- if (m_options.Test(eOptionEncodeCharacterEscapeSequences)) {
- std::string expanded_escape_value;
- Args::ExpandEscapedCharacters(m_current_value.c_str(),
- expanded_escape_value);
- if (dump_mask & eDumpOptionRaw)
- strm.Printf("%s", expanded_escape_value.c_str());
- else
- strm.Printf("\"%s\"", expanded_escape_value.c_str());
- } else {
- if (dump_mask & eDumpOptionRaw)
- strm.Printf("%s", m_current_value.c_str());
- else
- strm.Printf("\"%s\"", m_current_value.c_str());
- }
+ const bool escape = m_options.Test(eOptionEncodeCharacterEscapeSequences);
+ const bool raw = dump_mask & eDumpOptionRaw;
+ if (!m_current_value.empty() || m_value_was_set)
+ ::DumpValue(strm, m_current_value, escape, raw);
+
+ if (dump_mask & eDumpOptionDefaultValue &&
+ m_current_value != m_default_value && !m_default_value.empty()) {
+ DefaultValueFormat label{strm};
+ ::DumpValue(strm, m_default_value, escape, raw);
}
}
}
diff --git a/lldb/source/Interpreter/OptionValueUInt64.cpp b/lldb/source/Interpreter/OptionValueUInt64.cpp
index aa5e9a21c8c28..3b633425fb9be 100644
--- a/lldb/source/Interpreter/OptionValueUInt64.cpp
+++ b/lldb/source/Interpreter/OptionValueUInt64.cpp
@@ -8,6 +8,7 @@
#include "lldb/Interpreter/OptionValueUInt64.h"
+#include "lldb/Interpreter/OptionValue.h"
#include "lldb/Utility/Stream.h"
using namespace lldb;
@@ -30,6 +31,11 @@ void OptionValueUInt64::DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
if (dump_mask & eDumpOptionType)
strm.PutCString(" = ");
strm.Printf("%" PRIu64, m_current_value);
+ if (dump_mask & eDumpOptionDefaultValue &&
+ m_current_value != m_default_value) {
+ DefaultValueFormat label{strm};
+ strm.Printf("%" PRIu64, m_default_value);
+ }
}
}
diff --git a/lldb/source/Utility/ArchSpec.cpp b/lldb/source/Utility/ArchSpec.cpp
index 7c71aaae6bcf2..8f14cf6e39438 100644
--- a/lldb/source/Utility/ArchSpec.cpp
+++ b/lldb/source/Utility/ArchSpec.cpp
@@ -1439,6 +1439,10 @@ bool lldb_private::operator==(const ArchSpec &lhs, const ArchSpec &rhs) {
return lhs.GetCore() == rhs.GetCore();
}
+bool lldb_private::operator!=(const ArchSpec &lhs, const ArchSpec &rhs) {
+ return !(lhs == rhs);
+}
+
bool ArchSpec::IsFullySpecifiedTriple() const {
if (!TripleOSWasSpecified())
return false;
>From 6b5b7d5879b5f3a4e0a6043c9236275115a803dd Mon Sep 17 00:00:00 2001
From: Dave Lee <davelee.com at gmail.com>
Date: Tue, 12 Aug 2025 12:34:13 -0700
Subject: [PATCH 02/10] paren init
---
lldb/source/Interpreter/OptionValueArch.cpp | 2 +-
lldb/source/Interpreter/OptionValueBoolean.cpp | 2 +-
lldb/source/Interpreter/OptionValueChar.cpp | 2 +-
lldb/source/Interpreter/OptionValueEnumeration.cpp | 2 +-
lldb/source/Interpreter/OptionValueFileSpec.cpp | 2 +-
lldb/source/Interpreter/OptionValueFormat.cpp | 2 +-
lldb/source/Interpreter/OptionValueFormatEntity.cpp | 2 +-
lldb/source/Interpreter/OptionValueLanguage.cpp | 2 +-
lldb/source/Interpreter/OptionValueRegex.cpp | 2 +-
lldb/source/Interpreter/OptionValueSInt64.cpp | 2 +-
lldb/source/Interpreter/OptionValueString.cpp | 2 +-
lldb/source/Interpreter/OptionValueUInt64.cpp | 2 +-
12 files changed, 12 insertions(+), 12 deletions(-)
diff --git a/lldb/source/Interpreter/OptionValueArch.cpp b/lldb/source/Interpreter/OptionValueArch.cpp
index 62c53ee05f0ce..a960e39d35a62 100644
--- a/lldb/source/Interpreter/OptionValueArch.cpp
+++ b/lldb/source/Interpreter/OptionValueArch.cpp
@@ -34,7 +34,7 @@ void OptionValueArch::DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
if (dump_mask & eDumpOptionDefaultValue &&
m_current_value != m_default_value && m_default_value.IsValid()) {
- DefaultValueFormat label{strm};
+ DefaultValueFormat label(strm);
strm.PutCString(m_default_value.GetArchitectureName());
}
}
diff --git a/lldb/source/Interpreter/OptionValueBoolean.cpp b/lldb/source/Interpreter/OptionValueBoolean.cpp
index 1617e151f6bb2..023c243b3efc1 100644
--- a/lldb/source/Interpreter/OptionValueBoolean.cpp
+++ b/lldb/source/Interpreter/OptionValueBoolean.cpp
@@ -30,7 +30,7 @@ void OptionValueBoolean::DumpValue(const ExecutionContext *exe_ctx,
strm.PutCString(m_current_value ? "true" : "false");
if (dump_mask & eDumpOptionDefaultValue &&
m_current_value != m_default_value) {
- DefaultValueFormat label{strm};
+ DefaultValueFormat label(strm);
strm.PutCString(m_default_value ? "true" : "false");
}
}
diff --git a/lldb/source/Interpreter/OptionValueChar.cpp b/lldb/source/Interpreter/OptionValueChar.cpp
index 4efef2532bbb1..595dcba49b61a 100644
--- a/lldb/source/Interpreter/OptionValueChar.cpp
+++ b/lldb/source/Interpreter/OptionValueChar.cpp
@@ -35,7 +35,7 @@ void OptionValueChar::DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
DumpChar(strm, m_current_value);
if (dump_mask & eDumpOptionDefaultValue &&
m_current_value != m_default_value) {
- DefaultValueFormat label{strm};
+ DefaultValueFormat label(strm);
DumpChar(strm, m_default_value);
}
}
diff --git a/lldb/source/Interpreter/OptionValueEnumeration.cpp b/lldb/source/Interpreter/OptionValueEnumeration.cpp
index 671ceb79fab67..eb31bde498b7c 100644
--- a/lldb/source/Interpreter/OptionValueEnumeration.cpp
+++ b/lldb/source/Interpreter/OptionValueEnumeration.cpp
@@ -41,7 +41,7 @@ void OptionValueEnumeration::DumpValue(const ExecutionContext *exe_ctx,
DumpEnum(strm, m_current_value);
if (dump_mask & eDumpOptionDefaultValue &&
m_current_value != m_default_value) {
- DefaultValueFormat label{strm};
+ DefaultValueFormat label(strm);
DumpEnum(strm, m_default_value);
}
}
diff --git a/lldb/source/Interpreter/OptionValueFileSpec.cpp b/lldb/source/Interpreter/OptionValueFileSpec.cpp
index 0f186bdb6ebfa..89cc7226f69ca 100644
--- a/lldb/source/Interpreter/OptionValueFileSpec.cpp
+++ b/lldb/source/Interpreter/OptionValueFileSpec.cpp
@@ -46,7 +46,7 @@ void OptionValueFileSpec::DumpValue(const ExecutionContext *exe_ctx,
}
if (dump_mask & eDumpOptionDefaultValue &&
m_current_value != m_default_value && m_default_value) {
- DefaultValueFormat label{strm};
+ DefaultValueFormat label(strm);
strm.QuotedCString(m_default_value.GetPath().data());
}
}
diff --git a/lldb/source/Interpreter/OptionValueFormat.cpp b/lldb/source/Interpreter/OptionValueFormat.cpp
index f642595a56d97..05990fb50c356 100644
--- a/lldb/source/Interpreter/OptionValueFormat.cpp
+++ b/lldb/source/Interpreter/OptionValueFormat.cpp
@@ -26,7 +26,7 @@ void OptionValueFormat::DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
strm.PutCString(FormatManager::GetFormatAsCString(m_current_value));
if (dump_mask & eDumpOptionDefaultValue &&
m_current_value != m_default_value) {
- DefaultValueFormat label{strm};
+ DefaultValueFormat label(strm);
strm.PutCString(FormatManager::GetFormatAsCString(m_default_value));
}
}
diff --git a/lldb/source/Interpreter/OptionValueFormatEntity.cpp b/lldb/source/Interpreter/OptionValueFormatEntity.cpp
index 96529fd13c3b0..78afa14a66dd7 100644
--- a/lldb/source/Interpreter/OptionValueFormatEntity.cpp
+++ b/lldb/source/Interpreter/OptionValueFormatEntity.cpp
@@ -57,7 +57,7 @@ void OptionValueFormatEntity::DumpValue(const ExecutionContext *exe_ctx,
strm.QuotedCString(EscapeBackticks(m_current_format).data());
if (dump_mask & eDumpOptionDefaultValue &&
m_current_format != m_default_format) {
- DefaultValueFormat label{strm};
+ DefaultValueFormat label(strm);
strm.QuotedCString(EscapeBackticks(m_default_format).data());
}
}
diff --git a/lldb/source/Interpreter/OptionValueLanguage.cpp b/lldb/source/Interpreter/OptionValueLanguage.cpp
index 55023704ba887..bb28dc8debe6d 100644
--- a/lldb/source/Interpreter/OptionValueLanguage.cpp
+++ b/lldb/source/Interpreter/OptionValueLanguage.cpp
@@ -30,7 +30,7 @@ void OptionValueLanguage::DumpValue(const ExecutionContext *exe_ctx,
if (dump_mask & eDumpOptionDefaultValue &&
m_current_value != m_default_value &&
m_default_value != eLanguageTypeUnknown) {
- DefaultValueFormat label{strm};
+ DefaultValueFormat label(strm);
strm.PutCString(Language::GetNameForLanguageType(m_default_value));
}
}
diff --git a/lldb/source/Interpreter/OptionValueRegex.cpp b/lldb/source/Interpreter/OptionValueRegex.cpp
index 8d2e02c26177b..30e307a7240ef 100644
--- a/lldb/source/Interpreter/OptionValueRegex.cpp
+++ b/lldb/source/Interpreter/OptionValueRegex.cpp
@@ -28,7 +28,7 @@ void OptionValueRegex::DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
if (dump_mask & eDumpOptionDefaultValue &&
m_regex.GetText() != m_default_regex_str &&
!m_default_regex_str.empty()) {
- DefaultValueFormat label{strm};
+ DefaultValueFormat label(strm);
strm.PutCString(m_default_regex_str);
}
}
diff --git a/lldb/source/Interpreter/OptionValueSInt64.cpp b/lldb/source/Interpreter/OptionValueSInt64.cpp
index ec5a6d200ede0..00f1cc37dddac 100644
--- a/lldb/source/Interpreter/OptionValueSInt64.cpp
+++ b/lldb/source/Interpreter/OptionValueSInt64.cpp
@@ -29,7 +29,7 @@ void OptionValueSInt64::DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
strm.Printf("%" PRIi64, m_current_value);
if (dump_mask & eDumpOptionDefaultValue &&
m_current_value != m_default_value) {
- DefaultValueFormat label{strm};
+ DefaultValueFormat label(strm);
strm.Printf("%" PRIi64, m_default_value);
}
}
diff --git a/lldb/source/Interpreter/OptionValueString.cpp b/lldb/source/Interpreter/OptionValueString.cpp
index 62ca6f9890026..97b3e43e703eb 100644
--- a/lldb/source/Interpreter/OptionValueString.cpp
+++ b/lldb/source/Interpreter/OptionValueString.cpp
@@ -45,7 +45,7 @@ void OptionValueString::DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
if (dump_mask & eDumpOptionDefaultValue &&
m_current_value != m_default_value && !m_default_value.empty()) {
- DefaultValueFormat label{strm};
+ DefaultValueFormat label(strm);
::DumpValue(strm, m_default_value, escape, raw);
}
}
diff --git a/lldb/source/Interpreter/OptionValueUInt64.cpp b/lldb/source/Interpreter/OptionValueUInt64.cpp
index 3b633425fb9be..63f83cbcd60a3 100644
--- a/lldb/source/Interpreter/OptionValueUInt64.cpp
+++ b/lldb/source/Interpreter/OptionValueUInt64.cpp
@@ -33,7 +33,7 @@ void OptionValueUInt64::DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
strm.Printf("%" PRIu64, m_current_value);
if (dump_mask & eDumpOptionDefaultValue &&
m_current_value != m_default_value) {
- DefaultValueFormat label{strm};
+ DefaultValueFormat label(strm);
strm.Printf("%" PRIu64, m_default_value);
}
}
>From d87c7fb758011ac0f7e75b159bfd38585597e081 Mon Sep 17 00:00:00 2001
From: Dave Lee <davelee.com at gmail.com>
Date: Tue, 12 Aug 2025 12:38:12 -0700
Subject: [PATCH 03/10] restore unintentionally deleted line
---
lldb/source/Interpreter/OptionValueFormatEntity.cpp | 1 +
1 file changed, 1 insertion(+)
diff --git a/lldb/source/Interpreter/OptionValueFormatEntity.cpp b/lldb/source/Interpreter/OptionValueFormatEntity.cpp
index 78afa14a66dd7..bae1b5c77835b 100644
--- a/lldb/source/Interpreter/OptionValueFormatEntity.cpp
+++ b/lldb/source/Interpreter/OptionValueFormatEntity.cpp
@@ -36,6 +36,7 @@ void OptionValueFormatEntity::Clear() {
static std::string EscapeBackticks(llvm::StringRef str) {
std::string dst;
+ dst.reserve(str.size());
for (size_t i = 0, e = str.size(); i != e; ++i) {
char c = str[i];
if (c == '`') {
>From e818dae50584672fd75372e3fd5b7fe58c0ebf0c Mon Sep 17 00:00:00 2001
From: Dave Lee <davelee.com at gmail.com>
Date: Tue, 12 Aug 2025 12:39:29 -0700
Subject: [PATCH 04/10] rename string helper function
---
lldb/source/Interpreter/OptionValueString.cpp | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/lldb/source/Interpreter/OptionValueString.cpp b/lldb/source/Interpreter/OptionValueString.cpp
index 97b3e43e703eb..f6ddff3603906 100644
--- a/lldb/source/Interpreter/OptionValueString.cpp
+++ b/lldb/source/Interpreter/OptionValueString.cpp
@@ -16,12 +16,12 @@
using namespace lldb;
using namespace lldb_private;
-static void DumpValue(Stream &strm, const std::string &str, bool escape,
- bool raw) {
+static void DumpString(Stream &strm, const std::string &str, bool escape,
+ bool raw) {
if (escape) {
std::string escaped_str;
Args::ExpandEscapedCharacters(str.data(), escaped_str);
- ::DumpValue(strm, escaped_str, false, raw);
+ DumpString(strm, escaped_str, false, raw);
return;
}
@@ -41,12 +41,12 @@ void OptionValueString::DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
const bool escape = m_options.Test(eOptionEncodeCharacterEscapeSequences);
const bool raw = dump_mask & eDumpOptionRaw;
if (!m_current_value.empty() || m_value_was_set)
- ::DumpValue(strm, m_current_value, escape, raw);
+ DumpString(strm, m_current_value, escape, raw);
if (dump_mask & eDumpOptionDefaultValue &&
m_current_value != m_default_value && !m_default_value.empty()) {
DefaultValueFormat label(strm);
- ::DumpValue(strm, m_default_value, escape, raw);
+ DumpString(strm, m_default_value, escape, raw);
}
}
}
>From 1f70b5b3bb7c1be55fbca288814a0516b55508c0 Mon Sep 17 00:00:00 2001
From: Dave Lee <davelee.com at gmail.com>
Date: Tue, 12 Aug 2025 17:09:00 -0700
Subject: [PATCH 05/10] Rename flag to --include-defaults
---
lldb/source/Commands/CommandObjectSettings.cpp | 10 +++++-----
lldb/source/Commands/Options.td | 4 ++--
2 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/lldb/source/Commands/CommandObjectSettings.cpp b/lldb/source/Commands/CommandObjectSettings.cpp
index e638df75b8c9a..126f57c738115 100644
--- a/lldb/source/Commands/CommandObjectSettings.cpp
+++ b/lldb/source/Commands/CommandObjectSettings.cpp
@@ -261,8 +261,8 @@ class CommandObjectSettingsShow : public CommandObjectParsed {
ExecutionContext *execution_context) override {
const int short_option = m_getopt_table[option_idx].val;
switch (short_option) {
- case 'v':
- m_verbose = true;
+ case 'd':
+ m_include_defaults = true;
break;
default:
llvm_unreachable("Unimplemented option");
@@ -271,14 +271,14 @@ class CommandObjectSettingsShow : public CommandObjectParsed {
}
void OptionParsingStarting(ExecutionContext *execution_context) override {
- m_verbose = false;
+ m_include_defaults = false;
}
llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
return g_settings_show_options;
}
- bool m_verbose = false;
+ bool m_include_defaults = false;
};
protected:
@@ -286,7 +286,7 @@ class CommandObjectSettingsShow : public CommandObjectParsed {
result.SetStatus(eReturnStatusSuccessFinishResult);
uint32_t dump_mask = OptionValue::eDumpGroupValue;
- if (m_options.m_verbose)
+ if (m_options.m_include_defaults)
dump_mask |= OptionValue::eDumpOptionDefaultValue;
if (!args.empty()) {
diff --git a/lldb/source/Commands/Options.td b/lldb/source/Commands/Options.td
index 596f959b76d4a..fd72342c18413 100644
--- a/lldb/source/Commands/Options.td
+++ b/lldb/source/Commands/Options.td
@@ -57,8 +57,8 @@ let Command = "settings clear" in {
}
let Command = "settings show" in {
- def setshow_verbose : Option<"verbose", "v">,
- Desc<"Enable verbose output.">;
+ def setshow_include_defaults : Option<"include-defaults", "d">,
+ Desc<"Include default values if defined.">;
}
let Command = "breakpoint list" in {
>From b831cbfea8f54e7cda4c70d8e67a1299764cd41b Mon Sep 17 00:00:00 2001
From: Dave Lee <davelee.com at gmail.com>
Date: Wed, 13 Aug 2025 10:05:47 -0700
Subject: [PATCH 06/10] make DefaultValueFormat a class
---
lldb/include/lldb/Interpreter/OptionValue.h | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/lldb/include/lldb/Interpreter/OptionValue.h b/lldb/include/lldb/Interpreter/OptionValue.h
index cbf117f2f8326..9c992821251cb 100644
--- a/lldb/include/lldb/Interpreter/OptionValue.h
+++ b/lldb/include/lldb/Interpreter/OptionValue.h
@@ -340,11 +340,17 @@ class OptionValue {
// DeepCopy to it. Inherit from Cloneable to avoid doing this manually.
virtual lldb::OptionValueSP Clone() const = 0;
- struct DefaultValueFormat {
+ class DefaultValueFormat {
+ public:
DefaultValueFormat(Stream &stream) : stream(stream) {
stream.PutCString(" (default: ");
}
~DefaultValueFormat() { stream.PutChar(')'); }
+
+ DefaultValueFormat(const DefaultValueFormat &) = delete;
+ DefaultValueFormat &operator=(const DefaultValueFormat &) = delete;
+
+ private:
Stream &stream;
};
>From 281b80a3e6142147e8d850422dd91232229918b5 Mon Sep 17 00:00:00 2001
From: Dave Lee <davelee.com at gmail.com>
Date: Wed, 13 Aug 2025 10:06:47 -0700
Subject: [PATCH 07/10] revert to original quoting style
---
lldb/source/Interpreter/OptionValueFileSpec.cpp | 4 ++--
lldb/source/Interpreter/OptionValueFormatEntity.cpp | 4 ++--
lldb/source/Interpreter/OptionValueString.cpp | 4 ++--
3 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/lldb/source/Interpreter/OptionValueFileSpec.cpp b/lldb/source/Interpreter/OptionValueFileSpec.cpp
index 89cc7226f69ca..8d4966dcda0bc 100644
--- a/lldb/source/Interpreter/OptionValueFileSpec.cpp
+++ b/lldb/source/Interpreter/OptionValueFileSpec.cpp
@@ -42,12 +42,12 @@ void OptionValueFileSpec::DumpValue(const ExecutionContext *exe_ctx,
strm.PutCString(" = ");
if (m_current_value) {
- strm.QuotedCString(m_current_value.GetPath().data());
+ strm << '"' << m_current_value.GetPath() << '"';
}
if (dump_mask & eDumpOptionDefaultValue &&
m_current_value != m_default_value && m_default_value) {
DefaultValueFormat label(strm);
- strm.QuotedCString(m_default_value.GetPath().data());
+ strm << '"' << m_default_value.GetPath() << '"';
}
}
}
diff --git a/lldb/source/Interpreter/OptionValueFormatEntity.cpp b/lldb/source/Interpreter/OptionValueFormatEntity.cpp
index bae1b5c77835b..b31dd4e475878 100644
--- a/lldb/source/Interpreter/OptionValueFormatEntity.cpp
+++ b/lldb/source/Interpreter/OptionValueFormatEntity.cpp
@@ -55,11 +55,11 @@ void OptionValueFormatEntity::DumpValue(const ExecutionContext *exe_ctx,
if (dump_mask & eDumpOptionValue) {
if (dump_mask & eDumpOptionType)
strm.PutCString(" = ");
- strm.QuotedCString(EscapeBackticks(m_current_format).data());
+ strm << '"' << EscapeBackticks(m_current_format) << '"';
if (dump_mask & eDumpOptionDefaultValue &&
m_current_format != m_default_format) {
DefaultValueFormat label(strm);
- strm.QuotedCString(EscapeBackticks(m_default_format).data());
+ strm << '"' << EscapeBackticks(m_default_format) << '"';
}
}
}
diff --git a/lldb/source/Interpreter/OptionValueString.cpp b/lldb/source/Interpreter/OptionValueString.cpp
index f6ddff3603906..022a27d069f48 100644
--- a/lldb/source/Interpreter/OptionValueString.cpp
+++ b/lldb/source/Interpreter/OptionValueString.cpp
@@ -20,7 +20,7 @@ static void DumpString(Stream &strm, const std::string &str, bool escape,
bool raw) {
if (escape) {
std::string escaped_str;
- Args::ExpandEscapedCharacters(str.data(), escaped_str);
+ Args::ExpandEscapedCharacters(str.c_str(), escaped_str);
DumpString(strm, escaped_str, false, raw);
return;
}
@@ -28,7 +28,7 @@ static void DumpString(Stream &strm, const std::string &str, bool escape,
if (raw)
strm.PutCString(str);
else
- strm.QuotedCString(str.data());
+ strm.QuotedCString(str.c_str());
}
void OptionValueString::DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
>From 20a7fcc475cd96648982973caa7e7287b156cc48 Mon Sep 17 00:00:00 2001
From: Dave Lee <davelee.com at gmail.com>
Date: Sat, 16 Aug 2025 12:40:52 -0700
Subject: [PATCH 08/10] simplify flag name to --defaults
---
lldb/source/Commands/Options.td | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lldb/source/Commands/Options.td b/lldb/source/Commands/Options.td
index fd72342c18413..17d72cdcad129 100644
--- a/lldb/source/Commands/Options.td
+++ b/lldb/source/Commands/Options.td
@@ -57,7 +57,7 @@ let Command = "settings clear" in {
}
let Command = "settings show" in {
- def setshow_include_defaults : Option<"include-defaults", "d">,
+ def setshow_defaults : Option<"defaults", "d">,
Desc<"Include default values if defined.">;
}
>From 1697a6f1a31317f6562549bf53056fba0829fa8a Mon Sep 17 00:00:00 2001
From: Dave Lee <davelee.com at gmail.com>
Date: Sat, 16 Aug 2025 12:43:12 -0700
Subject: [PATCH 09/10] add tests for scalar settings types
---
.../API/commands/settings/TestSettings.py | 68 +++++++++++++++++++
1 file changed, 68 insertions(+)
diff --git a/lldb/test/API/commands/settings/TestSettings.py b/lldb/test/API/commands/settings/TestSettings.py
index bc864942055c0..e022b974ffb53 100644
--- a/lldb/test/API/commands/settings/TestSettings.py
+++ b/lldb/test/API/commands/settings/TestSettings.py
@@ -972,6 +972,74 @@ def test_settings_set_exists(self):
# A known option should fail if its argument is invalid.
self.expect("settings set auto-confirm bogus", error=True)
+ def test_settings_show_defaults(self):
+ # boolean
+ self.expect(
+ "settings show --defaults auto-one-line-summaries",
+ matching=False,
+ substrs=["(default: true)"],
+ )
+ self.runCmd("settings set auto-one-line-summaries false")
+ self.expect(
+ "settings show --defaults auto-one-line-summaries",
+ substrs=["= false (default: true)"],
+ )
+ # unsigned
+ self.expect(
+ "settings show --defaults stop-line-count-before",
+ matching=False,
+ patterns=[r"\(default: \d+\)"],
+ )
+ self.runCmd("settings set stop-line-count-before 99")
+ self.expect(
+ "settings show --defaults stop-line-count-before",
+ patterns=[r"= 99 \(default: \d+\)"],
+ )
+ # string
+ self.expect(
+ "settings show --defaults prompt",
+ matching=False,
+ patterns=[r'\(default: ".+"\)'],
+ )
+ self.runCmd("settings set prompt '<LlDb> '")
+ self.expect(
+ "settings show --defaults prompt",
+ patterns=[r'= "<LlDb> " \(default: ".+"\)'],
+ )
+ # enum
+ self.expect(
+ "settings show --defaults stop-disassembly-display",
+ matching=False,
+ patterns=[r"\(default: .+\)"],
+ )
+ self.runCmd("settings set stop-disassembly-display no-source")
+ self.expect(
+ "settings show --defaults stop-disassembly-display",
+ patterns=[r"= no-source \(default: .+\)"],
+ )
+ # regex
+ self.expect(
+ "settings show --defaults target.process.thread.step-avoid-regexp",
+ matching=False,
+ patterns=[r"\(default: .+\)"],
+ )
+ self.runCmd("settings set target.process.thread.step-avoid-regexp dotstar")
+ self.expect(
+ "settings show --defaults target.process.thread.step-avoid-regexp",
+ patterns=[r"= dotstar \(default: .+\)"],
+ )
+ # format-string
+ self.expect(
+ "settings show --defaults disassembly-format",
+ matching=False,
+ patterns=[r'\(default: ".+"\)'],
+ )
+ self.runCmd("settings set disassembly-format dollar")
+ self.expect(
+ "settings show --defaults disassembly-format",
+ patterns=[r'= "dollar" \(default: ".+"\)'],
+ )
+
def get_setting_json(self, setting_path=None):
settings_data = self.dbg.GetSetting(setting_path)
stream = lldb.SBStream()
>From eb7116c248535894a8cb1eb90a0a44d5599aadfe Mon Sep 17 00:00:00 2001
From: Dave Lee <davelee.com at gmail.com>
Date: Sat, 16 Aug 2025 13:49:58 -0700
Subject: [PATCH 10/10] now add support for collection settings
---
lldb/source/Interpreter/OptionValueArray.cpp | 12 ++++-
.../Interpreter/OptionValueDictionary.cpp | 8 +++-
.../Interpreter/OptionValueFileSpecList.cpp | 13 ++++--
.../Interpreter/OptionValuePathMappings.cpp | 12 ++++-
.../API/commands/settings/TestSettings.py | 44 +++++++++++++++++++
5 files changed, 81 insertions(+), 8 deletions(-)
diff --git a/lldb/source/Interpreter/OptionValueArray.cpp b/lldb/source/Interpreter/OptionValueArray.cpp
index f6c14dee525e9..5600333c111a7 100644
--- a/lldb/source/Interpreter/OptionValueArray.cpp
+++ b/lldb/source/Interpreter/OptionValueArray.cpp
@@ -8,6 +8,7 @@
#include "lldb/Interpreter/OptionValueArray.h"
+#include "lldb/Interpreter/OptionValue.h"
#include "lldb/Utility/Args.h"
#include "lldb/Utility/Stream.h"
@@ -27,8 +28,15 @@ void OptionValueArray::DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
if (dump_mask & eDumpOptionValue) {
const bool one_line = dump_mask & eDumpOptionCommand;
const uint32_t size = m_values.size();
- if (dump_mask & eDumpOptionType)
- strm.Printf(" =%s", (m_values.size() > 0 && !one_line) ? "\n" : "");
+ if (dump_mask & (eDumpOptionType | eDumpOptionDefaultValue)) {
+ strm.PutCString(" =");
+ if (dump_mask & eDumpOptionDefaultValue && !m_values.empty()) {
+ DefaultValueFormat label(strm);
+ strm.PutCString("empty");
+ }
+ if (!m_values.empty() && !one_line)
+ strm.PutCString("\n");
+ }
if (!one_line)
strm.IndentMore();
for (uint32_t i = 0; i < size; ++i) {
diff --git a/lldb/source/Interpreter/OptionValueDictionary.cpp b/lldb/source/Interpreter/OptionValueDictionary.cpp
index 19e21dd6f4c9a..0efc76bb7cd94 100644
--- a/lldb/source/Interpreter/OptionValueDictionary.cpp
+++ b/lldb/source/Interpreter/OptionValueDictionary.cpp
@@ -9,6 +9,7 @@
#include "lldb/Interpreter/OptionValueDictionary.h"
#include "lldb/DataFormatters/FormatManager.h"
+#include "lldb/Interpreter/OptionValue.h"
#include "lldb/Interpreter/OptionValueEnumeration.h"
#include "lldb/Interpreter/OptionValueString.h"
#include "lldb/Utility/Args.h"
@@ -30,8 +31,13 @@ void OptionValueDictionary::DumpValue(const ExecutionContext *exe_ctx,
}
if (dump_mask & eDumpOptionValue) {
const bool one_line = dump_mask & eDumpOptionCommand;
- if (dump_mask & eDumpOptionType)
+ if (dump_mask & (eDumpOptionType | eDumpOptionDefaultValue)) {
strm.PutCString(" =");
+ if (dump_mask & eDumpOptionDefaultValue && !m_values.empty()) {
+ DefaultValueFormat label(strm);
+ strm.PutCString("empty");
+ }
+ }
if (!one_line)
strm.IndentMore();
diff --git a/lldb/source/Interpreter/OptionValueFileSpecList.cpp b/lldb/source/Interpreter/OptionValueFileSpecList.cpp
index f252dc4603cc1..f331c5d13f461 100644
--- a/lldb/source/Interpreter/OptionValueFileSpecList.cpp
+++ b/lldb/source/Interpreter/OptionValueFileSpecList.cpp
@@ -8,6 +8,7 @@
#include "lldb/Interpreter/OptionValueFileSpecList.h"
+#include "lldb/Interpreter/OptionValue.h"
#include "lldb/Utility/Args.h"
#include "lldb/Utility/Stream.h"
@@ -22,9 +23,15 @@ void OptionValueFileSpecList::DumpValue(const ExecutionContext *exe_ctx,
if (dump_mask & eDumpOptionValue) {
const bool one_line = dump_mask & eDumpOptionCommand;
const uint32_t size = m_current_value.GetSize();
- if (dump_mask & eDumpOptionType)
- strm.Printf(" =%s",
- (m_current_value.GetSize() > 0 && !one_line) ? "\n" : "");
+ if (dump_mask & (eDumpOptionType | eDumpOptionDefaultValue)) {
+ strm.Printf(" =");
+ if (dump_mask & eDumpOptionDefaultValue && !m_current_value.IsEmpty()) {
+ DefaultValueFormat label(strm);
+ strm.PutCString("empty");
+ }
+ if (!m_current_value.IsEmpty() && !one_line)
+ strm.PutCString("\n");
+ }
if (!one_line)
strm.IndentMore();
for (uint32_t i = 0; i < size; ++i) {
diff --git a/lldb/source/Interpreter/OptionValuePathMappings.cpp b/lldb/source/Interpreter/OptionValuePathMappings.cpp
index 95b8e64171455..abf4d429602e4 100644
--- a/lldb/source/Interpreter/OptionValuePathMappings.cpp
+++ b/lldb/source/Interpreter/OptionValuePathMappings.cpp
@@ -9,6 +9,7 @@
#include "lldb/Interpreter/OptionValuePathMappings.h"
#include "lldb/Host/FileSystem.h"
+#include "lldb/Interpreter/OptionValue.h"
#include "lldb/Utility/Args.h"
#include "lldb/Utility/FileSpec.h"
#include "lldb/Utility/Stream.h"
@@ -28,8 +29,15 @@ void OptionValuePathMappings::DumpValue(const ExecutionContext *exe_ctx,
if (dump_mask & eDumpOptionType)
strm.Printf("(%s)", GetTypeAsCString());
if (dump_mask & eDumpOptionValue) {
- if (dump_mask & eDumpOptionType)
- strm.Printf(" =%s", (m_path_mappings.GetSize() > 0) ? "\n" : "");
+ if (dump_mask & (eDumpOptionType | eDumpOptionDefaultValue)) {
+ strm.Printf(" =");
+ if (dump_mask & eDumpOptionDefaultValue && !m_path_mappings.IsEmpty()) {
+ DefaultValueFormat label(strm);
+ strm.PutCString("empty");
+ }
+ if (!m_path_mappings.IsEmpty())
+ strm.PutCString("\n");
+ }
m_path_mappings.Dump(&strm);
}
}
diff --git a/lldb/test/API/commands/settings/TestSettings.py b/lldb/test/API/commands/settings/TestSettings.py
index e022b974ffb53..a7a92442e543f 100644
--- a/lldb/test/API/commands/settings/TestSettings.py
+++ b/lldb/test/API/commands/settings/TestSettings.py
@@ -1039,6 +1039,50 @@ def test_settings_show_defaults(self):
"settings show --defaults disassembly-format",
patterns=[r'= "dollar" \(default: ".+"\)'],
)
+ # arrays
+ self.expect(
+ "settings show --defaults target.unset-env-vars",
+ matching=False,
+ substrs=["(default: empty)"],
+ )
+ self.runCmd("settings set target.unset-env-vars PATH")
+ self.expect(
+ "settings show --defaults target.unset-env-vars",
+ substrs=["(default: empty)", '[0]: "PATH"'],
+ )
+ # dictionaries
+ self.expect(
+ "settings show --defaults target.env-vars",
+ matching=False,
+ substrs=["(default: empty)"],
+ )
+ self.runCmd("settings set target.env-vars THING=value")
+ self.expect(
+ "settings show --defaults target.env-vars",
+ substrs=["(default: empty)", "THING=value"],
+ )
+ # file list
+ self.expect(
+ "settings show --defaults target.exec-search-paths",
+ matching=False,
+ substrs=["(default: empty)"],
+ )
+ self.runCmd("settings set target.exec-search-paths /tmp")
+ self.expect(
+ "settings show --defaults target.exec-search-paths",
+ substrs=["(default: empty)", "[0]: /tmp"],
+ )
+ # path map
+ self.expect(
+ "settings show --defaults target.source-map",
+ matching=False,
+ substrs=["(default: empty)"],
+ )
+ self.runCmd("settings set target.source-map /abc /tmp")
+ self.expect(
+ "settings show --defaults target.source-map",
+ substrs=["(default: empty)", '[0] "/abc" -> "/tmp"'],
+ )
def get_setting_json(self, setting_path=None):
settings_data = self.dbg.GetSetting(setting_path)
More information about the lldb-commits
mailing list