2 Test lldb data formatter subsystem.
8 from lldbsuite.test.lldbtest import *
9 import lldbsuite.test.lldbutil as lldbutil
12 class AdvDataFormatterTestCase(TestBase):
14 mydir = TestBase.compute_mydir(__file__)
17 # Call super's setUp().
19 # Find the line number to break at.
20 self.line = line_number('main.cpp', '// Set break point at this line.')
22 def test_with_run_command(self):
23 """Test that that file and class static variables display correctly."""
25 self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
27 lldbutil.run_break_set_by_file_and_line(
28 self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True)
30 self.runCmd("run", RUN_SUCCEEDED)
32 # The stop reason of the thread should be breakpoint.
33 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
35 'stop reason = breakpoint'])
37 # This is the function to remove the custom formats in order to have a
38 # clean slate for the next test case.
40 self.runCmd('type format clear', check=False)
41 self.runCmd('type summary clear', check=False)
43 "settings set target.max-children-count 256",
46 # Execute the cleanup function during test case tear down.
47 self.addTearDownHook(cleanup)
49 self.runCmd("type summary add --summary-string \"pippo\" \"i_am_cool\"")
52 "type summary add --summary-string \"pluto\" -x \"i_am_cool[a-z]*\"")
54 self.expect("frame variable cool_boy",
57 self.expect("frame variable cooler_boy",
60 self.runCmd("type summary delete i_am_cool")
62 self.expect("frame variable cool_boy",
65 self.runCmd("type summary clear")
68 "type summary add --summary-string \"${var[]}\" -x \"int \\[[0-9]\\]")
70 self.expect("frame variable int_array",
71 substrs=['1,2,3,4,5'])
73 # this will fail if we don't do [] as regex correctly
75 'type summary add --summary-string "${var[].integer}" "i_am_cool[]')
77 self.expect("frame variable cool_array",
78 substrs=['1,1,1,1,6'])
80 self.runCmd("type summary clear")
83 "type summary add --summary-string \"${var[1-0]%x}\" \"int\"")
85 self.expect("frame variable iAmInt",
89 "type summary add --summary-string \"${var[0-1]%x}\" \"int\"")
91 self.expect("frame variable iAmInt",
94 self.runCmd("type summary clear")
96 self.runCmd("type summary add --summary-string \"${var[0-1]%x}\" int")
98 "type summary add --summary-string \"${var[0-31]%x}\" float")
100 self.expect("frame variable *pointer",
104 # check fix for <rdar://problem/11338654> LLDB crashes when using a
105 # "type summary" that uses bitfields with no format
106 self.runCmd("type summary add --summary-string \"${var[0-1]}\" int")
107 self.expect("frame variable iAmInt",
110 self.expect("frame variable cool_array[3].floating",
114 "type summary add --summary-string \"low bits are ${*var[0-1]} tgt is ${*var}\" \"int *\"")
116 self.expect("frame variable pointer",
117 substrs=['low bits are',
121 "frame variable int_array --summary-string \"${*var[0-1]}\"",
124 self.runCmd("type summary clear")
127 'type summary add --summary-string \"${var[0-1]}\" -x \"int \[[0-9]\]\"')
129 self.expect("frame variable int_array",
133 'type summary add --summary-string \"${var[0-1]}\" "int []"')
135 self.expect("frame variable int_array",
138 # Test the patterns are matched in reverse-chronological order.
140 'type summary add --summary-string \"${var[2-3]}\" "int []"')
142 self.expect("frame variable int_array",
145 self.runCmd("type summary clear")
147 self.runCmd("type summary add -c -x \"i_am_cool \[[0-9]\]\"")
148 self.runCmd("type summary add -c i_am_cool")
150 self.expect("frame variable cool_array",
161 "type summary add --summary-string \"int = ${*var.int_pointer}, float = ${*var.float_pointer}\" IWrapPointers")
163 self.expect("frame variable wrapper",
168 "type summary add --summary-string \"low bits = ${*var.int_pointer[2]}\" IWrapPointers -p")
170 self.expect("frame variable wrapper",
171 substrs=['low bits = 1'])
173 self.expect("frame variable *wrap_pointer",
174 substrs=['low bits = 1'])
176 self.runCmd("type summary clear")
179 "frame variable int_array --summary-string \"${var[0][0-2]%hex}\"",
184 self.runCmd("type summary clear")
187 "type summary add --summary-string \"${*var[].x[0-3]%hex} is a bitfield on a set of integers\" -x \"SimpleWithPointers \[[0-9]\]\"")
190 "frame variable couple --summary-string \"${*var.sp.x[0-2]} are low bits of integer ${*var.sp.x}. If I pretend it is an array I get ${var.sp.x[0-5]}\"",
192 '1 are low bits of integer 9.',
193 'If I pretend it is an array I get [9,'])
195 # if the summary has an error, we still display the value
197 "frame variable couple --summary-string \"${*var.sp.foo[0-2]\"",
199 '(Couple) couple = {',
206 "type summary add --summary-string \"${*var.sp.x[0-2]} are low bits of integer ${*var.sp.x}. If I pretend it is an array I get ${var.sp.x[0-5]}\" Couple")
208 self.expect("frame variable sparray",
209 substrs=['[0x0000000f,0x0000000c,0x00000009]'])
211 # check that we can format a variable in a summary even if a format is
212 # defined for its datatype
213 self.runCmd("type format add -f hex int")
215 "type summary add --summary-string \"x=${var.x%d}\" Simple")
217 self.expect("frame variable a_simple_object",
220 self.expect("frame variable a_simple_object", matching=False,
223 # now check that the default is applied if we do not hand out a format
224 self.runCmd("type summary add --summary-string \"x=${var.x}\" Simple")
226 self.expect("frame variable a_simple_object", matching=False,
229 self.expect("frame variable a_simple_object", matching=True,
230 substrs=['x=0x00000003'])
232 # check that we can correctly cap the number of children shown
233 self.runCmd("settings set target.max-children-count 5")
235 self.expect('frame variable a_long_guy', matching=True,
243 # check that no further stuff is printed (not ALL values are checked!)
244 self.expect('frame variable a_long_guy', matching=False,
256 self.runCmd("settings set target.max-children-count 1")
257 self.expect('frame variable a_long_guy', matching=True,
260 self.expect('frame variable a_long_guy', matching=False,
265 self.expect('frame variable a_long_guy', matching=False,
277 self.runCmd("settings set target.max-children-count 30")
278 self.expect('frame variable a_long_guy', matching=True,
290 self.expect('frame variable a_long_guy', matching=False,
300 'frame variable a_long_guy --show-all-children',
314 'frame variable a_long_guy --show-all-children',
324 'frame variable a_long_guy --show-all-children',