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
16 class CppDataFormatterTestCase(TestBase):
18 mydir = TestBase.compute_mydir(__file__)
21 # Call super's setUp().
23 # Find the line number to break at.
24 self.line = line_number('main.cpp', '// Set break point at this line.')
28 bugnumber="llvm.org/pr24462: Data formatters have problems on Windows")
29 def test_with_run_command(self):
30 """Test that that file and class static variables display correctly."""
32 self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)
34 lldbutil.run_break_set_by_file_and_line(
35 self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True)
37 self.runCmd("run", RUN_SUCCEEDED)
39 # The stop reason of the thread should be breakpoint.
40 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
42 'stop reason = breakpoint'])
44 self.expect("frame variable",
45 substrs=['(Speed) SPILookHex = 5.55' # Speed by default is 5.55.
48 # This is the function to remove the custom formats in order to have a
49 # clean slate for the next test case.
51 self.runCmd('type format clear', check=False)
52 self.runCmd('type summary clear', check=False)
54 # Execute the cleanup function during test case tear down.
55 self.addTearDownHook(cleanup)
57 self.runCmd("type format add -C yes -f x Speed BitField")
58 self.runCmd("type format add -C no -f c RealNumber")
59 self.runCmd("type format add -C no -f x Type2")
60 self.runCmd("type format add -C yes -f c Type1")
62 # The type format list should show our custom formats.
63 self.expect("type format list",
64 substrs=['RealNumber',
70 self.expect("frame variable",
71 patterns=['\(Speed\) SPILookHex = 0x[0-9a-f]+' # Speed should look hex-ish now.
74 # gcc4.2 on Mac OS X skips typedef chains in the DWARF output
75 if self.getCompiler() in ['clang', 'llvm-gcc']:
76 self.expect("frame variable",
77 patterns=['\(SignalMask\) SMILookHex = 0x[0-9a-f]+' # SignalMask should look hex-ish now.
79 self.expect("frame variable", matching=False,
80 patterns=['\(Type4\) T4ILookChar = 0x[0-9a-f]+' # Type4 should NOT look hex-ish now.
83 # Now let's delete the 'Speed' custom format.
84 self.runCmd("type format delete Speed")
86 # The type format list should not show 'Speed' at this point.
87 self.expect("type format list", matching=False,
90 # Delete type format for 'Speed', we should expect an error message.
91 self.expect("type format delete Speed", error=True,
92 substrs=['no custom formatter for Speed'])
95 "type summary add --summary-string \"arr = ${var%s}\" -x \"char \\[[0-9]+\\]\" -v")
97 self.expect("frame variable strarr",
98 substrs=['arr = "Hello world!"'])
100 self.runCmd("type summary clear")
103 "type summary add --summary-string \"ptr = ${var%s}\" \"char *\" -v")
105 self.expect("frame variable strptr",
106 substrs=['ptr = "Hello world!"'])
109 "type summary add --summary-string \"arr = ${var%s}\" -x \"char \\[[0-9]+\\]\" -v")
111 self.expect("frame variable strarr",
112 substrs=['arr = "Hello world!'])
114 # check that rdar://problem/10011145 (Standard summary format for
115 # char[] doesn't work as the result of "expr".) is solved
116 self.expect("p strarr",
117 substrs=['arr = "Hello world!'])
119 self.expect("frame variable strptr",
120 substrs=['ptr = "Hello world!"'])
122 self.expect("p strptr",
123 substrs=['ptr = "Hello world!"'])
126 "p (char*)\"1234567890123456789012345678901234567890123456789012345678901234ABC\"",
130 ' "1234567890123456789012345678901234567890123456789012345678901234ABC"'])
132 self.runCmd("type summary add -c Point")
134 self.expect("frame variable iAmSomewhere",
138 self.expect("type summary list",
142 self.runCmd("type summary add --summary-string \"y=${var.y%x}\" Point")
144 self.expect("frame variable iAmSomewhere",
148 "type summary add --summary-string \"y=${var.y},x=${var.x}\" Point")
150 self.expect("frame variable iAmSomewhere",
154 self.runCmd("type summary add --summary-string \"hello\" Point -e")
156 self.expect("type summary list",
160 self.expect("frame variable iAmSomewhere",
166 "type summary add --summary-string \"Sign: ${var[31]%B} Exponent: ${var[23-30]%x} Mantissa: ${var[0-22]%u}\" ShowMyGuts")
168 self.expect("frame variable cool_pointer->floating",
169 substrs=['Sign: true',
173 self.runCmd("type summary add --summary-string \"a test\" i_am_cool")
175 self.expect("frame variable cool_pointer",
179 "type summary add --summary-string \"a test\" i_am_cool --skip-pointers")
181 self.expect("frame variable cool_pointer",
186 "type summary add --summary-string \"${var[1-3]}\" \"int [5]\"")
188 self.expect("frame variable int_array",
193 self.runCmd("type summary clear")
196 "type summary add --summary-string \"${var[0-2].integer}\" \"i_am_cool *\"")
198 "type summary add --summary-string \"${var[2-4].integer}\" \"i_am_cool [5]\"")
200 self.expect("frame variable cool_array",
203 self.expect("frame variable cool_pointer",
206 # test special symbols for formatting variables into summaries
208 "type summary add --summary-string \"cool object @ ${var%L}\" i_am_cool")
209 self.runCmd("type summary delete \"i_am_cool [5]\"")
211 # this test might fail if the compiler tries to store
212 # these values into registers.. hopefully this is not
213 # going to be the case
214 self.expect("frame variable cool_array",
215 substrs=['[0] = cool object @ 0x',
216 '[1] = cool object @ 0x',
217 '[2] = cool object @ 0x',
218 '[3] = cool object @ 0x',
219 '[4] = cool object @ 0x'])
221 # test getting similar output by exploiting ${var} = 'type @ location'
223 self.runCmd("type summary add --summary-string \"${var}\" i_am_cool")
225 # this test might fail if the compiler tries to store
226 # these values into registers.. hopefully this is not
227 # going to be the case
228 self.expect("frame variable cool_array",
229 substrs=['[0] = i_am_cool @ 0x',
230 '[1] = i_am_cool @ 0x',
231 '[2] = i_am_cool @ 0x',
232 '[3] = i_am_cool @ 0x',
233 '[4] = i_am_cool @ 0x'])
235 # test getting same output by exploiting %T and %L together for
238 "type summary add --summary-string \"${var%T} @ ${var%L}\" i_am_cool")
240 # this test might fail if the compiler tries to store
241 # these values into registers.. hopefully this is not
242 # going to be the case
243 self.expect("frame variable cool_array",
244 substrs=['[0] = i_am_cool @ 0x',
245 '[1] = i_am_cool @ 0x',
246 '[2] = i_am_cool @ 0x',
247 '[3] = i_am_cool @ 0x',
248 '[4] = i_am_cool @ 0x'])
250 self.runCmd("type summary add --summary-string \"goofy\" i_am_cool")
252 "type summary add --summary-string \"${var.second_cool%S}\" i_am_cooler")
254 self.expect("frame variable the_coolest_guy",
255 substrs=['(i_am_cooler) the_coolest_guy = goofy'])
257 # check that unwanted type specifiers are removed
258 self.runCmd("type summary delete i_am_cool")
260 "type summary add --summary-string \"goofy\" \"class i_am_cool\"")
261 self.expect("frame variable the_coolest_guy",
262 substrs=['(i_am_cooler) the_coolest_guy = goofy'])
264 self.runCmd("type summary delete i_am_cool")
266 "type summary add --summary-string \"goofy\" \"enum i_am_cool\"")
267 self.expect("frame variable the_coolest_guy",
268 substrs=['(i_am_cooler) the_coolest_guy = goofy'])
270 self.runCmd("type summary delete i_am_cool")
272 "type summary add --summary-string \"goofy\" \"struct i_am_cool\"")
273 self.expect("frame variable the_coolest_guy",
274 substrs=['(i_am_cooler) the_coolest_guy = goofy'])
276 # many spaces, but we still do the right thing
277 self.runCmd("type summary delete i_am_cool")
279 "type summary add --summary-string \"goofy\" \"union i_am_cool\"")
280 self.expect("frame variable the_coolest_guy",
281 substrs=['(i_am_cooler) the_coolest_guy = goofy'])
283 # but that not *every* specifier is removed
284 self.runCmd("type summary delete i_am_cool")
286 "type summary add --summary-string \"goofy\" \"wrong i_am_cool\"")
287 self.expect("frame variable the_coolest_guy", matching=False,
288 substrs=['(i_am_cooler) the_coolest_guy = goofy'])
290 # check that formats are not sticking since that is the behavior we
292 self.expect("frame variable iAmInt --format hex",
293 substrs=['(int) iAmInt = 0x00000001'])
295 "frame variable iAmInt",
297 substrs=['(int) iAmInt = 0x00000001'])
298 self.expect("frame variable iAmInt", substrs=['(int) iAmInt = 1'])