diff --git a/lldb/include/lldb/Interpreter/OptionValue.h b/lldb/include/lldb/Interpreter/OptionValue.h index 8735106c3d142..730ec65dd054b 100644 --- a/lldb/include/lldb/Interpreter/OptionValue.h +++ b/lldb/include/lldb/Interpreter/OptionValue.h @@ -10,6 +10,7 @@ #define LLDB_INTERPRETER_OPTIONVALUE_H #include "lldb/Core/FormatEntity.h" +#include "lldb/Utility/ArchSpec.h" #include "lldb/Utility/Cloneable.h" #include "lldb/Utility/CompletionRequest.h" #include "lldb/Utility/ConstString.h" @@ -307,6 +308,10 @@ class OptionValue { bool SetUUIDValue(const UUID &uuid); + std::optional GetArchSpecValue() const; + + bool SetArchSpecValue(ArchSpec arch_spec); + bool OptionWasSet() const { return m_value_was_set; } void SetOptionWasSet() { m_value_was_set = true; } @@ -346,6 +351,8 @@ class OptionValue { return GetLanguageValue(); if constexpr (std::is_same_v) return GetStringValue(); + if constexpr (std::is_same_v) + return GetArchSpecValue(); if constexpr (std::is_enum_v) if (std::optional value = GetEnumerationValue()) return static_cast(*value); @@ -372,6 +379,8 @@ class OptionValue { bool SetValueAs(FileSpec v) { return SetFileSpecValue(v); } + bool SetValueAs(ArchSpec v) { return SetArchSpecValue(v); } + template , bool> = true> bool SetValueAs(T t) { return SetEnumerationValue(t); diff --git a/lldb/include/lldb/Interpreter/OptionValueProperties.h b/lldb/include/lldb/Interpreter/OptionValueProperties.h index f4e119cdd83d3..5a6bf2a81e4b8 100644 --- a/lldb/include/lldb/Interpreter/OptionValueProperties.h +++ b/lldb/include/lldb/Interpreter/OptionValueProperties.h @@ -106,9 +106,6 @@ class OptionValueProperties Status SetSubValue(const ExecutionContext *exe_ctx, VarSetOperationType op, llvm::StringRef path, llvm::StringRef value) override; - OptionValueArch *GetPropertyAtIndexAsOptionValueArch( - uint32_t idx, const ExecutionContext *exe_ctx = nullptr) const; - bool GetPropertyAtIndexAsArgs(uint32_t idx, Args &args, const ExecutionContext *exe_ctx = nullptr) const; diff --git a/lldb/source/Interpreter/OptionValue.cpp b/lldb/source/Interpreter/OptionValue.cpp index b9da1f122ebee..d29f86db82353 100644 --- a/lldb/source/Interpreter/OptionValue.cpp +++ b/lldb/source/Interpreter/OptionValue.cpp @@ -431,6 +431,20 @@ bool OptionValue::SetUUIDValue(const UUID &uuid) { return false; } +std::optional OptionValue::GetArchSpecValue() const { + if (const OptionValueArch *option_value = GetAsArch()) + return option_value->GetCurrentValue(); + return {}; +} + +bool OptionValue::SetArchSpecValue(ArchSpec arch_spec) { + if (OptionValueArch *option_value = GetAsArch()) { + option_value->SetCurrentValue(arch_spec, false); + return true; + } + return false; +} + const char *OptionValue::GetBuiltinTypeAsCString(Type t) { switch (t) { case eTypeInvalid: diff --git a/lldb/source/Interpreter/OptionValueProperties.cpp b/lldb/source/Interpreter/OptionValueProperties.cpp index 29dfe92860aeb..a061c41982fc9 100644 --- a/lldb/source/Interpreter/OptionValueProperties.cpp +++ b/lldb/source/Interpreter/OptionValueProperties.cpp @@ -193,14 +193,6 @@ OptionValueProperties::GetPropertyAtIndexAsOptionValueFileSpecList( return nullptr; } -OptionValueArch *OptionValueProperties::GetPropertyAtIndexAsOptionValueArch( - uint32_t idx, const ExecutionContext *exe_ctx) const { - const Property *property = GetPropertyAtIndex(idx, exe_ctx); - if (property) - return property->GetValue()->GetAsArch(); - return nullptr; -} - bool OptionValueProperties::GetPropertyAtIndexAsArgs( uint32_t idx, Args &args, const ExecutionContext *exe_ctx) const { const Property *property = GetPropertyAtIndex(idx, exe_ctx); diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp index 7df4af8dd0f26..b5a6e4ad22e4d 100644 --- a/lldb/source/Target/Target.cpp +++ b/lldb/source/Target/Target.cpp @@ -4153,18 +4153,13 @@ void TargetProperties::SetInjectLocalVariables(ExecutionContext *exe_ctx, } ArchSpec TargetProperties::GetDefaultArchitecture() const { - OptionValueArch *value = m_collection_sp->GetPropertyAtIndexAsOptionValueArch( - ePropertyDefaultArch); - if (value) - return value->GetCurrentValue(); - return ArchSpec(); + const uint32_t idx = ePropertyDefaultArch; + return GetPropertyAtIndexAs(idx, {}); } void TargetProperties::SetDefaultArchitecture(const ArchSpec &arch) { - OptionValueArch *value = m_collection_sp->GetPropertyAtIndexAsOptionValueArch( - ePropertyDefaultArch); - if (value) - return value->SetCurrentValue(arch, true); + const uint32_t idx = ePropertyDefaultArch; + SetPropertyAtIndex(idx, arch); } bool TargetProperties::GetMoveToNearestCode() const {