Skip to content

Conversation

@da-viper
Copy link
Contributor

Completes the ToJSON for OptionValueArch and OptionValueFileColumnLine and make the interface function pure virtual

@da-viper da-viper requested a review from JDevlieghere as a code owner April 25, 2025 17:58
@llvmbot llvmbot added the lldb label Apr 25, 2025
@llvmbot
Copy link
Member

llvmbot commented Apr 25, 2025

@llvm/pr-subscribers-lldb

Author: Ebuka Ezike (da-viper)

Changes

Completes the ToJSON for OptionValueArch and OptionValueFileColumnLine and make the interface function pure virtual


Patch is 22.40 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/137375.diff

34 Files Affected:

  • (modified) lldb/include/lldb/Interpreter/OptionValue.h (+1-9)
  • (modified) lldb/include/lldb/Interpreter/OptionValueArch.h (+2)
  • (modified) lldb/include/lldb/Interpreter/OptionValueArray.h (+1-1)
  • (modified) lldb/include/lldb/Interpreter/OptionValueBoolean.h (+1-1)
  • (modified) lldb/include/lldb/Interpreter/OptionValueChar.h (+1-1)
  • (modified) lldb/include/lldb/Interpreter/OptionValueDictionary.h (+1-1)
  • (modified) lldb/include/lldb/Interpreter/OptionValueEnumeration.h (+1-1)
  • (modified) lldb/include/lldb/Interpreter/OptionValueFileColonLine.h (+2)
  • (modified) lldb/include/lldb/Interpreter/OptionValueFileSpec.h (+1-1)
  • (modified) lldb/include/lldb/Interpreter/OptionValueFileSpecList.h (+1-1)
  • (modified) lldb/include/lldb/Interpreter/OptionValueFormat.h (+1-1)
  • (modified) lldb/include/lldb/Interpreter/OptionValueFormatEntity.h (+1-1)
  • (modified) lldb/include/lldb/Interpreter/OptionValueLanguage.h (+1-1)
  • (modified) lldb/include/lldb/Interpreter/OptionValuePathMappings.h (+1-1)
  • (modified) lldb/include/lldb/Interpreter/OptionValueProperties.h (+1-1)
  • (modified) lldb/include/lldb/Interpreter/OptionValueRegex.h (+1-1)
  • (modified) lldb/include/lldb/Interpreter/OptionValueSInt64.h (+1-1)
  • (modified) lldb/include/lldb/Interpreter/OptionValueString.h (+1-1)
  • (modified) lldb/include/lldb/Interpreter/OptionValueUInt64.h (+1-1)
  • (modified) lldb/include/lldb/Interpreter/OptionValueUUID.h (+1-1)
  • (modified) lldb/include/lldb/Target/PathMappingList.h (+1-1)
  • (modified) lldb/source/Interpreter/OptionValueArch.cpp (+9)
  • (modified) lldb/source/Interpreter/OptionValueArray.cpp (+2-1)
  • (modified) lldb/source/Interpreter/OptionValueDictionary.cpp (+1-1)
  • (modified) lldb/source/Interpreter/OptionValueEnumeration.cpp (+1-1)
  • (modified) lldb/source/Interpreter/OptionValueFileColonLine.cpp (+13)
  • (modified) lldb/source/Interpreter/OptionValueFileSpecList.cpp (+1-1)
  • (modified) lldb/source/Interpreter/OptionValueFormat.cpp (+2-1)
  • (modified) lldb/source/Interpreter/OptionValueFormatEntity.cpp (+1-1)
  • (modified) lldb/source/Interpreter/OptionValueLanguage.cpp (+2-1)
  • (modified) lldb/source/Interpreter/OptionValuePathMappings.cpp (+1-1)
  • (modified) lldb/source/Interpreter/OptionValueProperties.cpp (+1-1)
  • (modified) lldb/source/Target/PathMappingList.cpp (+1-1)
  • (modified) lldb/test/API/commands/settings/TestSettings.py (+4)
diff --git a/lldb/include/lldb/Interpreter/OptionValue.h b/lldb/include/lldb/Interpreter/OptionValue.h
index ebc438517a7b1..e3c139155b0ef 100644
--- a/lldb/include/lldb/Interpreter/OptionValue.h
+++ b/lldb/include/lldb/Interpreter/OptionValue.h
@@ -93,15 +93,7 @@ class OptionValue {
   virtual void DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
                          uint32_t dump_mask) = 0;
 
-  // TODO: make this function pure virtual after implementing it in all
-  // child classes.
-  virtual llvm::json::Value ToJSON(const ExecutionContext *exe_ctx) {
-    // Return nullptr which will create a llvm::json::Value() that is a NULL
-    // value. No setting should ever really have a NULL value in JSON. This
-    // indicates an error occurred and if/when we add a FromJSON() it will know
-    // to fail if someone tries to set it with a NULL JSON value.
-    return nullptr;
-  }
+  virtual llvm::json::Value ToJSON(const ExecutionContext *exe_ctx) const = 0;
 
   virtual Status
   SetValueFromString(llvm::StringRef value,
diff --git a/lldb/include/lldb/Interpreter/OptionValueArch.h b/lldb/include/lldb/Interpreter/OptionValueArch.h
index e175208794474..3ba07b65dd618 100644
--- a/lldb/include/lldb/Interpreter/OptionValueArch.h
+++ b/lldb/include/lldb/Interpreter/OptionValueArch.h
@@ -38,6 +38,8 @@ class OptionValueArch : public Cloneable<OptionValueArch, OptionValue> {
   void DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
                  uint32_t dump_mask) override;
 
+  llvm::json::Value ToJSON(const ExecutionContext *exe_ctx) const override;
+
   Status
   SetValueFromString(llvm::StringRef value,
                      VarSetOperationType op = eVarSetOperationAssign) override;
diff --git a/lldb/include/lldb/Interpreter/OptionValueArray.h b/lldb/include/lldb/Interpreter/OptionValueArray.h
index 0e1bae103d41f..34170ef06a188 100644
--- a/lldb/include/lldb/Interpreter/OptionValueArray.h
+++ b/lldb/include/lldb/Interpreter/OptionValueArray.h
@@ -29,7 +29,7 @@ class OptionValueArray : public Cloneable<OptionValueArray, OptionValue> {
   void DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
                  uint32_t dump_mask) override;
 
-  llvm::json::Value ToJSON(const ExecutionContext *exe_ctx) override;
+  llvm::json::Value ToJSON(const ExecutionContext *exe_ctx) const override;
 
   Status
   SetValueFromString(llvm::StringRef value,
diff --git a/lldb/include/lldb/Interpreter/OptionValueBoolean.h b/lldb/include/lldb/Interpreter/OptionValueBoolean.h
index 01e7c6c09d8e8..6d15dcd2fca5d 100644
--- a/lldb/include/lldb/Interpreter/OptionValueBoolean.h
+++ b/lldb/include/lldb/Interpreter/OptionValueBoolean.h
@@ -29,7 +29,7 @@ class OptionValueBoolean : public Cloneable<OptionValueBoolean, OptionValue> {
   void DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
                  uint32_t dump_mask) override;
 
-  llvm::json::Value ToJSON(const ExecutionContext *exe_ctx) override {
+  llvm::json::Value ToJSON(const ExecutionContext *exe_ctx) const override {
     return m_current_value;
   }
 
diff --git a/lldb/include/lldb/Interpreter/OptionValueChar.h b/lldb/include/lldb/Interpreter/OptionValueChar.h
index 32ec2bb59fc55..2e2cf1ac1e08d 100644
--- a/lldb/include/lldb/Interpreter/OptionValueChar.h
+++ b/lldb/include/lldb/Interpreter/OptionValueChar.h
@@ -30,7 +30,7 @@ class OptionValueChar : public Cloneable<OptionValueChar, OptionValue> {
   void DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
                  uint32_t dump_mask) override;
 
-  llvm::json::Value ToJSON(const ExecutionContext *exe_ctx) override {
+  llvm::json::Value ToJSON(const ExecutionContext *exe_ctx) const override {
     return m_current_value;
   }
 
diff --git a/lldb/include/lldb/Interpreter/OptionValueDictionary.h b/lldb/include/lldb/Interpreter/OptionValueDictionary.h
index 18ef448237157..800b7fc687640 100644
--- a/lldb/include/lldb/Interpreter/OptionValueDictionary.h
+++ b/lldb/include/lldb/Interpreter/OptionValueDictionary.h
@@ -34,7 +34,7 @@ class OptionValueDictionary
   void DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
                  uint32_t dump_mask) override;
 
-  llvm::json::Value ToJSON(const ExecutionContext *exe_ctx) override;
+  llvm::json::Value ToJSON(const ExecutionContext *exe_ctx) const override;
 
   Status
   SetValueFromString(llvm::StringRef value,
diff --git a/lldb/include/lldb/Interpreter/OptionValueEnumeration.h b/lldb/include/lldb/Interpreter/OptionValueEnumeration.h
index 924fcc10cbb00..a3a13ca7b15eb 100644
--- a/lldb/include/lldb/Interpreter/OptionValueEnumeration.h
+++ b/lldb/include/lldb/Interpreter/OptionValueEnumeration.h
@@ -41,7 +41,7 @@ class OptionValueEnumeration
   void DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
                  uint32_t dump_mask) override;
 
-  llvm::json::Value ToJSON(const ExecutionContext *exe_ctx) override;
+  llvm::json::Value ToJSON(const ExecutionContext *exe_ctx) const override;
 
   Status
   SetValueFromString(llvm::StringRef value,
diff --git a/lldb/include/lldb/Interpreter/OptionValueFileColonLine.h b/lldb/include/lldb/Interpreter/OptionValueFileColonLine.h
index 181ef18bbcdf1..70f035da649e7 100644
--- a/lldb/include/lldb/Interpreter/OptionValueFileColonLine.h
+++ b/lldb/include/lldb/Interpreter/OptionValueFileColonLine.h
@@ -29,6 +29,8 @@ class OptionValueFileColonLine :
   void DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
                  uint32_t dump_mask) override;
 
+  llvm::json::Value ToJSON(const ExecutionContext *exe_ctx) const override;
+
   Status
   SetValueFromString(llvm::StringRef value,
                      VarSetOperationType op = eVarSetOperationAssign) override;
diff --git a/lldb/include/lldb/Interpreter/OptionValueFileSpec.h b/lldb/include/lldb/Interpreter/OptionValueFileSpec.h
index 52349bf36262f..66c5e328180f5 100644
--- a/lldb/include/lldb/Interpreter/OptionValueFileSpec.h
+++ b/lldb/include/lldb/Interpreter/OptionValueFileSpec.h
@@ -35,7 +35,7 @@ class OptionValueFileSpec : public Cloneable<OptionValueFileSpec, OptionValue> {
   void DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
                  uint32_t dump_mask) override;
 
-  llvm::json::Value ToJSON(const ExecutionContext *exe_ctx) override {
+  llvm::json::Value ToJSON(const ExecutionContext *exe_ctx) const override {
     return m_current_value.GetPath();
   }
 
diff --git a/lldb/include/lldb/Interpreter/OptionValueFileSpecList.h b/lldb/include/lldb/Interpreter/OptionValueFileSpecList.h
index 200ce701cb922..6250b5ee6fcb2 100644
--- a/lldb/include/lldb/Interpreter/OptionValueFileSpecList.h
+++ b/lldb/include/lldb/Interpreter/OptionValueFileSpecList.h
@@ -33,7 +33,7 @@ class OptionValueFileSpecList
   void DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
                  uint32_t dump_mask) override;
 
-  llvm::json::Value ToJSON(const ExecutionContext *exe_ctx) override;
+  llvm::json::Value ToJSON(const ExecutionContext *exe_ctx) const override;
 
   Status
   SetValueFromString(llvm::StringRef value,
diff --git a/lldb/include/lldb/Interpreter/OptionValueFormat.h b/lldb/include/lldb/Interpreter/OptionValueFormat.h
index 5be885fe4f70d..5fd3192304573 100644
--- a/lldb/include/lldb/Interpreter/OptionValueFormat.h
+++ b/lldb/include/lldb/Interpreter/OptionValueFormat.h
@@ -31,7 +31,7 @@ class OptionValueFormat
   void DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
                  uint32_t dump_mask) override;
 
-  llvm::json::Value ToJSON(const ExecutionContext *exe_ctx) override;
+  llvm::json::Value ToJSON(const ExecutionContext *exe_ctx) const override;
 
   Status
   SetValueFromString(llvm::StringRef value,
diff --git a/lldb/include/lldb/Interpreter/OptionValueFormatEntity.h b/lldb/include/lldb/Interpreter/OptionValueFormatEntity.h
index b8ef03a44d033..0718e37625d71 100644
--- a/lldb/include/lldb/Interpreter/OptionValueFormatEntity.h
+++ b/lldb/include/lldb/Interpreter/OptionValueFormatEntity.h
@@ -28,7 +28,7 @@ class OptionValueFormatEntity
   void DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
                  uint32_t dump_mask) override;
 
-  llvm::json::Value ToJSON(const ExecutionContext *exe_ctx) override;
+  llvm::json::Value ToJSON(const ExecutionContext *exe_ctx) const override;
 
   Status
   SetValueFromString(llvm::StringRef value,
diff --git a/lldb/include/lldb/Interpreter/OptionValueLanguage.h b/lldb/include/lldb/Interpreter/OptionValueLanguage.h
index f20a2c64f698d..e1c1f85493ad6 100644
--- a/lldb/include/lldb/Interpreter/OptionValueLanguage.h
+++ b/lldb/include/lldb/Interpreter/OptionValueLanguage.h
@@ -33,7 +33,7 @@ class OptionValueLanguage : public Cloneable<OptionValueLanguage, OptionValue> {
   void DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
                  uint32_t dump_mask) override;
 
-  llvm::json::Value ToJSON(const ExecutionContext *exe_ctx) override;
+  llvm::json::Value ToJSON(const ExecutionContext *exe_ctx) const override;
 
   Status
   SetValueFromString(llvm::StringRef value,
diff --git a/lldb/include/lldb/Interpreter/OptionValuePathMappings.h b/lldb/include/lldb/Interpreter/OptionValuePathMappings.h
index 82a968a77c12e..e0aac2fd44484 100644
--- a/lldb/include/lldb/Interpreter/OptionValuePathMappings.h
+++ b/lldb/include/lldb/Interpreter/OptionValuePathMappings.h
@@ -29,7 +29,7 @@ class OptionValuePathMappings
   void DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
                  uint32_t dump_mask) override;
 
-  llvm::json::Value ToJSON(const ExecutionContext *exe_ctx) override;
+  llvm::json::Value ToJSON(const ExecutionContext *exe_ctx) const override;
 
   Status
   SetValueFromString(llvm::StringRef value,
diff --git a/lldb/include/lldb/Interpreter/OptionValueProperties.h b/lldb/include/lldb/Interpreter/OptionValueProperties.h
index 2ee13c63c38c1..91a3955962372 100644
--- a/lldb/include/lldb/Interpreter/OptionValueProperties.h
+++ b/lldb/include/lldb/Interpreter/OptionValueProperties.h
@@ -46,7 +46,7 @@ class OptionValueProperties
   void DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
                  uint32_t dump_mask) override;
 
-  llvm::json::Value ToJSON(const ExecutionContext *exe_ctx) override;
+  llvm::json::Value ToJSON(const ExecutionContext *exe_ctx) const override;
 
   llvm::StringRef GetName() const override { return m_name; }
 
diff --git a/lldb/include/lldb/Interpreter/OptionValueRegex.h b/lldb/include/lldb/Interpreter/OptionValueRegex.h
index 3c188003ceb23..b952cb2476012 100644
--- a/lldb/include/lldb/Interpreter/OptionValueRegex.h
+++ b/lldb/include/lldb/Interpreter/OptionValueRegex.h
@@ -28,7 +28,7 @@ class OptionValueRegex : public Cloneable<OptionValueRegex, OptionValue> {
   void DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
                  uint32_t dump_mask) override;
 
-  llvm::json::Value ToJSON(const ExecutionContext *exe_ctx) override {
+  llvm::json::Value ToJSON(const ExecutionContext *exe_ctx) const override {
     return m_regex.GetText();
   }
 
diff --git a/lldb/include/lldb/Interpreter/OptionValueSInt64.h b/lldb/include/lldb/Interpreter/OptionValueSInt64.h
index f7e72684e4102..c220ac29e461f 100644
--- a/lldb/include/lldb/Interpreter/OptionValueSInt64.h
+++ b/lldb/include/lldb/Interpreter/OptionValueSInt64.h
@@ -35,7 +35,7 @@ class OptionValueSInt64 : public Cloneable<OptionValueSInt64, OptionValue> {
   void DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
                  uint32_t dump_mask) override;
 
-  llvm::json::Value ToJSON(const ExecutionContext *exe_ctx) override {
+  llvm::json::Value ToJSON(const ExecutionContext *exe_ctx) const override {
     return m_current_value;
   }
 
diff --git a/lldb/include/lldb/Interpreter/OptionValueString.h b/lldb/include/lldb/Interpreter/OptionValueString.h
index becf35f8e88ef..4ec98176b6f8b 100644
--- a/lldb/include/lldb/Interpreter/OptionValueString.h
+++ b/lldb/include/lldb/Interpreter/OptionValueString.h
@@ -69,7 +69,7 @@ class OptionValueString : public Cloneable<OptionValueString, OptionValue> {
   void DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
                  uint32_t dump_mask) override;
 
-  llvm::json::Value ToJSON(const ExecutionContext *exe_ctx) override {
+  llvm::json::Value ToJSON(const ExecutionContext *exe_ctx) const override {
     return m_current_value;
   }
 
diff --git a/lldb/include/lldb/Interpreter/OptionValueUInt64.h b/lldb/include/lldb/Interpreter/OptionValueUInt64.h
index 5cccff177cb1d..087c1d3ee321a 100644
--- a/lldb/include/lldb/Interpreter/OptionValueUInt64.h
+++ b/lldb/include/lldb/Interpreter/OptionValueUInt64.h
@@ -38,7 +38,7 @@ class OptionValueUInt64 : public Cloneable<OptionValueUInt64, OptionValue> {
   void DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
                  uint32_t dump_mask) override;
 
-  llvm::json::Value ToJSON(const ExecutionContext *exe_ctx) override {
+  llvm::json::Value ToJSON(const ExecutionContext *exe_ctx) const override {
     return m_current_value;
   }
 
diff --git a/lldb/include/lldb/Interpreter/OptionValueUUID.h b/lldb/include/lldb/Interpreter/OptionValueUUID.h
index e0e4235fdf076..2b7d9e41bcf77 100644
--- a/lldb/include/lldb/Interpreter/OptionValueUUID.h
+++ b/lldb/include/lldb/Interpreter/OptionValueUUID.h
@@ -29,7 +29,7 @@ class OptionValueUUID : public Cloneable<OptionValueUUID, OptionValue> {
   void DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
                  uint32_t dump_mask) override;
 
-  llvm::json::Value ToJSON(const ExecutionContext *exe_ctx) override {
+  llvm::json::Value ToJSON(const ExecutionContext *exe_ctx) const override {
     return m_uuid.GetAsString();
   }
 
diff --git a/lldb/include/lldb/Target/PathMappingList.h b/lldb/include/lldb/Target/PathMappingList.h
index 825278cf9afbc..2cf9569358f52 100644
--- a/lldb/include/lldb/Target/PathMappingList.h
+++ b/lldb/include/lldb/Target/PathMappingList.h
@@ -49,7 +49,7 @@ class PathMappingList {
   // By default, dump all pairs.
   void Dump(Stream *s, int pair_index = -1);
 
-  llvm::json::Value ToJSON();
+  llvm::json::Value ToJSON() const;
 
   bool IsEmpty() const {
     std::lock_guard<std::mutex> lock(m_pairs_mutex);
diff --git a/lldb/source/Interpreter/OptionValueArch.cpp b/lldb/source/Interpreter/OptionValueArch.cpp
index a2fed7737fc3e..bb47b5888421a 100644
--- a/lldb/source/Interpreter/OptionValueArch.cpp
+++ b/lldb/source/Interpreter/OptionValueArch.cpp
@@ -33,6 +33,15 @@ void OptionValueArch::DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
   }
 }
 
+llvm::json::Value
+OptionValueArch::ToJSON(const ExecutionContext *exe_ctx) const {
+  if (m_current_value.IsValid()) {
+    return llvm::json::Value(m_current_value.GetArchitectureName());
+  }
+
+  return {};
+}
+
 Status OptionValueArch::SetValueFromString(llvm::StringRef value,
                                            VarSetOperationType op) {
   Status error;
diff --git a/lldb/source/Interpreter/OptionValueArray.cpp b/lldb/source/Interpreter/OptionValueArray.cpp
index 067172dd5690a..f6c14dee525e9 100644
--- a/lldb/source/Interpreter/OptionValueArray.cpp
+++ b/lldb/source/Interpreter/OptionValueArray.cpp
@@ -75,7 +75,8 @@ void OptionValueArray::DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
   }
 }
 
-llvm::json::Value OptionValueArray::ToJSON(const ExecutionContext *exe_ctx) {
+llvm::json::Value
+OptionValueArray::ToJSON(const ExecutionContext *exe_ctx) const {
   llvm::json::Array json_array;
   const uint32_t size = m_values.size();
   for (uint32_t i = 0; i < size; ++i)
diff --git a/lldb/source/Interpreter/OptionValueDictionary.cpp b/lldb/source/Interpreter/OptionValueDictionary.cpp
index 4ee8e59d19a7b..19e21dd6f4c9a 100644
--- a/lldb/source/Interpreter/OptionValueDictionary.cpp
+++ b/lldb/source/Interpreter/OptionValueDictionary.cpp
@@ -88,7 +88,7 @@ void OptionValueDictionary::DumpValue(const ExecutionContext *exe_ctx,
 }
 
 llvm::json::Value
-OptionValueDictionary::ToJSON(const ExecutionContext *exe_ctx) {
+OptionValueDictionary::ToJSON(const ExecutionContext *exe_ctx) const {
   llvm::json::Object dict;
   for (const auto &value : m_values) {
     dict.try_emplace(value.first(), value.second->ToJSON(exe_ctx));
diff --git a/lldb/source/Interpreter/OptionValueEnumeration.cpp b/lldb/source/Interpreter/OptionValueEnumeration.cpp
index dd231f43e0d96..cf646233c80da 100644
--- a/lldb/source/Interpreter/OptionValueEnumeration.cpp
+++ b/lldb/source/Interpreter/OptionValueEnumeration.cpp
@@ -38,7 +38,7 @@ void OptionValueEnumeration::DumpValue(const ExecutionContext *exe_ctx,
 }
 
 llvm::json::Value
-OptionValueEnumeration::ToJSON(const ExecutionContext *exe_ctx) {
+OptionValueEnumeration::ToJSON(const ExecutionContext *exe_ctx) const {
   for (const auto &enums : m_enumerations) {
     if (enums.value.value == m_current_value)
       return enums.cstring.GetStringRef();
diff --git a/lldb/source/Interpreter/OptionValueFileColonLine.cpp b/lldb/source/Interpreter/OptionValueFileColonLine.cpp
index 87d390d1b5ef4..a4f65da8adb03 100644
--- a/lldb/source/Interpreter/OptionValueFileColonLine.cpp
+++ b/lldb/source/Interpreter/OptionValueFileColonLine.cpp
@@ -46,6 +46,19 @@ void OptionValueFileColonLine::DumpValue(const ExecutionContext *exe_ctx,
   }
 }
 
+llvm::json::Value
+OptionValueFileColonLine::ToJSON(const ExecutionContext *exe_ctx) const {
+  StreamString stream;
+  if (m_file_spec)
+    stream << '"' << m_file_spec.GetPath().c_str() << '"';
+  if (m_line_number != LLDB_INVALID_LINE_NUMBER)
+    stream.Printf(":%d", m_line_number);
+  if (m_column_number != LLDB_INVALID_COLUMN_NUMBER)
+    stream.Printf(":%d", m_column_number);
+
+  return llvm::json::Value(stream.GetString());
+}
+
 Status OptionValueFileColonLine::SetValueFromString(llvm::StringRef value,
                                                     VarSetOperationType op) {
   Status error;
diff --git a/lldb/source/Interpreter/OptionValueFileSpecList.cpp b/lldb/source/Interpreter/OptionValueFileSpecList.cpp
index 84607eb8d0595..f252dc4603cc1 100644
--- a/lldb/source/Interpreter/OptionValueFileSpecList.cpp
+++ b/lldb/source/Interpreter/OptionValueFileSpecList.cpp
@@ -42,7 +42,7 @@ void OptionValueFileSpecList::DumpValue(const ExecutionContext *exe_ctx,
 }
 
 llvm::json::Value
-OptionValueFileSpecList::ToJSON(const ExecutionContext *exe_ctx) {
+OptionValueFileSpecList::ToJSON(const ExecutionContext *exe_ctx) const {
   std::lock_guard<std::recursive_mutex> lock(m_mutex);
   llvm::json::Array array;
   for (const auto &file_spec : m_current_value)
diff --git a/lldb/source/Interpreter/OptionValueFormat.cpp b/lldb/source/Interpreter/OptionValueFormat.cpp
index ab89f673e96fe..bc4e77923d10e 100644
--- a/lldb/source/Interpreter/OptionValueFormat.cpp
+++ b/lldb/source/Interpreter/OptionValueFormat.cpp
@@ -26,7 +26,8 @@ void OptionValueFormat::DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
   }
 }
 
-llvm::json::Value OptionValueFormat::ToJSON(const ExecutionContext *exe_ctx) {
+llvm::json::Value
+OptionValueFormat::ToJSON(const ExecutionContext *exe_ctx) const {
   return FormatManager::GetFormatAsCString(m_current_value);
 }
 
diff --git a/lldb/source/Interpreter/OptionValueFormatEntity.cpp b/lldb/source/Interpreter/OptionValueFormatEntity.cpp
index addcfe019b4f7..d8b830115005c 100644
--- a/lldb/source/Interpreter/OptionValueFormatEntity.cpp
+++ b/lldb/source/Interpreter/OptionValueFormatEntity.cpp
@@ -61,7 +61,7 @@ void OptionValueFormatEntity::DumpValue(const ExecutionContext *exe_ctx,
 }
 
 llvm::json::Value
-OptionValueFormatEntity::ToJSON(const ExecutionContext *exe_ctx) {
+OptionValueFormatEntity::ToJSON(const ExecutionContext *exe_ctx) const {
   std::string escaped;
   EscapeBackticks(m_current_format, escaped);
   return escaped;
diff --git a/lldb/source/Interpreter/OptionValueLanguage.cpp b/lldb/source/Interpreter/OptionValueLanguage.cpp
index eb8eef0c600b2..0fdaacb02594e 100644
--- a/lldb/source/Interpreter/OptionValueLanguage.cpp
+++ b/lldb/source/Interpreter/OptionValueLanguage.cpp
@@ -29,7 +29,8 @@ void OptionValueLanguage::DumpValue(const ExecutionContext *exe_ctx,
   }
 }
 
-llvm::json::Value OptionValueLanguage::ToJSON(const ExecutionContext *exe_ctx) {
+llvm::json::Value
+OptionValueLanguage::ToJSON(const ExecutionContext *exe_ctx) const {
   return Language::GetNameForLanguageType(m_current_value);
 }
 
diff --git a/lldb/source/Interpreter/OptionValuePathMappings.cpp b/lldb/source/Interpreter/OptionValuePathMappin...
[truncated]

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.

Thank you, LGTM!

@da-viper da-viper merged commit d1adb0b into llvm:main Apr 27, 2025
10 checks passed
@da-viper da-viper deleted the complete_tojson_for_option_values branch April 27, 2025 11:11
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
Completes the ToJSON function for `OptionValue` types and make the interface function pure virtual

---------

Co-authored-by: Jonas Devlieghere <[email protected]>
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