2 Test lldb data formatter subsystem.
8 from lldbsuite.test.decorators import *
9 from lldbsuite.test.lldbtest import *
10 from lldbsuite.test import lldbutil
13 class SmartArrayDataFormatterTestCase(TestBase):
15 mydir = TestBase.compute_mydir(__file__)
17 def test_with_run_command(self):
18 """Test data formatter commands."""
20 self.data_formatter_commands()
23 # Call super's setUp().
25 # Find the line number to break at.
26 self.line = line_number('main.cpp', '// Set break point at this line.')
28 def data_formatter_commands(self):
29 """Test that that file and class static variables display correctly."""
30 self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
32 lldbutil.run_break_set_by_file_and_line(
33 self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True)
35 self.runCmd("run", RUN_SUCCEEDED)
37 process = self.dbg.GetSelectedTarget().GetProcess()
39 # The stop reason of the thread should be breakpoint.
40 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
42 'stop reason = breakpoint'])
44 # This is the function to remove the custom formats in order to have a
45 # clean slate for the next test case.
47 self.runCmd('type format clear', check=False)
48 self.runCmd('type summary clear', check=False)
50 # Execute the cleanup function during test case tear down.
51 self.addTearDownHook(cleanup)
53 # check that we are not looping here
54 self.runCmd("type summary add --summary-string \"${var%V}\" SomeData")
56 self.expect("frame variable data",
57 substrs=['SomeData @ 0x'])
60 "type summary add --summary-string \"ptr = ${var%s}\" \"char *\"")
62 self.expect("frame variable strptr",
66 self.expect("frame variable other.strptr",
68 'Nested Hello world!'])
71 "type summary add --summary-string \"arr = ${var%s}\" -x \"char \\[[0-9]+\\]\"")
73 self.expect("frame variable strarr",
77 self.expect("frame variable other.strarr",
79 'Nested Hello world!'])
81 self.expect("p strarr",
85 self.expect("p other.strarr",
87 'Nested Hello world!'])
91 "type summary add --summary-string \"ptr = ${var%c}\" \"char *\"")
93 self.expect("frame variable strptr",
97 self.expect("frame variable other.strptr",
99 'Nested Hello world!'])
101 self.expect("p strptr",
105 self.expect("p other.strptr",
107 'Nested Hello world!'])
110 "type summary add --summary-string \"arr = ${var%c}\" -x \"char \\[[0-9]+\\]\"")
112 self.expect("frame variable strarr",
116 self.expect("frame variable other.strarr",
118 'Nested Hello world!'])
120 self.expect("p strarr",
124 self.expect("p other.strarr",
126 'Nested Hello world!'])
130 "type summary add --summary-string \"arr = ${var%char[]}\" -x \"char \\[[0-9]+\\]\"")
132 self.expect("frame variable strarr",
136 self.expect("frame variable other.strarr",
138 'Nested Hello world!'])
140 self.expect("p strarr",
144 self.expect("p other.strarr",
146 'Nested Hello world!'])
149 "type summary add --summary-string \"ptr = ${var%char[]}\" \"char *\"")
151 self.expect("frame variable strptr",
155 self.expect("frame variable other.strptr",
157 'Nested Hello world!'])
159 self.expect("p strptr",
163 self.expect("p other.strptr",
165 'Nested Hello world!'])
169 "type summary add --summary-string \"arr = ${var%a}\" -x \"char \\[[0-9]+\\]\"")
171 self.expect("frame variable strarr",
175 self.expect("frame variable other.strarr",
177 'Nested Hello world!'])
179 self.expect("p strarr",
183 self.expect("p other.strarr",
185 'Nested Hello world!'])
188 "type summary add --summary-string \"ptr = ${var%a}\" \"char *\"")
190 self.expect("frame variable strptr",
194 self.expect("frame variable other.strptr",
196 'Nested Hello world!'])
198 self.expect("p strptr",
202 self.expect("p other.strptr",
204 'Nested Hello world!'])
207 "type summary add --summary-string \"ptr = ${var[]%char[]}\" \"char *\"")
209 # I do not know the size of the data, but you are asking for a full array slice..
210 # use the ${var%char[]} to obtain a string as result
211 self.expect("frame variable strptr", matching=False,
215 self.expect("frame variable other.strptr", matching=False,
217 'Nested Hello world!'])
219 self.expect("p strptr", matching=False,
223 self.expect("p other.strptr", matching=False,
225 'Nested Hello world!'])
227 # You asked an array-style printout...
229 "type summary add --summary-string \"ptr = ${var[0-1]%char[]}\" \"char *\"")
231 self.expect("frame variable strptr",
235 self.expect("frame variable other.strptr",
239 self.expect("p strptr",
243 self.expect("p other.strptr",
247 # using [] is required here
249 "type summary add --summary-string \"arr = ${var%x}\" \"int [5]\"")
251 self.expect("frame variable intarr", matching=False, substrs=[
252 '0x00000001,0x00000001,0x00000002,0x00000003,0x00000005'])
254 self.expect("frame variable other.intarr", matching=False, substrs=[
255 '0x00000009,0x00000008,0x00000007,0x00000006,0x00000005'])
258 "type summary add --summary-string \"arr = ${var[]%x}\" \"int [5]\"")
261 "frame variable intarr",
264 '0x00000001,0x00000001,0x00000002,0x00000003,0x00000005'])
267 "frame variable other.intarr",
270 '0x00000009,0x00000008,0x00000007,0x00000006,0x00000005'])
272 # printing each array item as an array
274 "type summary add --summary-string \"arr = ${var[]%uint32_t[]}\" \"int [5]\"")
277 "frame variable intarr",
280 '{0x00000001},{0x00000001},{0x00000002},{0x00000003},{0x00000005}'])
283 "frame variable other.intarr",
286 '{0x00000009},{0x00000008},{0x00000007},{0x00000006},{0x00000005}'])
288 # printing full array as an array
290 "type summary add --summary-string \"arr = ${var%uint32_t[]}\" \"int [5]\"")
293 "frame variable intarr",
296 '0x00000001,0x00000001,0x00000002,0x00000003,0x00000005'])
299 "frame variable other.intarr",
302 '0x00000009,0x00000008,0x00000007,0x00000006,0x00000005'])
304 # printing each array item as an array
306 "type summary add --summary-string \"arr = ${var[]%float32[]}\" \"float [7]\"")
309 "frame variable flarr",
312 '{78.5},{77.25},{78},{76.125},{76.75},{76.875},{77}'])
315 "frame variable other.flarr",
318 '{25.5},{25.25},{25.125},{26.75},{27.375},{27.5},{26.125}'])
320 # printing full array as an array
322 "type summary add --summary-string \"arr = ${var%float32[]}\" \"float [7]\"")
324 self.expect("frame variable flarr",
325 substrs=['flarr = arr =',
326 '78.5,77.25,78,76.125,76.75,76.875,77'])
328 self.expect("frame variable other.flarr",
329 substrs=['flarr = arr =',
330 '25.5,25.25,25.125,26.75,27.375,27.5,26.125'])
332 # using array smart summary strings for pointers should make no sense
334 "type summary add --summary-string \"arr = ${var%float32[]}\" \"float *\"")
336 "type summary add --summary-string \"arr = ${var%int32_t[]}\" \"int *\"")
338 self.expect("frame variable flptr", matching=False,
339 substrs=['78.5,77.25,78,76.125,76.75,76.875,77'])
341 self.expect("frame variable intptr", matching=False,
342 substrs=['1,1,2,3,5'])
346 "type summary add --summary-string \"arr = ${var%y}\" \"float [7]\"")
348 "type summary add --summary-string \"arr = ${var%y}\" \"int [5]\"")
350 if process.GetByteOrder() == lldb.eByteOrderLittle:
352 "frame variable flarr",
355 '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'])
358 "frame variable flarr",
361 '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'])
363 if process.GetByteOrder() == lldb.eByteOrderLittle:
365 "frame variable other.flarr",
368 '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'])
371 "frame variable other.flarr",
374 '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'])
376 if process.GetByteOrder() == lldb.eByteOrderLittle:
378 "frame variable intarr",
381 '01 00 00 00,01 00 00 00,02 00 00 00,03 00 00 00,05 00 00 00'])
384 "frame variable intarr",
387 '00 00 00 01,00 00 00 01,00 00 00 02,00 00 00 03,00 00 00 05'])
389 if process.GetByteOrder() == lldb.eByteOrderLittle:
391 "frame variable other.intarr",
394 '09 00 00 00,08 00 00 00,07 00 00 00,06 00 00 00,05 00 00 00'])
397 "frame variable other.intarr",
400 '00 00 00 09,00 00 00 08,00 00 00 07,00 00 00 06,00 00 00 05'])
403 "type summary add --summary-string \"arr = ${var%Y}\" \"float [7]\"")
405 "type summary add --summary-string \"arr = ${var%Y}\" \"int [5]\"")
407 if process.GetByteOrder() == lldb.eByteOrderLittle:
409 "frame variable flarr",
412 '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'])
415 "frame variable flarr",
418 '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'])
420 if process.GetByteOrder() == lldb.eByteOrderLittle:
422 "frame variable other.flarr",
425 '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'])
428 "frame variable other.flarr",
431 '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'])
433 if process.GetByteOrder() == lldb.eByteOrderLittle:
434 self.expect("frame variable intarr",
435 substrs=['intarr = arr =',
439 self.expect("frame variable intarr",
440 substrs=['intarr = arr =',
444 if process.GetByteOrder() == lldb.eByteOrderLittle:
445 self.expect("frame variable other.intarr",
446 substrs=['intarr = arr = ',
450 self.expect("frame variable other.intarr",
451 substrs=['intarr = arr = ',