2 Test lldb data formatter subsystem.
5 from __future__ import print_function
11 from lldbsuite.test.decorators import *
12 from lldbsuite.test.lldbtest import *
13 from lldbsuite.test import lldbutil
15 class PythonSynthDataFormatterTestCase(TestBase):
17 mydir = TestBase.compute_mydir(__file__)
19 @skipIfFreeBSD # llvm.org/pr20545 bogus output confuses buildbot parser
20 def test_with_run_command(self):
21 """Test data formatter commands."""
23 self.data_formatter_commands()
25 def test_rdar10960550_with_run_command(self):
26 """Test data formatter commands."""
28 self.rdar10960550_formatter_commands()
32 # Call super's setUp().
34 # Find the line number to break at.
35 self.line = line_number('main.cpp', '// Set break point at this line.')
36 self.line2 = line_number('main.cpp', '// Set cast break point at this line.')
37 self.line3 = line_number('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 a.out", CURRENT_EXECUTABLE_SET)
43 lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True)
45 self.runCmd("run", RUN_SUCCEEDED)
47 process = self.dbg.GetSelectedTarget().GetProcess()
49 # The stop reason of the thread should be breakpoint.
50 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
52 'stop reason = breakpoint'])
54 # This is the function to remove the custom formats in order to have a
55 # clean slate for the next test case.
57 self.runCmd('type format clear', check=False)
58 self.runCmd('type summary clear', check=False)
59 self.runCmd('type filter clear', check=False)
60 self.runCmd('type synth clear', check=False)
62 # Execute the cleanup function during test case tear down.
63 self.addTearDownHook(cleanup)
65 # print the f00_1 variable without a synth
66 self.expect("frame variable f00_1",
71 # now set up the synth
72 self.runCmd("script from fooSynthProvider import *")
73 self.runCmd("type synth add -l fooSynthProvider foo")
74 self.expect("type synthetic list foo", substrs=['fooSynthProvider'])
76 # note that the value of fake_a depends on target byte order
77 if process.GetByteOrder() == lldb.eByteOrderLittle:
78 fake_a_val = 0x02000000
80 fake_a_val = 0x00000100
82 # check that we get the two real vars and the fake_a variables
83 self.expect("frame variable f00_1",
85 'fake_a = %d' % fake_a_val,
88 # check that we do not get the extra vars
89 self.expect("frame variable f00_1", matching=False,
92 # check access to members by name
93 self.expect('frame variable f00_1.fake_a',
94 substrs = ['%d' % fake_a_val])
96 # check access to members by index
97 self.expect('frame variable f00_1[1]',
98 substrs = ['%d' % fake_a_val])
100 # put synthetic children in summary in several combinations
101 self.runCmd("type summary add --summary-string \"fake_a=${svar.fake_a}\" foo")
102 self.expect('frame variable f00_1',
103 substrs = ['fake_a=%d' % fake_a_val])
104 self.runCmd("type summary add --summary-string \"fake_a=${svar[1]}\" foo")
105 self.expect('frame variable f00_1',
106 substrs = ['fake_a=%d' % fake_a_val])
109 self.runCmd("type summary delete foo")
111 # check that the caching does not span beyond the stopoint
114 if process.GetByteOrder() == lldb.eByteOrderLittle:
115 fake_a_val = 0x02000000
117 fake_a_val = 0x00000200
119 self.expect("frame variable f00_1",
121 'fake_a = %d' % fake_a_val,
124 # check that altering the object also alters fake_a
125 self.runCmd("expr f00_1.a = 280")
127 if process.GetByteOrder() == lldb.eByteOrderLittle:
128 fake_a_val = 0x02000001
130 fake_a_val = 0x00011800
132 self.expect("frame variable f00_1",
134 'fake_a = %d' % fake_a_val,
137 # check that expanding a pointer does the right thing
138 if process.GetByteOrder() == lldb.eByteOrderLittle:
139 fake_a_val = 0x0d000000
141 fake_a_val = 0x00000c00
143 self.expect("frame variable --ptr-depth 1 f00_ptr",
145 'fake_a = %d' % fake_a_val,
148 # now add a filter.. it should fail
149 self.expect("type filter add foo --child b --child j", error=True,
150 substrs = ['cannot add'])
152 # we get the synth again..
153 self.expect('frame variable f00_1', matching=False,
156 self.expect("frame variable --ptr-depth 1 f00_ptr",
158 'fake_a = %d' % fake_a_val,
161 # now delete the synth and add the filter
162 self.runCmd("type synth delete foo")
163 self.runCmd("type filter add foo --child b --child j")
165 self.expect('frame variable f00_1',
168 self.expect("frame variable --ptr-depth 1 f00_ptr", matching=False,
170 'fake_a = %d' % fake_a_val,
173 # now add the synth and it should fail
174 self.expect("type synth add -l fooSynthProvider foo", error=True,
175 substrs = ['cannot add'])
178 self.expect('type synth list', matching=False,
180 'Python class fooSynthProvider'])
181 self.expect('type filter list',
186 # delete the filter, add the synth
187 self.runCmd("type filter delete foo")
188 self.runCmd("type synth add -l fooSynthProvider foo")
190 self.expect('frame variable f00_1', matching=False,
193 self.expect("frame variable --ptr-depth 1 f00_ptr",
195 'fake_a = %d' % fake_a_val,
199 self.expect('type synth list',
201 'Python class fooSynthProvider'])
202 self.expect('type filter list', matching=False,
207 # delete the synth and check that we get good output
208 self.runCmd("type synth delete foo")
210 self.expect("frame variable f00_1",
211 substrs = ['a = 280',
215 self.expect("frame variable f00_1", matching=False,
216 substrs = ['fake_a = '])
218 def rdar10960550_formatter_commands(self):
219 """Test that synthetic children persist stoppoints."""
220 self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)
222 # The second breakpoint is on a multi-line expression, so the comment can't be on the right line...
223 lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.line2, num_expected_locations=1, loc_exact=False)
224 lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.line3, num_expected_locations=1, loc_exact=True)
226 self.runCmd("run", RUN_SUCCEEDED)
228 # The stop reason of the thread should be breakpoint.
229 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
230 substrs = ['stopped',
231 'stop reason = breakpoint'])
233 # This is the function to remove the custom formats in order to have a
234 # clean slate for the next test case.
236 self.runCmd('type format clear', check=False)
237 self.runCmd('type summary clear', check=False)
238 self.runCmd('type filter clear', check=False)
239 self.runCmd('type synth clear', check=False)
241 # Execute the cleanup function during test case tear down.
242 self.addTearDownHook(cleanup)
244 self.runCmd("command script import ./ftsp.py --allow-reload")
245 self.runCmd("type synth add -l ftsp.ftsp wrapint")
247 # we need to check that the VO is properly updated so that the same synthetic children are reused
248 # but their values change correctly across stop-points - in order to do this, self.runCmd("next")
249 # does not work because it forces a wipe of the stack frame - this is why we are using this more contrived
250 # mechanism to achieve our goal of preserving test_cast as a VO
251 test_cast = self.dbg.GetSelectedTarget().GetProcess().GetSelectedThread().GetSelectedFrame().FindVariable('test_cast')
253 str_cast = str(test_cast)
258 self.assertTrue(str_cast.find('A') != -1, 'could not find A in output')
259 self.assertTrue(str_cast.find('B') != -1, 'could not find B in output')
260 self.assertTrue(str_cast.find('C') != -1, 'could not find C in output')
261 self.assertTrue(str_cast.find('D') != -1, 'could not find D in output')
262 self.assertTrue(str_cast.find("4 = '\\0'") != -1, 'could not find item 4 == 0')
264 self.dbg.GetSelectedTarget().GetProcess().GetSelectedThread().StepOver()
266 str_cast = str(test_cast)
271 # we detect that all the values of the child objects have changed - but the counter-generated item
272 # is still fixed at 0 because it is cached - this would fail if update(self): in ftsp returned False
273 # or if synthetic children were not being preserved
274 self.assertTrue(str_cast.find('Q') != -1, 'could not find Q in output')
275 self.assertTrue(str_cast.find('X') != -1, 'could not find X in output')
276 self.assertTrue(str_cast.find('T') != -1, 'could not find T in output')
277 self.assertTrue(str_cast.find('F') != -1, 'could not find F in output')
278 self.assertTrue(str_cast.find("4 = '\\0'") != -1, 'could not find item 4 == 0')