llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-lldb Author: Pavel Labath (labath) <details> <summary>Changes</summary> We don't have a std::vector formatter on windows, so use a custom formatter in this test to avoid relying on std::vector. --- Full diff: https://github.com/llvm/llvm-project/pull/75908.diff 3 Files Affected: - (modified) lldb/test/API/python_api/sbvalue_synthetic/TestSBValueSynthetic.py (+6-4) - (added) lldb/test/API/python_api/sbvalue_synthetic/formatter.py (+23) - (modified) lldb/test/API/python_api/sbvalue_synthetic/main.cpp (+7-5) ``````````diff 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 } `````````` </details> https://github.com/llvm/llvm-project/pull/75908 _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits