d9da0c3886e28a02905a8fc542cd6f61fcdc338b
[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 LibcxxMapDataFormatterTestCase(TestBase):
14
15     mydir = TestBase.compute_mydir(__file__)
16
17     def setUp(self):
18         TestBase.setUp(self)
19         ns = 'ndk' if lldbplatformutil.target_is_android() else ''
20         self.namespace = 'std::__' + ns + '1'
21
22     @add_test_categories(["libc++"])
23     def test_with_run_command(self):
24         """Test that that file and class static variables display correctly."""
25         self.build()
26         self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
27
28         bkpt = self.target().FindBreakpointByID(
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         ns = self.namespace
54         self.expect('p ii',
55                     substrs=['%s::map' % ns,
56                              'size=0',
57                              '{}'])
58         self.expect('frame var ii',
59                     substrs=['%s::map' % ns,
60                              'size=0',
61                              '{}'])
62
63         lldbutil.continue_to_breakpoint(self.process(), bkpt)
64
65         self.expect('p ii',
66                     substrs=['%s::map' % ns, 'size=2',
67                              '[0] = ',
68                              'first = 0',
69                              'second = 0',
70                              '[1] = ',
71                              'first = 1',
72                              'second = 1'])
73
74         self.expect('frame variable ii',
75                     substrs=['%s::map' % ns, 'size=2',
76                              '[0] = ',
77                              'first = 0',
78                              'second = 0',
79                              '[1] = ',
80                              'first = 1',
81                              'second = 1'])
82
83         lldbutil.continue_to_breakpoint(self.process(), bkpt)
84
85         self.expect('frame variable ii',
86                     substrs=['%s::map' % ns, 'size=4',
87                              '[2] = ',
88                              'first = 2',
89                              'second = 0',
90                              '[3] = ',
91                              'first = 3',
92                              'second = 1'])
93
94         lldbutil.continue_to_breakpoint(self.process(), bkpt)
95
96         self.expect("p ii",
97                     substrs=['%s::map' % ns, 'size=8',
98                              '[5] = ',
99                              'first = 5',
100                              'second = 0',
101                              '[7] = ',
102                              'first = 7',
103                              'second = 1'])
104
105         self.expect("frame var ii",
106                     substrs=['%s::map' % ns, 'size=8',
107                              '[5] = ',
108                              'first = 5',
109                              'second = 0',
110                              '[7] = ',
111                              'first = 7',
112                              'second = 1'])
113
114         # check access-by-index
115         self.expect("frame variable ii[0]",
116                     substrs=['first = 0',
117                              'second = 0'])
118         self.expect("frame variable ii[3]",
119                     substrs=['first =',
120                              'second ='])
121
122         # check that MightHaveChildren() gets it right
123         self.assertTrue(
124             self.frame().FindVariable("ii").MightHaveChildren(),
125             "ii.MightHaveChildren() says False for non empty!")
126
127         # check that the expression parser does not make use of
128         # synthetic children instead of running code
129         # TOT clang has a fix for this, which makes the expression command here succeed
130         # since this would make the test fail or succeed depending on clang version in use
131         # this is safer commented for the time being
132         # self.expect("expression ii[8]", matching=False, error=True,
133         #            substrs = ['1234567'])
134
135         self.runCmd("continue")
136
137         self.expect('frame variable ii',
138                     substrs=['%s::map' % ns, 'size=0',
139                              '{}'])
140
141         self.expect('frame variable si',
142                     substrs=['%s::map' % ns, 'size=0',
143                              '{}'])
144
145         self.runCmd("continue")
146
147         self.expect('frame variable si',
148                     substrs=['%s::map' % ns, 'size=1',
149                              '[0] = ',
150                              'first = \"zero\"',
151                              'second = 0'])
152
153         lldbutil.continue_to_breakpoint(self.process(), bkpt)
154
155         self.expect("frame variable si",
156                     substrs=['%s::map' % ns, 'size=4',
157                              '[0] = ',
158                              'first = \"zero\"',
159                              'second = 0',
160                              '[1] = ',
161                              'first = \"one\"',
162                              'second = 1',
163                              '[2] = ',
164                              'first = \"two\"',
165                              'second = 2',
166                              '[3] = ',
167                              'first = \"three\"',
168                              'second = 3'])
169
170         self.expect("p si",
171                     substrs=['%s::map' % ns, 'size=4',
172                              '[0] = ',
173                              'first = \"zero\"',
174                              'second = 0',
175                              '[1] = ',
176                              'first = \"one\"',
177                              'second = 1',
178                              '[2] = ',
179                              'first = \"two\"',
180                              'second = 2',
181                              '[3] = ',
182                              'first = \"three\"',
183                              'second = 3'])
184
185         # check that MightHaveChildren() gets it right
186         self.assertTrue(
187             self.frame().FindVariable("si").MightHaveChildren(),
188             "si.MightHaveChildren() says False for non empty!")
189
190         # check access-by-index
191         self.expect("frame variable si[0]",
192                     substrs=['first = ', 'one',
193                              'second = 1'])
194
195         # check that the expression parser does not make use of
196         # synthetic children instead of running code
197         # TOT clang has a fix for this, which makes the expression command here succeed
198         # since this would make the test fail or succeed depending on clang version in use
199         # this is safer commented for the time being
200         # self.expect("expression si[0]", matching=False, error=True,
201         #            substrs = ['first = ', 'zero'])
202
203         lldbutil.continue_to_breakpoint(self.process(), bkpt)
204
205         self.expect('frame variable si',
206                     substrs=['%s::map' % ns, 'size=0',
207                              '{}'])
208
209         lldbutil.continue_to_breakpoint(self.process(), bkpt)
210
211         self.expect('frame variable is',
212                     substrs=['%s::map' % ns, 'size=0',
213                              '{}'])
214
215         lldbutil.continue_to_breakpoint(self.process(), bkpt)
216
217         self.expect("frame variable is",
218                     substrs=['%s::map' % ns, 'size=4',
219                              '[0] = ',
220                              'second = \"goofy\"',
221                              'first = 85',
222                              '[1] = ',
223                              'second = \"is\"',
224                              'first = 1',
225                              '[2] = ',
226                              'second = \"smart\"',
227                              'first = 2',
228                              '[3] = ',
229                              'second = \"!!!\"',
230                              'first = 3'])
231
232         self.expect("p is",
233                     substrs=['%s::map' % ns, 'size=4',
234                              '[0] = ',
235                              'second = \"goofy\"',
236                              'first = 85',
237                              '[1] = ',
238                              'second = \"is\"',
239                              'first = 1',
240                              '[2] = ',
241                              'second = \"smart\"',
242                              'first = 2',
243                              '[3] = ',
244                              'second = \"!!!\"',
245                              'first = 3'])
246
247         # check that MightHaveChildren() gets it right
248         self.assertTrue(
249             self.frame().FindVariable("is").MightHaveChildren(),
250             "is.MightHaveChildren() says False for non empty!")
251
252         # check access-by-index
253         self.expect("frame variable is[0]",
254                     substrs=['first = ',
255                              'second ='])
256
257         # check that the expression parser does not make use of
258         # synthetic children instead of running code
259         # TOT clang has a fix for this, which makes the expression command here succeed
260         # since this would make the test fail or succeed depending on clang version in use
261         # this is safer commented for the time being
262         # self.expect("expression is[0]", matching=False, error=True,
263         #            substrs = ['first = ', 'goofy'])
264
265         lldbutil.continue_to_breakpoint(self.process(), bkpt)
266
267         self.expect('frame variable is',
268                     substrs=['%s::map' % ns, 'size=0',
269                              '{}'])
270
271         lldbutil.continue_to_breakpoint(self.process(), bkpt)
272
273         self.expect('frame variable ss',
274                     substrs=['%s::map' % ns, 'size=0',
275                              '{}'])
276
277         lldbutil.continue_to_breakpoint(self.process(), bkpt)
278
279         self.expect("frame variable ss",
280                     substrs=['%s::map' % ns, 'size=3',
281                              '[0] = ',
282                              'second = \"hello\"',
283                              'first = \"ciao\"',
284                              '[1] = ',
285                              'second = \"house\"',
286                              'first = \"casa\"',
287                              '[2] = ',
288                              'second = \"cat\"',
289                              'first = \"gatto\"'])
290
291         self.expect("p ss",
292                     substrs=['%s::map' % ns, 'size=3',
293                              '[0] = ',
294                              'second = \"hello\"',
295                              'first = \"ciao\"',
296                              '[1] = ',
297                              'second = \"house\"',
298                              'first = \"casa\"',
299                              '[2] = ',
300                              'second = \"cat\"',
301                              'first = \"gatto\"'])
302
303         # check that MightHaveChildren() gets it right
304         self.assertTrue(
305             self.frame().FindVariable("ss").MightHaveChildren(),
306             "ss.MightHaveChildren() says False for non empty!")
307
308         # check access-by-index
309         self.expect("frame variable ss[2]",
310                     substrs=['gatto', 'cat'])
311
312         # check that the expression parser does not make use of
313         # synthetic children instead of running code
314         # TOT clang has a fix for this, which makes the expression command here succeed
315         # since this would make the test fail or succeed depending on clang version in use
316         # this is safer commented for the time being
317         # self.expect("expression ss[3]", matching=False, error=True,
318         #            substrs = ['gatto'])
319
320         lldbutil.continue_to_breakpoint(self.process(), bkpt)
321
322         self.expect('frame variable ss',
323                     substrs=['%s::map' % ns, 'size=0',
324                              '{}'])