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