2 Test lldb data formatter subsystem.
8 from lldbsuite.test.lldbtest import *
9 import lldbsuite.test.lldbutil as lldbutil
12 class SynthDataFormatterTestCase(TestBase):
14 mydir = TestBase.compute_mydir(__file__)
17 # Call super's setUp().
19 # Find the line number to break at.
20 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.
40 self.runCmd('type format clear', check=False)
41 self.runCmd('type summary clear', check=False)
42 self.runCmd('type filter clear', check=False)
44 # Execute the cleanup function during test case tear down.
45 self.addTearDownHook(cleanup)
47 # Pick some values and check that the basics work
48 self.runCmd("type filter add BagOfInts --child x --child z")
49 self.expect("frame variable int_bag",
53 # Check we can still access the missing child by summary
55 "type summary add BagOfInts --summary-string \"y=${var.y}\"")
56 self.expect('frame variable int_bag',
59 # Even if we have synth children, the summary prevails
60 self.expect("frame variable int_bag", matching=False,
64 # if we skip synth and summary show y
66 "frame variable int_bag --synthetic-type false --no-summary-depth=1",
72 # if we ask for raw output same happens
73 self.expect("frame variable int_bag --raw-output",
78 # Summary+Synth must work together
80 "type summary add BagOfInts --summary-string \"x=${var.x}\" -e")
81 self.expect('frame variable int_bag',
86 # Same output, but using Python
88 "type summary add BagOfInts --python-script \"return 'x=%s' % valobj.GetChildMemberWithName('x').GetValue()\" -e")
89 self.expect('frame variable int_bag',
94 # If I skip summaries, still give me the artificial children
95 self.expect("frame variable int_bag --no-summary-depth=1",
99 # Delete synth and check that the view reflects it immediately
100 self.runCmd("type filter delete BagOfInts")
101 self.expect("frame variable int_bag",
106 # Add the synth again and check that it's honored deeper in the
108 self.runCmd("type filter add BagOfInts --child x --child z")
109 self.expect('frame variable bag_bag',
110 substrs=['x = x=69 {',
116 self.expect('frame variable bag_bag', matching=False,
120 # Check that a synth can expand nested stuff
121 self.runCmd("type filter add BagOfBags --child x.y --child y.z")
122 self.expect('frame variable bag_bag',
126 # ...even if we get -> and . wrong
127 self.runCmd("type filter add BagOfBags --child x.y --child \"y->z\"")
128 self.expect('frame variable bag_bag',
134 "type filter add BagOfBags --child x.y --child \"y->z[1-2]\"")
135 self.expect('frame variable bag_bag --show-types',
137 '(int:2) y->z[1-2] = 2'])
139 # ...even if we format the bitfields
141 "type filter add BagOfBags --child x.y --child \"y->y[0-0]\"")
142 self.runCmd("type format add \"int:1\" -f bool")
143 self.expect('frame variable bag_bag --show-types',
145 '(int:1) y->y[0-0] = true'])
147 # ...even if we use one-liner summaries
148 self.runCmd("type summary add -c BagOfBags")
149 self.expect('frame variable bag_bag', substrs=[
150 '(BagOfBags) bag_bag = (x.y = 70, y->y[0-0] = true)'])
152 self.runCmd("type summary delete BagOfBags")
154 # now check we are dynamic (and arrays work)
156 "type filter add Plenty --child bitfield --child array[0] --child array[2]")
157 self.expect('frame variable plenty_of_stuff',
158 substrs=['bitfield = 1',
163 self.expect('frame variable plenty_of_stuff',
164 substrs=['bitfield = 17',
168 # skip synthetic children
169 self.expect('frame variable plenty_of_stuff --synthetic-type no',
170 substrs=['some_values = 0x',
174 # check flat printing with synthetic children
175 self.expect('frame variable plenty_of_stuff --flat',
176 substrs=['plenty_of_stuff.bitfield = 17',
177 '*(plenty_of_stuff.array) = 5',
178 '*(plenty_of_stuff.array) = 3'])
180 # check that we do not lose location information for our children
181 self.expect('frame variable plenty_of_stuff --location',
185 # check we work across pointer boundaries
186 self.expect('frame variable plenty_of_stuff.some_values --ptr-depth=1',
187 substrs=['(BagOfInts *) plenty_of_stuff.some_values',
191 # but not if we don't want to
192 self.runCmd("type filter add BagOfInts --child x --child z -p")
193 self.expect('frame variable plenty_of_stuff.some_values --ptr-depth=1',
194 substrs=['(BagOfInts *) plenty_of_stuff.some_values',
199 # check we're dynamic even if nested
200 self.runCmd("type filter add BagOfBags --child x.z")
201 self.expect('frame variable bag_bag',
202 substrs=['x.z = 71'])
205 self.expect('frame variable bag_bag',
206 substrs=['x.z = 12'])
209 'type summary add -e -s "I am always empty but have" EmptyStruct')
210 self.expect('frame variable es', substrs=[
211 "I am always empty but have {}"])
212 self.runCmd('type summary add -e -h -s "I am really empty" EmptyStruct')
213 self.expect('frame variable es', substrs=["I am really empty"])
216 substrs=["I am really empty {}"],