Skip to content
Open
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
24 changes: 24 additions & 0 deletions lldb/include/lldb/Interpreter/OptionValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -61,6 +62,8 @@ class OptionValue {
eDumpOptionDescription = (1u << 3),
eDumpOptionRaw = (1u << 4),
eDumpOptionCommand = (1u << 5),
eDumpOptionDefaultValue = (1u << 6),
eDumpOptionOnlyChanged = (1u << 7),
eDumpGroupValue = (eDumpOptionName | eDumpOptionType | eDumpOptionValue),
eDumpGroupHelp =
(eDumpOptionName | eDumpOptionType | eDumpOptionDescription),
Expand Down Expand Up @@ -247,6 +250,13 @@ class OptionValue {

void SetOptionWasSet() { m_value_was_set = true; }

/// Return true if the current value equals the default value.
///
/// Subclasses that store a default value should override this to compare
/// against it. The base implementation falls back to `OptionWasSet()`, which
/// is a reasonable approximation for types without an explicit default.
virtual bool IsDefault() const { return !OptionWasSet(); }

void SetParent(const lldb::OptionValueSP &parent_sp) {
m_parent_wp = parent_sp;
}
Expand Down Expand Up @@ -338,6 +348,20 @@ class OptionValue {
// DeepCopy to it. Inherit from Cloneable to avoid doing this manually.
virtual lldb::OptionValueSP Clone() const = 0;

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;
};

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
Expand Down
2 changes: 2 additions & 0 deletions lldb/include/lldb/Interpreter/OptionValueArch.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class OptionValueArch : public Cloneable<OptionValueArch, OptionValue> {
m_value_was_set = false;
}

bool IsDefault() const override { return m_current_value == m_default_value; }

void AutoComplete(CommandInterpreter &interpreter,
lldb_private::CompletionRequest &request) override;

Expand Down
2 changes: 2 additions & 0 deletions lldb/include/lldb/Interpreter/OptionValueBoolean.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class OptionValueBoolean : public Cloneable<OptionValueBoolean, OptionValue> {
void AutoComplete(CommandInterpreter &interpreter,
CompletionRequest &request) override;

bool IsDefault() const override { return m_current_value == m_default_value; }

// Subclass specific functions

/// Convert to bool operator.
Expand Down
2 changes: 2 additions & 0 deletions lldb/include/lldb/Interpreter/OptionValueChar.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class OptionValueChar : public Cloneable<OptionValueChar, OptionValue> {
m_value_was_set = false;
}

bool IsDefault() const override { return m_current_value == m_default_value; }

// Subclass specific functions

const char &operator=(char c) {
Expand Down
3 changes: 3 additions & 0 deletions lldb/include/lldb/Interpreter/OptionValueEnumeration.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ class OptionValueEnumeration
m_value_was_set = false;
}

bool IsDefault() const override { return m_current_value == m_default_value; }

void AutoComplete(CommandInterpreter &interpreter,
CompletionRequest &request) override;

Expand All @@ -72,6 +74,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;
Expand Down
2 changes: 2 additions & 0 deletions lldb/include/lldb/Interpreter/OptionValueFileSpec.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class OptionValueFileSpec : public Cloneable<OptionValueFileSpec, OptionValue> {
void AutoComplete(CommandInterpreter &interpreter,
CompletionRequest &request) override;

bool IsDefault() const override { return m_current_value == m_default_value; }

// Subclass specific functions

FileSpec &GetCurrentValue() { return m_current_value; }
Expand Down
2 changes: 2 additions & 0 deletions lldb/include/lldb/Interpreter/OptionValueFormat.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class OptionValueFormat
m_value_was_set = false;
}

bool IsDefault() const override { return m_current_value == m_default_value; }

// Subclass specific functions

lldb::Format GetCurrentValue() const { return m_current_value; }
Expand Down
4 changes: 4 additions & 0 deletions lldb/include/lldb/Interpreter/OptionValueFormatEntity.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ class OptionValueFormatEntity

void Clear() override;

bool IsDefault() const override {
return m_current_format == m_default_format;
}

void AutoComplete(CommandInterpreter &interpreter,
CompletionRequest &request) override;

Expand Down
2 changes: 2 additions & 0 deletions lldb/include/lldb/Interpreter/OptionValueLanguage.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class OptionValueLanguage : public Cloneable<OptionValueLanguage, OptionValue> {
m_value_was_set = false;
}

bool IsDefault() const override { return m_current_value == m_default_value; }

// Subclass specific functions

lldb::LanguageType GetCurrentValue() const { return m_current_value; }
Expand Down
2 changes: 2 additions & 0 deletions lldb/include/lldb/Interpreter/OptionValueProperties.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class OptionValueProperties
void DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
uint32_t dump_mask) override;

bool IsDefault() const override;

llvm::json::Value ToJSON(const ExecutionContext *exe_ctx) const override;

llvm::StringRef GetName() const override { return m_name; }
Expand Down
4 changes: 4 additions & 0 deletions lldb/include/lldb/Interpreter/OptionValueRegex.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ class OptionValueRegex : public Cloneable<OptionValueRegex, OptionValue> {
m_value_was_set = false;
}

bool IsDefault() const override {
return m_regex.GetText() == m_default_regex_str;
}

// Subclass specific functions
const RegularExpression *GetCurrentValue() const {
return (m_regex.IsValid() ? &m_regex : nullptr);
Expand Down
2 changes: 2 additions & 0 deletions lldb/include/lldb/Interpreter/OptionValueSInt64.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ class OptionValueSInt64 : public Cloneable<OptionValueSInt64, OptionValue> {
m_value_was_set = false;
}

bool IsDefault() const override { return m_current_value == m_default_value; }

// Subclass specific functions

const int64_t &operator=(int64_t value) {
Expand Down
2 changes: 2 additions & 0 deletions lldb/include/lldb/Interpreter/OptionValueString.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ class OptionValueString : public Cloneable<OptionValueString, OptionValue> {
m_value_was_set = false;
}

bool IsDefault() const override { return m_current_value == m_default_value; }

// Subclass specific functions

Flags &GetOptions() { return m_options; }
Expand Down
2 changes: 2 additions & 0 deletions lldb/include/lldb/Interpreter/OptionValueUInt64.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class OptionValueUInt64 : public Cloneable<OptionValueUInt64, OptionValue> {
m_value_was_set = false;
}

bool IsDefault() const override { return m_current_value == m_default_value; }

// Subclass specific functions

const uint64_t &operator=(uint64_t value) {
Expand Down
1 change: 1 addition & 0 deletions lldb/include/lldb/Utility/ArchSpec.h
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,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);

Expand Down
63 changes: 58 additions & 5 deletions lldb/source/Commands/CommandObjectSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,28 +237,78 @@ 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 'd':
m_include_defaults = true;
break;
case 'c':
m_only_changed = true;
break;
default:
llvm_unreachable("Unimplemented option");
}
return {};
}

void OptionParsingStarting(ExecutionContext *execution_context) override {
m_include_defaults = false;
m_only_changed = false;
}

llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
return g_settings_show_options;
}

bool m_include_defaults = false;
bool m_only_changed = 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 (m_options.m_only_changed) {
dump_mask |= OptionValue::eDumpOptionOnlyChanged;
dump_mask |= OptionValue::eDumpOptionDefaultValue;
}

if (!args.empty()) {
for (const auto &arg : args) {
if (m_options.m_only_changed) {
Status lookup_error;
lldb::OptionValueSP value_sp = GetDebugger().GetPropertyValue(
&m_exe_ctx, arg.ref(), lookup_error);
if (value_sp && value_sp->IsDefault())
continue;
}
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 {
Expand All @@ -267,9 +317,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
Expand Down
8 changes: 8 additions & 0 deletions lldb/source/Commands/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ let Command = "settings clear" in {
Desc<"Clear all settings.">;
}

let Command = "settings show" in {
def setshow_defaults : Option<"defaults", "d">,
Desc<"Include default values if defined.">;
def setshow_changed : Option<"changed", "c">,
Desc<"Only show settings whose value differs from the "
"default.">;
}

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.
Expand Down
7 changes: 7 additions & 0 deletions lldb/source/Interpreter/OptionValueArch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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());
}
}
}

Expand Down
12 changes: 10 additions & 2 deletions lldb/source/Interpreter/OptionValueArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "lldb/Interpreter/OptionValueArray.h"

#include "lldb/Interpreter/OptionValue.h"
#include "lldb/Utility/Args.h"
#include "lldb/Utility/Stream.h"

Expand All @@ -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) {
Expand Down
6 changes: 6 additions & 0 deletions lldb/source/Interpreter/OptionValueBoolean.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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");
}
}
}

Expand Down
Loading