Skip to content

Commit 3068d27

Browse files
authored
[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.
1 parent 87bf1af commit 3068d27

File tree

3 files changed

+38
-9
lines changed

3 files changed

+38
-9
lines changed

lldb/test/API/python_api/sbvalue_synthetic/TestSBValueSynthetic.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,12 @@ def test_str(self):
1212
lldbutil.run_to_source_breakpoint(
1313
self, "break here", lldb.SBFileSpec("main.cpp")
1414
)
15+
self.runCmd("command script import formatter.py")
16+
self.runCmd(
17+
"type synthetic add --python-class formatter.FooSyntheticProvider Foo"
18+
)
1519

16-
vector = self.frame().FindVariable("vector")
17-
has_vector = self.frame().FindVariable("has_vector")
18-
self.expect(str(vector), exe=False, substrs=["42", "47"])
19-
self.expect(str(has_vector), exe=False, substrs=["42", "47"])
20+
formatted = self.frame().FindVariable("foo")
21+
has_formatted = self.frame().FindVariable("has_foo")
22+
self.expect(str(formatted), exe=False, substrs=["synth_child"])
23+
self.expect(str(has_formatted), exe=False, substrs=["synth_child"])
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import lldb
2+
3+
4+
class FooSyntheticProvider:
5+
def __init__(self, valobj, dict):
6+
target = valobj.GetTarget()
7+
data = lldb.SBData.CreateDataFromCString(lldb.eByteOrderLittle, 8, "S")
8+
self._child = valobj.CreateValueFromData(
9+
"synth_child", data, target.GetBasicType(lldb.eBasicTypeChar)
10+
)
11+
12+
def num_children(self):
13+
return 1
14+
15+
def get_child_at_index(self, index):
16+
if index != 0:
17+
return None
18+
return self._child
19+
20+
def get_child_index(self, name):
21+
if name == "synth_child":
22+
return 0
23+
return None
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
#include <vector>
1+
struct Foo {
2+
int real_child = 47;
3+
};
24

3-
struct HasVector {
4-
std::vector<int> v;
5+
struct HasFoo {
6+
Foo f;
57
};
68

79
int main() {
8-
std::vector<int> vector = {42, 47};
9-
HasVector has_vector = {vector};
10+
Foo foo;
11+
HasFoo has_foo;
1012
return 0; // break here
1113
}

0 commit comments

Comments
 (0)