246ebb3d4ae2cdecef8fe83f4616f96ddca8a603
[openbsd] /
1 """
2 Test lldb data formatter subsystem.
3 """
4
5
6
7 import lldb
8 from lldbsuite.test.lldbtest import *
9 import lldbsuite.test.lldbutil as lldbutil
10
11
12 class AdvDataFormatterTestCase(TestBase):
13
14     mydir = TestBase.compute_mydir(__file__)
15
16     def setUp(self):
17         # Call super's setUp().
18         TestBase.setUp(self)
19         # Find the line number to break at.
20         self.line = line_number('main.cpp', '// Set break point at this line.')
21
22     def test_with_run_command(self):
23         """Test that that file and class static variables display correctly."""
24         self.build()
25         self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
26
27         lldbutil.run_break_set_by_file_and_line(
28             self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True)
29
30         self.runCmd("run", RUN_SUCCEEDED)
31
32         # The stop reason of the thread should be breakpoint.
33         self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
34                     substrs=['stopped',
35                              'stop reason = breakpoint'])
36
37         # This is the function to remove the custom formats in order to have a
38         # clean slate for the next test case.
39         def cleanup():
40             self.runCmd('type format clear', check=False)
41             self.runCmd('type summary clear', check=False)
42             self.runCmd(
43                 "settings set target.max-children-count 256",
44                 check=False)
45
46         # Execute the cleanup function during test case tear down.
47         self.addTearDownHook(cleanup)
48
49         self.runCmd("type summary add --summary-string \"pippo\" \"i_am_cool\"")
50
51         self.runCmd(
52             "type summary add --summary-string \"pluto\" -x \"i_am_cool[a-z]*\"")
53
54         self.expect("frame variable cool_boy",
55                     substrs=['pippo'])
56
57         self.expect("frame variable cooler_boy",
58                     substrs=['pluto'])
59
60         self.runCmd("type summary delete i_am_cool")
61
62         self.expect("frame variable cool_boy",
63                     substrs=['pluto'])
64
65         self.runCmd("type summary clear")
66
67         self.runCmd(
68             "type summary add --summary-string \"${var[]}\" -x \"int \\[[0-9]\\]")
69
70         self.expect("frame variable int_array",
71                     substrs=['1,2,3,4,5'])
72
73         # this will fail if we don't do [] as regex correctly
74         self.runCmd(
75             'type summary add --summary-string "${var[].integer}" "i_am_cool[]')
76
77         self.expect("frame variable cool_array",
78                     substrs=['1,1,1,1,6'])
79
80         self.runCmd("type summary clear")
81
82         self.runCmd(
83             "type summary add --summary-string \"${var[1-0]%x}\" \"int\"")
84
85         self.expect("frame variable iAmInt",
86                     substrs=['01'])
87
88         self.runCmd(
89             "type summary add --summary-string \"${var[0-1]%x}\" \"int\"")
90
91         self.expect("frame variable iAmInt",
92                     substrs=['01'])
93
94         self.runCmd("type summary clear")
95
96         self.runCmd("type summary add --summary-string \"${var[0-1]%x}\" int")
97         self.runCmd(
98             "type summary add --summary-string \"${var[0-31]%x}\" float")
99
100         self.expect("frame variable *pointer",
101                     substrs=['0x',
102                              '2'])
103
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",
108                     substrs=['9 1'])
109
110         self.expect("frame variable cool_array[3].floating",
111                     substrs=['0x'])
112
113         self.runCmd(
114             "type summary add --summary-string \"low bits are ${*var[0-1]} tgt is ${*var}\" \"int *\"")
115
116         self.expect("frame variable pointer",
117                     substrs=['low bits are',
118                              'tgt is 6'])
119
120         self.expect(
121             "frame variable int_array --summary-string \"${*var[0-1]}\"",
122             substrs=['3'])
123
124         self.runCmd("type summary clear")
125
126         self.runCmd(
127             'type summary add --summary-string \"${var[0-1]}\" -x \"int \[[0-9]\]\"')
128
129         self.expect("frame variable int_array",
130                     substrs=['1,2'])
131
132         self.runCmd(
133             'type summary add --summary-string \"${var[0-1]}\" "int []"')
134
135         self.expect("frame variable int_array",
136                     substrs=['1,2'])
137
138         # Test the patterns are matched in reverse-chronological order.
139         self.runCmd(
140             'type summary add --summary-string \"${var[2-3]}\" "int []"')
141
142         self.expect("frame variable int_array",
143                     substrs=['3,4'])
144
145         self.runCmd("type summary clear")
146
147         self.runCmd("type summary add -c -x \"i_am_cool \[[0-9]\]\"")
148         self.runCmd("type summary add -c i_am_cool")
149
150         self.expect("frame variable cool_array",
151                     substrs=['[0]',
152                              '[1]',
153                              '[2]',
154                              '[3]',
155                              '[4]',
156                              'integer',
157                              'character',
158                              'floating'])
159
160         self.runCmd(
161             "type summary add --summary-string \"int = ${*var.int_pointer}, float = ${*var.float_pointer}\" IWrapPointers")
162
163         self.expect("frame variable wrapper",
164                     substrs=['int = 4',
165                              'float = 1.1'])
166
167         self.runCmd(
168             "type summary add --summary-string \"low bits = ${*var.int_pointer[2]}\" IWrapPointers -p")
169
170         self.expect("frame variable wrapper",
171                     substrs=['low bits = 1'])
172
173         self.expect("frame variable *wrap_pointer",
174                     substrs=['low bits = 1'])
175
176         self.runCmd("type summary clear")
177
178         self.expect(
179             "frame variable int_array --summary-string \"${var[0][0-2]%hex}\"",
180             substrs=[
181                 '0x',
182                 '7'])
183
184         self.runCmd("type summary clear")
185
186         self.runCmd(
187             "type summary add --summary-string \"${*var[].x[0-3]%hex} is a bitfield on a set of integers\" -x \"SimpleWithPointers \[[0-9]\]\"")
188
189         self.expect(
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]}\"",
191             substrs=[
192                 '1 are low bits of integer 9.',
193                 'If I pretend it is an array I get [9,'])
194
195         # if the summary has an error, we still display the value
196         self.expect(
197             "frame variable couple --summary-string \"${*var.sp.foo[0-2]\"",
198             substrs=[
199                 '(Couple) couple = {',
200                 'x = 0x',
201                 'y = 0x',
202                 'z = 0x',
203                 's = 0x'])
204
205         self.runCmd(
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")
207
208         self.expect("frame variable sparray",
209                     substrs=['[0x0000000f,0x0000000c,0x00000009]'])
210
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")
214         self.runCmd(
215             "type summary add --summary-string \"x=${var.x%d}\" Simple")
216
217         self.expect("frame variable a_simple_object",
218                     substrs=['x=3'])
219
220         self.expect("frame variable a_simple_object", matching=False,
221                     substrs=['0x0'])
222
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")
225
226         self.expect("frame variable a_simple_object", matching=False,
227                     substrs=['x=3'])
228
229         self.expect("frame variable a_simple_object", matching=True,
230                     substrs=['x=0x00000003'])
231
232         # check that we can correctly cap the number of children shown
233         self.runCmd("settings set target.max-children-count 5")
234
235         self.expect('frame variable a_long_guy', matching=True,
236                     substrs=['a_1',
237                              'b_1',
238                              'c_1',
239                              'd_1',
240                              'e_1',
241                              '...'])
242
243         # check that no further stuff is printed (not ALL values are checked!)
244         self.expect('frame variable a_long_guy', matching=False,
245                     substrs=['f_1',
246                              'g_1',
247                              'h_1',
248                              'i_1',
249                              'j_1',
250                              'q_1',
251                              'a_2',
252                              'f_2',
253                              't_2',
254                              'w_2'])
255
256         self.runCmd("settings set target.max-children-count 1")
257         self.expect('frame variable a_long_guy', matching=True,
258                     substrs=['a_1',
259                              '...'])
260         self.expect('frame variable a_long_guy', matching=False,
261                     substrs=['b_1',
262                              'c_1',
263                              'd_1',
264                              'e_1'])
265         self.expect('frame variable a_long_guy', matching=False,
266                     substrs=['f_1',
267                              'g_1',
268                              'h_1',
269                              'i_1',
270                              'j_1',
271                              'q_1',
272                              'a_2',
273                              'f_2',
274                              't_2',
275                              'w_2'])
276
277         self.runCmd("settings set target.max-children-count 30")
278         self.expect('frame variable a_long_guy', matching=True,
279                     substrs=['a_1',
280                              'b_1',
281                              'c_1',
282                              'd_1',
283                              'e_1',
284                              'z_1',
285                              'a_2',
286                              'b_2',
287                              'c_2',
288                              'd_2',
289                              '...'])
290         self.expect('frame variable a_long_guy', matching=False,
291                     substrs=['e_2',
292                              'n_2',
293                              'r_2',
294                              'i_2',
295                              'k_2',
296                              'o_2'])
297
298         # override the cap
299         self.expect(
300             'frame variable a_long_guy --show-all-children',
301             matching=True,
302             substrs=[
303                 'a_1',
304                 'b_1',
305                 'c_1',
306                 'd_1',
307                 'e_1',
308                 'z_1',
309                 'a_2',
310                 'b_2',
311                 'c_2',
312                 'd_2'])
313         self.expect(
314             'frame variable a_long_guy --show-all-children',
315             matching=True,
316             substrs=[
317                 'e_2',
318                 'n_2',
319                 'r_2',
320                 'i_2',
321                 'k_2',
322                 'o_2'])
323         self.expect(
324             'frame variable a_long_guy --show-all-children',
325             matching=False,
326             substrs=['...'])