07f7a538b92798cccf6d24f909170020b93f4f79
[openbsd] /
1 """
2 Test lldb data formatter subsystem.
3 """
4
5 import lldb
6 from lldbsuite.test.decorators import *
7 from lldbsuite.test.lldbtest import *
8 from lldbsuite.test import lldbutil
9
10
11 class CategoriesDataFormatterTestCase(TestBase):
12
13     mydir = TestBase.compute_mydir(__file__)
14
15     def setUp(self):
16         # Call super's setUp().
17         TestBase.setUp(self)
18         # Find the line number to break at.
19         self.line = line_number('main.cpp', '// Set break point at this line.')
20
21     @expectedFlakeyNetBSD
22     def test_with_run_command(self):
23         """Test that that file and class static variables display correctly."""
24         self.build()
25         self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
26
27         lldbutil.run_break_set_by_file_and_line(
28             self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True)
29
30         self.runCmd("run", RUN_SUCCEEDED)
31
32         # The stop reason of the thread should be breakpoint.
33         self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
34                     substrs=['stopped',
35                              'stop reason = breakpoint'])
36
37         # This is the function to remove the custom formats in order to have a
38         # clean slate for the next test case (most of these categories do not
39         # exist anymore, but we just make sure we delete all of them)
40         def cleanup():
41             self.runCmd('type format clear', check=False)
42             self.runCmd('type summary clear', check=False)
43             self.runCmd('type category delete Category1', check=False)
44             self.runCmd('type category delete Category2', check=False)
45             self.runCmd('type category delete NewCategory', check=False)
46             self.runCmd("type category delete CircleCategory", check=False)
47             self.runCmd(
48                 "type category delete RectangleStarCategory",
49                 check=False)
50             self.runCmd("type category delete BaseCategory", check=False)
51
52         # Execute the cleanup function during test case tear down.
53         self.addTearDownHook(cleanup)
54
55         # Add a summary to a new category and check that it works
56         self.runCmd(
57             "type summary add Rectangle --summary-string \"ARectangle\" -w NewCategory")
58
59         self.expect("frame variable r1 r2 r3", matching=False,
60                     substrs=['r1 = ARectangle',
61                              'r2 = ARectangle',
62                              'r3 = ARectangle'])
63
64         self.runCmd("type category enable NewCategory")
65
66         self.expect("frame variable r1 r2 r3", matching=True,
67                     substrs=['r1 = ARectangle',
68                              'r2 = ARectangle',
69                              'r3 = ARectangle'])
70
71         # Disable the category and check that the old stuff is there
72         self.runCmd("type category disable NewCategory")
73
74         self.expect("frame variable r1 r2 r3",
75                     substrs=['r1 = {',
76                              'r2 = {',
77                              'r3 = {'])
78
79         # Re-enable the category and check that it works
80         self.runCmd("type category enable NewCategory")
81
82         self.expect("frame variable r1 r2 r3",
83                     substrs=['r1 = ARectangle',
84                              'r2 = ARectangle',
85                              'r3 = ARectangle'])
86
87         # Delete the category and the old stuff should be there
88         self.runCmd("type category delete NewCategory")
89
90         self.expect("frame variable r1 r2 r3",
91                     substrs=['r1 = {',
92                              'r2 = {',
93                              'r3 = {'])
94
95         # Add summaries to two different categories and check that we can
96         # switch
97         self.runCmd(
98             "type summary add --summary-string \"Width = ${var.w}, Height = ${var.h}\" Rectangle -w Category1")
99         self.runCmd("type summary add --python-script \"return 'Area = ' + str( int(valobj.GetChildMemberWithName('w').GetValue()) * int(valobj.GetChildMemberWithName('h').GetValue()) );\" Rectangle -w Category2")
100
101         # check that enable A B is the same as enable B enable A
102         self.runCmd("type category enable Category1 Category2")
103
104         self.expect("frame variable r1 r2 r3",
105                     substrs=['r1 = Width = ',
106                              'r2 = Width = ',
107                              'r3 = Width = '])
108
109         self.runCmd("type category disable Category1")
110
111         self.expect("frame variable r1 r2 r3",
112                     substrs=['r1 = Area = ',
113                              'r2 = Area = ',
114                              'r3 = Area = '])
115
116         # switch again
117
118         self.runCmd("type category enable Category1")
119
120         self.expect("frame variable r1 r2 r3",
121                     substrs=['r1 = Width = ',
122                              'r2 = Width = ',
123                              'r3 = Width = '])
124
125         # Re-enable the category and show that the preference is persisted
126         self.runCmd("type category disable Category2")
127         self.runCmd("type category enable Category2")
128
129         self.expect("frame variable r1 r2 r3",
130                     substrs=['r1 = Area = ',
131                              'r2 = Area = ',
132                              'r3 = Area = '])
133
134         # Now delete the favorite summary
135         self.runCmd("type summary delete Rectangle -w Category2")
136
137         self.expect("frame variable r1 r2 r3",
138                     substrs=['r1 = Width = ',
139                              'r2 = Width = ',
140                              'r3 = Width = '])
141
142         # Delete the summary from the default category (that does not have it)
143         self.runCmd("type summary delete Rectangle", check=False)
144
145         self.expect("frame variable r1 r2 r3",
146                     substrs=['r1 = Width = ',
147                              'r2 = Width = ',
148                              'r3 = Width = '])
149
150         # Now add another summary to another category and switch back and forth
151         self.runCmd("type category delete Category1 Category2")
152
153         self.runCmd(
154             "type summary add Rectangle -w Category1 --summary-string \"Category1\"")
155         self.runCmd(
156             "type summary add Rectangle -w Category2 --summary-string \"Category2\"")
157
158         self.runCmd("type category enable Category2")
159         self.runCmd("type category enable Category1")
160
161         self.runCmd("type summary list -w Category1")
162         self.expect("type summary list -w NoSuchCategoryHere",
163                     substrs=['no matching results found'])
164
165         self.expect("frame variable r1 r2 r3",
166                     substrs=['r1 = Category1',
167                              'r2 = Category1',
168                              'r3 = Category1'])
169
170         self.runCmd("type category disable Category1")
171
172         self.expect("frame variable r1 r2 r3",
173                     substrs=['r1 = Category2',
174                              'r2 = Category2',
175                              'r3 = Category2'])
176
177         # Check that re-enabling an enabled category works
178         self.runCmd("type category enable Category1")
179
180         self.expect("frame variable r1 r2 r3",
181                     substrs=['r1 = Category1',
182                              'r2 = Category1',
183                              'r3 = Category1'])
184
185         self.runCmd("type category delete Category1")
186         self.runCmd("type category delete Category2")
187
188         self.expect("frame variable r1 r2 r3",
189                     substrs=['r1 = {',
190                              'r2 = {',
191                              'r3 = {'])
192
193         # Check that multiple summaries can go into one category
194         self.runCmd(
195             "type summary add -w Category1 --summary-string \"Width = ${var.w}, Height = ${var.h}\" Rectangle")
196         self.runCmd(
197             "type summary add -w Category1 --summary-string \"Radius = ${var.r}\" Circle")
198
199         self.runCmd("type category enable Category1")
200
201         self.expect("frame variable r1 r2 r3",
202                     substrs=['r1 = Width = ',
203                              'r2 = Width = ',
204                              'r3 = Width = '])
205
206         self.expect("frame variable c1 c2 c3",
207                     substrs=['c1 = Radius = ',
208                              'c2 = Radius = ',
209                              'c3 = Radius = '])
210
211         self.runCmd("type summary delete Circle -w Category1")
212
213         self.expect("frame variable c1 c2 c3",
214                     substrs=['c1 = {',
215                              'c2 = {',
216                              'c3 = {'])
217
218         # Add a regex based summary to a category
219         self.runCmd(
220             "type summary add -w Category1 --summary-string \"Radius = ${var.r}\" -x Circle")
221
222         self.expect("frame variable r1 r2 r3",
223                     substrs=['r1 = Width = ',
224                              'r2 = Width = ',
225                              'r3 = Width = '])
226
227         self.expect("frame variable c1 c2 c3",
228                     substrs=['c1 = Radius = ',
229                              'c2 = Radius = ',
230                              'c3 = Radius = '])
231
232         # Delete it
233         self.runCmd("type summary delete Circle -w Category1")
234
235         self.expect("frame variable c1 c2 c3",
236                     substrs=['c1 = {',
237                              'c2 = {',
238                              'c3 = {'])
239
240         # Change a summary inside a category and check that the change is
241         # reflected
242         self.runCmd(
243             "type summary add Circle -w Category1 --summary-string \"summary1\"")
244
245         self.expect("frame variable c1 c2 c3",
246                     substrs=['c1 = summary1',
247                              'c2 = summary1',
248                              'c3 = summary1'])
249
250         self.runCmd(
251             "type summary add Circle -w Category1 --summary-string \"summary2\"")
252
253         self.expect("frame variable c1 c2 c3",
254                     substrs=['c1 = summary2',
255                              'c2 = summary2',
256                              'c3 = summary2'])
257
258         # Check that our order of priority works. Start by clearing categories
259         self.runCmd("type category delete Category1")
260
261         self.runCmd(
262             "type summary add Shape -w BaseCategory --summary-string \"AShape\"")
263         self.runCmd("type category enable BaseCategory")
264
265         self.expect("print (Shape*)&c1",
266                     substrs=['AShape'])
267         self.expect("print (Shape*)&r1",
268                     substrs=['AShape'])
269         self.expect("print (Shape*)c_ptr",
270                     substrs=['AShape'])
271         self.expect("print (Shape*)r_ptr",
272                     substrs=['AShape'])
273
274         self.runCmd(
275             "type summary add Circle -w CircleCategory --summary-string \"ACircle\"")
276         self.runCmd(
277             "type summary add Rectangle -w RectangleCategory --summary-string \"ARectangle\"")
278         self.runCmd("type category enable CircleCategory")
279
280         self.expect("frame variable c1",
281                     substrs=['ACircle'])
282         self.expect("frame variable c_ptr",
283                     substrs=['ACircle'])
284
285         self.runCmd(
286             "type summary add \"Rectangle *\" -w RectangleStarCategory --summary-string \"ARectangleStar\"")
287         self.runCmd("type category enable RectangleStarCategory")
288
289         self.expect("frame variable c1 r1 c_ptr r_ptr",
290                     substrs=['ACircle',
291                              'ARectangleStar'])
292
293         self.runCmd("type category enable RectangleCategory")
294
295         self.expect("frame variable c1 r1 c_ptr r_ptr",
296                     substrs=['ACircle',
297                              'ACircle',
298                              'ARectangle'])
299
300         # Check that abruptly deleting an enabled category does not crash us
301         self.runCmd("type category delete RectangleCategory")
302
303         self.expect("frame variable c1 r1 c_ptr r_ptr",
304                     substrs=['ACircle',
305                              '(Rectangle) r1 = ', 'w = 5', 'h = 6',
306                              'ACircle',
307                              'ARectangleStar'])
308
309         # check that list commands work
310         self.expect("type category list",
311                     substrs=['RectangleStarCategory (enabled)'])
312
313         self.expect("type summary list",
314                     substrs=['ARectangleStar'])
315
316         # Disable a category and check that it fallsback
317         self.runCmd("type category disable CircleCategory")
318
319         # check that list commands work
320         self.expect("type category list",
321                     substrs=['CircleCategory (disabled'])
322
323         self.expect("frame variable c1 r_ptr",
324                     substrs=['AShape',
325                              'ARectangleStar'])
326
327         # check that filters work into categories
328         self.runCmd(
329             "type filter add Rectangle --child w --category RectangleCategory")
330         self.runCmd("type category enable RectangleCategory")
331         self.runCmd(
332             "type summary add Rectangle --category RectangleCategory --summary-string \" \" -e")
333         self.expect('frame variable r2',
334                     substrs=['w = 9'])
335         self.runCmd("type summary add Rectangle --summary-string \" \" -e")
336         self.expect('frame variable r2', matching=False,
337                     substrs=['h = 16'])
338
339         # Now delete all categories
340         self.runCmd(
341             "type category delete CircleCategory RectangleStarCategory BaseCategory RectangleCategory")
342
343         # check that a deleted category with filter does not blow us up
344         self.expect('frame variable r2',
345                     substrs=['w = 9',
346                              'h = 16'])
347
348         # and also validate that one can print formatters for a language
349         self.expect(
350             'type summary list -l c++',
351             substrs=[
352                 'vector',
353                 'map',
354                 'list',
355                 'string'])