[Lldb-commits] [lldb] [lldb] Show target.debug-file-search-paths setting from python SBDebugger (PR #131683)
Ebuka Ezike via lldb-commits
lldb-commits at lists.llvm.org
Wed Mar 19 04:34:49 PDT 2025
https://github.com/da-viper updated https://github.com/llvm/llvm-project/pull/131683
>From 6d9b82be9fc681f25967a57a5c23148f3d023022 Mon Sep 17 00:00:00 2001
From: Ebuka Ezike <yerimyah1 at gmail.com>
Date: Mon, 17 Mar 2025 23:54:30 +0000
Subject: [PATCH 1/5] [lldb] Add JSON serialization for FileSpec and
FileSpecList
Add a `ToJSON` method in FileSpec and OptionValueFileSpecList to enable JSON serialization.
---
.../lldb/Interpreter/OptionValueFileSpecList.h | 2 ++
lldb/include/lldb/Utility/FileSpec.h | 12 ++++++++++++
lldb/source/Interpreter/OptionValueFileSpecList.cpp | 10 ++++++++++
lldb/source/Utility/FileSpec.cpp | 7 +++++++
4 files changed, 31 insertions(+)
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..386a31f7b5c4a 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,17 @@ 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..9877d5033a88f 100644
--- a/lldb/source/Interpreter/OptionValueFileSpecList.cpp
+++ b/lldb/source/Interpreter/OptionValueFileSpecList.cpp
@@ -41,6 +41,16 @@ 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 spec_list;
+ for (const auto &file_spec : m_current_value) {
+ spec_list.emplace_back(file_spec.ToJSON());
+ }
+ return spec_list;
+}
+
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..57d2bc0a07164 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 file_spec{};
+ llvm::raw_string_ostream stream(file_spec);
+ this->Dump(stream);
+ return llvm::json::Value(std::move(file_spec));
+}
+
FileSpec::Style FileSpec::GetPathStyle() const { return m_style; }
void FileSpec::SetDirectory(ConstString directory) {
>From f455bb7cbe3505ccc7c29c04e0435bf56fd630ea Mon Sep 17 00:00:00 2001
From: Ebuka Ezike <yerimyah1 at gmail.com>
Date: Mon, 17 Mar 2025 23:57:00 +0000
Subject: [PATCH 2/5] Update lldb/include/lldb/Utility/FileSpec.h
Co-authored-by: Jonas Devlieghere <jonas at devlieghere.com>
---
lldb/include/lldb/Utility/FileSpec.h | 1 -
1 file changed, 1 deletion(-)
diff --git a/lldb/include/lldb/Utility/FileSpec.h b/lldb/include/lldb/Utility/FileSpec.h
index 386a31f7b5c4a..3fa89b1dcff28 100644
--- a/lldb/include/lldb/Utility/FileSpec.h
+++ b/lldb/include/lldb/Utility/FileSpec.h
@@ -215,7 +215,6 @@ 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
>From d2848a768db3d01484a285c919ea2487a0ec0fb2 Mon Sep 17 00:00:00 2001
From: Ebuka Ezike <yerimyah1 at gmail.com>
Date: Mon, 17 Mar 2025 23:57:10 +0000
Subject: [PATCH 3/5] Update
lldb/source/Interpreter/OptionValueFileSpecList.cpp
Co-authored-by: Jonas Devlieghere <jonas at devlieghere.com>
---
lldb/source/Interpreter/OptionValueFileSpecList.cpp | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/lldb/source/Interpreter/OptionValueFileSpecList.cpp b/lldb/source/Interpreter/OptionValueFileSpecList.cpp
index 9877d5033a88f..567a44900851c 100644
--- a/lldb/source/Interpreter/OptionValueFileSpecList.cpp
+++ b/lldb/source/Interpreter/OptionValueFileSpecList.cpp
@@ -45,9 +45,8 @@ llvm::json::Value
OptionValueFileSpecList::ToJSON(const ExecutionContext *exe_ctx) {
std::lock_guard<std::recursive_mutex> lock(m_mutex);
llvm::json::Array spec_list;
- for (const auto &file_spec : m_current_value) {
+ for (const auto &file_spec : m_current_value)
spec_list.emplace_back(file_spec.ToJSON());
- }
return spec_list;
}
>From 19b0f6f0a93c07ddbf74d82c6c85526d10ac2e73 Mon Sep 17 00:00:00 2001
From: Ebuka Ezike <yerimyah1 at gmail.com>
Date: Tue, 18 Mar 2025 00:08:18 +0000
Subject: [PATCH 4/5] [lldb] update requested changes.
---
lldb/source/Interpreter/OptionValueFileSpecList.cpp | 8 ++++----
lldb/source/Utility/FileSpec.cpp | 6 +++---
2 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/lldb/source/Interpreter/OptionValueFileSpecList.cpp b/lldb/source/Interpreter/OptionValueFileSpecList.cpp
index 567a44900851c..84607eb8d0595 100644
--- a/lldb/source/Interpreter/OptionValueFileSpecList.cpp
+++ b/lldb/source/Interpreter/OptionValueFileSpecList.cpp
@@ -44,10 +44,10 @@ 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 spec_list;
- for (const auto &file_spec : m_current_value)
- spec_list.emplace_back(file_spec.ToJSON());
- return spec_list;
+ 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,
diff --git a/lldb/source/Utility/FileSpec.cpp b/lldb/source/Utility/FileSpec.cpp
index 57d2bc0a07164..1520026dfee88 100644
--- a/lldb/source/Utility/FileSpec.cpp
+++ b/lldb/source/Utility/FileSpec.cpp
@@ -331,10 +331,10 @@ void FileSpec::Dump(llvm::raw_ostream &s) const {
}
llvm::json::Value FileSpec::ToJSON() const {
- std::string file_spec{};
- llvm::raw_string_ostream stream(file_spec);
+ std::string str{};
+ llvm::raw_string_ostream stream(str);
this->Dump(stream);
- return llvm::json::Value(std::move(file_spec));
+ return llvm::json::Value(std::move(str));
}
FileSpec::Style FileSpec::GetPathStyle() const { return m_style; }
>From a1bd945f9016860404fb1facdceb1dabf0259ad7 Mon Sep 17 00:00:00 2001
From: Ebuka Ezike <yerimyah1 at gmail.com>
Date: Wed, 19 Mar 2025 11:33:11 +0000
Subject: [PATCH 5/5] [lldb] Add test for OptionValueFileSpec and
OptionValueFileSpecList
Signed-off-by: Ebuka Ezike <yerimyah1 at gmail.com>
---
lldb/source/Utility/FileSpec.cpp | 2 +-
lldb/test/API/commands/settings/TestSettings.py | 7 +++++++
2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/lldb/source/Utility/FileSpec.cpp b/lldb/source/Utility/FileSpec.cpp
index 1520026dfee88..bb2b8647342b8 100644
--- a/lldb/source/Utility/FileSpec.cpp
+++ b/lldb/source/Utility/FileSpec.cpp
@@ -331,7 +331,7 @@ void FileSpec::Dump(llvm::raw_ostream &s) const {
}
llvm::json::Value FileSpec::ToJSON() const {
- std::string str{};
+ std::string str;
llvm::raw_string_ostream stream(str);
this->Dump(stream);
return llvm::json::Value(std::move(str));
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