15ffd83dbSDimitry Andric //===-- OptionValue.cpp ---------------------------------------------------===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric
90b57cec5SDimitry Andric #include "lldb/Interpreter/OptionValue.h"
100b57cec5SDimitry Andric #include "lldb/Interpreter/OptionValues.h"
110b57cec5SDimitry Andric #include "lldb/Utility/StringList.h"
120b57cec5SDimitry Andric
135ffd83dbSDimitry Andric #include <memory>
145ffd83dbSDimitry Andric
150b57cec5SDimitry Andric using namespace lldb;
160b57cec5SDimitry Andric using namespace lldb_private;
170b57cec5SDimitry Andric
OptionValue(const OptionValue & other)18*5f757f3fSDimitry Andric OptionValue::OptionValue(const OptionValue &other) {
19*5f757f3fSDimitry Andric std::lock_guard<std::mutex> lock(other.m_mutex);
20*5f757f3fSDimitry Andric
21*5f757f3fSDimitry Andric m_parent_wp = other.m_parent_wp;
22*5f757f3fSDimitry Andric m_callback = other.m_callback;
23*5f757f3fSDimitry Andric m_value_was_set = other.m_value_was_set;
24*5f757f3fSDimitry Andric
25*5f757f3fSDimitry Andric }
26*5f757f3fSDimitry Andric
operator =(const OptionValue & other)27*5f757f3fSDimitry Andric OptionValue& OptionValue::operator=(const OptionValue &other) {
28*5f757f3fSDimitry Andric std::scoped_lock<std::mutex, std::mutex> lock(m_mutex, other.m_mutex);
29*5f757f3fSDimitry Andric
30*5f757f3fSDimitry Andric m_parent_wp = other.m_parent_wp;
31*5f757f3fSDimitry Andric m_callback = other.m_callback;
32*5f757f3fSDimitry Andric m_value_was_set = other.m_value_was_set;
33*5f757f3fSDimitry Andric
34*5f757f3fSDimitry Andric return *this;
35*5f757f3fSDimitry Andric }
36*5f757f3fSDimitry Andric
SetSubValue(const ExecutionContext * exe_ctx,VarSetOperationType op,llvm::StringRef name,llvm::StringRef value)370b57cec5SDimitry Andric Status OptionValue::SetSubValue(const ExecutionContext *exe_ctx,
380b57cec5SDimitry Andric VarSetOperationType op, llvm::StringRef name,
390b57cec5SDimitry Andric llvm::StringRef value) {
400b57cec5SDimitry Andric Status error;
41e8d8bef9SDimitry Andric error.SetErrorString("SetSubValue is not supported");
420b57cec5SDimitry Andric return error;
430b57cec5SDimitry Andric }
440b57cec5SDimitry Andric
GetAsBoolean()450b57cec5SDimitry Andric OptionValueBoolean *OptionValue::GetAsBoolean() {
460b57cec5SDimitry Andric if (GetType() == OptionValue::eTypeBoolean)
470b57cec5SDimitry Andric return static_cast<OptionValueBoolean *>(this);
480b57cec5SDimitry Andric return nullptr;
490b57cec5SDimitry Andric }
500b57cec5SDimitry Andric
GetAsBoolean() const510b57cec5SDimitry Andric const OptionValueBoolean *OptionValue::GetAsBoolean() const {
520b57cec5SDimitry Andric if (GetType() == OptionValue::eTypeBoolean)
530b57cec5SDimitry Andric return static_cast<const OptionValueBoolean *>(this);
540b57cec5SDimitry Andric return nullptr;
550b57cec5SDimitry Andric }
560b57cec5SDimitry Andric
GetAsChar() const570b57cec5SDimitry Andric const OptionValueChar *OptionValue::GetAsChar() const {
580b57cec5SDimitry Andric if (GetType() == OptionValue::eTypeChar)
590b57cec5SDimitry Andric return static_cast<const OptionValueChar *>(this);
600b57cec5SDimitry Andric return nullptr;
610b57cec5SDimitry Andric }
620b57cec5SDimitry Andric
GetAsChar()630b57cec5SDimitry Andric OptionValueChar *OptionValue::GetAsChar() {
640b57cec5SDimitry Andric if (GetType() == OptionValue::eTypeChar)
650b57cec5SDimitry Andric return static_cast<OptionValueChar *>(this);
660b57cec5SDimitry Andric return nullptr;
670b57cec5SDimitry Andric }
680b57cec5SDimitry Andric
GetAsFileSpec()690b57cec5SDimitry Andric OptionValueFileSpec *OptionValue::GetAsFileSpec() {
700b57cec5SDimitry Andric if (GetType() == OptionValue::eTypeFileSpec)
710b57cec5SDimitry Andric return static_cast<OptionValueFileSpec *>(this);
720b57cec5SDimitry Andric return nullptr;
730b57cec5SDimitry Andric }
740b57cec5SDimitry Andric
GetAsFileSpec() const750b57cec5SDimitry Andric const OptionValueFileSpec *OptionValue::GetAsFileSpec() const {
760b57cec5SDimitry Andric if (GetType() == OptionValue::eTypeFileSpec)
770b57cec5SDimitry Andric return static_cast<const OptionValueFileSpec *>(this);
780b57cec5SDimitry Andric return nullptr;
790b57cec5SDimitry Andric }
800b57cec5SDimitry Andric
GetAsFileSpecList()810b57cec5SDimitry Andric OptionValueFileSpecList *OptionValue::GetAsFileSpecList() {
820b57cec5SDimitry Andric if (GetType() == OptionValue::eTypeFileSpecList)
830b57cec5SDimitry Andric return static_cast<OptionValueFileSpecList *>(this);
840b57cec5SDimitry Andric return nullptr;
850b57cec5SDimitry Andric }
860b57cec5SDimitry Andric
GetAsFileSpecList() const870b57cec5SDimitry Andric const OptionValueFileSpecList *OptionValue::GetAsFileSpecList() const {
880b57cec5SDimitry Andric if (GetType() == OptionValue::eTypeFileSpecList)
890b57cec5SDimitry Andric return static_cast<const OptionValueFileSpecList *>(this);
900b57cec5SDimitry Andric return nullptr;
910b57cec5SDimitry Andric }
920b57cec5SDimitry Andric
GetAsArch()930b57cec5SDimitry Andric OptionValueArch *OptionValue::GetAsArch() {
940b57cec5SDimitry Andric if (GetType() == OptionValue::eTypeArch)
950b57cec5SDimitry Andric return static_cast<OptionValueArch *>(this);
960b57cec5SDimitry Andric return nullptr;
970b57cec5SDimitry Andric }
980b57cec5SDimitry Andric
GetAsArch() const990b57cec5SDimitry Andric const OptionValueArch *OptionValue::GetAsArch() const {
1000b57cec5SDimitry Andric if (GetType() == OptionValue::eTypeArch)
1010b57cec5SDimitry Andric return static_cast<const OptionValueArch *>(this);
1020b57cec5SDimitry Andric return nullptr;
1030b57cec5SDimitry Andric }
1040b57cec5SDimitry Andric
GetAsArray()1050b57cec5SDimitry Andric OptionValueArray *OptionValue::GetAsArray() {
1060b57cec5SDimitry Andric if (GetType() == OptionValue::eTypeArray)
1070b57cec5SDimitry Andric return static_cast<OptionValueArray *>(this);
1080b57cec5SDimitry Andric return nullptr;
1090b57cec5SDimitry Andric }
1100b57cec5SDimitry Andric
GetAsArray() const1110b57cec5SDimitry Andric const OptionValueArray *OptionValue::GetAsArray() const {
1120b57cec5SDimitry Andric if (GetType() == OptionValue::eTypeArray)
1130b57cec5SDimitry Andric return static_cast<const OptionValueArray *>(this);
1140b57cec5SDimitry Andric return nullptr;
1150b57cec5SDimitry Andric }
1160b57cec5SDimitry Andric
GetAsArgs()1170b57cec5SDimitry Andric OptionValueArgs *OptionValue::GetAsArgs() {
1180b57cec5SDimitry Andric if (GetType() == OptionValue::eTypeArgs)
1190b57cec5SDimitry Andric return static_cast<OptionValueArgs *>(this);
1200b57cec5SDimitry Andric return nullptr;
1210b57cec5SDimitry Andric }
1220b57cec5SDimitry Andric
GetAsArgs() const1230b57cec5SDimitry Andric const OptionValueArgs *OptionValue::GetAsArgs() const {
1240b57cec5SDimitry Andric if (GetType() == OptionValue::eTypeArgs)
1250b57cec5SDimitry Andric return static_cast<const OptionValueArgs *>(this);
1260b57cec5SDimitry Andric return nullptr;
1270b57cec5SDimitry Andric }
1280b57cec5SDimitry Andric
GetAsDictionary()1290b57cec5SDimitry Andric OptionValueDictionary *OptionValue::GetAsDictionary() {
1300b57cec5SDimitry Andric if (GetType() == OptionValue::eTypeDictionary)
1310b57cec5SDimitry Andric return static_cast<OptionValueDictionary *>(this);
1320b57cec5SDimitry Andric return nullptr;
1330b57cec5SDimitry Andric }
1340b57cec5SDimitry Andric
GetAsDictionary() const1350b57cec5SDimitry Andric const OptionValueDictionary *OptionValue::GetAsDictionary() const {
1360b57cec5SDimitry Andric if (GetType() == OptionValue::eTypeDictionary)
1370b57cec5SDimitry Andric return static_cast<const OptionValueDictionary *>(this);
1380b57cec5SDimitry Andric return nullptr;
1390b57cec5SDimitry Andric }
1400b57cec5SDimitry Andric
GetAsEnumeration()1410b57cec5SDimitry Andric OptionValueEnumeration *OptionValue::GetAsEnumeration() {
1420b57cec5SDimitry Andric if (GetType() == OptionValue::eTypeEnum)
1430b57cec5SDimitry Andric return static_cast<OptionValueEnumeration *>(this);
1440b57cec5SDimitry Andric return nullptr;
1450b57cec5SDimitry Andric }
1460b57cec5SDimitry Andric
GetAsEnumeration() const1470b57cec5SDimitry Andric const OptionValueEnumeration *OptionValue::GetAsEnumeration() const {
1480b57cec5SDimitry Andric if (GetType() == OptionValue::eTypeEnum)
1490b57cec5SDimitry Andric return static_cast<const OptionValueEnumeration *>(this);
1500b57cec5SDimitry Andric return nullptr;
1510b57cec5SDimitry Andric }
1520b57cec5SDimitry Andric
GetAsFormat()1530b57cec5SDimitry Andric OptionValueFormat *OptionValue::GetAsFormat() {
1540b57cec5SDimitry Andric if (GetType() == OptionValue::eTypeFormat)
1550b57cec5SDimitry Andric return static_cast<OptionValueFormat *>(this);
1560b57cec5SDimitry Andric return nullptr;
1570b57cec5SDimitry Andric }
1580b57cec5SDimitry Andric
GetAsFormat() const1590b57cec5SDimitry Andric const OptionValueFormat *OptionValue::GetAsFormat() const {
1600b57cec5SDimitry Andric if (GetType() == OptionValue::eTypeFormat)
1610b57cec5SDimitry Andric return static_cast<const OptionValueFormat *>(this);
1620b57cec5SDimitry Andric return nullptr;
1630b57cec5SDimitry Andric }
1640b57cec5SDimitry Andric
GetAsLanguage()1650b57cec5SDimitry Andric OptionValueLanguage *OptionValue::GetAsLanguage() {
1660b57cec5SDimitry Andric if (GetType() == OptionValue::eTypeLanguage)
1670b57cec5SDimitry Andric return static_cast<OptionValueLanguage *>(this);
1680b57cec5SDimitry Andric return nullptr;
1690b57cec5SDimitry Andric }
1700b57cec5SDimitry Andric
GetAsLanguage() const1710b57cec5SDimitry Andric const OptionValueLanguage *OptionValue::GetAsLanguage() const {
1720b57cec5SDimitry Andric if (GetType() == OptionValue::eTypeLanguage)
1730b57cec5SDimitry Andric return static_cast<const OptionValueLanguage *>(this);
1740b57cec5SDimitry Andric return nullptr;
1750b57cec5SDimitry Andric }
1760b57cec5SDimitry Andric
GetAsFormatEntity()1770b57cec5SDimitry Andric OptionValueFormatEntity *OptionValue::GetAsFormatEntity() {
1780b57cec5SDimitry Andric if (GetType() == OptionValue::eTypeFormatEntity)
1790b57cec5SDimitry Andric return static_cast<OptionValueFormatEntity *>(this);
1800b57cec5SDimitry Andric return nullptr;
1810b57cec5SDimitry Andric }
1820b57cec5SDimitry Andric
GetAsFormatEntity() const1830b57cec5SDimitry Andric const OptionValueFormatEntity *OptionValue::GetAsFormatEntity() const {
1840b57cec5SDimitry Andric if (GetType() == OptionValue::eTypeFormatEntity)
1850b57cec5SDimitry Andric return static_cast<const OptionValueFormatEntity *>(this);
1860b57cec5SDimitry Andric return nullptr;
1870b57cec5SDimitry Andric }
1880b57cec5SDimitry Andric
GetAsPathMappings()1890b57cec5SDimitry Andric OptionValuePathMappings *OptionValue::GetAsPathMappings() {
1900b57cec5SDimitry Andric if (GetType() == OptionValue::eTypePathMap)
1910b57cec5SDimitry Andric return static_cast<OptionValuePathMappings *>(this);
1920b57cec5SDimitry Andric return nullptr;
1930b57cec5SDimitry Andric }
1940b57cec5SDimitry Andric
GetAsPathMappings() const1950b57cec5SDimitry Andric const OptionValuePathMappings *OptionValue::GetAsPathMappings() const {
1960b57cec5SDimitry Andric if (GetType() == OptionValue::eTypePathMap)
1970b57cec5SDimitry Andric return static_cast<const OptionValuePathMappings *>(this);
1980b57cec5SDimitry Andric return nullptr;
1990b57cec5SDimitry Andric }
2000b57cec5SDimitry Andric
GetAsProperties()2010b57cec5SDimitry Andric OptionValueProperties *OptionValue::GetAsProperties() {
2020b57cec5SDimitry Andric if (GetType() == OptionValue::eTypeProperties)
2030b57cec5SDimitry Andric return static_cast<OptionValueProperties *>(this);
2040b57cec5SDimitry Andric return nullptr;
2050b57cec5SDimitry Andric }
2060b57cec5SDimitry Andric
GetAsProperties() const2070b57cec5SDimitry Andric const OptionValueProperties *OptionValue::GetAsProperties() const {
2080b57cec5SDimitry Andric if (GetType() == OptionValue::eTypeProperties)
2090b57cec5SDimitry Andric return static_cast<const OptionValueProperties *>(this);
2100b57cec5SDimitry Andric return nullptr;
2110b57cec5SDimitry Andric }
2120b57cec5SDimitry Andric
GetAsRegex()2130b57cec5SDimitry Andric OptionValueRegex *OptionValue::GetAsRegex() {
2140b57cec5SDimitry Andric if (GetType() == OptionValue::eTypeRegex)
2150b57cec5SDimitry Andric return static_cast<OptionValueRegex *>(this);
2160b57cec5SDimitry Andric return nullptr;
2170b57cec5SDimitry Andric }
2180b57cec5SDimitry Andric
GetAsRegex() const2190b57cec5SDimitry Andric const OptionValueRegex *OptionValue::GetAsRegex() const {
2200b57cec5SDimitry Andric if (GetType() == OptionValue::eTypeRegex)
2210b57cec5SDimitry Andric return static_cast<const OptionValueRegex *>(this);
2220b57cec5SDimitry Andric return nullptr;
2230b57cec5SDimitry Andric }
2240b57cec5SDimitry Andric
GetAsSInt64()2250b57cec5SDimitry Andric OptionValueSInt64 *OptionValue::GetAsSInt64() {
2260b57cec5SDimitry Andric if (GetType() == OptionValue::eTypeSInt64)
2270b57cec5SDimitry Andric return static_cast<OptionValueSInt64 *>(this);
2280b57cec5SDimitry Andric return nullptr;
2290b57cec5SDimitry Andric }
2300b57cec5SDimitry Andric
GetAsSInt64() const2310b57cec5SDimitry Andric const OptionValueSInt64 *OptionValue::GetAsSInt64() const {
2320b57cec5SDimitry Andric if (GetType() == OptionValue::eTypeSInt64)
2330b57cec5SDimitry Andric return static_cast<const OptionValueSInt64 *>(this);
2340b57cec5SDimitry Andric return nullptr;
2350b57cec5SDimitry Andric }
2360b57cec5SDimitry Andric
GetAsString()2370b57cec5SDimitry Andric OptionValueString *OptionValue::GetAsString() {
2380b57cec5SDimitry Andric if (GetType() == OptionValue::eTypeString)
2390b57cec5SDimitry Andric return static_cast<OptionValueString *>(this);
2400b57cec5SDimitry Andric return nullptr;
2410b57cec5SDimitry Andric }
2420b57cec5SDimitry Andric
GetAsString() const2430b57cec5SDimitry Andric const OptionValueString *OptionValue::GetAsString() const {
2440b57cec5SDimitry Andric if (GetType() == OptionValue::eTypeString)
2450b57cec5SDimitry Andric return static_cast<const OptionValueString *>(this);
2460b57cec5SDimitry Andric return nullptr;
2470b57cec5SDimitry Andric }
2480b57cec5SDimitry Andric
GetAsUInt64()2490b57cec5SDimitry Andric OptionValueUInt64 *OptionValue::GetAsUInt64() {
2500b57cec5SDimitry Andric if (GetType() == OptionValue::eTypeUInt64)
2510b57cec5SDimitry Andric return static_cast<OptionValueUInt64 *>(this);
2520b57cec5SDimitry Andric return nullptr;
2530b57cec5SDimitry Andric }
2540b57cec5SDimitry Andric
GetAsUInt64() const2550b57cec5SDimitry Andric const OptionValueUInt64 *OptionValue::GetAsUInt64() const {
2560b57cec5SDimitry Andric if (GetType() == OptionValue::eTypeUInt64)
2570b57cec5SDimitry Andric return static_cast<const OptionValueUInt64 *>(this);
2580b57cec5SDimitry Andric return nullptr;
2590b57cec5SDimitry Andric }
2600b57cec5SDimitry Andric
GetAsUUID()2610b57cec5SDimitry Andric OptionValueUUID *OptionValue::GetAsUUID() {
2620b57cec5SDimitry Andric if (GetType() == OptionValue::eTypeUUID)
2630b57cec5SDimitry Andric return static_cast<OptionValueUUID *>(this);
2640b57cec5SDimitry Andric return nullptr;
2650b57cec5SDimitry Andric }
2660b57cec5SDimitry Andric
GetAsUUID() const2670b57cec5SDimitry Andric const OptionValueUUID *OptionValue::GetAsUUID() const {
2680b57cec5SDimitry Andric if (GetType() == OptionValue::eTypeUUID)
2690b57cec5SDimitry Andric return static_cast<const OptionValueUUID *>(this);
2700b57cec5SDimitry Andric return nullptr;
2710b57cec5SDimitry Andric }
2720b57cec5SDimitry Andric
GetBooleanValue() const27306c3fb27SDimitry Andric std::optional<bool> OptionValue::GetBooleanValue() const {
274*5f757f3fSDimitry Andric std::lock_guard<std::mutex> lock(m_mutex);
27506c3fb27SDimitry Andric if (const OptionValueBoolean *option_value = GetAsBoolean())
2760b57cec5SDimitry Andric return option_value->GetCurrentValue();
27706c3fb27SDimitry Andric return {};
2780b57cec5SDimitry Andric }
2790b57cec5SDimitry Andric
SetBooleanValue(bool new_value)2800b57cec5SDimitry Andric bool OptionValue::SetBooleanValue(bool new_value) {
281*5f757f3fSDimitry Andric std::lock_guard<std::mutex> lock(m_mutex);
28206c3fb27SDimitry Andric if (OptionValueBoolean *option_value = GetAsBoolean()) {
2830b57cec5SDimitry Andric option_value->SetCurrentValue(new_value);
2840b57cec5SDimitry Andric return true;
2850b57cec5SDimitry Andric }
2860b57cec5SDimitry Andric return false;
2870b57cec5SDimitry Andric }
2880b57cec5SDimitry Andric
GetCharValue() const28906c3fb27SDimitry Andric std::optional<char> OptionValue::GetCharValue() const {
290*5f757f3fSDimitry Andric std::lock_guard<std::mutex> lock(m_mutex);
29106c3fb27SDimitry Andric if (const OptionValueChar *option_value = GetAsChar())
2920b57cec5SDimitry Andric return option_value->GetCurrentValue();
29306c3fb27SDimitry Andric return {};
2940b57cec5SDimitry Andric }
2950b57cec5SDimitry Andric
SetCharValue(char new_value)29606c3fb27SDimitry Andric bool OptionValue::SetCharValue(char new_value) {
297*5f757f3fSDimitry Andric std::lock_guard<std::mutex> lock(m_mutex);
29806c3fb27SDimitry Andric if (OptionValueChar *option_value = GetAsChar()) {
2990b57cec5SDimitry Andric option_value->SetCurrentValue(new_value);
3000b57cec5SDimitry Andric return true;
3010b57cec5SDimitry Andric }
3020b57cec5SDimitry Andric return false;
3030b57cec5SDimitry Andric }
3040b57cec5SDimitry Andric
GetEnumerationValue() const30506c3fb27SDimitry Andric std::optional<int64_t> OptionValue::GetEnumerationValue() const {
306*5f757f3fSDimitry Andric std::lock_guard<std::mutex> lock(m_mutex);
30706c3fb27SDimitry Andric if (const OptionValueEnumeration *option_value = GetAsEnumeration())
3080b57cec5SDimitry Andric return option_value->GetCurrentValue();
30906c3fb27SDimitry Andric return {};
3100b57cec5SDimitry Andric }
3110b57cec5SDimitry Andric
SetEnumerationValue(int64_t value)3120b57cec5SDimitry Andric bool OptionValue::SetEnumerationValue(int64_t value) {
313*5f757f3fSDimitry Andric std::lock_guard<std::mutex> lock(m_mutex);
31406c3fb27SDimitry Andric if (OptionValueEnumeration *option_value = GetAsEnumeration()) {
3150b57cec5SDimitry Andric option_value->SetCurrentValue(value);
3160b57cec5SDimitry Andric return true;
3170b57cec5SDimitry Andric }
3180b57cec5SDimitry Andric return false;
3190b57cec5SDimitry Andric }
3200b57cec5SDimitry Andric
GetFileSpecValue() const32106c3fb27SDimitry Andric std::optional<FileSpec> OptionValue::GetFileSpecValue() const {
322*5f757f3fSDimitry Andric std::lock_guard<std::mutex> lock(m_mutex);
32306c3fb27SDimitry Andric if (const OptionValueFileSpec *option_value = GetAsFileSpec())
3240b57cec5SDimitry Andric return option_value->GetCurrentValue();
32506c3fb27SDimitry Andric return {};
3260b57cec5SDimitry Andric }
3270b57cec5SDimitry Andric
SetFileSpecValue(FileSpec file_spec)32806c3fb27SDimitry Andric bool OptionValue::SetFileSpecValue(FileSpec file_spec) {
329*5f757f3fSDimitry Andric std::lock_guard<std::mutex> lock(m_mutex);
33006c3fb27SDimitry Andric if (OptionValueFileSpec *option_value = GetAsFileSpec()) {
3310b57cec5SDimitry Andric option_value->SetCurrentValue(file_spec, false);
3320b57cec5SDimitry Andric return true;
3330b57cec5SDimitry Andric }
3340b57cec5SDimitry Andric return false;
3350b57cec5SDimitry Andric }
3360b57cec5SDimitry Andric
AppendFileSpecValue(FileSpec file_spec)33706c3fb27SDimitry Andric bool OptionValue::AppendFileSpecValue(FileSpec file_spec) {
338*5f757f3fSDimitry Andric std::lock_guard<std::mutex> lock(m_mutex);
33906c3fb27SDimitry Andric if (OptionValueFileSpecList *option_value = GetAsFileSpecList()) {
34006c3fb27SDimitry Andric option_value->AppendCurrentValue(file_spec);
34106c3fb27SDimitry Andric return true;
34206c3fb27SDimitry Andric }
34306c3fb27SDimitry Andric return false;
3440b57cec5SDimitry Andric }
3450b57cec5SDimitry Andric
GetFileSpecListValue() const34606c3fb27SDimitry Andric std::optional<FileSpecList> OptionValue::GetFileSpecListValue() const {
347*5f757f3fSDimitry Andric std::lock_guard<std::mutex> lock(m_mutex);
34806c3fb27SDimitry Andric if (const OptionValueFileSpecList *option_value = GetAsFileSpecList())
3490b57cec5SDimitry Andric return option_value->GetCurrentValue();
35006c3fb27SDimitry Andric return {};
35106c3fb27SDimitry Andric }
35206c3fb27SDimitry Andric
GetFormatValue() const35306c3fb27SDimitry Andric std::optional<lldb::Format> OptionValue::GetFormatValue() const {
354*5f757f3fSDimitry Andric std::lock_guard<std::mutex> lock(m_mutex);
35506c3fb27SDimitry Andric if (const OptionValueFormat *option_value = GetAsFormat())
35606c3fb27SDimitry Andric return option_value->GetCurrentValue();
35706c3fb27SDimitry Andric return {};
3580b57cec5SDimitry Andric }
3590b57cec5SDimitry Andric
SetFormatValue(lldb::Format new_value)3600b57cec5SDimitry Andric bool OptionValue::SetFormatValue(lldb::Format new_value) {
361*5f757f3fSDimitry Andric std::lock_guard<std::mutex> lock(m_mutex);
36206c3fb27SDimitry Andric if (OptionValueFormat *option_value = GetAsFormat()) {
3630b57cec5SDimitry Andric option_value->SetCurrentValue(new_value);
3640b57cec5SDimitry Andric return true;
3650b57cec5SDimitry Andric }
3660b57cec5SDimitry Andric return false;
3670b57cec5SDimitry Andric }
3680b57cec5SDimitry Andric
GetLanguageValue() const36906c3fb27SDimitry Andric std::optional<lldb::LanguageType> OptionValue::GetLanguageValue() const {
370*5f757f3fSDimitry Andric std::lock_guard<std::mutex> lock(m_mutex);
37106c3fb27SDimitry Andric if (const OptionValueLanguage *option_value = GetAsLanguage())
3720b57cec5SDimitry Andric return option_value->GetCurrentValue();
37306c3fb27SDimitry Andric return {};
3740b57cec5SDimitry Andric }
3750b57cec5SDimitry Andric
SetLanguageValue(lldb::LanguageType new_language)3760b57cec5SDimitry Andric bool OptionValue::SetLanguageValue(lldb::LanguageType new_language) {
377*5f757f3fSDimitry Andric std::lock_guard<std::mutex> lock(m_mutex);
37806c3fb27SDimitry Andric if (OptionValueLanguage *option_value = GetAsLanguage()) {
3790b57cec5SDimitry Andric option_value->SetCurrentValue(new_language);
3800b57cec5SDimitry Andric return true;
3810b57cec5SDimitry Andric }
3820b57cec5SDimitry Andric return false;
3830b57cec5SDimitry Andric }
3840b57cec5SDimitry Andric
GetFormatEntity() const3850b57cec5SDimitry Andric const FormatEntity::Entry *OptionValue::GetFormatEntity() const {
386*5f757f3fSDimitry Andric std::lock_guard<std::mutex> lock(m_mutex);
38706c3fb27SDimitry Andric if (const OptionValueFormatEntity *option_value = GetAsFormatEntity())
3880b57cec5SDimitry Andric return &option_value->GetCurrentValue();
3890b57cec5SDimitry Andric return nullptr;
3900b57cec5SDimitry Andric }
3910b57cec5SDimitry Andric
GetRegexValue() const3920b57cec5SDimitry Andric const RegularExpression *OptionValue::GetRegexValue() const {
393*5f757f3fSDimitry Andric std::lock_guard<std::mutex> lock(m_mutex);
39406c3fb27SDimitry Andric if (const OptionValueRegex *option_value = GetAsRegex())
3950b57cec5SDimitry Andric return option_value->GetCurrentValue();
3960b57cec5SDimitry Andric return nullptr;
3970b57cec5SDimitry Andric }
3980b57cec5SDimitry Andric
GetSInt64Value() const39906c3fb27SDimitry Andric std::optional<int64_t> OptionValue::GetSInt64Value() const {
400*5f757f3fSDimitry Andric std::lock_guard<std::mutex> lock(m_mutex);
40106c3fb27SDimitry Andric if (const OptionValueSInt64 *option_value = GetAsSInt64())
4020b57cec5SDimitry Andric return option_value->GetCurrentValue();
40306c3fb27SDimitry Andric return {};
4040b57cec5SDimitry Andric }
4050b57cec5SDimitry Andric
SetSInt64Value(int64_t new_value)4060b57cec5SDimitry Andric bool OptionValue::SetSInt64Value(int64_t new_value) {
407*5f757f3fSDimitry Andric std::lock_guard<std::mutex> lock(m_mutex);
40806c3fb27SDimitry Andric if (OptionValueSInt64 *option_value = GetAsSInt64()) {
4090b57cec5SDimitry Andric option_value->SetCurrentValue(new_value);
4100b57cec5SDimitry Andric return true;
4110b57cec5SDimitry Andric }
4120b57cec5SDimitry Andric return false;
4130b57cec5SDimitry Andric }
4140b57cec5SDimitry Andric
GetStringValue() const41506c3fb27SDimitry Andric std::optional<llvm::StringRef> OptionValue::GetStringValue() const {
416*5f757f3fSDimitry Andric std::lock_guard<std::mutex> lock(m_mutex);
41706c3fb27SDimitry Andric if (const OptionValueString *option_value = GetAsString())
4180b57cec5SDimitry Andric return option_value->GetCurrentValueAsRef();
41906c3fb27SDimitry Andric return {};
4200b57cec5SDimitry Andric }
4210b57cec5SDimitry Andric
SetStringValue(llvm::StringRef new_value)4220b57cec5SDimitry Andric bool OptionValue::SetStringValue(llvm::StringRef new_value) {
423*5f757f3fSDimitry Andric std::lock_guard<std::mutex> lock(m_mutex);
42406c3fb27SDimitry Andric if (OptionValueString *option_value = GetAsString()) {
4250b57cec5SDimitry Andric option_value->SetCurrentValue(new_value);
4260b57cec5SDimitry Andric return true;
4270b57cec5SDimitry Andric }
4280b57cec5SDimitry Andric return false;
4290b57cec5SDimitry Andric }
4300b57cec5SDimitry Andric
GetUInt64Value() const43106c3fb27SDimitry Andric std::optional<uint64_t> OptionValue::GetUInt64Value() const {
432*5f757f3fSDimitry Andric std::lock_guard<std::mutex> lock(m_mutex);
43306c3fb27SDimitry Andric if (const OptionValueUInt64 *option_value = GetAsUInt64())
4340b57cec5SDimitry Andric return option_value->GetCurrentValue();
43506c3fb27SDimitry Andric return {};
4360b57cec5SDimitry Andric }
4370b57cec5SDimitry Andric
SetUInt64Value(uint64_t new_value)4380b57cec5SDimitry Andric bool OptionValue::SetUInt64Value(uint64_t new_value) {
439*5f757f3fSDimitry Andric std::lock_guard<std::mutex> lock(m_mutex);
44006c3fb27SDimitry Andric if (OptionValueUInt64 *option_value = GetAsUInt64()) {
4410b57cec5SDimitry Andric option_value->SetCurrentValue(new_value);
4420b57cec5SDimitry Andric return true;
4430b57cec5SDimitry Andric }
4440b57cec5SDimitry Andric return false;
4450b57cec5SDimitry Andric }
4460b57cec5SDimitry Andric
GetUUIDValue() const44706c3fb27SDimitry Andric std::optional<UUID> OptionValue::GetUUIDValue() const {
448*5f757f3fSDimitry Andric std::lock_guard<std::mutex> lock(m_mutex);
44906c3fb27SDimitry Andric if (const OptionValueUUID *option_value = GetAsUUID())
4500b57cec5SDimitry Andric return option_value->GetCurrentValue();
45106c3fb27SDimitry Andric return {};
4520b57cec5SDimitry Andric }
4530b57cec5SDimitry Andric
SetUUIDValue(const UUID & uuid)4540b57cec5SDimitry Andric bool OptionValue::SetUUIDValue(const UUID &uuid) {
455*5f757f3fSDimitry Andric std::lock_guard<std::mutex> lock(m_mutex);
45606c3fb27SDimitry Andric if (OptionValueUUID *option_value = GetAsUUID()) {
4570b57cec5SDimitry Andric option_value->SetCurrentValue(uuid);
4580b57cec5SDimitry Andric return true;
4590b57cec5SDimitry Andric }
4600b57cec5SDimitry Andric return false;
4610b57cec5SDimitry Andric }
4620b57cec5SDimitry Andric
GetArchSpecValue() const46306c3fb27SDimitry Andric std::optional<ArchSpec> OptionValue::GetArchSpecValue() const {
464*5f757f3fSDimitry Andric std::lock_guard<std::mutex> lock(m_mutex);
46506c3fb27SDimitry Andric if (const OptionValueArch *option_value = GetAsArch())
46606c3fb27SDimitry Andric return option_value->GetCurrentValue();
46706c3fb27SDimitry Andric return {};
46806c3fb27SDimitry Andric }
46906c3fb27SDimitry Andric
SetArchSpecValue(ArchSpec arch_spec)47006c3fb27SDimitry Andric bool OptionValue::SetArchSpecValue(ArchSpec arch_spec) {
471*5f757f3fSDimitry Andric std::lock_guard<std::mutex> lock(m_mutex);
47206c3fb27SDimitry Andric if (OptionValueArch *option_value = GetAsArch()) {
47306c3fb27SDimitry Andric option_value->SetCurrentValue(arch_spec, false);
47406c3fb27SDimitry Andric return true;
47506c3fb27SDimitry Andric }
47606c3fb27SDimitry Andric return false;
47706c3fb27SDimitry Andric }
47806c3fb27SDimitry Andric
GetBuiltinTypeAsCString(Type t)4790b57cec5SDimitry Andric const char *OptionValue::GetBuiltinTypeAsCString(Type t) {
4800b57cec5SDimitry Andric switch (t) {
4810b57cec5SDimitry Andric case eTypeInvalid:
4820b57cec5SDimitry Andric return "invalid";
4830b57cec5SDimitry Andric case eTypeArch:
4840b57cec5SDimitry Andric return "arch";
4850b57cec5SDimitry Andric case eTypeArgs:
4860b57cec5SDimitry Andric return "arguments";
4870b57cec5SDimitry Andric case eTypeArray:
4880b57cec5SDimitry Andric return "array";
4890b57cec5SDimitry Andric case eTypeBoolean:
4900b57cec5SDimitry Andric return "boolean";
4910b57cec5SDimitry Andric case eTypeChar:
4920b57cec5SDimitry Andric return "char";
4930b57cec5SDimitry Andric case eTypeDictionary:
4940b57cec5SDimitry Andric return "dictionary";
4950b57cec5SDimitry Andric case eTypeEnum:
4960b57cec5SDimitry Andric return "enum";
497e8d8bef9SDimitry Andric case eTypeFileLineColumn:
498e8d8bef9SDimitry Andric return "file:line:column specifier";
4990b57cec5SDimitry Andric case eTypeFileSpec:
5000b57cec5SDimitry Andric return "file";
5010b57cec5SDimitry Andric case eTypeFileSpecList:
5020b57cec5SDimitry Andric return "file-list";
5030b57cec5SDimitry Andric case eTypeFormat:
5040b57cec5SDimitry Andric return "format";
5050b57cec5SDimitry Andric case eTypeFormatEntity:
5060b57cec5SDimitry Andric return "format-string";
5070b57cec5SDimitry Andric case eTypeLanguage:
5080b57cec5SDimitry Andric return "language";
5090b57cec5SDimitry Andric case eTypePathMap:
5100b57cec5SDimitry Andric return "path-map";
5110b57cec5SDimitry Andric case eTypeProperties:
5120b57cec5SDimitry Andric return "properties";
5130b57cec5SDimitry Andric case eTypeRegex:
5140b57cec5SDimitry Andric return "regex";
5150b57cec5SDimitry Andric case eTypeSInt64:
5160b57cec5SDimitry Andric return "int";
5170b57cec5SDimitry Andric case eTypeString:
5180b57cec5SDimitry Andric return "string";
5190b57cec5SDimitry Andric case eTypeUInt64:
5200b57cec5SDimitry Andric return "unsigned";
5210b57cec5SDimitry Andric case eTypeUUID:
5220b57cec5SDimitry Andric return "uuid";
5230b57cec5SDimitry Andric }
5240b57cec5SDimitry Andric return nullptr;
5250b57cec5SDimitry Andric }
5260b57cec5SDimitry Andric
CreateValueFromCStringForTypeMask(const char * value_cstr,uint32_t type_mask,Status & error)5270b57cec5SDimitry Andric lldb::OptionValueSP OptionValue::CreateValueFromCStringForTypeMask(
5280b57cec5SDimitry Andric const char *value_cstr, uint32_t type_mask, Status &error) {
5290b57cec5SDimitry Andric // If only 1 bit is set in the type mask for a dictionary or array then we
5300b57cec5SDimitry Andric // know how to decode a value from a cstring
5310b57cec5SDimitry Andric lldb::OptionValueSP value_sp;
5320b57cec5SDimitry Andric switch (type_mask) {
5330b57cec5SDimitry Andric case 1u << eTypeArch:
5345ffd83dbSDimitry Andric value_sp = std::make_shared<OptionValueArch>();
5350b57cec5SDimitry Andric break;
5360b57cec5SDimitry Andric case 1u << eTypeBoolean:
5375ffd83dbSDimitry Andric value_sp = std::make_shared<OptionValueBoolean>(false);
5380b57cec5SDimitry Andric break;
5390b57cec5SDimitry Andric case 1u << eTypeChar:
5405ffd83dbSDimitry Andric value_sp = std::make_shared<OptionValueChar>('\0');
5410b57cec5SDimitry Andric break;
5420b57cec5SDimitry Andric case 1u << eTypeFileSpec:
5435ffd83dbSDimitry Andric value_sp = std::make_shared<OptionValueFileSpec>();
5440b57cec5SDimitry Andric break;
5450b57cec5SDimitry Andric case 1u << eTypeFormat:
5465ffd83dbSDimitry Andric value_sp = std::make_shared<OptionValueFormat>(eFormatInvalid);
5470b57cec5SDimitry Andric break;
5480b57cec5SDimitry Andric case 1u << eTypeFormatEntity:
5495ffd83dbSDimitry Andric value_sp = std::make_shared<OptionValueFormatEntity>(nullptr);
5500b57cec5SDimitry Andric break;
5510b57cec5SDimitry Andric case 1u << eTypeLanguage:
5525ffd83dbSDimitry Andric value_sp = std::make_shared<OptionValueLanguage>(eLanguageTypeUnknown);
5530b57cec5SDimitry Andric break;
5540b57cec5SDimitry Andric case 1u << eTypeSInt64:
5555ffd83dbSDimitry Andric value_sp = std::make_shared<OptionValueSInt64>();
5560b57cec5SDimitry Andric break;
5570b57cec5SDimitry Andric case 1u << eTypeString:
5585ffd83dbSDimitry Andric value_sp = std::make_shared<OptionValueString>();
5590b57cec5SDimitry Andric break;
5600b57cec5SDimitry Andric case 1u << eTypeUInt64:
5615ffd83dbSDimitry Andric value_sp = std::make_shared<OptionValueUInt64>();
5620b57cec5SDimitry Andric break;
5630b57cec5SDimitry Andric case 1u << eTypeUUID:
5645ffd83dbSDimitry Andric value_sp = std::make_shared<OptionValueUUID>();
5650b57cec5SDimitry Andric break;
5660b57cec5SDimitry Andric }
5670b57cec5SDimitry Andric
5680b57cec5SDimitry Andric if (value_sp)
569fe6060f1SDimitry Andric error = value_sp->SetValueFromString(value_cstr, eVarSetOperationAssign);
5700b57cec5SDimitry Andric else
5710b57cec5SDimitry Andric error.SetErrorString("unsupported type mask");
5720b57cec5SDimitry Andric return value_sp;
5730b57cec5SDimitry Andric }
5740b57cec5SDimitry Andric
DumpQualifiedName(Stream & strm) const5750b57cec5SDimitry Andric bool OptionValue::DumpQualifiedName(Stream &strm) const {
5760b57cec5SDimitry Andric bool dumped_something = false;
5770b57cec5SDimitry Andric lldb::OptionValueSP m_parent_sp(m_parent_wp.lock());
5780b57cec5SDimitry Andric if (m_parent_sp) {
5790b57cec5SDimitry Andric if (m_parent_sp->DumpQualifiedName(strm))
5800b57cec5SDimitry Andric dumped_something = true;
5810b57cec5SDimitry Andric }
58206c3fb27SDimitry Andric llvm::StringRef name(GetName());
58306c3fb27SDimitry Andric if (!name.empty()) {
5840b57cec5SDimitry Andric if (dumped_something)
5850b57cec5SDimitry Andric strm.PutChar('.');
5860b57cec5SDimitry Andric else
5870b57cec5SDimitry Andric dumped_something = true;
5880b57cec5SDimitry Andric strm << name;
5890b57cec5SDimitry Andric }
5900b57cec5SDimitry Andric return dumped_something;
5910b57cec5SDimitry Andric }
5920b57cec5SDimitry Andric
DeepCopy(const OptionValueSP & new_parent) const593fe6060f1SDimitry Andric OptionValueSP OptionValue::DeepCopy(const OptionValueSP &new_parent) const {
594fe6060f1SDimitry Andric auto clone = Clone();
595fe6060f1SDimitry Andric clone->SetParent(new_parent);
596fe6060f1SDimitry Andric return clone;
597fe6060f1SDimitry Andric }
598fe6060f1SDimitry Andric
AutoComplete(CommandInterpreter & interpreter,CompletionRequest & request)5999dba64beSDimitry Andric void OptionValue::AutoComplete(CommandInterpreter &interpreter,
6009dba64beSDimitry Andric CompletionRequest &request) {}
6010b57cec5SDimitry Andric
SetValueFromString(llvm::StringRef value,VarSetOperationType op)6020b57cec5SDimitry Andric Status OptionValue::SetValueFromString(llvm::StringRef value,
6030b57cec5SDimitry Andric VarSetOperationType op) {
6040b57cec5SDimitry Andric Status error;
6050b57cec5SDimitry Andric switch (op) {
6060b57cec5SDimitry Andric case eVarSetOperationReplace:
6070b57cec5SDimitry Andric error.SetErrorStringWithFormat(
6080b57cec5SDimitry Andric "%s objects do not support the 'replace' operation",
6090b57cec5SDimitry Andric GetTypeAsCString());
6100b57cec5SDimitry Andric break;
6110b57cec5SDimitry Andric case eVarSetOperationInsertBefore:
6120b57cec5SDimitry Andric error.SetErrorStringWithFormat(
6130b57cec5SDimitry Andric "%s objects do not support the 'insert-before' operation",
6140b57cec5SDimitry Andric GetTypeAsCString());
6150b57cec5SDimitry Andric break;
6160b57cec5SDimitry Andric case eVarSetOperationInsertAfter:
6170b57cec5SDimitry Andric error.SetErrorStringWithFormat(
6180b57cec5SDimitry Andric "%s objects do not support the 'insert-after' operation",
6190b57cec5SDimitry Andric GetTypeAsCString());
6200b57cec5SDimitry Andric break;
6210b57cec5SDimitry Andric case eVarSetOperationRemove:
6220b57cec5SDimitry Andric error.SetErrorStringWithFormat(
6230b57cec5SDimitry Andric "%s objects do not support the 'remove' operation", GetTypeAsCString());
6240b57cec5SDimitry Andric break;
6250b57cec5SDimitry Andric case eVarSetOperationAppend:
6260b57cec5SDimitry Andric error.SetErrorStringWithFormat(
6270b57cec5SDimitry Andric "%s objects do not support the 'append' operation", GetTypeAsCString());
6280b57cec5SDimitry Andric break;
6290b57cec5SDimitry Andric case eVarSetOperationClear:
6300b57cec5SDimitry Andric error.SetErrorStringWithFormat(
6310b57cec5SDimitry Andric "%s objects do not support the 'clear' operation", GetTypeAsCString());
6320b57cec5SDimitry Andric break;
6330b57cec5SDimitry Andric case eVarSetOperationAssign:
6340b57cec5SDimitry Andric error.SetErrorStringWithFormat(
6350b57cec5SDimitry Andric "%s objects do not support the 'assign' operation", GetTypeAsCString());
6360b57cec5SDimitry Andric break;
6370b57cec5SDimitry Andric case eVarSetOperationInvalid:
6380b57cec5SDimitry Andric error.SetErrorStringWithFormat("invalid operation performed on a %s object",
6390b57cec5SDimitry Andric GetTypeAsCString());
6400b57cec5SDimitry Andric break;
6410b57cec5SDimitry Andric }
6420b57cec5SDimitry Andric return error;
6430b57cec5SDimitry Andric }
644