[Lldb-commits] [lldb] 3068d27 - [lldb] Fix TestSBValueSynthetic on windows (#75908)

via lldb-commits lldb-commits at lists.llvm.org
Tue Dec 19 00:58:28 PST 2023


Author: Pavel Labath
Date: 2023-12-19T09:58:25+01:00
New Revision: 3068d277fd5ad0590a11dcb23af170ab31d7bda0

URL: https://github.com/llvm/llvm-project/commit/3068d277fd5ad0590a11dcb23af170ab31d7bda0
DIFF: https://github.com/llvm/llvm-project/commit/3068d277fd5ad0590a11dcb23af170ab31d7bda0.diff

LOG: [lldb] Fix TestSBValueSynthetic on windows (#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.

Added: 
    lldb/test/API/python_api/sbvalue_synthetic/formatter.py

Modified: 
    lldb/test/API/python_api/sbvalue_synthetic/TestSBValueSynthetic.py
    lldb/test/API/python_api/sbvalue_synthetic/main.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/test/API/python_api/sbvalue_synthetic/TestSBValueSynthetic.py b/lldb/test/API/python_api/sbvalue_synthetic/TestSBValueSynthetic.py
index 5dcf3c1a9c6c44..2fd1e0ce9c6a3d 100644
--- a/lldb/test/API/python_api/sbvalue_synthetic/TestSBValueSynthetic.py
+++ b/lldb/test/API/python_api/sbvalue_synthetic/TestSBValueSynthetic.py
@@ -12,8 +12,12 @@ 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..65e65afc3ef186
--- /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
 }


        


More information about the lldb-commits mailing list