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