2 Test lldb data formatter subsystem.
6 from lldbsuite.test.decorators import *
7 from lldbsuite.test.lldbtest import *
8 from lldbsuite.test import lldbutil
11 class CategoriesDataFormatterTestCase(TestBase):
13 mydir = TestBase.compute_mydir(__file__)
16 # Call super's setUp().
18 # Find the line number to break at.
19 self.line = line_number('main.cpp', '// Set break point at this line.')
22 def test_with_run_command(self):
23 """Test that that file and class static variables display correctly."""
25 self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
27 lldbutil.run_break_set_by_file_and_line(
28 self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True)
30 self.runCmd("run", RUN_SUCCEEDED)
32 # The stop reason of the thread should be breakpoint.
33 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
35 'stop reason = breakpoint'])
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)
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)
48 "type category delete RectangleStarCategory",
50 self.runCmd("type category delete BaseCategory", check=False)
52 # Execute the cleanup function during test case tear down.
53 self.addTearDownHook(cleanup)
55 # Add a summary to a new category and check that it works
57 "type summary add Rectangle --summary-string \"ARectangle\" -w NewCategory")
59 self.expect("frame variable r1 r2 r3", matching=False,
60 substrs=['r1 = ARectangle',
64 self.runCmd("type category enable NewCategory")
66 self.expect("frame variable r1 r2 r3", matching=True,
67 substrs=['r1 = ARectangle',
71 # Disable the category and check that the old stuff is there
72 self.runCmd("type category disable NewCategory")
74 self.expect("frame variable r1 r2 r3",
79 # Re-enable the category and check that it works
80 self.runCmd("type category enable NewCategory")
82 self.expect("frame variable r1 r2 r3",
83 substrs=['r1 = ARectangle',
87 # Delete the category and the old stuff should be there
88 self.runCmd("type category delete NewCategory")
90 self.expect("frame variable r1 r2 r3",
95 # Add summaries to two different categories and check that we can
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")
101 # check that enable A B is the same as enable B enable A
102 self.runCmd("type category enable Category1 Category2")
104 self.expect("frame variable r1 r2 r3",
105 substrs=['r1 = Width = ',
109 self.runCmd("type category disable Category1")
111 self.expect("frame variable r1 r2 r3",
112 substrs=['r1 = Area = ',
118 self.runCmd("type category enable Category1")
120 self.expect("frame variable r1 r2 r3",
121 substrs=['r1 = Width = ',
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")
129 self.expect("frame variable r1 r2 r3",
130 substrs=['r1 = Area = ',
134 # Now delete the favorite summary
135 self.runCmd("type summary delete Rectangle -w Category2")
137 self.expect("frame variable r1 r2 r3",
138 substrs=['r1 = Width = ',
142 # Delete the summary from the default category (that does not have it)
143 self.runCmd("type summary delete Rectangle", check=False)
145 self.expect("frame variable r1 r2 r3",
146 substrs=['r1 = Width = ',
150 # Now add another summary to another category and switch back and forth
151 self.runCmd("type category delete Category1 Category2")
154 "type summary add Rectangle -w Category1 --summary-string \"Category1\"")
156 "type summary add Rectangle -w Category2 --summary-string \"Category2\"")
158 self.runCmd("type category enable Category2")
159 self.runCmd("type category enable Category1")
161 self.runCmd("type summary list -w Category1")
162 self.expect("type summary list -w NoSuchCategoryHere",
163 substrs=['no matching results found'])
165 self.expect("frame variable r1 r2 r3",
166 substrs=['r1 = Category1',
170 self.runCmd("type category disable Category1")
172 self.expect("frame variable r1 r2 r3",
173 substrs=['r1 = Category2',
177 # Check that re-enabling an enabled category works
178 self.runCmd("type category enable Category1")
180 self.expect("frame variable r1 r2 r3",
181 substrs=['r1 = Category1',
185 self.runCmd("type category delete Category1")
186 self.runCmd("type category delete Category2")
188 self.expect("frame variable r1 r2 r3",
193 # Check that multiple summaries can go into one category
195 "type summary add -w Category1 --summary-string \"Width = ${var.w}, Height = ${var.h}\" Rectangle")
197 "type summary add -w Category1 --summary-string \"Radius = ${var.r}\" Circle")
199 self.runCmd("type category enable Category1")
201 self.expect("frame variable r1 r2 r3",
202 substrs=['r1 = Width = ',
206 self.expect("frame variable c1 c2 c3",
207 substrs=['c1 = Radius = ',
211 self.runCmd("type summary delete Circle -w Category1")
213 self.expect("frame variable c1 c2 c3",
218 # Add a regex based summary to a category
220 "type summary add -w Category1 --summary-string \"Radius = ${var.r}\" -x Circle")
222 self.expect("frame variable r1 r2 r3",
223 substrs=['r1 = Width = ',
227 self.expect("frame variable c1 c2 c3",
228 substrs=['c1 = Radius = ',
233 self.runCmd("type summary delete Circle -w Category1")
235 self.expect("frame variable c1 c2 c3",
240 # Change a summary inside a category and check that the change is
243 "type summary add Circle -w Category1 --summary-string \"summary1\"")
245 self.expect("frame variable c1 c2 c3",
246 substrs=['c1 = summary1',
251 "type summary add Circle -w Category1 --summary-string \"summary2\"")
253 self.expect("frame variable c1 c2 c3",
254 substrs=['c1 = summary2',
258 # Check that our order of priority works. Start by clearing categories
259 self.runCmd("type category delete Category1")
262 "type summary add Shape -w BaseCategory --summary-string \"AShape\"")
263 self.runCmd("type category enable BaseCategory")
265 self.expect("print (Shape*)&c1",
267 self.expect("print (Shape*)&r1",
269 self.expect("print (Shape*)c_ptr",
271 self.expect("print (Shape*)r_ptr",
275 "type summary add Circle -w CircleCategory --summary-string \"ACircle\"")
277 "type summary add Rectangle -w RectangleCategory --summary-string \"ARectangle\"")
278 self.runCmd("type category enable CircleCategory")
280 self.expect("frame variable c1",
282 self.expect("frame variable c_ptr",
286 "type summary add \"Rectangle *\" -w RectangleStarCategory --summary-string \"ARectangleStar\"")
287 self.runCmd("type category enable RectangleStarCategory")
289 self.expect("frame variable c1 r1 c_ptr r_ptr",
293 self.runCmd("type category enable RectangleCategory")
295 self.expect("frame variable c1 r1 c_ptr r_ptr",
300 # Check that abruptly deleting an enabled category does not crash us
301 self.runCmd("type category delete RectangleCategory")
303 self.expect("frame variable c1 r1 c_ptr r_ptr",
305 '(Rectangle) r1 = ', 'w = 5', 'h = 6',
309 # check that list commands work
310 self.expect("type category list",
311 substrs=['RectangleStarCategory (enabled)'])
313 self.expect("type summary list",
314 substrs=['ARectangleStar'])
316 # Disable a category and check that it fallsback
317 self.runCmd("type category disable CircleCategory")
319 # check that list commands work
320 self.expect("type category list",
321 substrs=['CircleCategory (disabled'])
323 self.expect("frame variable c1 r_ptr",
327 # check that filters work into categories
329 "type filter add Rectangle --child w --category RectangleCategory")
330 self.runCmd("type category enable RectangleCategory")
332 "type summary add Rectangle --category RectangleCategory --summary-string \" \" -e")
333 self.expect('frame variable r2',
335 self.runCmd("type summary add Rectangle --summary-string \" \" -e")
336 self.expect('frame variable r2', matching=False,
339 # Now delete all categories
341 "type category delete CircleCategory RectangleStarCategory BaseCategory RectangleCategory")
343 # check that a deleted category with filter does not blow us up
344 self.expect('frame variable r2',
348 # and also validate that one can print formatters for a language
350 'type summary list -l c++',