649c0fee4bd9cc9c1fa8599516a1c912777f4ce0
[openbsd] /
1 """
2 Test lldb data formatter subsystem.
3 """
4
5
6
7 import lldb
8 from lldbsuite.test.decorators import *
9 from lldbsuite.test.lldbtest import *
10 from lldbsuite.test import lldbutil
11
12
13 class LibcxxVectorDataFormatterTestCase(TestBase):
14
15     mydir = TestBase.compute_mydir(__file__)
16
17     def check_numbers(self, var_name):
18         self.expect("frame variable " + var_name,
19                     substrs=[var_name + ' = size=7',
20                              '[0] = 1',
21                              '[1] = 12',
22                              '[2] = 123',
23                              '[3] = 1234',
24                              '[4] = 12345',
25                              '[5] = 123456',
26                              '[6] = 1234567',
27                              '}'])
28
29         self.expect("p " + var_name,
30                     substrs=['$', 'size=7',
31                              '[0] = 1',
32                              '[1] = 12',
33                              '[2] = 123',
34                              '[3] = 1234',
35                              '[4] = 12345',
36                              '[5] = 123456',
37                              '[6] = 1234567',
38                              '}'])
39
40         # check access-by-index
41         self.expect("frame variable " + var_name + "[0]",
42                     substrs=['1'])
43         self.expect("frame variable " + var_name + "[1]",
44                     substrs=['12'])
45         self.expect("frame variable " + var_name + "[2]",
46                     substrs=['123'])
47         self.expect("frame variable " + var_name + "[3]",
48                     substrs=['1234'])
49
50     @add_test_categories(["libc++"])
51     def test_with_run_command(self):
52         """Test that that file and class static variables display correctly."""
53         self.build()
54         (self.target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(
55             self, "break here", lldb.SBFileSpec("main.cpp", False))
56
57         # This is the function to remove the custom formats in order to have a
58         # clean slate for the next test case.
59         def cleanup():
60             self.runCmd('type format clear', check=False)
61             self.runCmd('type summary clear', check=False)
62             self.runCmd('type filter clear', check=False)
63             self.runCmd('type synth clear', check=False)
64             self.runCmd(
65                 "settings set target.max-children-count 256",
66                 check=False)
67
68         # Execute the cleanup function during test case tear down.
69         self.addTearDownHook(cleanup)
70
71         # empty vectors (and storage pointers SHOULD BOTH BE NULL..)
72         self.expect("frame variable numbers",
73                     substrs=['numbers = size=0'])
74
75         lldbutil.continue_to_breakpoint(process, bkpt)
76
77         # first value added
78         self.expect("frame variable numbers",
79                     substrs=['numbers = size=1',
80                              '[0] = 1',
81                              '}'])
82
83         # add some more data
84         lldbutil.continue_to_breakpoint(process, bkpt)
85
86         self.expect("frame variable numbers",
87                     substrs=['numbers = size=4',
88                              '[0] = 1',
89                              '[1] = 12',
90                              '[2] = 123',
91                              '[3] = 1234',
92                              '}'])
93
94         self.expect("p numbers",
95                     substrs=['$', 'size=4',
96                              '[0] = 1',
97                              '[1] = 12',
98                              '[2] = 123',
99                              '[3] = 1234',
100                              '}'])
101
102         # check access to synthetic children
103         self.runCmd(
104             "type summary add --summary-string \"item 0 is ${var[0]}\" std::int_vect int_vect")
105         self.expect('frame variable numbers',
106                     substrs=['item 0 is 1'])
107
108         self.runCmd(
109             "type summary add --summary-string \"item 0 is ${svar[0]}\" std::int_vect int_vect")
110         self.expect('frame variable numbers',
111                     substrs=['item 0 is 1'])
112         # move on with synths
113         self.runCmd("type summary delete std::int_vect")
114         self.runCmd("type summary delete int_vect")
115
116         # add some more data
117         lldbutil.continue_to_breakpoint(process, bkpt)
118
119         self.check_numbers("numbers")
120
121         # clear out the vector and see that we do the right thing once again
122         lldbutil.continue_to_breakpoint(process, bkpt)
123
124         self.expect("frame variable numbers",
125                     substrs=['numbers = size=0'])
126
127         lldbutil.continue_to_breakpoint(process, bkpt)
128
129         # first value added
130         self.expect("frame variable numbers",
131                     substrs=['numbers = size=1',
132                              '[0] = 7',
133                              '}'])
134
135         # check if we can display strings
136         self.expect("frame variable strings",
137                     substrs=['goofy',
138                              'is',
139                              'smart'])
140
141         self.expect("p strings",
142                     substrs=['goofy',
143                              'is',
144                              'smart'])
145
146         # test summaries based on synthetic children
147         self.runCmd(
148             "type summary add std::string_vect string_vect --summary-string \"vector has ${svar%#} items\" -e")
149         self.expect("frame variable strings",
150                     substrs=['vector has 3 items',
151                              'goofy',
152                              'is',
153                              'smart'])
154
155         self.expect("p strings",
156                     substrs=['vector has 3 items',
157                              'goofy',
158                              'is',
159                              'smart'])
160
161         lldbutil.continue_to_breakpoint(process, bkpt)
162
163         self.expect("frame variable strings",
164                     substrs=['vector has 4 items'])
165
166         # check access-by-index
167         self.expect("frame variable strings[0]",
168                     substrs=['goofy'])
169         self.expect("frame variable strings[1]",
170                     substrs=['is'])
171
172         lldbutil.continue_to_breakpoint(process, bkpt)
173
174         self.expect("frame variable strings",
175                     substrs=['vector has 0 items'])
176
177     @add_test_categories(["libc++"])
178     def test_ref_and_ptr(self):
179         """Test that that file and class static variables display correctly."""
180         self.build()
181         (self.target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(
182             self, "Stop here to check by ref", lldb.SBFileSpec("main.cpp", False))
183
184         # The reference should display the same was as the value did
185         self.check_numbers("ref")
186
187         # The pointer should just show the right number of elements:
188
189         self.expect("frame variable ptr", substrs=['ptr =', ' size=7'])
190
191         self.expect("p ptr", substrs=['$', 'size=7'])