94d1b573f4018fd9fde8751d9381dc95c35c6b25
[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 StdMapDataFormatterTestCase(TestBase):
14
15     mydir = TestBase.compute_mydir(__file__)
16
17     def setUp(self):
18         # Call super's setUp().
19         TestBase.setUp(self)
20         # Find the line number to break at.
21         self.line = line_number('main.cpp', '// Set break point at this line.')
22
23     @add_test_categories(["libstdcxx"])
24     def test_with_run_command(self):
25         """Test that that file and class static variables display correctly."""
26         self.build()
27         self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
28
29         lldbutil.run_break_set_by_source_regexp(
30             self, "Set break point at this line.")
31
32         self.runCmd("run", RUN_SUCCEEDED)
33
34         # The stop reason of the thread should be breakpoint.
35         self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
36                     substrs=['stopped',
37                              'stop reason = breakpoint'])
38
39         # This is the function to remove the custom formats in order to have a
40         # clean slate for the next test case.
41         def cleanup():
42             self.runCmd('type format clear', check=False)
43             self.runCmd('type summary clear', check=False)
44             self.runCmd('type filter clear', check=False)
45             self.runCmd('type synth clear', check=False)
46             self.runCmd(
47                 "settings set target.max-children-count 256",
48                 check=False)
49
50         # Execute the cleanup function during test case tear down.
51         self.addTearDownHook(cleanup)
52
53         self.runCmd("frame variable ii --show-types")
54
55         self.runCmd(
56             "type summary add -x \"std::map<\" --summary-string \"map has ${svar%#} items\" -e")
57
58         self.expect('frame variable ii',
59                     substrs=['map has 0 items',
60                              '{}'])
61
62         self.runCmd("c")
63
64         self.expect('frame variable ii',
65                     substrs=['map has 2 items',
66                              '[0] = ',
67                              'first = 0',
68                              'second = 0',
69                              '[1] = ',
70                              'first = 1',
71                              'second = 1'])
72
73         self.runCmd("c")
74
75         self.expect('frame variable ii',
76                     substrs=['map has 4 items',
77                              '[2] = ',
78                              'first = 2',
79                              'second = 0',
80                              '[3] = ',
81                              'first = 3',
82                              'second = 1'])
83
84         self.runCmd("c")
85
86         self.expect("frame variable ii",
87                     substrs=['map has 9 items',
88                              '[5] = ',
89                              'first = 5',
90                              'second = 0',
91                              '[7] = ',
92                              'first = 7',
93                              'second = 1'])
94
95         self.expect("p ii",
96                     substrs=['map has 9 items',
97                              '[5] = ',
98                              'first = 5',
99                              'second = 0',
100                              '[7] = ',
101                              'first = 7',
102                              'second = 1'])
103
104         # check access-by-index
105         self.expect("frame variable ii[0]",
106                     substrs=['first = 0',
107                              'second = 0'])
108         self.expect("frame variable ii[3]",
109                     substrs=['first =',
110                              'second ='])
111
112         self.expect("frame variable ii[8]", matching=True,
113                     substrs=['1234567'])
114
115         # check that MightHaveChildren() gets it right
116         self.assertTrue(
117             self.frame().FindVariable("ii").MightHaveChildren(),
118             "ii.MightHaveChildren() says False for non empty!")
119
120         # check that the expression parser does not make use of
121         # synthetic children instead of running code
122         # TOT clang has a fix for this, which makes the expression command here succeed
123         # since this would make the test fail or succeed depending on clang version in use
124         # this is safer commented for the time being
125         # self.expect("expression ii[8]", matching=False, error=True,
126         #            substrs = ['1234567'])
127
128         self.runCmd("c")
129
130         self.expect('frame variable ii',
131                     substrs=['map has 0 items',
132                              '{}'])
133
134         self.runCmd("frame variable si --show-types")
135
136         self.expect('frame variable si',
137                     substrs=['map has 0 items',
138                              '{}'])
139
140         self.runCmd("c")
141
142         self.expect('frame variable si',
143                     substrs=['map has 1 items',
144                              '[0] = ',
145                              'first = \"zero\"',
146                              'second = 0'])
147
148         self.runCmd("c")
149
150         self.expect("frame variable si",
151                     substrs=['map has 5 items',
152                              '[0] = ',
153                              'first = \"zero\"',
154                              'second = 0',
155                              '[1] = ',
156                              'first = \"one\"',
157                              'second = 1',
158                              '[2] = ',
159                              'first = \"two\"',
160                              'second = 2',
161                              '[3] = ',
162                              'first = \"three\"',
163                              'second = 3',
164                              '[4] = ',
165                              'first = \"four\"',
166                              'second = 4'])
167
168         self.expect("p si",
169                     substrs=['map has 5 items',
170                              '[0] = ',
171                              'first = \"zero\"',
172                              'second = 0',
173                              '[1] = ',
174                              'first = \"one\"',
175                              'second = 1',
176                              '[2] = ',
177                              'first = \"two\"',
178                              'second = 2',
179                              '[3] = ',
180                              'first = \"three\"',
181                              'second = 3',
182                              '[4] = ',
183                              'first = \"four\"',
184                              'second = 4'])
185
186         # check access-by-index
187         self.expect("frame variable si[0]",
188                     substrs=['first = ', 'four',
189                              'second = 4'])
190
191         # check that MightHaveChildren() gets it right
192         self.assertTrue(
193             self.frame().FindVariable("si").MightHaveChildren(),
194             "si.MightHaveChildren() says False for non empty!")
195
196         # check that the expression parser does not make use of
197         # synthetic children instead of running code
198         # TOT clang has a fix for this, which makes the expression command here succeed
199         # since this would make the test fail or succeed depending on clang version in use
200         # this is safer commented for the time being
201         # self.expect("expression si[0]", matching=False, error=True,
202         #            substrs = ['first = ', 'zero'])
203
204         self.runCmd("c")
205
206         self.expect('frame variable si',
207                     substrs=['map has 0 items',
208                              '{}'])
209
210         self.runCmd("frame variable is --show-types")
211
212         self.expect('frame variable is',
213                     substrs=['map has 0 items',
214                              '{}'])
215
216         self.runCmd("c")
217
218         self.expect("frame variable is",
219                     substrs=['map has 4 items',
220                              '[0] = ',
221                              'second = \"goofy\"',
222                              'first = 85',
223                              '[1] = ',
224                              'second = \"is\"',
225                              'first = 1',
226                              '[2] = ',
227                              'second = \"smart\"',
228                              'first = 2',
229                              '[3] = ',
230                              'second = \"!!!\"',
231                              'first = 3'])
232
233         self.expect("p is",
234                     substrs=['map has 4 items',
235                              '[0] = ',
236                              'second = \"goofy\"',
237                              'first = 85',
238                              '[1] = ',
239                              'second = \"is\"',
240                              'first = 1',
241                              '[2] = ',
242                              'second = \"smart\"',
243                              'first = 2',
244                              '[3] = ',
245                              'second = \"!!!\"',
246                              'first = 3'])
247
248         # check access-by-index
249         self.expect("frame variable is[0]",
250                     substrs=['first = ',
251                              'second ='])
252
253         # check that MightHaveChildren() gets it right
254         self.assertTrue(
255             self.frame().FindVariable("is").MightHaveChildren(),
256             "is.MightHaveChildren() says False for non empty!")
257
258         # check that the expression parser does not make use of
259         # synthetic children instead of running code
260         # TOT clang has a fix for this, which makes the expression command here succeed
261         # since this would make the test fail or succeed depending on clang version in use
262         # this is safer commented for the time being
263         # self.expect("expression is[0]", matching=False, error=True,
264         #            substrs = ['first = ', 'goofy'])
265
266         self.runCmd("c")
267
268         self.expect('frame variable is',
269                     substrs=['map has 0 items',
270                              '{}'])
271
272         self.runCmd("frame variable ss --show-types")
273
274         self.expect('frame variable ss',
275                     substrs=['map has 0 items',
276                              '{}'])
277
278         self.runCmd("c")
279
280         self.expect("frame variable ss",
281                     substrs=['map has 4 items',
282                              '[0] = ',
283                              'second = \"hello\"',
284                              'first = \"ciao\"',
285                              '[1] = ',
286                              'second = \"house\"',
287                              'first = \"casa\"',
288                              '[2] = ',
289                              'second = \"cat\"',
290                              'first = \"gatto\"',
291                              '[3] = ',
292                              'second = \"..is always a Mac!\"',
293                              'first = \"a Mac..\"'])
294
295         self.expect("p ss",
296                     substrs=['map has 4 items',
297                              '[0] = ',
298                              'second = \"hello\"',
299                              'first = \"ciao\"',
300                              '[1] = ',
301                              'second = \"house\"',
302                              'first = \"casa\"',
303                              '[2] = ',
304                              'second = \"cat\"',
305                              'first = \"gatto\"',
306                              '[3] = ',
307                              'second = \"..is always a Mac!\"',
308                              'first = \"a Mac..\"'])
309
310         # check access-by-index
311         self.expect("frame variable ss[3]",
312                     substrs=['gatto', 'cat'])
313
314         # check that MightHaveChildren() gets it right
315         self.assertTrue(
316             self.frame().FindVariable("ss").MightHaveChildren(),
317             "ss.MightHaveChildren() says False for non empty!")
318
319         # check that the expression parser does not make use of
320         # synthetic children instead of running code
321         # TOT clang has a fix for this, which makes the expression command here succeed
322         # since this would make the test fail or succeed depending on clang version in use
323         # this is safer commented for the time being
324         # self.expect("expression ss[3]", matching=False, error=True,
325         #            substrs = ['gatto'])
326
327         self.runCmd("c")
328
329         self.expect('frame variable ss',
330                     substrs=['map has 0 items',
331                              '{}'])