[Lldb-commits] [lldb] 4b41984 - [lldb] Show target.debug-file-search-paths setting from python SBDebugger (#131683)
via lldb-commits
lldb-commits at lists.llvm.org
Fri Mar 21 04:20:40 PDT 2025
Author: Ebuka Ezike
Date: 2025-03-21T11:20:35Z
New Revision: 4b419840c883b0de03ae72c7d352c37f24c1932c
URL: https://github.com/llvm/llvm-project/commit/4b419840c883b0de03ae72c7d352c37f24c1932c
DIFF: https://github.com/llvm/llvm-project/commit/4b419840c883b0de03ae72c7d352c37f24c1932c.diff
LOG: [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 at gmail.com>
Co-authored-by: Jonas Devlieghere <jonas at devlieghere.com>
Added:
Modified:
lldb/include/lldb/Interpreter/OptionValueFileSpecList.h
lldb/include/lldb/Utility/FileSpec.h
lldb/source/Interpreter/OptionValueFileSpecList.cpp
lldb/source/Utility/FileSpec.cpp
lldb/test/API/commands/settings/TestSettings.py
Removed:
################################################################################
diff --git a/lldb/include/lldb/Interpreter/OptionValueFileSpecList.h b/lldb/include/lldb/Interpreter/OptionValueFileSpecList.h
index bda6b5071d599..200ce701cb922 100644
--- a/lldb/include/lldb/Interpreter/OptionValueFileSpecList.h
+++ b/lldb/include/lldb/Interpreter/OptionValueFileSpecList.h
@@ -33,6 +33,8 @@ class OptionValueFileSpecList
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 2e867b2b40b94..3fa89b1dcff28 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 @@ class FileSpec {
/// 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 98f4938fc6c19..84607eb8d0595 100644
--- a/lldb/source/Interpreter/OptionValueFileSpecList.cpp
+++ b/lldb/source/Interpreter/OptionValueFileSpecList.cpp
@@ -41,6 +41,15 @@ void OptionValueFileSpecList::DumpValue(const ExecutionContext *exe_ctx,
}
}
+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 4bebbc9ff175f..bb2b8647342b8 100644
--- a/lldb/source/Utility/FileSpec.cpp
+++ b/lldb/source/Utility/FileSpec.cpp
@@ -330,6 +330,13 @@ void FileSpec::Dump(llvm::raw_ostream &s) const {
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 d36e08875919a..6b89ff76a2900 100644
--- a/lldb/test/API/commands/settings/TestSettings.py
+++ b/lldb/test/API/commands/settings/TestSettings.py
@@ -1016,6 +1016,13 @@ def test_settings_api(self):
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}}{,
More information about the lldb-commits
mailing list