https://github.com/da-viper updated https://github.com/llvm/llvm-project/pull/137007
>From 5ffbb9db5031e4f4146dce9736235421fbc5abca Mon Sep 17 00:00:00 2001 From: Ebuka Ezike <yerimy...@gmail.com> Date: Mon, 7 Apr 2025 21:07:34 +0100 Subject: [PATCH 1/2] [lldb][lldb-dap] Add ToJSON for OptionValueEnumeration This automatically enables dumping enum settings in the python api --- .../lldb/Interpreter/OptionValueEnumeration.h | 2 ++ lldb/source/Interpreter/OptionValueEnumeration.cpp | 14 ++++++++++++-- lldb/test/API/commands/settings/TestSettings.py | 3 +++ 3 files changed, 17 insertions(+), 2 deletions(-) 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..bd91f6e2ad446 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 llvm::formatv("%", PRIu64, 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 >From c252815ab3a1f788d2ca60d6dd522cadbbb81dbd Mon Sep 17 00:00:00 2001 From: Ebuka Ezike <yerimy...@gmail.com> Date: Wed, 23 Apr 2025 20:13:02 +0100 Subject: [PATCH 2/2] [lldb][lldb-dap] Review changes. --- lldb/source/Interpreter/OptionValueEnumeration.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lldb/source/Interpreter/OptionValueEnumeration.cpp b/lldb/source/Interpreter/OptionValueEnumeration.cpp index bd91f6e2ad446..dd231f43e0d96 100644 --- a/lldb/source/Interpreter/OptionValueEnumeration.cpp +++ b/lldb/source/Interpreter/OptionValueEnumeration.cpp @@ -44,7 +44,7 @@ OptionValueEnumeration::ToJSON(const ExecutionContext *exe_ctx) { return enums.cstring.GetStringRef(); } - return llvm::formatv("%", PRIu64, static_cast<uint64_t>(m_current_value)); + return std::to_string(static_cast<uint64_t>(m_current_value)); } Status OptionValueEnumeration::SetValueFromString(llvm::StringRef value, _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits