2 Test lldb data formatter subsystem.
5 from __future__ import print_function
11 from lldbsuite.test.decorators import *
12 from lldbsuite.test.lldbtest import *
13 from lldbsuite.test import lldbutil
15 class SmartArrayDataFormatterTestCase(TestBase):
17 mydir = TestBase.compute_mydir(__file__)
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."""
23 self.data_formatter_commands()
26 # Call super's setUp().
28 # Find the line number to break at.
29 self.line = line_number('main.cpp', '// Set break point at this line.')
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)
35 lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True)
37 self.runCmd("run", RUN_SUCCEEDED)
39 process = self.dbg.GetSelectedTarget().GetProcess()
41 # The stop reason of the thread should be breakpoint.
42 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
44 'stop reason = breakpoint'])
46 # This is the function to remove the custom formats in order to have a
47 # clean slate for the next test case.
49 self.runCmd('type format clear', check=False)
50 self.runCmd('type summary clear', check=False)
52 # Execute the cleanup function during test case tear down.
53 self.addTearDownHook(cleanup)
55 # check that we are not looping here
56 self.runCmd("type summary add --summary-string \"${var%V}\" SomeData")
58 self.expect("frame variable data",
59 substrs = ['SomeData @ 0x'])
61 self.runCmd("type summary add --summary-string \"ptr = ${var%s}\" \"char *\"")
63 self.expect("frame variable strptr",
64 substrs = ['ptr = \"',
67 self.expect("frame variable other.strptr",
68 substrs = ['ptr = \"',
69 'Nested Hello world!'])
71 self.runCmd("type summary add --summary-string \"arr = ${var%s}\" -x \"char \\[[0-9]+\\]\"")
73 self.expect("frame variable strarr",
74 substrs = ['arr = \"',
77 self.expect("frame variable other.strarr",
78 substrs = ['arr = \"',
79 'Nested Hello world!'])
81 self.expect("p strarr",
82 substrs = ['arr = \"',
85 self.expect("p other.strarr",
86 substrs = ['arr = \"',
87 'Nested Hello world!'])
90 self.runCmd("type summary add --summary-string \"ptr = ${var%c}\" \"char *\"")
92 self.expect("frame variable strptr",
93 substrs = ['ptr = \"',
96 self.expect("frame variable other.strptr",
97 substrs = ['ptr = \"',
98 'Nested Hello world!'])
100 self.expect("p strptr",
101 substrs = ['ptr = \"',
104 self.expect("p other.strptr",
105 substrs = ['ptr = \"',
106 'Nested Hello world!'])
108 self.runCmd("type summary add --summary-string \"arr = ${var%c}\" -x \"char \\[[0-9]+\\]\"")
110 self.expect("frame variable strarr",
111 substrs = ['arr = \"',
114 self.expect("frame variable other.strarr",
115 substrs = ['arr = \"',
116 'Nested Hello world!'])
118 self.expect("p strarr",
119 substrs = ['arr = \"',
122 self.expect("p other.strarr",
123 substrs = ['arr = \"',
124 'Nested Hello world!'])
127 self.runCmd("type summary add --summary-string \"arr = ${var%char[]}\" -x \"char \\[[0-9]+\\]\"")
129 self.expect("frame variable strarr",
130 substrs = ['arr = \"',
133 self.expect("frame variable other.strarr",
135 'Nested Hello world!'])
137 self.expect("p strarr",
138 substrs = ['arr = \"',
141 self.expect("p other.strarr",
143 'Nested Hello world!'])
145 self.runCmd("type summary add --summary-string \"ptr = ${var%char[]}\" \"char *\"")
147 self.expect("frame variable strptr",
148 substrs = ['ptr = \"',
151 self.expect("frame variable other.strptr",
152 substrs = ['ptr = \"',
153 'Nested Hello world!'])
155 self.expect("p strptr",
156 substrs = ['ptr = \"',
159 self.expect("p other.strptr",
160 substrs = ['ptr = \"',
161 'Nested Hello world!'])
164 self.runCmd("type summary add --summary-string \"arr = ${var%a}\" -x \"char \\[[0-9]+\\]\"")
166 self.expect("frame variable strarr",
167 substrs = ['arr = \"',
170 self.expect("frame variable other.strarr",
172 'Nested Hello world!'])
174 self.expect("p strarr",
175 substrs = ['arr = \"',
178 self.expect("p other.strarr",
180 'Nested Hello world!'])
182 self.runCmd("type summary add --summary-string \"ptr = ${var%a}\" \"char *\"")
184 self.expect("frame variable strptr",
185 substrs = ['ptr = \"',
188 self.expect("frame variable other.strptr",
189 substrs = ['ptr = \"',
190 'Nested Hello world!'])
192 self.expect("p strptr",
193 substrs = ['ptr = \"',
196 self.expect("p other.strptr",
197 substrs = ['ptr = \"',
198 'Nested Hello world!'])
200 self.runCmd("type summary add --summary-string \"ptr = ${var[]%char[]}\" \"char *\"")
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 = \"',
208 self.expect("frame variable other.strptr", matching=False,
209 substrs = ['ptr = \"',
210 'Nested Hello world!'])
212 self.expect("p strptr", matching=False,
213 substrs = ['ptr = \"',
216 self.expect("p other.strptr", matching=False,
217 substrs = ['ptr = \"',
218 'Nested Hello world!'])
220 # You asked an array-style printout...
221 self.runCmd("type summary add --summary-string \"ptr = ${var[0-1]%char[]}\" \"char *\"")
223 self.expect("frame variable strptr",
227 self.expect("frame variable other.strptr",
231 self.expect("p strptr",
235 self.expect("p other.strptr",
239 # using [] is required here
240 self.runCmd("type summary add --summary-string \"arr = ${var%x}\" \"int [5]\"")
242 self.expect("frame variable intarr",matching=False,
243 substrs = ['0x00000001,0x00000001,0x00000002,0x00000003,0x00000005'])
245 self.expect("frame variable other.intarr", matching=False,
246 substrs = ['0x00000009,0x00000008,0x00000007,0x00000006,0x00000005'])
248 self.runCmd("type summary add --summary-string \"arr = ${var[]%x}\" \"int [5]\"")
250 self.expect("frame variable intarr",
251 substrs = ['intarr = arr =',
252 '0x00000001,0x00000001,0x00000002,0x00000003,0x00000005'])
254 self.expect("frame variable other.intarr",
255 substrs = ['intarr = arr =',
256 '0x00000009,0x00000008,0x00000007,0x00000006,0x00000005'])
258 # printing each array item as an array
259 self.runCmd("type summary add --summary-string \"arr = ${var[]%uint32_t[]}\" \"int [5]\"")
261 self.expect("frame variable intarr",
262 substrs = ['intarr = arr =',
263 '{0x00000001},{0x00000001},{0x00000002},{0x00000003},{0x00000005}'])
265 self.expect("frame variable other.intarr",
266 substrs = ['intarr = arr = ',
267 '{0x00000009},{0x00000008},{0x00000007},{0x00000006},{0x00000005}'])
269 # printing full array as an array
270 self.runCmd("type summary add --summary-string \"arr = ${var%uint32_t[]}\" \"int [5]\"")
272 self.expect("frame variable intarr",
273 substrs = ['intarr = arr =',
274 '0x00000001,0x00000001,0x00000002,0x00000003,0x00000005'])
276 self.expect("frame variable other.intarr",
277 substrs = ['intarr = arr =',
278 '0x00000009,0x00000008,0x00000007,0x00000006,0x00000005'])
280 # printing each array item as an array
281 self.runCmd("type summary add --summary-string \"arr = ${var[]%float32[]}\" \"float [7]\"")
283 self.expect("frame variable flarr",
284 substrs = ['flarr = arr =',
285 '{78.5},{77.25},{78},{76.125},{76.75},{76.875},{77}'])
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}'])
291 # printing full array as an array
292 self.runCmd("type summary add --summary-string \"arr = ${var%float32[]}\" \"float [7]\"")
294 self.expect("frame variable flarr",
295 substrs = ['flarr = arr =',
296 '78.5,77.25,78,76.125,76.75,76.875,77'])
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'])
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 *\"")
306 self.expect("frame variable flptr", matching=False,
307 substrs = ['78.5,77.25,78,76.125,76.75,76.875,77'])
309 self.expect("frame variable intptr", matching=False,
310 substrs = ['1,1,2,3,5'])
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]\"")
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'])
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'])
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'])
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'])
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'])
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'])
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'])
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'])
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]\"")
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'])
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...'])
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'])
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...'])
373 if process.GetByteOrder() == lldb.eByteOrderLittle:
374 self.expect("frame variable intarr",
375 substrs = ['intarr = arr =',
379 self.expect("frame variable intarr",
380 substrs = ['intarr = arr =',
384 if process.GetByteOrder() == lldb.eByteOrderLittle:
385 self.expect("frame variable other.intarr",
386 substrs = ['intarr = arr = ',
390 self.expect("frame variable other.intarr",
391 substrs = ['intarr = arr = ',