[Lldb-commits] [lldb] [lldb] Fix TestSBValueSynthetic on windows (PR #75908)
Pavel Labath via lldb-commits
lldb-commits at lists.llvm.org
Tue Dec 19 00:55:17 PST 2023
https://github.com/labath updated https://github.com/llvm/llvm-project/pull/75908
>From b8dbd31b95058f8098f9ef57c540a1635a9a1fde Mon Sep 17 00:00:00 2001
From: Pavel Labath <pavel at labath.sk>
Date: Tue, 19 Dec 2023 09:37:20 +0100
Subject: [PATCH 1/2] [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
}
>From beb831ccee568bc2cee79e3fbcacc07866700b32 Mon Sep 17 00:00:00 2001
From: Pavel Labath <pavel at labath.sk>
Date: Tue, 19 Dec 2023 09:54:45 +0100
Subject: [PATCH 2/2] fixup! [lldb] Fix TestSBValueSynthetic on windows
---
.../API/python_api/sbvalue_synthetic/TestSBValueSynthetic.py | 4 +++-
lldb/test/API/python_api/sbvalue_synthetic/formatter.py | 2 +-
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/lldb/test/API/python_api/sbvalue_synthetic/TestSBValueSynthetic.py b/lldb/test/API/python_api/sbvalue_synthetic/TestSBValueSynthetic.py
index 62a9477533ba44..2fd1e0ce9c6a3d 100644
--- a/lldb/test/API/python_api/sbvalue_synthetic/TestSBValueSynthetic.py
+++ b/lldb/test/API/python_api/sbvalue_synthetic/TestSBValueSynthetic.py
@@ -13,7 +13,9 @@ def test_str(self):
self, "break here", lldb.SBFileSpec("main.cpp")
)
self.runCmd("command script import formatter.py")
- self.runCmd("type synthetic add --python-class formatter.FooSyntheticProvider Foo")
+ self.runCmd(
+ "type synthetic add --python-class formatter.FooSyntheticProvider Foo"
+ )
formatted = self.frame().FindVariable("foo")
has_formatted = self.frame().FindVariable("has_foo")
diff --git a/lldb/test/API/python_api/sbvalue_synthetic/formatter.py b/lldb/test/API/python_api/sbvalue_synthetic/formatter.py
index 17a436c37ed0f3..65e65afc3ef186 100644
--- a/lldb/test/API/python_api/sbvalue_synthetic/formatter.py
+++ b/lldb/test/API/python_api/sbvalue_synthetic/formatter.py
@@ -6,7 +6,7 @@ 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)
+ "synth_child", data, target.GetBasicType(lldb.eBasicTypeChar)
)
def num_children(self):
More information about the lldb-commits
mailing list