]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-cpp/TestDataFormatterCpp.py
Vendor import of lldb trunk r290819:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / functionalities / data-formatter / data-formatter-cpp / TestDataFormatterCpp.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.decorators import *
12 from lldbsuite.test.lldbtest import *
13 from lldbsuite.test import lldbutil
14
15
16 class CppDataFormatterTestCase(TestBase):
17
18     mydir = TestBase.compute_mydir(__file__)
19
20     def setUp(self):
21         # Call super's setUp().
22         TestBase.setUp(self)
23         # Find the line number to break at.
24         self.line = line_number('main.cpp', '// Set break point at this line.')
25
26     @expectedFailureAll(
27         oslist=["windows"],
28         bugnumber="llvm.org/pr24462: Data formatters have problems on Windows")
29     def test_with_run_command(self):
30         """Test that that file and class static variables display correctly."""
31         self.build()
32         self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)
33
34         lldbutil.run_break_set_by_file_and_line(
35             self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True)
36
37         self.runCmd("run", RUN_SUCCEEDED)
38
39         # The stop reason of the thread should be breakpoint.
40         self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
41                     substrs=['stopped',
42                              'stop reason = breakpoint'])
43
44         self.expect("frame variable",
45                     substrs=['(Speed) SPILookHex = 5.55'  # Speed by default is 5.55.
46                              ])
47
48         # This is the function to remove the custom formats in order to have a
49         # clean slate for the next test case.
50         def cleanup():
51             self.runCmd('type format clear', check=False)
52             self.runCmd('type summary clear', check=False)
53
54         # Execute the cleanup function during test case tear down.
55         self.addTearDownHook(cleanup)
56
57         self.runCmd("type format add -C yes -f x Speed BitField")
58         self.runCmd("type format add -C no -f c RealNumber")
59         self.runCmd("type format add -C no -f x Type2")
60         self.runCmd("type format add -C yes -f c Type1")
61
62         # The type format list should show our custom formats.
63         self.expect("type format list",
64                     substrs=['RealNumber',
65                              'Speed',
66                              'BitField',
67                              'Type1',
68                              'Type2'])
69
70         self.expect("frame variable",
71                     patterns=['\(Speed\) SPILookHex = 0x[0-9a-f]+'  # Speed should look hex-ish now.
72                               ])
73
74         # gcc4.2 on Mac OS X skips typedef chains in the DWARF output
75         if self.getCompiler() in ['clang', 'llvm-gcc']:
76             self.expect("frame variable",
77                         patterns=['\(SignalMask\) SMILookHex = 0x[0-9a-f]+'  # SignalMask should look hex-ish now.
78                                   ])
79             self.expect("frame variable", matching=False,
80                         patterns=['\(Type4\) T4ILookChar = 0x[0-9a-f]+'  # Type4 should NOT look hex-ish now.
81                                   ])
82
83         # Now let's delete the 'Speed' custom format.
84         self.runCmd("type format delete Speed")
85
86         # The type format list should not show 'Speed' at this point.
87         self.expect("type format list", matching=False,
88                     substrs=['Speed'])
89
90         # Delete type format for 'Speed', we should expect an error message.
91         self.expect("type format delete Speed", error=True,
92                     substrs=['no custom formatter for Speed'])
93
94         self.runCmd(
95             "type summary add --summary-string \"arr = ${var%s}\" -x \"char \\[[0-9]+\\]\" -v")
96
97         self.expect("frame variable strarr",
98                     substrs=['arr = "Hello world!"'])
99
100         self.runCmd("type summary clear")
101
102         self.runCmd(
103             "type summary add --summary-string \"ptr = ${var%s}\" \"char *\" -v")
104
105         self.expect("frame variable strptr",
106                     substrs=['ptr = "Hello world!"'])
107
108         self.runCmd(
109             "type summary add --summary-string \"arr = ${var%s}\" -x \"char \\[[0-9]+\\]\" -v")
110
111         self.expect("frame variable strarr",
112                     substrs=['arr = "Hello world!'])
113
114         # check that rdar://problem/10011145 (Standard summary format for
115         # char[] doesn't work as the result of "expr".) is solved
116         self.expect("p strarr",
117                     substrs=['arr = "Hello world!'])
118
119         self.expect("frame variable strptr",
120                     substrs=['ptr = "Hello world!"'])
121
122         self.expect("p strptr",
123                     substrs=['ptr = "Hello world!"'])
124
125         self.expect(
126             "p (char*)\"1234567890123456789012345678901234567890123456789012345678901234ABC\"",
127             substrs=[
128                 '(char *) $',
129                 ' = ptr = ',
130                 ' "1234567890123456789012345678901234567890123456789012345678901234ABC"'])
131
132         self.runCmd("type summary add -c Point")
133
134         self.expect("frame variable iAmSomewhere",
135                     substrs=['x = 4',
136                              'y = 6'])
137
138         self.expect("type summary list",
139                     substrs=['Point',
140                              'one-line'])
141
142         self.runCmd("type summary add --summary-string \"y=${var.y%x}\" Point")
143
144         self.expect("frame variable iAmSomewhere",
145                     substrs=['y=0x'])
146
147         self.runCmd(
148             "type summary add --summary-string \"y=${var.y},x=${var.x}\" Point")
149
150         self.expect("frame variable iAmSomewhere",
151                     substrs=['y=6',
152                              'x=4'])
153
154         self.runCmd("type summary add --summary-string \"hello\" Point -e")
155
156         self.expect("type summary list",
157                     substrs=['Point',
158                              'show children'])
159
160         self.expect("frame variable iAmSomewhere",
161                     substrs=['hello',
162                              'x = 4',
163                              '}'])
164
165         self.runCmd(
166             "type summary add --summary-string \"Sign: ${var[31]%B} Exponent: ${var[23-30]%x} Mantissa: ${var[0-22]%u}\" ShowMyGuts")
167
168         self.expect("frame variable cool_pointer->floating",
169                     substrs=['Sign: true',
170                              'Exponent: 0x',
171                              '80'])
172
173         self.runCmd("type summary add --summary-string \"a test\" i_am_cool")
174
175         self.expect("frame variable cool_pointer",
176                     substrs=['a test'])
177
178         self.runCmd(
179             "type summary add --summary-string \"a test\" i_am_cool --skip-pointers")
180
181         self.expect("frame variable cool_pointer",
182                     substrs=['a test'],
183                     matching=False)
184
185         self.runCmd(
186             "type summary add --summary-string \"${var[1-3]}\" \"int [5]\"")
187
188         self.expect("frame variable int_array",
189                     substrs=['2',
190                              '3',
191                              '4'])
192
193         self.runCmd("type summary clear")
194
195         self.runCmd(
196             "type summary add --summary-string \"${var[0-2].integer}\" \"i_am_cool *\"")
197         self.runCmd(
198             "type summary add --summary-string \"${var[2-4].integer}\" \"i_am_cool [5]\"")
199
200         self.expect("frame variable cool_array",
201                     substrs=['1,1,6'])
202
203         self.expect("frame variable cool_pointer",
204                     substrs=['3,0,0'])
205
206         # test special symbols for formatting variables into summaries
207         self.runCmd(
208             "type summary add --summary-string \"cool object @ ${var%L}\" i_am_cool")
209         self.runCmd("type summary delete \"i_am_cool [5]\"")
210
211         # this test might fail if the compiler tries to store
212         # these values into registers.. hopefully this is not
213         # going to be the case
214         self.expect("frame variable cool_array",
215                     substrs=['[0] = cool object @ 0x',
216                              '[1] = cool object @ 0x',
217                              '[2] = cool object @ 0x',
218                              '[3] = cool object @ 0x',
219                              '[4] = cool object @ 0x'])
220
221         # test getting similar output by exploiting ${var} = 'type @ location'
222         # for aggregates
223         self.runCmd("type summary add --summary-string \"${var}\" i_am_cool")
224
225         # this test might fail if the compiler tries to store
226         # these values into registers.. hopefully this is not
227         # going to be the case
228         self.expect("frame variable cool_array",
229                     substrs=['[0] = i_am_cool @ 0x',
230                              '[1] = i_am_cool @ 0x',
231                              '[2] = i_am_cool @ 0x',
232                              '[3] = i_am_cool @ 0x',
233                              '[4] = i_am_cool @ 0x'])
234
235         # test getting same output by exploiting %T and %L together for
236         # aggregates
237         self.runCmd(
238             "type summary add --summary-string \"${var%T} @ ${var%L}\" i_am_cool")
239
240         # this test might fail if the compiler tries to store
241         # these values into registers.. hopefully this is not
242         # going to be the case
243         self.expect("frame variable cool_array",
244                     substrs=['[0] = i_am_cool @ 0x',
245                              '[1] = i_am_cool @ 0x',
246                              '[2] = i_am_cool @ 0x',
247                              '[3] = i_am_cool @ 0x',
248                              '[4] = i_am_cool @ 0x'])
249
250         self.runCmd("type summary add --summary-string \"goofy\" i_am_cool")
251         self.runCmd(
252             "type summary add --summary-string \"${var.second_cool%S}\" i_am_cooler")
253
254         self.expect("frame variable the_coolest_guy",
255                     substrs=['(i_am_cooler) the_coolest_guy = goofy'])
256
257         # check that unwanted type specifiers are removed
258         self.runCmd("type summary delete i_am_cool")
259         self.runCmd(
260             "type summary add --summary-string \"goofy\" \"class i_am_cool\"")
261         self.expect("frame variable the_coolest_guy",
262                     substrs=['(i_am_cooler) the_coolest_guy = goofy'])
263
264         self.runCmd("type summary delete i_am_cool")
265         self.runCmd(
266             "type summary add --summary-string \"goofy\" \"enum i_am_cool\"")
267         self.expect("frame variable the_coolest_guy",
268                     substrs=['(i_am_cooler) the_coolest_guy = goofy'])
269
270         self.runCmd("type summary delete i_am_cool")
271         self.runCmd(
272             "type summary add --summary-string \"goofy\" \"struct i_am_cool\"")
273         self.expect("frame variable the_coolest_guy",
274                     substrs=['(i_am_cooler) the_coolest_guy = goofy'])
275
276         # many spaces, but we still do the right thing
277         self.runCmd("type summary delete i_am_cool")
278         self.runCmd(
279             "type summary add --summary-string \"goofy\" \"union     i_am_cool\"")
280         self.expect("frame variable the_coolest_guy",
281                     substrs=['(i_am_cooler) the_coolest_guy = goofy'])
282
283         # but that not *every* specifier is removed
284         self.runCmd("type summary delete i_am_cool")
285         self.runCmd(
286             "type summary add --summary-string \"goofy\" \"wrong i_am_cool\"")
287         self.expect("frame variable the_coolest_guy", matching=False,
288                     substrs=['(i_am_cooler) the_coolest_guy = goofy'])
289
290         # check that formats are not sticking since that is the behavior we
291         # want
292         self.expect("frame variable iAmInt --format hex",
293                     substrs=['(int) iAmInt = 0x00000001'])
294         self.expect(
295             "frame variable iAmInt",
296             matching=False,
297             substrs=['(int) iAmInt = 0x00000001'])
298         self.expect("frame variable iAmInt", substrs=['(int) iAmInt = 1'])