2 Test lldb data formatter subsystem.
8 from lldbsuite.test.decorators import *
9 from lldbsuite.test.lldbtest import *
10 from lldbsuite.test import lldbutil
13 class CppDataFormatterTestCase(TestBase):
15 mydir = TestBase.compute_mydir(__file__)
18 # Call super's setUp().
20 # Find the line number to break at.
21 self.line = line_number('main.cpp', '// Set break point at this line.')
23 @skipIf(debug_info="gmodules",
24 bugnumber="https://bugs.llvm.org/show_bug.cgi?id=36048")
25 def test_with_run_command(self):
26 """Test that that file and class static variables display correctly."""
28 self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
30 lldbutil.run_break_set_by_file_and_line(
31 self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True)
33 self.runCmd("run", RUN_SUCCEEDED)
35 # The stop reason of the thread should be breakpoint.
36 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
38 'stop reason = breakpoint'])
40 self.expect("frame variable",
41 substrs=['(Speed) SPILookHex = 5.55' # Speed by default is 5.55.
44 # This is the function to remove the custom formats in order to have a
45 # clean slate for the next test case.
47 self.runCmd('type format clear', check=False)
48 self.runCmd('type summary clear', check=False)
50 # Execute the cleanup function during test case tear down.
51 self.addTearDownHook(cleanup)
53 self.runCmd("type format add -C yes -f x Speed BitField")
54 self.runCmd("type format add -C no -f c RealNumber")
55 self.runCmd("type format add -C no -f x Type2")
56 self.runCmd("type format add -C yes -f c Type1")
58 # The type format list should show our custom formats.
59 self.expect("type format list",
60 substrs=['RealNumber',
66 self.expect("frame variable",
67 patterns=['\(Speed\) SPILookHex = 0x[0-9a-f]+' # Speed should look hex-ish now.
70 # gcc4.2 on Mac OS X skips typedef chains in the DWARF output
71 if self.getCompiler() in ['clang', 'llvm-gcc']:
72 self.expect("frame variable",
73 patterns=['\(SignalMask\) SMILookHex = 0x[0-9a-f]+' # SignalMask should look hex-ish now.
75 self.expect("frame variable", matching=False,
76 patterns=['\(Type4\) T4ILookChar = 0x[0-9a-f]+' # Type4 should NOT look hex-ish now.
79 # Now let's delete the 'Speed' custom format.
80 self.runCmd("type format delete Speed")
82 # The type format list should not show 'Speed' at this point.
83 self.expect("type format list", matching=False,
86 # Delete type format for 'Speed', we should expect an error message.
87 self.expect("type format delete Speed", error=True,
88 substrs=['no custom formatter for Speed'])
91 "type summary add --summary-string \"arr = ${var%s}\" -x \"char \\[[0-9]+\\]\" -v")
93 self.expect("frame variable strarr",
94 substrs=['arr = "Hello world!"'])
96 self.runCmd("type summary clear")
99 "type summary add --summary-string \"ptr = ${var%s}\" \"char *\" -v")
101 self.expect("frame variable strptr",
102 substrs=['ptr = "Hello world!"'])
105 "type summary add --summary-string \"arr = ${var%s}\" -x \"char \\[[0-9]+\\]\" -v")
107 self.expect("frame variable strarr",
108 substrs=['arr = "Hello world!'])
110 # check that rdar://problem/10011145 (Standard summary format for
111 # char[] doesn't work as the result of "expr".) is solved
112 self.expect("p strarr",
113 substrs=['arr = "Hello world!'])
115 self.expect("frame variable strptr",
116 substrs=['ptr = "Hello world!"'])
118 self.expect("p strptr",
119 substrs=['ptr = "Hello world!"'])
122 "p (char*)\"1234567890123456789012345678901234567890123456789012345678901234ABC\"",
126 ' "1234567890123456789012345678901234567890123456789012345678901234ABC"'])
128 self.runCmd("type summary add -c Point")
130 self.expect("frame variable iAmSomewhere",
134 self.expect("type summary list",
138 self.runCmd("type summary add --summary-string \"y=${var.y%x}\" Point")
140 self.expect("frame variable iAmSomewhere",
144 "type summary add --summary-string \"y=${var.y},x=${var.x}\" Point")
146 self.expect("frame variable iAmSomewhere",
150 self.runCmd("type summary add --summary-string \"hello\" Point -e")
152 self.expect("type summary list",
156 self.expect("frame variable iAmSomewhere",
162 "type summary add --summary-string \"Sign: ${var[31]%B} Exponent: ${var[23-30]%x} Mantissa: ${var[0-22]%u}\" ShowMyGuts")
164 self.expect("frame variable cool_pointer->floating",
165 substrs=['Sign: true',
169 self.runCmd("type summary add --summary-string \"a test\" i_am_cool")
171 self.expect("frame variable cool_pointer",
175 "type summary add --summary-string \"a test\" i_am_cool --skip-pointers")
177 self.expect("frame variable cool_pointer",
182 "type summary add --summary-string \"${var[1-3]}\" \"int [5]\"")
184 self.expect("frame variable int_array",
189 self.runCmd("type summary clear")
192 "type summary add --summary-string \"${var[0-2].integer}\" \"i_am_cool *\"")
194 "type summary add --summary-string \"${var[2-4].integer}\" \"i_am_cool [5]\"")
196 self.expect("frame variable cool_array",
199 self.expect("frame variable cool_pointer",
202 # test special symbols for formatting variables into summaries
204 "type summary add --summary-string \"cool object @ ${var%L}\" i_am_cool")
205 self.runCmd("type summary delete \"i_am_cool [5]\"")
207 # this test might fail if the compiler tries to store
208 # these values into registers.. hopefully this is not
209 # going to be the case
210 self.expect("frame variable cool_array",
211 substrs=['[0] = cool object @ 0x',
212 '[1] = cool object @ 0x',
213 '[2] = cool object @ 0x',
214 '[3] = cool object @ 0x',
215 '[4] = cool object @ 0x'])
217 # test getting similar output by exploiting ${var} = 'type @ location'
219 self.runCmd("type summary add --summary-string \"${var}\" i_am_cool")
221 # this test might fail if the compiler tries to store
222 # these values into registers.. hopefully this is not
223 # going to be the case
224 self.expect("frame variable cool_array",
225 substrs=['[0] = i_am_cool @ 0x',
226 '[1] = i_am_cool @ 0x',
227 '[2] = i_am_cool @ 0x',
228 '[3] = i_am_cool @ 0x',
229 '[4] = i_am_cool @ 0x'])
231 # test getting same output by exploiting %T and %L together for
234 "type summary add --summary-string \"${var%T} @ ${var%L}\" i_am_cool")
236 # this test might fail if the compiler tries to store
237 # these values into registers.. hopefully this is not
238 # going to be the case
239 self.expect("frame variable cool_array",
240 substrs=['[0] = i_am_cool @ 0x',
241 '[1] = i_am_cool @ 0x',
242 '[2] = i_am_cool @ 0x',
243 '[3] = i_am_cool @ 0x',
244 '[4] = i_am_cool @ 0x'])
246 self.runCmd("type summary add --summary-string \"goofy\" i_am_cool")
248 "type summary add --summary-string \"${var.second_cool%S}\" i_am_cooler")
250 self.expect("frame variable the_coolest_guy",
251 substrs=['(i_am_cooler) the_coolest_guy = goofy'])
253 # check that unwanted type specifiers are removed
254 self.runCmd("type summary delete i_am_cool")
256 "type summary add --summary-string \"goofy\" \"class i_am_cool\"")
257 self.expect("frame variable the_coolest_guy",
258 substrs=['(i_am_cooler) the_coolest_guy = goofy'])
260 self.runCmd("type summary delete i_am_cool")
262 "type summary add --summary-string \"goofy\" \"enum i_am_cool\"")
263 self.expect("frame variable the_coolest_guy",
264 substrs=['(i_am_cooler) the_coolest_guy = goofy'])
266 self.runCmd("type summary delete i_am_cool")
268 "type summary add --summary-string \"goofy\" \"struct i_am_cool\"")
269 self.expect("frame variable the_coolest_guy",
270 substrs=['(i_am_cooler) the_coolest_guy = goofy'])
272 # many spaces, but we still do the right thing
273 self.runCmd("type summary delete i_am_cool")
275 "type summary add --summary-string \"goofy\" \"union i_am_cool\"")
276 self.expect("frame variable the_coolest_guy",
277 substrs=['(i_am_cooler) the_coolest_guy = goofy'])
279 # but that not *every* specifier is removed
280 self.runCmd("type summary delete i_am_cool")
282 "type summary add --summary-string \"goofy\" \"wrong i_am_cool\"")
283 self.expect("frame variable the_coolest_guy", matching=False,
284 substrs=['(i_am_cooler) the_coolest_guy = goofy'])
286 # check that formats are not sticking since that is the behavior we
288 self.expect("frame variable iAmInt --format hex",
289 substrs=['(int) iAmInt = 0x00000001'])
291 "frame variable iAmInt",
293 substrs=['(int) iAmInt = 0x00000001'])
294 self.expect("frame variable iAmInt", substrs=['(int) iAmInt = 1'])