diff --git a/lldb/include/lldb/Interpreter/OptionValue.h b/lldb/include/lldb/Interpreter/OptionValue.h --- a/lldb/include/lldb/Interpreter/OptionValue.h +++ b/lldb/include/lldb/Interpreter/OptionValue.h @@ -23,6 +23,7 @@ #include "lldb/lldb-private-enumerations.h" #include "lldb/lldb-private-interfaces.h" #include "llvm/Support/JSON.h" +#include namespace lldb_private { @@ -70,6 +71,10 @@ virtual ~OptionValue() = default; + OptionValue(const OptionValue &other); + + OptionValue& operator=(const OptionValue &other); + // Subclasses should override these functions virtual Type GetType() const = 0; @@ -382,6 +387,8 @@ const FormatEntity::Entry *GetFormatEntity() const; const RegularExpression *GetRegexValue() const; + + mutable std::mutex m_mutex; }; } // namespace lldb_private diff --git a/lldb/source/Interpreter/OptionValue.cpp b/lldb/source/Interpreter/OptionValue.cpp --- a/lldb/source/Interpreter/OptionValue.cpp +++ b/lldb/source/Interpreter/OptionValue.cpp @@ -15,6 +15,25 @@ using namespace lldb; using namespace lldb_private; +OptionValue::OptionValue(const OptionValue &other) { + std::lock_guard lock(other.m_mutex); + + m_parent_wp = other.m_parent_wp; + m_callback = other.m_callback; + m_value_was_set = other.m_value_was_set; + +} + +OptionValue& OptionValue::operator=(const OptionValue &other) { + std::scoped_lock lock(m_mutex, other.m_mutex); + + m_parent_wp = other.m_parent_wp; + m_callback = other.m_callback; + m_value_was_set = other.m_value_was_set; + + return *this; +} + Status OptionValue::SetSubValue(const ExecutionContext *exe_ctx, VarSetOperationType op, llvm::StringRef name, llvm::StringRef value) { @@ -252,12 +271,14 @@ } std::optional OptionValue::GetBooleanValue() const { + std::lock_guard lock(m_mutex); if (const OptionValueBoolean *option_value = GetAsBoolean()) return option_value->GetCurrentValue(); return {}; } bool OptionValue::SetBooleanValue(bool new_value) { + std::lock_guard lock(m_mutex); if (OptionValueBoolean *option_value = GetAsBoolean()) { option_value->SetCurrentValue(new_value); return true; @@ -266,12 +287,14 @@ } std::optional OptionValue::GetCharValue() const { + std::lock_guard lock(m_mutex); if (const OptionValueChar *option_value = GetAsChar()) return option_value->GetCurrentValue(); return {}; } bool OptionValue::SetCharValue(char new_value) { + std::lock_guard lock(m_mutex); if (OptionValueChar *option_value = GetAsChar()) { option_value->SetCurrentValue(new_value); return true; @@ -280,12 +303,14 @@ } std::optional OptionValue::GetEnumerationValue() const { + std::lock_guard lock(m_mutex); if (const OptionValueEnumeration *option_value = GetAsEnumeration()) return option_value->GetCurrentValue(); return {}; } bool OptionValue::SetEnumerationValue(int64_t value) { + std::lock_guard lock(m_mutex); if (OptionValueEnumeration *option_value = GetAsEnumeration()) { option_value->SetCurrentValue(value); return true; @@ -294,12 +319,14 @@ } std::optional OptionValue::GetFileSpecValue() const { + std::lock_guard lock(m_mutex); if (const OptionValueFileSpec *option_value = GetAsFileSpec()) return option_value->GetCurrentValue(); return {}; } bool OptionValue::SetFileSpecValue(FileSpec file_spec) { + std::lock_guard lock(m_mutex); if (OptionValueFileSpec *option_value = GetAsFileSpec()) { option_value->SetCurrentValue(file_spec, false); return true; @@ -308,6 +335,7 @@ } bool OptionValue::AppendFileSpecValue(FileSpec file_spec) { + std::lock_guard lock(m_mutex); if (OptionValueFileSpecList *option_value = GetAsFileSpecList()) { option_value->AppendCurrentValue(file_spec); return true; @@ -316,18 +344,21 @@ } std::optional OptionValue::GetFileSpecListValue() const { + std::lock_guard lock(m_mutex); if (const OptionValueFileSpecList *option_value = GetAsFileSpecList()) return option_value->GetCurrentValue(); return {}; } std::optional OptionValue::GetFormatValue() const { + std::lock_guard lock(m_mutex); if (const OptionValueFormat *option_value = GetAsFormat()) return option_value->GetCurrentValue(); return {}; } bool OptionValue::SetFormatValue(lldb::Format new_value) { + std::lock_guard lock(m_mutex); if (OptionValueFormat *option_value = GetAsFormat()) { option_value->SetCurrentValue(new_value); return true; @@ -336,12 +367,14 @@ } std::optional OptionValue::GetLanguageValue() const { + std::lock_guard lock(m_mutex); if (const OptionValueLanguage *option_value = GetAsLanguage()) return option_value->GetCurrentValue(); return {}; } bool OptionValue::SetLanguageValue(lldb::LanguageType new_language) { + std::lock_guard lock(m_mutex); if (OptionValueLanguage *option_value = GetAsLanguage()) { option_value->SetCurrentValue(new_language); return true; @@ -350,24 +383,28 @@ } const FormatEntity::Entry *OptionValue::GetFormatEntity() const { + std::lock_guard lock(m_mutex); if (const OptionValueFormatEntity *option_value = GetAsFormatEntity()) return &option_value->GetCurrentValue(); return nullptr; } const RegularExpression *OptionValue::GetRegexValue() const { + std::lock_guard lock(m_mutex); if (const OptionValueRegex *option_value = GetAsRegex()) return option_value->GetCurrentValue(); return nullptr; } std::optional OptionValue::GetSInt64Value() const { + std::lock_guard lock(m_mutex); if (const OptionValueSInt64 *option_value = GetAsSInt64()) return option_value->GetCurrentValue(); return {}; } bool OptionValue::SetSInt64Value(int64_t new_value) { + std::lock_guard lock(m_mutex); if (OptionValueSInt64 *option_value = GetAsSInt64()) { option_value->SetCurrentValue(new_value); return true; @@ -376,12 +413,14 @@ } std::optional OptionValue::GetStringValue() const { + std::lock_guard lock(m_mutex); if (const OptionValueString *option_value = GetAsString()) return option_value->GetCurrentValueAsRef(); return {}; } bool OptionValue::SetStringValue(llvm::StringRef new_value) { + std::lock_guard lock(m_mutex); if (OptionValueString *option_value = GetAsString()) { option_value->SetCurrentValue(new_value); return true; @@ -390,12 +429,14 @@ } std::optional OptionValue::GetUInt64Value() const { + std::lock_guard lock(m_mutex); if (const OptionValueUInt64 *option_value = GetAsUInt64()) return option_value->GetCurrentValue(); return {}; } bool OptionValue::SetUInt64Value(uint64_t new_value) { + std::lock_guard lock(m_mutex); if (OptionValueUInt64 *option_value = GetAsUInt64()) { option_value->SetCurrentValue(new_value); return true; @@ -404,12 +445,14 @@ } std::optional OptionValue::GetUUIDValue() const { + std::lock_guard lock(m_mutex); if (const OptionValueUUID *option_value = GetAsUUID()) return option_value->GetCurrentValue(); return {}; } bool OptionValue::SetUUIDValue(const UUID &uuid) { + std::lock_guard lock(m_mutex); if (OptionValueUUID *option_value = GetAsUUID()) { option_value->SetCurrentValue(uuid); return true; @@ -418,12 +461,14 @@ } std::optional OptionValue::GetArchSpecValue() const { + std::lock_guard lock(m_mutex); if (const OptionValueArch *option_value = GetAsArch()) return option_value->GetCurrentValue(); return {}; } bool OptionValue::SetArchSpecValue(ArchSpec arch_spec) { + std::lock_guard lock(m_mutex); if (OptionValueArch *option_value = GetAsArch()) { option_value->SetCurrentValue(arch_spec, false); return true;