Skip to content

Commit 4b41984

Browse files
da-viperJDevlieghere
andauthoredMar 21, 2025
[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 <[email protected]> Co-authored-by: Jonas Devlieghere <[email protected]>
1 parent 3bcab6f commit 4b41984

File tree

5 files changed

+36
-0
lines changed

5 files changed

+36
-0
lines changed
 

‎lldb/include/lldb/Interpreter/OptionValueFileSpecList.h

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ class OptionValueFileSpecList
3333
void DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
3434
uint32_t dump_mask) override;
3535

36+
llvm::json::Value ToJSON(const ExecutionContext *exe_ctx) override;
37+
3638
Status
3739
SetValueFromString(llvm::StringRef value,
3840
VarSetOperationType op = eVarSetOperationAssign) override;

‎lldb/include/lldb/Utility/FileSpec.h

+11
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "llvm/ADT/StringRef.h"
1919
#include "llvm/Support/FileSystem.h"
2020
#include "llvm/Support/FormatVariadic.h"
21+
#include "llvm/Support/JSON.h"
2122
#include "llvm/Support/Path.h"
2223

2324
#include <cstddef>
@@ -214,6 +215,16 @@ class FileSpec {
214215
/// The stream to which to dump the object description.
215216
void Dump(llvm::raw_ostream &s) const;
216217

218+
/// Convert the filespec object to a json value.
219+
///
220+
/// Convert the filespec object to a json value. If the object contains a
221+
/// valid directory name, it will be displayed followed by a directory
222+
/// delimiter, and the filename.
223+
///
224+
/// \return
225+
/// A json value representation of a filespec.
226+
llvm::json::Value ToJSON() const;
227+
217228
Style GetPathStyle() const;
218229

219230
/// Directory string const get accessor.

‎lldb/source/Interpreter/OptionValueFileSpecList.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@ void OptionValueFileSpecList::DumpValue(const ExecutionContext *exe_ctx,
4141
}
4242
}
4343

44+
llvm::json::Value
45+
OptionValueFileSpecList::ToJSON(const ExecutionContext *exe_ctx) {
46+
std::lock_guard<std::recursive_mutex> lock(m_mutex);
47+
llvm::json::Array array;
48+
for (const auto &file_spec : m_current_value)
49+
array.emplace_back(file_spec.ToJSON());
50+
return array;
51+
}
52+
4453
Status OptionValueFileSpecList::SetValueFromString(llvm::StringRef value,
4554
VarSetOperationType op) {
4655
std::lock_guard<std::recursive_mutex> lock(m_mutex);

‎lldb/source/Utility/FileSpec.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,13 @@ void FileSpec::Dump(llvm::raw_ostream &s) const {
330330
s << path_separator;
331331
}
332332

333+
llvm::json::Value FileSpec::ToJSON() const {
334+
std::string str;
335+
llvm::raw_string_ostream stream(str);
336+
this->Dump(stream);
337+
return llvm::json::Value(std::move(str));
338+
}
339+
333340
FileSpec::Style FileSpec::GetPathStyle() const { return m_style; }
334341

335342
void FileSpec::SetDirectory(ConstString directory) {

‎lldb/test/API/commands/settings/TestSettings.py

+7
Original file line numberDiff line numberDiff line change
@@ -1016,6 +1016,13 @@ def test_settings_api(self):
10161016
settings_json = self.get_setting_json(setting_path)
10171017
self.assertEqual(settings_json, setting_value)
10181018

1019+
# Test OptionValueFileSpec and OptionValueFileSpecList
1020+
setting_path = "target.debug-file-search-paths"
1021+
setting_value = ["/tmp" "/tmp2"]
1022+
self.runCmd("settings set %s %s" % (setting_path, " ".join(setting_value)))
1023+
settings_json = self.get_setting_json(setting_path)
1024+
self.assertEqual(settings_json, setting_value)
1025+
10191026
# Test OptionValueFormatEntity
10201027
setting_value = """thread #${thread.index}{, name = \\'${thread.name}\\
10211028
'}{, queue = ${ansi.fg.green}\\'${thread.queue}\\'${ansi.normal}}{,

0 commit comments

Comments
 (0)
Please sign in to comment.