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
15 class AdvDataFormatterTestCase(TestBase):
17 mydir = TestBase.compute_mydir(__file__)
20 # Call super's setUp().
22 # Find the line number to break at.
23 self.line = line_number('main.cpp', '// Set break point at this line.')
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(
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 # This is the function to remove the custom formats in order to have a
41 # clean slate for the next test case.
43 self.runCmd('type format clear', check=False)
44 self.runCmd('type summary clear', check=False)
46 "settings set target.max-children-count 256",
49 # Execute the cleanup function during test case tear down.
50 self.addTearDownHook(cleanup)
52 self.runCmd("type summary add --summary-string \"pippo\" \"i_am_cool\"")
55 "type summary add --summary-string \"pluto\" -x \"i_am_cool[a-z]*\"")
57 self.expect("frame variable cool_boy",
60 self.expect("frame variable cooler_boy",
63 self.runCmd("type summary delete i_am_cool")
65 self.expect("frame variable cool_boy",
68 self.runCmd("type summary clear")
71 "type summary add --summary-string \"${var[]}\" -x \"int \\[[0-9]\\]")
73 self.expect("frame variable int_array",
74 substrs=['1,2,3,4,5'])
76 # this will fail if we don't do [] as regex correctly
78 'type summary add --summary-string "${var[].integer}" "i_am_cool[]')
80 self.expect("frame variable cool_array",
81 substrs=['1,1,1,1,6'])
83 self.runCmd("type summary clear")
86 "type summary add --summary-string \"${var[1-0]%x}\" \"int\"")
88 self.expect("frame variable iAmInt",
92 "type summary add --summary-string \"${var[0-1]%x}\" \"int\"")
94 self.expect("frame variable iAmInt",
97 self.runCmd("type summary clear")
99 self.runCmd("type summary add --summary-string \"${var[0-1]%x}\" int")
101 "type summary add --summary-string \"${var[0-31]%x}\" float")
103 self.expect("frame variable *pointer",
107 # check fix for <rdar://problem/11338654> LLDB crashes when using a
108 # "type summary" that uses bitfields with no format
109 self.runCmd("type summary add --summary-string \"${var[0-1]}\" int")
110 self.expect("frame variable iAmInt",
113 self.expect("frame variable cool_array[3].floating",
117 "type summary add --summary-string \"low bits are ${*var[0-1]} tgt is ${*var}\" \"int *\"")
119 self.expect("frame variable pointer",
120 substrs=['low bits are',
124 "frame variable int_array --summary-string \"${*var[0-1]}\"",
127 self.runCmd("type summary clear")
130 'type summary add --summary-string \"${var[0-1]}\" -x \"int \[[0-9]\]\"')
132 self.expect("frame variable int_array",
136 'type summary add --summary-string \"${var[0-1]}\" "int []"')
138 self.expect("frame variable int_array",
141 self.runCmd("type summary clear")
143 self.runCmd("type summary add -c -x \"i_am_cool \[[0-9]\]\"")
144 self.runCmd("type summary add -c i_am_cool")
146 self.expect("frame variable cool_array",
157 "type summary add --summary-string \"int = ${*var.int_pointer}, float = ${*var.float_pointer}\" IWrapPointers")
159 self.expect("frame variable wrapper",
164 "type summary add --summary-string \"low bits = ${*var.int_pointer[2]}\" IWrapPointers -p")
166 self.expect("frame variable wrapper",
167 substrs=['low bits = 1'])
169 self.expect("frame variable *wrap_pointer",
170 substrs=['low bits = 1'])
172 self.runCmd("type summary clear")
175 "frame variable int_array --summary-string \"${var[0][0-2]%hex}\"",
180 self.runCmd("type summary clear")
183 "type summary add --summary-string \"${*var[].x[0-3]%hex} is a bitfield on a set of integers\" -x \"SimpleWithPointers \[[0-9]\]\"")
186 "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]}\"",
188 '1 are low bits of integer 9.',
189 'If I pretend it is an array I get [9,'])
191 # if the summary has an error, we still display the value
193 "frame variable couple --summary-string \"${*var.sp.foo[0-2]\"",
195 '(Couple) couple = {',
202 "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")
204 self.expect("frame variable sparray",
205 substrs=['[0x0000000f,0x0000000c,0x00000009]'])
207 # check that we can format a variable in a summary even if a format is
208 # defined for its datatype
209 self.runCmd("type format add -f hex int")
211 "type summary add --summary-string \"x=${var.x%d}\" Simple")
213 self.expect("frame variable a_simple_object",
216 self.expect("frame variable a_simple_object", matching=False,
219 # now check that the default is applied if we do not hand out a format
220 self.runCmd("type summary add --summary-string \"x=${var.x}\" Simple")
222 self.expect("frame variable a_simple_object", matching=False,
225 self.expect("frame variable a_simple_object", matching=True,
226 substrs=['x=0x00000003'])
228 # check that we can correctly cap the number of children shown
229 self.runCmd("settings set target.max-children-count 5")
231 self.expect('frame variable a_long_guy', matching=True,
239 # check that no further stuff is printed (not ALL values are checked!)
240 self.expect('frame variable a_long_guy', matching=False,
252 self.runCmd("settings set target.max-children-count 1")
253 self.expect('frame variable a_long_guy', matching=True,
256 self.expect('frame variable a_long_guy', matching=False,
261 self.expect('frame variable a_long_guy', matching=False,
273 self.runCmd("settings set target.max-children-count 30")
274 self.expect('frame variable a_long_guy', matching=True,
286 self.expect('frame variable a_long_guy', matching=False,
296 'frame variable a_long_guy --show-all-children',
310 'frame variable a_long_guy --show-all-children',
320 'frame variable a_long_guy --show-all-children',