]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-skip-summary/TestDataFormatterSkipSummary.py
Vendor import of lldb trunk r290819:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / functionalities / data-formatter / data-formatter-skip-summary / TestDataFormatterSkipSummary.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 SkipSummaryDataFormatterTestCase(TestBase):
17
18     mydir = TestBase.compute_mydir(__file__)
19
20     @expectedFailureAll(
21         oslist=['freebsd'],
22         bugnumber="llvm.org/pr20548 fails to build on lab.llvm.org buildbot")
23     @expectedFailureAll(
24         oslist=["windows"],
25         bugnumber="llvm.org/pr24462, Data formatters have problems on Windows")
26     def test_with_run_command(self):
27         """Test data formatter commands."""
28         self.build()
29         self.data_formatter_commands()
30
31     def setUp(self):
32         # Call super's setUp().
33         TestBase.setUp(self)
34         # Find the line number to break at.
35         self.line = line_number('main.cpp', '// Set break point at this line.')
36
37     def data_formatter_commands(self):
38         """Test that that file and class static variables display correctly."""
39         self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)
40
41         #import lldbsuite.test.lldbutil as lldbutil
42         lldbutil.run_break_set_by_file_and_line(
43             self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True)
44
45         self.runCmd("run", RUN_SUCCEEDED)
46
47         # The stop reason of the thread should be breakpoint.
48         self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
49                     substrs=['stopped',
50                              'stop reason = breakpoint'])
51
52         # This is the function to remove the custom formats in order to have a
53         # clean slate for the next test case.
54         def cleanup():
55             self.runCmd('type format clear', check=False)
56             self.runCmd('type summary clear', check=False)
57
58         # Execute the cleanup function during test case tear down.
59         self.addTearDownHook(cleanup)
60
61         # Setup the summaries for this scenario
62         #self.runCmd("type summary add --summary-string \"${var._M_dataplus._M_p}\" std::string")
63         self.runCmd(
64             "type summary add --summary-string \"Level 1\" \"DeepData_1\"")
65         self.runCmd(
66             "type summary add --summary-string \"Level 2\" \"DeepData_2\" -e")
67         self.runCmd(
68             "type summary add --summary-string \"Level 3\" \"DeepData_3\"")
69         self.runCmd(
70             "type summary add --summary-string \"Level 4\" \"DeepData_4\"")
71         self.runCmd(
72             "type summary add --summary-string \"Level 5\" \"DeepData_5\"")
73
74         # Default case, just print out summaries
75         self.expect('frame variable',
76                     substrs=['(DeepData_1) data1 = Level 1',
77                              '(DeepData_2) data2 = Level 2 {',
78                              'm_child1 = Level 3',
79                              'm_child2 = Level 3',
80                              'm_child3 = Level 3',
81                              'm_child4 = Level 3',
82                              '}'])
83
84         # Skip the default (should be 1) levels of summaries
85         self.expect('frame variable --no-summary-depth',
86                     substrs=['(DeepData_1) data1 = {',
87                              'm_child1 = 0x',
88                              '}',
89                              '(DeepData_2) data2 = {',
90                              'm_child1 = Level 3',
91                              'm_child2 = Level 3',
92                              'm_child3 = Level 3',
93                              'm_child4 = Level 3',
94                              '}'])
95
96         # Now skip 2 levels of summaries
97         self.expect('frame variable --no-summary-depth=2',
98                     substrs=['(DeepData_1) data1 = {',
99                              'm_child1 = 0x',
100                              '}',
101                              '(DeepData_2) data2 = {',
102                              'm_child1 = {',
103                              'm_child1 = 0x',
104                              'Level 4',
105                              'm_child2 = {',
106                              'm_child3 = {',
107                              '}'])
108
109         # Check that no "Level 3" comes out
110         self.expect(
111             'frame variable data1.m_child1 --no-summary-depth=2',
112             matching=False,
113             substrs=['Level 3'])
114
115         # Now expand a pointer with 2 level of skipped summaries
116         self.expect('frame variable data1.m_child1 --no-summary-depth=2',
117                     substrs=['(DeepData_2 *) data1.m_child1 = 0x'])
118
119         # Deref and expand said pointer
120         self.expect('frame variable *data1.m_child1 --no-summary-depth=2',
121                     substrs=['(DeepData_2) *data1.m_child1 = {',
122                              'm_child2 = {',
123                              'm_child1 = 0x',
124                              'Level 4',
125                              '}'])
126
127         # Expand an expression, skipping 2 layers of summaries
128         self.expect(
129             'frame variable data1.m_child1->m_child2 --no-summary-depth=2',
130             substrs=[
131                 '(DeepData_3) data1.m_child1->m_child2 = {',
132                 'm_child2 = {',
133                 'm_child1 = Level 5',
134                 'm_child2 = Level 5',
135                 'm_child3 = Level 5',
136                 '}'])
137
138         # Expand same expression, skipping only 1 layer of summaries
139         self.expect(
140             'frame variable data1.m_child1->m_child2 --no-summary-depth=1',
141             substrs=[
142                 '(DeepData_3) data1.m_child1->m_child2 = {',
143                 'm_child1 = 0x',
144                 'Level 4',
145                 'm_child2 = Level 4',
146                 '}'])
147
148         # Bad debugging info on SnowLeopard gcc (Apple Inc. build 5666).
149         # Skip the following tests if the condition is met.
150         if self.getCompiler().endswith('gcc') and not self.getCompiler().endswith('llvm-gcc'):
151             import re
152             gcc_version_output = system(
153                 [[lldbutil.which(self.getCompiler()), "-v"]])[1]
154             #print("my output:", gcc_version_output)
155             for line in gcc_version_output.split(os.linesep):
156                 m = re.search('\(Apple Inc\. build ([0-9]+)\)', line)
157                 #print("line:", line)
158                 if m:
159                     gcc_build = int(m.group(1))
160                     #print("gcc build:", gcc_build)
161                     if gcc_build >= 5666:
162                         # rdar://problem/9804600"
163                         self.skipTest(
164                             "rdar://problem/9804600 wrong namespace for std::string in debug info")
165
166         # Expand same expression, skipping 3 layers of summaries
167         self.expect(
168             'frame variable data1.m_child1->m_child2 --show-types --no-summary-depth=3',
169             substrs=[
170                 '(DeepData_3) data1.m_child1->m_child2 = {',
171                 'm_some_text = "Just a test"',
172                 'm_child2 = {',
173                 'm_some_text = "Just a test"'])
174
175         # Expand within a standard string (might depend on the implementation
176         # of the C++ stdlib you use)
177         self.expect(
178             'frame variable data1.m_child1->m_child2.m_child1.m_child2 --no-summary-depth=2',
179             substrs=[
180                 '(DeepData_5) data1.m_child1->m_child2.m_child1.m_child2 = {',
181                 'm_some_text = {',
182                 '_M_dataplus = (_M_p = "Just a test")'])
183
184         # Repeat the above, but only skip 1 level of summaries
185         self.expect(
186             'frame variable data1.m_child1->m_child2.m_child1.m_child2 --no-summary-depth=1',
187             substrs=[
188                 '(DeepData_5) data1.m_child1->m_child2.m_child1.m_child2 = {',
189                 'm_some_text = "Just a test"',
190                 '}'])
191
192         # Change summary and expand, first without --no-summary-depth then with
193         # --no-summary-depth
194         self.runCmd(
195             "type summary add --summary-string \"${var.m_some_text}\" DeepData_5")
196
197         self.expect('fr var data2.m_child4.m_child2.m_child2', substrs=[
198                     '(DeepData_5) data2.m_child4.m_child2.m_child2 = "Just a test"'])
199
200         self.expect(
201             'fr var data2.m_child4.m_child2.m_child2 --no-summary-depth',
202             substrs=[
203                 '(DeepData_5) data2.m_child4.m_child2.m_child2 = {',
204                 'm_some_text = "Just a test"',
205                 '}'])