https://github.com/labath created https://github.com/llvm/llvm-project/pull/75908
We don't have a std::vector formatter on windows, so use a custom formatter in this test to avoid relying on std::vector. >From b8dbd31b95058f8098f9ef57c540a1635a9a1fde Mon Sep 17 00:00:00 2001 From: Pavel Labath <pa...@labath.sk> Date: Tue, 19 Dec 2023 09:37:20 +0100 Subject: [PATCH] [lldb] Fix TestSBValueSynthetic on windows We don't have a std::vector formatter on windows, so use a custom formatter in this test to avoid relying on std::vector. --- .../sbvalue_synthetic/TestSBValueSynthetic.py | 10 ++++---- .../python_api/sbvalue_synthetic/formatter.py | 23 +++++++++++++++++++ .../API/python_api/sbvalue_synthetic/main.cpp | 12 ++++++---- 3 files changed, 36 insertions(+), 9 deletions(-) create mode 100644 lldb/test/API/python_api/sbvalue_synthetic/formatter.py diff --git a/lldb/test/API/python_api/sbvalue_synthetic/TestSBValueSynthetic.py b/lldb/test/API/python_api/sbvalue_synthetic/TestSBValueSynthetic.py index 5dcf3c1a9c6c44..62a9477533ba44 100644 --- a/lldb/test/API/python_api/sbvalue_synthetic/TestSBValueSynthetic.py +++ b/lldb/test/API/python_api/sbvalue_synthetic/TestSBValueSynthetic.py @@ -12,8 +12,10 @@ def test_str(self): lldbutil.run_to_source_breakpoint( self, "break here", lldb.SBFileSpec("main.cpp") ) + self.runCmd("command script import formatter.py") + self.runCmd("type synthetic add --python-class formatter.FooSyntheticProvider Foo") - vector = self.frame().FindVariable("vector") - has_vector = self.frame().FindVariable("has_vector") - self.expect(str(vector), exe=False, substrs=["42", "47"]) - self.expect(str(has_vector), exe=False, substrs=["42", "47"]) + formatted = self.frame().FindVariable("foo") + has_formatted = self.frame().FindVariable("has_foo") + self.expect(str(formatted), exe=False, substrs=["synth_child"]) + self.expect(str(has_formatted), exe=False, substrs=["synth_child"]) diff --git a/lldb/test/API/python_api/sbvalue_synthetic/formatter.py b/lldb/test/API/python_api/sbvalue_synthetic/formatter.py new file mode 100644 index 00000000000000..17a436c37ed0f3 --- /dev/null +++ b/lldb/test/API/python_api/sbvalue_synthetic/formatter.py @@ -0,0 +1,23 @@ +import lldb + + +class FooSyntheticProvider: + def __init__(self, valobj, dict): + target = valobj.GetTarget() + data = lldb.SBData.CreateDataFromCString(lldb.eByteOrderLittle, 8, "S") + self._child = valobj.CreateValueFromData( + "synth_child", data, target.GetBasicType(lldb.eBasicTypeChar) + ) + + def num_children(self): + return 1 + + def get_child_at_index(self, index): + if index != 0: + return None + return self._child + + def get_child_index(self, name): + if name == "synth_child": + return 0 + return None diff --git a/lldb/test/API/python_api/sbvalue_synthetic/main.cpp b/lldb/test/API/python_api/sbvalue_synthetic/main.cpp index e6b6ec50f307f8..52c6474d7a1b28 100644 --- a/lldb/test/API/python_api/sbvalue_synthetic/main.cpp +++ b/lldb/test/API/python_api/sbvalue_synthetic/main.cpp @@ -1,11 +1,13 @@ -#include <vector> +struct Foo { + int real_child = 47; +}; -struct HasVector { - std::vector<int> v; +struct HasFoo { + Foo f; }; int main() { - std::vector<int> vector = {42, 47}; - HasVector has_vector = {vector}; + Foo foo; + HasFoo has_foo; return 0; // break here } _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits