Skip to content

[lldb][lldb-dap] Add ToJSON for OptionValueEnumeration #137007

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 24, 2025

Conversation

da-viper
Copy link
Contributor

This automatically enables dumping enum settings in the python api

This automatically enables dumping enum settings in the python api
@da-viper da-viper requested a review from JDevlieghere as a code owner April 23, 2025 15:44
@llvmbot llvmbot added the lldb label Apr 23, 2025
@llvmbot
Copy link
Member

llvmbot commented Apr 23, 2025

@llvm/pr-subscribers-lldb

Author: Ebuka Ezike (da-viper)

Changes

This automatically enables dumping enum settings in the python api


Full diff: https://github.com/llvm/llvm-project/pull/137007.diff

3 Files Affected:

  • (modified) lldb/include/lldb/Interpreter/OptionValueEnumeration.h (+2)
  • (modified) lldb/source/Interpreter/OptionValueEnumeration.cpp (+12-2)
  • (modified) lldb/test/API/commands/settings/TestSettings.py (+3)
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

Copy link
Member

@JDevlieghere JDevlieghere left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@da-viper da-viper merged commit fb0000b into llvm:main Apr 24, 2025
10 checks passed
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
This automatically enables reading enum settings in the SB API
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
This automatically enables reading enum settings in the SB API
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
This automatically enables reading enum settings in the SB API
Ankur-0429 pushed a commit to Ankur-0429/llvm-project that referenced this pull request May 9, 2025
This automatically enables reading enum settings in the SB API
@da-viper da-viper deleted the add-to-json-for-option-value-enums branch May 11, 2025 11:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants