]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-smart-array/TestDataFormatterSmartArray.py
Vendor import of lldb release_39 branch r276489:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / functionalities / data-formatter / data-formatter-smart-array / TestDataFormatterSmartArray.py
1 """
2 Test lldb data formatter subsystem.
3 """
4
5 from __future__ import print_function
6
7
8
9 import os, time
10 import lldb
11 from lldbsuite.test.decorators import *
12 from lldbsuite.test.lldbtest import *
13 from lldbsuite.test import lldbutil
14
15 class SmartArrayDataFormatterTestCase(TestBase):
16
17     mydir = TestBase.compute_mydir(__file__)
18
19     @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24462, Data formatters have problems on Windows")
20     def test_with_run_command(self):
21         """Test data formatter commands."""
22         self.build()
23         self.data_formatter_commands()
24
25     def setUp(self):
26         # Call super's setUp().
27         TestBase.setUp(self)
28         # Find the line number to break at.
29         self.line = line_number('main.cpp', '// Set break point at this line.')
30
31     def data_formatter_commands(self):
32         """Test that that file and class static variables display correctly."""
33         self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)
34
35         lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True)
36
37         self.runCmd("run", RUN_SUCCEEDED)
38
39         process = self.dbg.GetSelectedTarget().GetProcess()
40
41         # The stop reason of the thread should be breakpoint.
42         self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
43             substrs = ['stopped',
44                        'stop reason = breakpoint'])
45         
46         # This is the function to remove the custom formats in order to have a
47         # clean slate for the next test case.
48         def cleanup():
49             self.runCmd('type format clear', check=False)
50             self.runCmd('type summary clear', check=False)
51
52         # Execute the cleanup function during test case tear down.
53         self.addTearDownHook(cleanup)
54
55 # check that we are not looping here
56         self.runCmd("type summary add --summary-string \"${var%V}\" SomeData")
57
58         self.expect("frame variable data",
59             substrs = ['SomeData @ 0x'])
60 # ${var%s}
61         self.runCmd("type summary add --summary-string \"ptr = ${var%s}\" \"char *\"")
62
63         self.expect("frame variable strptr",
64             substrs = ['ptr = \"',
65                        'Hello world!'])
66
67         self.expect("frame variable other.strptr",
68             substrs = ['ptr = \"',
69                         'Nested Hello world!'])
70         
71         self.runCmd("type summary add --summary-string \"arr = ${var%s}\" -x \"char \\[[0-9]+\\]\"")
72         
73         self.expect("frame variable strarr",
74                     substrs = ['arr = \"',
75                                'Hello world!'])
76         
77         self.expect("frame variable other.strarr",
78                     substrs = ['arr = \"',
79                                'Nested Hello world!'])
80
81         self.expect("p strarr",
82                     substrs = ['arr = \"',
83                                'Hello world!'])
84
85         self.expect("p other.strarr",
86                     substrs = ['arr = \"',
87                                'Nested Hello world!'])
88
89 # ${var%c}
90         self.runCmd("type summary add --summary-string \"ptr = ${var%c}\" \"char *\"")
91     
92         self.expect("frame variable strptr",
93                 substrs = ['ptr = \"',
94                            'Hello world!'])
95     
96         self.expect("frame variable other.strptr",
97                 substrs = ['ptr = \"',
98                            'Nested Hello world!'])
99
100         self.expect("p strptr",
101                     substrs = ['ptr = \"',
102                                'Hello world!'])
103
104         self.expect("p other.strptr",
105                     substrs = ['ptr = \"',
106                                'Nested Hello world!'])
107
108         self.runCmd("type summary add --summary-string \"arr = ${var%c}\" -x \"char \\[[0-9]+\\]\"")
109
110         self.expect("frame variable strarr",
111                     substrs = ['arr = \"',
112                                'Hello world!'])
113
114         self.expect("frame variable other.strarr",
115                     substrs = ['arr = \"',
116                                'Nested Hello world!'])
117         
118         self.expect("p strarr",
119                     substrs = ['arr = \"',
120                                'Hello world!'])
121
122         self.expect("p other.strarr",
123                     substrs = ['arr = \"',
124                                'Nested Hello world!'])
125
126 # ${var%char[]}
127         self.runCmd("type summary add --summary-string \"arr = ${var%char[]}\" -x \"char \\[[0-9]+\\]\"")
128
129         self.expect("frame variable strarr",
130                     substrs = ['arr = \"',
131                                'Hello world!'])
132
133         self.expect("frame variable other.strarr",
134                     substrs = ['arr = ',
135                                'Nested Hello world!'])
136
137         self.expect("p strarr",
138                     substrs = ['arr = \"',
139                                'Hello world!'])
140
141         self.expect("p other.strarr",
142                     substrs = ['arr = ',
143                                'Nested Hello world!'])
144
145         self.runCmd("type summary add --summary-string \"ptr = ${var%char[]}\" \"char *\"")
146
147         self.expect("frame variable strptr",
148             substrs = ['ptr = \"',
149             'Hello world!'])
150         
151         self.expect("frame variable other.strptr",
152             substrs = ['ptr = \"',
153             'Nested Hello world!'])
154
155         self.expect("p strptr",
156                     substrs = ['ptr = \"',
157                                'Hello world!'])
158
159         self.expect("p other.strptr",
160                     substrs = ['ptr = \"',
161                                'Nested Hello world!'])
162
163 # ${var%a}
164         self.runCmd("type summary add --summary-string \"arr = ${var%a}\" -x \"char \\[[0-9]+\\]\"")
165
166         self.expect("frame variable strarr",
167                     substrs = ['arr = \"',
168                                'Hello world!'])
169
170         self.expect("frame variable other.strarr",
171                     substrs = ['arr = ',
172                                'Nested Hello world!'])
173
174         self.expect("p strarr",
175                     substrs = ['arr = \"',
176                                'Hello world!'])
177
178         self.expect("p other.strarr",
179                     substrs = ['arr = ',
180                                'Nested Hello world!'])
181
182         self.runCmd("type summary add --summary-string \"ptr = ${var%a}\" \"char *\"")
183
184         self.expect("frame variable strptr",
185                     substrs = ['ptr = \"',
186                                'Hello world!'])
187
188         self.expect("frame variable other.strptr",
189                     substrs = ['ptr = \"',
190                                'Nested Hello world!'])
191
192         self.expect("p strptr",
193                     substrs = ['ptr = \"',
194                                'Hello world!'])
195
196         self.expect("p other.strptr",
197                     substrs = ['ptr = \"',
198                                'Nested Hello world!'])
199
200         self.runCmd("type summary add --summary-string \"ptr = ${var[]%char[]}\" \"char *\"")
201         
202 # I do not know the size of the data, but you are asking for a full array slice..
203 # use the ${var%char[]} to obtain a string as result
204         self.expect("frame variable strptr", matching=False,
205                     substrs = ['ptr = \"',
206                                'Hello world!'])
207         
208         self.expect("frame variable other.strptr", matching=False,
209                     substrs = ['ptr = \"',
210                                'Nested Hello world!'])
211
212         self.expect("p strptr", matching=False,
213                     substrs = ['ptr = \"',
214                                'Hello world!'])
215
216         self.expect("p other.strptr", matching=False,
217                     substrs = ['ptr = \"',
218                                'Nested Hello world!'])
219
220 # You asked an array-style printout...
221         self.runCmd("type summary add --summary-string \"ptr = ${var[0-1]%char[]}\" \"char *\"")
222         
223         self.expect("frame variable strptr",
224                     substrs = ['ptr = ',
225                                '[{H},{e}]'])
226         
227         self.expect("frame variable other.strptr",
228                     substrs = ['ptr = ',
229                                '[{N},{e}]'])
230
231         self.expect("p strptr",
232                     substrs = ['ptr = ',
233                                '[{H},{e}]'])
234
235         self.expect("p other.strptr",
236                     substrs = ['ptr = ',
237                                '[{N},{e}]'])
238
239 # using [] is required here
240         self.runCmd("type summary add --summary-string \"arr = ${var%x}\" \"int [5]\"")
241         
242         self.expect("frame variable intarr",matching=False,
243                     substrs = ['0x00000001,0x00000001,0x00000002,0x00000003,0x00000005'])
244         
245         self.expect("frame variable other.intarr", matching=False,
246                     substrs = ['0x00000009,0x00000008,0x00000007,0x00000006,0x00000005'])
247
248         self.runCmd("type summary add --summary-string \"arr = ${var[]%x}\" \"int [5]\"")
249         
250         self.expect("frame variable intarr",
251                     substrs = ['intarr = arr =',
252                                '0x00000001,0x00000001,0x00000002,0x00000003,0x00000005'])
253         
254         self.expect("frame variable other.intarr",
255                     substrs = ['intarr = arr =',
256                                '0x00000009,0x00000008,0x00000007,0x00000006,0x00000005'])
257
258 # printing each array item as an array
259         self.runCmd("type summary add --summary-string \"arr = ${var[]%uint32_t[]}\" \"int [5]\"")
260         
261         self.expect("frame variable intarr",
262                     substrs = ['intarr = arr =',
263                                '{0x00000001},{0x00000001},{0x00000002},{0x00000003},{0x00000005}'])
264         
265         self.expect("frame variable other.intarr",
266                     substrs = ['intarr = arr = ',
267                                '{0x00000009},{0x00000008},{0x00000007},{0x00000006},{0x00000005}'])
268
269 # printing full array as an array
270         self.runCmd("type summary add --summary-string \"arr = ${var%uint32_t[]}\" \"int [5]\"")
271         
272         self.expect("frame variable intarr",
273                     substrs = ['intarr = arr =',
274                                '0x00000001,0x00000001,0x00000002,0x00000003,0x00000005'])
275
276         self.expect("frame variable other.intarr",
277                     substrs = ['intarr = arr =',
278                                '0x00000009,0x00000008,0x00000007,0x00000006,0x00000005'])
279
280 # printing each array item as an array
281         self.runCmd("type summary add --summary-string \"arr = ${var[]%float32[]}\" \"float [7]\"")
282         
283         self.expect("frame variable flarr",
284                     substrs = ['flarr = arr =',
285                                '{78.5},{77.25},{78},{76.125},{76.75},{76.875},{77}'])
286         
287         self.expect("frame variable other.flarr",
288                     substrs = ['flarr = arr = ',
289                                '{25.5},{25.25},{25.125},{26.75},{27.375},{27.5},{26.125}'])
290         
291 # printing full array as an array
292         self.runCmd("type summary add --summary-string \"arr = ${var%float32[]}\" \"float [7]\"")
293         
294         self.expect("frame variable flarr",
295                     substrs = ['flarr = arr =',
296                                '78.5,77.25,78,76.125,76.75,76.875,77'])
297         
298         self.expect("frame variable other.flarr",
299                     substrs = ['flarr = arr =',
300                                '25.5,25.25,25.125,26.75,27.375,27.5,26.125'])
301
302 # using array smart summary strings for pointers should make no sense
303         self.runCmd("type summary add --summary-string \"arr = ${var%float32[]}\" \"float *\"")
304         self.runCmd("type summary add --summary-string \"arr = ${var%int32_t[]}\" \"int *\"")
305
306         self.expect("frame variable flptr", matching=False,
307                     substrs = ['78.5,77.25,78,76.125,76.75,76.875,77'])
308         
309         self.expect("frame variable intptr", matching=False,
310                     substrs = ['1,1,2,3,5'])
311
312 # use y and Y
313         self.runCmd("type summary add --summary-string \"arr = ${var%y}\" \"float [7]\"")
314         self.runCmd("type summary add --summary-string \"arr = ${var%y}\" \"int [5]\"")
315
316         if process.GetByteOrder() == lldb.eByteOrderLittle:
317             self.expect("frame variable flarr",
318                         substrs = ['flarr = arr =',
319                                    '00 00 9d 42,00 80 9a 42,00 00 9c 42,00 40 98 42,00 80 99 42,00 c0 99 42,00 00 9a 42'])
320         else:
321             self.expect("frame variable flarr",
322                         substrs = ['flarr = arr =',
323                                    '42 9d 00 00,42 9a 80 00,42 9c 00 00,42 98 40 00,42 99 80 00,42 99 c0 00,42 9a 00 00'])
324
325         if process.GetByteOrder() == lldb.eByteOrderLittle:
326             self.expect("frame variable other.flarr",
327                         substrs = ['flarr = arr =',
328                                    '00 00 cc 41,00 00 ca 41,00 00 c9 41,00 00 d6 41,00 00 db 41,00 00 dc 41,00 00 d1 41'])
329         else:
330             self.expect("frame variable other.flarr",
331                         substrs = ['flarr = arr =',
332                                    '41 cc 00 00,41 ca 00 00,41 c9 00 00,41 d6 00 00,41 db 00 00,41 dc 00 00,41 d1 00 00'])
333
334         if process.GetByteOrder() == lldb.eByteOrderLittle:
335             self.expect("frame variable intarr",
336                         substrs = ['intarr = arr =',
337                                    '01 00 00 00,01 00 00 00,02 00 00 00,03 00 00 00,05 00 00 00'])
338         else:
339             self.expect("frame variable intarr",
340                         substrs = ['intarr = arr =',
341                                    '00 00 00 01,00 00 00 01,00 00 00 02,00 00 00 03,00 00 00 05'])
342
343         if process.GetByteOrder() == lldb.eByteOrderLittle:
344             self.expect("frame variable other.intarr",
345                         substrs = ['intarr = arr = ',
346                                    '09 00 00 00,08 00 00 00,07 00 00 00,06 00 00 00,05 00 00 00'])
347         else:
348             self.expect("frame variable other.intarr",
349                         substrs = ['intarr = arr = ',
350                                    '00 00 00 09,00 00 00 08,00 00 00 07,00 00 00 06,00 00 00 05'])
351                     
352         self.runCmd("type summary add --summary-string \"arr = ${var%Y}\" \"float [7]\"")
353         self.runCmd("type summary add --summary-string \"arr = ${var%Y}\" \"int [5]\"")
354             
355         if process.GetByteOrder() == lldb.eByteOrderLittle:
356             self.expect("frame variable flarr",
357                         substrs = ['flarr = arr =',
358                                    '00 00 9d 42             ...B,00 80 9a 42             ...B,00 00 9c 42             ...B,00 40 98 42             .@.B,00 80 99 42             ...B,00 c0 99 42             ...B,00 00 9a 42             ...B'])
359         else:
360             self.expect("frame variable flarr",
361                         substrs = ['flarr = arr =',
362                                    '42 9d 00 00             B...,42 9a 80 00             B...,42 9c 00 00             B...,42 98 40 00             B.@.,42 99 80 00             B...,42 99 c0 00             B...,42 9a 00 00             B...'])
363
364         if process.GetByteOrder() == lldb.eByteOrderLittle:
365             self.expect("frame variable other.flarr",
366                         substrs = ['flarr = arr =',
367                                    '00 00 cc 41             ...A,00 00 ca 41             ...A,00 00 c9 41             ...A,00 00 d6 41             ...A,00 00 db 41             ...A,00 00 dc 41             ...A,00 00 d1 41             ...A'])
368         else:
369             self.expect("frame variable other.flarr",
370                         substrs = ['flarr = arr =',
371                                    '41 cc 00 00             A...,41 ca 00 00             A...,41 c9 00 00             A...,41 d6 00 00             A...,41 db 00 00             A...,41 dc 00 00             A...,41 d1 00 00             A...'])
372
373         if process.GetByteOrder() == lldb.eByteOrderLittle:
374             self.expect("frame variable intarr",
375                         substrs = ['intarr = arr =',
376                                    '....,01 00 00 00',
377                                    '....,05 00 00 00'])
378         else:
379             self.expect("frame variable intarr",
380                         substrs = ['intarr = arr =',
381                                    '....,00 00 00 01',
382                                    '....,00 00 00 05'])
383
384         if process.GetByteOrder() == lldb.eByteOrderLittle:
385             self.expect("frame variable other.intarr",
386                         substrs = ['intarr = arr = ',
387                                    '09 00 00 00',
388                                    '....,07 00 00 00'])
389         else:
390             self.expect("frame variable other.intarr",
391                         substrs = ['intarr = arr = ',
392                                    '00 00 00 09',
393                                    '....,00 00 00 07'])