Author: Ebuka Ezike Date: 2025-04-24T07:38:35+01:00 New Revision: fb0000b6624a5f2df25d10e3667111e96dd1abd5
URL: https://github.com/llvm/llvm-project/commit/fb0000b6624a5f2df25d10e3667111e96dd1abd5 DIFF: https://github.com/llvm/llvm-project/commit/fb0000b6624a5f2df25d10e3667111e96dd1abd5.diff LOG: [lldb][lldb-dap] Add ToJSON for OptionValueEnumeration (#137007) This automatically enables reading enum settings in the SB API Added: Modified: lldb/include/lldb/Interpreter/OptionValueEnumeration.h lldb/source/Interpreter/OptionValueEnumeration.cpp lldb/test/API/commands/settings/TestSettings.py Removed: ################################################################################ diff --git a/lldb/include/lldb/Interpreter/OptionValueEnumeration.h b/lldb/include/lldb/Interpreter/OptionValueEnumeration.h index 7dc6eea4e69de..924fcc10cbb00 100644 --- a/lldb/include/lldb/Interpreter/OptionValueEnumeration.h +++ b/lldb/include/lldb/Interpreter/OptionValueEnumeration.h @@ -41,6 +41,8 @@ class OptionValueEnumeration void DumpValue(const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask) override; + llvm::json::Value ToJSON(const ExecutionContext *exe_ctx) override; + Status SetValueFromString(llvm::StringRef value, VarSetOperationType op = eVarSetOperationAssign) override; diff --git a/lldb/source/Interpreter/OptionValueEnumeration.cpp b/lldb/source/Interpreter/OptionValueEnumeration.cpp index 8088695243545..dd231f43e0d96 100644 --- a/lldb/source/Interpreter/OptionValueEnumeration.cpp +++ b/lldb/source/Interpreter/OptionValueEnumeration.cpp @@ -37,6 +37,16 @@ void OptionValueEnumeration::DumpValue(const ExecutionContext *exe_ctx, } } +llvm::json::Value +OptionValueEnumeration::ToJSON(const ExecutionContext *exe_ctx) { + for (const auto &enums : m_enumerations) { + if (enums.value.value == m_current_value) + return enums.cstring.GetStringRef(); + } + + return std::to_string(static_cast<uint64_t>(m_current_value)); +} + Status OptionValueEnumeration::SetValueFromString(llvm::StringRef value, VarSetOperationType op) { Status error; @@ -105,6 +115,6 @@ void OptionValueEnumeration::AutoComplete(CommandInterpreter &interpreter, } return; } - for (size_t i = 0; i < num_enumerators; ++i) - request.AddCompletion(m_enumerations.GetCStringAtIndex(i).GetStringRef()); + for (size_t i = 0; i < num_enumerators; ++i) + request.AddCompletion(m_enumerations.GetCStringAtIndex(i).GetStringRef()); } diff --git a/lldb/test/API/commands/settings/TestSettings.py b/lldb/test/API/commands/settings/TestSettings.py index b9b66ea953971..f05a285b47d16 100644 --- a/lldb/test/API/commands/settings/TestSettings.py +++ b/lldb/test/API/commands/settings/TestSettings.py @@ -1041,6 +1041,9 @@ def test_settings_api(self): # Test OptionValueLanguage self.verify_setting_value_json("repl-lang", "c++") + # Test OptionValueEnumeration + self.verify_setting_value_json("target.x86-disassembly-flavor", "intel") + def test_global_option(self): # This command used to crash the settings because -g was signaled by a # NULL execution context (not one with an empty Target...) and in the _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits