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