[lldb] Show target.debug-file-search-paths setting from  python SBDebugger (#131683)

When printing setting variables using the python SBDebugger API if the type is of OptionValueFileSpec
it defaults to null as the value even if it has a value. This patch fixes that.

---------

Signed-off-by: Ebuka Ezike <yerimyah1@gmail.com>
Co-authored-by: Jonas Devlieghere <jonas@devlieghere.com>
diff --git a/lldb/include/lldb/Interpreter/OptionValueFileSpecList.h b/lldb/include/lldb/Interpreter/OptionValueFileSpecList.h
index bda6b50..200ce70 100644
--- a/lldb/include/lldb/Interpreter/OptionValueFileSpecList.h
+++ b/lldb/include/lldb/Interpreter/OptionValueFileSpecList.h
@@ -33,6 +33,8 @@
   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/include/lldb/Utility/FileSpec.h b/lldb/include/lldb/Utility/FileSpec.h
index 2e867b2..3fa89b1 100644
--- a/lldb/include/lldb/Utility/FileSpec.h
+++ b/lldb/include/lldb/Utility/FileSpec.h
@@ -18,6 +18,7 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/FormatVariadic.h"
+#include "llvm/Support/JSON.h"
 #include "llvm/Support/Path.h"
 
 #include <cstddef>
@@ -214,6 +215,16 @@
   ///     The stream to which to dump the object description.
   void Dump(llvm::raw_ostream &s) const;
 
+  /// Convert the filespec object to a json value.
+  ///
+  /// Convert the filespec object to a json value. If the object contains a
+  /// valid directory name, it will be displayed followed by a directory
+  /// delimiter, and the filename.
+  ///
+  /// \return
+  ///     A json value representation of a filespec.
+  llvm::json::Value ToJSON() const;
+
   Style GetPathStyle() const;
 
   /// Directory string const get accessor.
diff --git a/lldb/source/Interpreter/OptionValueFileSpecList.cpp b/lldb/source/Interpreter/OptionValueFileSpecList.cpp
index 98f4938..84607eb 100644
--- a/lldb/source/Interpreter/OptionValueFileSpecList.cpp
+++ b/lldb/source/Interpreter/OptionValueFileSpecList.cpp
@@ -41,6 +41,15 @@
   }
 }
 
+llvm::json::Value
+OptionValueFileSpecList::ToJSON(const ExecutionContext *exe_ctx) {
+  std::lock_guard<std::recursive_mutex> lock(m_mutex);
+  llvm::json::Array array;
+  for (const auto &file_spec : m_current_value)
+    array.emplace_back(file_spec.ToJSON());
+  return array;
+}
+
 Status OptionValueFileSpecList::SetValueFromString(llvm::StringRef value,
                                                    VarSetOperationType op) {
   std::lock_guard<std::recursive_mutex> lock(m_mutex);
diff --git a/lldb/source/Utility/FileSpec.cpp b/lldb/source/Utility/FileSpec.cpp
index 4bebbc9..bb2b864 100644
--- a/lldb/source/Utility/FileSpec.cpp
+++ b/lldb/source/Utility/FileSpec.cpp
@@ -330,6 +330,13 @@
     s << path_separator;
 }
 
+llvm::json::Value FileSpec::ToJSON() const {
+  std::string str;
+  llvm::raw_string_ostream stream(str);
+  this->Dump(stream);
+  return llvm::json::Value(std::move(str));
+}
+
 FileSpec::Style FileSpec::GetPathStyle() const { return m_style; }
 
 void FileSpec::SetDirectory(ConstString directory) {
diff --git a/lldb/test/API/commands/settings/TestSettings.py b/lldb/test/API/commands/settings/TestSettings.py
index d36e088..6b89ff7 100644
--- a/lldb/test/API/commands/settings/TestSettings.py
+++ b/lldb/test/API/commands/settings/TestSettings.py
@@ -1016,6 +1016,13 @@
         settings_json = self.get_setting_json(setting_path)
         self.assertEqual(settings_json, setting_value)
 
+        # Test OptionValueFileSpec and OptionValueFileSpecList
+        setting_path = "target.debug-file-search-paths"
+        setting_value = ["/tmp" "/tmp2"]
+        self.runCmd("settings set %s %s" % (setting_path, " ".join(setting_value)))
+        settings_json = self.get_setting_json(setting_path)
+        self.assertEqual(settings_json, setting_value)
+
         # Test OptionValueFormatEntity
         setting_value = """thread #${thread.index}{, name = \\'${thread.name}\\
         '}{, queue = ${ansi.fg.green}\\'${thread.queue}\\'${ansi.normal}}{,