2 Test lldb data formatter subsystem.
5 from __future__ import print_function
11 from lldbsuite.test.lldbtest import *
12 import lldbsuite.test.lldbutil as lldbutil
14 class CppDataFormatterTestCase(TestBase):
16 mydir = TestBase.compute_mydir(__file__)
19 # Call super's setUp().
21 # Find the line number to break at.
22 self.line = line_number('main.cpp', '// Set break point at this line.')
24 @expectedFailureWindows("llvm.org/pr24462") # Data formatters have problems on Windows
25 def test_with_run_command(self):
26 """Test that that file and class static variables display correctly."""
28 self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)
30 lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True)
32 self.runCmd("run", RUN_SUCCEEDED)
34 # The stop reason of the thread should be breakpoint.
35 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
37 'stop reason = breakpoint'])
39 self.expect("frame variable",
40 substrs = ['(Speed) SPILookHex = 5.55' # Speed by default is 5.55.
43 # This is the function to remove the custom formats in order to have a
44 # clean slate for the next test case.
46 self.runCmd('type format clear', check=False)
47 self.runCmd('type summary clear', check=False)
49 # Execute the cleanup function during test case tear down.
50 self.addTearDownHook(cleanup)
52 self.runCmd("type format add -C yes -f x Speed BitField")
53 self.runCmd("type format add -C no -f c RealNumber")
54 self.runCmd("type format add -C no -f x Type2")
55 self.runCmd("type format add -C yes -f c Type1")
57 # The type format list should show our custom formats.
58 self.expect("type format list",
59 substrs = ['RealNumber',
65 self.expect("frame variable",
66 patterns = ['\(Speed\) SPILookHex = 0x[0-9a-f]+' # Speed should look hex-ish now.
69 # gcc4.2 on Mac OS X skips typedef chains in the DWARF output
70 if self.getCompiler() in ['clang', 'llvm-gcc']:
71 self.expect("frame variable",
72 patterns = ['\(SignalMask\) SMILookHex = 0x[0-9a-f]+' # SignalMask should look hex-ish now.
74 self.expect("frame variable", matching=False,
75 patterns = ['\(Type4\) T4ILookChar = 0x[0-9a-f]+' # Type4 should NOT look hex-ish now.
78 # Now let's delete the 'Speed' custom format.
79 self.runCmd("type format delete Speed")
81 # The type format list should not show 'Speed' at this point.
82 self.expect("type format list", matching=False,
85 # Delete type format for 'Speed', we should expect an error message.
86 self.expect("type format delete Speed", error=True,
87 substrs = ['no custom formatter for Speed'])
89 self.runCmd("type summary add --summary-string \"arr = ${var%s}\" -x \"char \\[[0-9]+\\]\" -v")
91 self.expect("frame variable strarr",
92 substrs = ['arr = "Hello world!"'])
94 self.runCmd("type summary clear")
96 self.runCmd("type summary add --summary-string \"ptr = ${var%s}\" \"char *\" -v")
98 self.expect("frame variable strptr",
99 substrs = ['ptr = "Hello world!"'])
101 self.runCmd("type summary add --summary-string \"arr = ${var%s}\" -x \"char \\[[0-9]+\\]\" -v")
103 self.expect("frame variable strarr",
104 substrs = ['arr = "Hello world!'])
106 # check that rdar://problem/10011145 (Standard summary format for char[] doesn't work as the result of "expr".) is solved
107 self.expect("p strarr",
108 substrs = ['arr = "Hello world!'])
110 self.expect("frame variable strptr",
111 substrs = ['ptr = "Hello world!"'])
113 self.expect("p strptr",
114 substrs = ['ptr = "Hello world!"'])
116 self.expect("p (char*)\"1234567890123456789012345678901234567890123456789012345678901234ABC\"",
117 substrs = ['(char *) $', ' = ptr = ', ' "1234567890123456789012345678901234567890123456789012345678901234ABC"'])
119 self.runCmd("type summary add -c Point")
121 self.expect("frame variable iAmSomewhere",
125 self.expect("type summary list",
129 self.runCmd("type summary add --summary-string \"y=${var.y%x}\" Point")
131 self.expect("frame variable iAmSomewhere",
134 self.runCmd("type summary add --summary-string \"y=${var.y},x=${var.x}\" Point")
136 self.expect("frame variable iAmSomewhere",
140 self.runCmd("type summary add --summary-string \"hello\" Point -e")
142 self.expect("type summary list",
146 self.expect("frame variable iAmSomewhere",
151 self.runCmd("type summary add --summary-string \"Sign: ${var[31]%B} Exponent: ${var[23-30]%x} Mantissa: ${var[0-22]%u}\" ShowMyGuts")
153 self.expect("frame variable cool_pointer->floating",
154 substrs = ['Sign: true',
158 self.runCmd("type summary add --summary-string \"a test\" i_am_cool")
160 self.expect("frame variable cool_pointer",
161 substrs = ['a test'])
163 self.runCmd("type summary add --summary-string \"a test\" i_am_cool --skip-pointers")
165 self.expect("frame variable cool_pointer",
166 substrs = ['a test'],
169 self.runCmd("type summary add --summary-string \"${var[1-3]}\" \"int [5]\"")
171 self.expect("frame variable int_array",
176 self.runCmd("type summary clear")
178 self.runCmd("type summary add --summary-string \"${var[0-2].integer}\" \"i_am_cool *\"")
179 self.runCmd("type summary add --summary-string \"${var[2-4].integer}\" \"i_am_cool [5]\"")
181 self.expect("frame variable cool_array",
184 self.expect("frame variable cool_pointer",
187 # test special symbols for formatting variables into summaries
188 self.runCmd("type summary add --summary-string \"cool object @ ${var%L}\" i_am_cool")
189 self.runCmd("type summary delete \"i_am_cool [5]\"")
191 # this test might fail if the compiler tries to store
192 # these values into registers.. hopefully this is not
193 # going to be the case
194 self.expect("frame variable cool_array",
195 substrs = ['[0] = cool object @ 0x',
196 '[1] = cool object @ 0x',
197 '[2] = cool object @ 0x',
198 '[3] = cool object @ 0x',
199 '[4] = cool object @ 0x'])
201 # test getting similar output by exploiting ${var} = 'type @ location' for aggregates
202 self.runCmd("type summary add --summary-string \"${var}\" i_am_cool")
204 # this test might fail if the compiler tries to store
205 # these values into registers.. hopefully this is not
206 # going to be the case
207 self.expect("frame variable cool_array",
208 substrs = ['[0] = i_am_cool @ 0x',
209 '[1] = i_am_cool @ 0x',
210 '[2] = i_am_cool @ 0x',
211 '[3] = i_am_cool @ 0x',
212 '[4] = i_am_cool @ 0x'])
215 # test getting same output by exploiting %T and %L together for aggregates
216 self.runCmd("type summary add --summary-string \"${var%T} @ ${var%L}\" i_am_cool")
218 # this test might fail if the compiler tries to store
219 # these values into registers.. hopefully this is not
220 # going to be the case
221 self.expect("frame variable cool_array",
222 substrs = ['[0] = i_am_cool @ 0x',
223 '[1] = i_am_cool @ 0x',
224 '[2] = i_am_cool @ 0x',
225 '[3] = i_am_cool @ 0x',
226 '[4] = i_am_cool @ 0x'])
228 self.runCmd("type summary add --summary-string \"goofy\" i_am_cool")
229 self.runCmd("type summary add --summary-string \"${var.second_cool%S}\" i_am_cooler")
231 self.expect("frame variable the_coolest_guy",
232 substrs = ['(i_am_cooler) the_coolest_guy = goofy'])
234 # check that unwanted type specifiers are removed
235 self.runCmd("type summary delete i_am_cool")
236 self.runCmd("type summary add --summary-string \"goofy\" \"class i_am_cool\"")
237 self.expect("frame variable the_coolest_guy",
238 substrs = ['(i_am_cooler) the_coolest_guy = goofy'])
240 self.runCmd("type summary delete i_am_cool")
241 self.runCmd("type summary add --summary-string \"goofy\" \"enum i_am_cool\"")
242 self.expect("frame variable the_coolest_guy",
243 substrs = ['(i_am_cooler) the_coolest_guy = goofy'])
245 self.runCmd("type summary delete i_am_cool")
246 self.runCmd("type summary add --summary-string \"goofy\" \"struct i_am_cool\"")
247 self.expect("frame variable the_coolest_guy",
248 substrs = ['(i_am_cooler) the_coolest_guy = goofy'])
250 # many spaces, but we still do the right thing
251 self.runCmd("type summary delete i_am_cool")
252 self.runCmd("type summary add --summary-string \"goofy\" \"union i_am_cool\"")
253 self.expect("frame variable the_coolest_guy",
254 substrs = ['(i_am_cooler) the_coolest_guy = goofy'])
256 # but that not *every* specifier is removed
257 self.runCmd("type summary delete i_am_cool")
258 self.runCmd("type summary add --summary-string \"goofy\" \"wrong i_am_cool\"")
259 self.expect("frame variable the_coolest_guy", matching=False,
260 substrs = ['(i_am_cooler) the_coolest_guy = goofy'])
262 # check that formats are not sticking since that is the behavior we want
263 self.expect("frame variable iAmInt --format hex", substrs = ['(int) iAmInt = 0x00000001'])
264 self.expect("frame variable iAmInt", matching=False, substrs = ['(int) iAmInt = 0x00000001'])
265 self.expect("frame variable iAmInt", substrs = ['(int) iAmInt = 1'])