2 Test lldb data formatter subsystem.
5 from __future__ import print_function
9 from lldbsuite.test.decorators import *
10 from lldbsuite.test.lldbtest import *
11 from lldbsuite.test import lldbutil
14 class PythonSynthDataFormatterTestCase(TestBase):
16 mydir = TestBase.compute_mydir(__file__)
18 @skipIfFreeBSD # llvm.org/pr20545 bogus output confuses buildbot parser
19 def test_with_run_command(self):
20 """Test data formatter commands."""
22 self.data_formatter_commands()
24 def test_rdar10960550_with_run_command(self):
25 """Test data formatter commands."""
27 self.rdar10960550_formatter_commands()
30 # Call super's setUp().
32 # Find the line number to break at.
33 self.line = line_number('main.cpp', '// Set break point at this line.')
34 self.line2 = line_number('main.cpp',
35 '// Set cast break point at this line.')
36 self.line3 = line_number(
37 'main.cpp', '// Set second cast break point at this line.')
39 def data_formatter_commands(self):
40 """Test using Python synthetic children provider."""
41 self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
43 lldbutil.run_break_set_by_file_and_line(
44 self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True)
46 self.runCmd("run", RUN_SUCCEEDED)
48 process = self.dbg.GetSelectedTarget().GetProcess()
50 # The stop reason of the thread should be breakpoint.
51 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
53 'stop reason = breakpoint'])
55 # This is the function to remove the custom formats in order to have a
56 # clean slate for the next test case.
58 self.runCmd('type format clear', check=False)
59 self.runCmd('type summary clear', check=False)
60 self.runCmd('type filter clear', check=False)
61 self.runCmd('type synth clear', check=False)
63 # Execute the cleanup function during test case tear down.
64 self.addTearDownHook(cleanup)
66 # print the f00_1 variable without a synth
67 self.expect("frame variable f00_1",
72 # now set up the synth
73 self.runCmd("script from fooSynthProvider import *")
74 self.runCmd("type synth add -l fooSynthProvider foo")
75 self.expect("type synthetic list foo", substrs=['fooSynthProvider'])
77 # note that the value of fake_a depends on target byte order
78 if process.GetByteOrder() == lldb.eByteOrderLittle:
79 fake_a_val = 0x02000000
81 fake_a_val = 0x00000100
83 # check that we get the two real vars and the fake_a variables
84 self.expect("frame variable f00_1",
86 'fake_a = %d' % fake_a_val,
89 # check that we do not get the extra vars
90 self.expect("frame variable f00_1", matching=False,
93 # check access to members by name
94 self.expect('frame variable f00_1.fake_a',
95 substrs=['%d' % fake_a_val])
97 # check access to members by index
98 self.expect('frame variable f00_1[1]',
99 substrs=['%d' % fake_a_val])
101 # put synthetic children in summary in several combinations
103 "type summary add --summary-string \"fake_a=${svar.fake_a}\" foo")
104 self.expect('frame variable f00_1',
105 substrs=['fake_a=%d' % fake_a_val])
107 "type summary add --summary-string \"fake_a=${svar[1]}\" foo")
108 self.expect('frame variable f00_1',
109 substrs=['fake_a=%d' % fake_a_val])
112 self.runCmd("type summary delete foo")
114 # check that the caching does not span beyond the stopoint
117 if process.GetByteOrder() == lldb.eByteOrderLittle:
118 fake_a_val = 0x02000000
120 fake_a_val = 0x00000200
122 self.expect("frame variable f00_1",
124 'fake_a = %d' % fake_a_val,
127 # check that altering the object also alters fake_a
128 self.runCmd("expr f00_1.a = 280")
130 if process.GetByteOrder() == lldb.eByteOrderLittle:
131 fake_a_val = 0x02000001
133 fake_a_val = 0x00011800
135 self.expect("frame variable f00_1",
137 'fake_a = %d' % fake_a_val,
140 # check that expanding a pointer does the right thing
141 if process.GetByteOrder() == lldb.eByteOrderLittle:
142 fake_a_val = 0x0d000000
144 fake_a_val = 0x00000c00
146 self.expect("frame variable --ptr-depth 1 f00_ptr",
148 'fake_a = %d' % fake_a_val,
151 # now add a filter.. it should fail
152 self.expect("type filter add foo --child b --child j", error=True,
153 substrs=['cannot add'])
155 # we get the synth again..
156 self.expect('frame variable f00_1', matching=False,
159 self.expect("frame variable --ptr-depth 1 f00_ptr",
161 'fake_a = %d' % fake_a_val,
164 # now delete the synth and add the filter
165 self.runCmd("type synth delete foo")
166 self.runCmd("type filter add foo --child b --child j")
168 self.expect('frame variable f00_1',
171 self.expect("frame variable --ptr-depth 1 f00_ptr", matching=False,
173 'fake_a = %d' % fake_a_val,
176 # now add the synth and it should fail
177 self.expect("type synth add -l fooSynthProvider foo", error=True,
178 substrs=['cannot add'])
181 self.expect('type synth list', matching=False,
183 'Python class fooSynthProvider'])
184 self.expect('type filter list',
189 # delete the filter, add the synth
190 self.runCmd("type filter delete foo")
191 self.runCmd("type synth add -l fooSynthProvider foo")
193 self.expect('frame variable f00_1', matching=False,
196 self.expect("frame variable --ptr-depth 1 f00_ptr",
198 'fake_a = %d' % fake_a_val,
202 self.expect('type synth list',
204 'Python class fooSynthProvider'])
205 self.expect('type filter list', matching=False,
210 # delete the synth and check that we get good output
211 self.runCmd("type synth delete foo")
213 self.expect("frame variable f00_1",
218 self.expect("frame variable f00_1", matching=False,
219 substrs=['fake_a = '])
221 def rdar10960550_formatter_commands(self):
222 """Test that synthetic children persist stoppoints."""
223 self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
225 # The second breakpoint is on a multi-line expression, so the comment
226 # can't be on the right line...
227 lldbutil.run_break_set_by_file_and_line(
228 self, "main.cpp", self.line2, num_expected_locations=1, loc_exact=False)
229 lldbutil.run_break_set_by_file_and_line(
230 self, "main.cpp", self.line3, num_expected_locations=1, loc_exact=True)
232 self.runCmd("run", RUN_SUCCEEDED)
234 # The stop reason of the thread should be breakpoint.
235 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
237 'stop reason = breakpoint'])
239 # This is the function to remove the custom formats in order to have a
240 # clean slate for the next test case.
242 self.runCmd('type format clear', check=False)
243 self.runCmd('type summary clear', check=False)
244 self.runCmd('type filter clear', check=False)
245 self.runCmd('type synth clear', check=False)
247 # Execute the cleanup function during test case tear down.
248 self.addTearDownHook(cleanup)
250 self.runCmd("command script import ./ftsp.py --allow-reload")
251 self.runCmd("type synth add -l ftsp.ftsp wrapint")
253 # we need to check that the VO is properly updated so that the same synthetic children are reused
254 # but their values change correctly across stop-points - in order to do this, self.runCmd("next")
255 # does not work because it forces a wipe of the stack frame - this is why we are using this more contrived
256 # mechanism to achieve our goal of preserving test_cast as a VO
257 test_cast = self.dbg.GetSelectedTarget().GetProcess(
258 ).GetSelectedThread().GetSelectedFrame().FindVariable('test_cast')
260 str_cast = str(test_cast)
265 self.assertTrue(str_cast.find('A') != -1, 'could not find A in output')
266 self.assertTrue(str_cast.find('B') != -1, 'could not find B in output')
267 self.assertTrue(str_cast.find('C') != -1, 'could not find C in output')
268 self.assertTrue(str_cast.find('D') != -1, 'could not find D in output')
270 str_cast.find("4 = '\\0'") != -1,
271 'could not find item 4 == 0')
273 self.dbg.GetSelectedTarget().GetProcess().GetSelectedThread().StepOver()
275 str_cast = str(test_cast)
280 # we detect that all the values of the child objects have changed - but the counter-generated item
281 # is still fixed at 0 because it is cached - this would fail if update(self): in ftsp returned False
282 # or if synthetic children were not being preserved
283 self.assertTrue(str_cast.find('Q') != -1, 'could not find Q in output')
284 self.assertTrue(str_cast.find('X') != -1, 'could not find X in output')
285 self.assertTrue(str_cast.find('T') != -1, 'could not find T in output')
286 self.assertTrue(str_cast.find('F') != -1, 'could not find F in output')
288 str_cast.find("4 = '\\0'") != -1,
289 'could not find item 4 == 0')