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