c65393f39bbf9b586565bae1a54b4ecae0101412
[openbsd] /
1 """
2 Test lldb data formatter subsystem.
3 """
4
5
6
7 import lldb
8 from lldbsuite.test.decorators import *
9 from lldbsuite.test.lldbtest import *
10 from lldbsuite.test import lldbutil
11
12
13 class StdListDataFormatterTestCase(TestBase):
14
15     mydir = TestBase.compute_mydir(__file__)
16
17     def setUp(self):
18         # Call super's setUp().
19         TestBase.setUp(self)
20         # Find the line numbers to break at for the different tests.
21         self.line = line_number('main.cpp', '// Set break point at this line.')
22         self.optional_line = line_number(
23             'main.cpp', '// Optional break point at this line.')
24         self.final_line = line_number(
25             'main.cpp', '// Set final break point at this line.')
26
27     @add_test_categories(["libstdcxx"])
28     def test_with_run_command(self):
29         """Test that that file and class static variables display correctly."""
30         self.build()
31         self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
32
33         lldbutil.run_break_set_by_file_and_line(
34             self, "main.cpp", self.line, num_expected_locations=-1)
35
36         self.runCmd("run", RUN_SUCCEEDED)
37
38         # The stop reason of the thread should be breakpoint.
39         self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
40                     substrs=['stopped',
41                              'stop reason = breakpoint'])
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             self.runCmd('type filter clear', check=False)
49             self.runCmd('type synth clear', check=False)
50             self.runCmd(
51                 "settings set target.max-children-count 256",
52                 check=False)
53
54         # Execute the cleanup function during test case tear down.
55         self.addTearDownHook(cleanup)
56
57         self.runCmd("frame variable numbers_list --show-types")
58
59         self.runCmd("type format add -f hex int")
60
61         self.expect("frame variable numbers_list --raw", matching=False,
62                     substrs=['size=0',
63                              '{}'])
64         self.expect(
65             "frame variable &numbers_list._M_impl._M_node --raw",
66             matching=False,
67             substrs=[
68                 'size=0',
69                 '{}'])
70
71         self.expect("frame variable numbers_list",
72                     substrs=['size=0',
73                              '{}'])
74
75         self.expect("p numbers_list",
76                     substrs=['size=0',
77                              '{}'])
78
79         self.runCmd("n")
80
81         self.expect("frame variable numbers_list",
82                     substrs=['size=1',
83                              '[0] = ',
84                              '0x12345678'])
85
86         self.runCmd("n")
87         self.runCmd("n")
88         self.runCmd("n")
89
90         self.expect("frame variable numbers_list",
91                     substrs=['size=4',
92                              '[0] = ',
93                              '0x12345678',
94                              '[1] =',
95                              '0x11223344',
96                              '[2] =',
97                              '0xbeeffeed',
98                              '[3] =',
99                              '0x00abba00'])
100
101         self.runCmd("n")
102         self.runCmd("n")
103
104         self.expect("frame variable numbers_list",
105                     substrs=['size=6',
106                              '[0] = ',
107                              '0x12345678',
108                              '0x11223344',
109                              '0xbeeffeed',
110                              '0x00abba00',
111                              '[4] =',
112                              '0x0abcdef0',
113                              '[5] =',
114                              '0x0cab0cab'])
115
116         self.expect("p numbers_list",
117                     substrs=['size=6',
118                              '[0] = ',
119                              '0x12345678',
120                              '0x11223344',
121                              '0xbeeffeed',
122                              '0x00abba00',
123                              '[4] =',
124                              '0x0abcdef0',
125                              '[5] =',
126                              '0x0cab0cab'])
127
128         # check access-by-index
129         self.expect("frame variable numbers_list[0]",
130                     substrs=['0x12345678'])
131         self.expect("frame variable numbers_list[1]",
132                     substrs=['0x11223344'])
133
134         # but check that expression does not rely on us
135         self.expect("expression numbers_list[0]", matching=False, error=True,
136                     substrs=['0x12345678'])
137
138         # check that MightHaveChildren() gets it right
139         self.assertTrue(
140             self.frame().FindVariable("numbers_list").MightHaveChildren(),
141             "numbers_list.MightHaveChildren() says False for non empty!")
142
143         self.runCmd("n")
144
145         self.expect("frame variable numbers_list",
146                     substrs=['size=0',
147                              '{}'])
148
149         self.runCmd("n")
150         self.runCmd("n")
151         self.runCmd("n")
152         self.runCmd("n")
153
154         self.expect("frame variable numbers_list",
155                     substrs=['size=4',
156                              '[0] = ', '1',
157                              '[1] = ', '2',
158                              '[2] = ', '3',
159                              '[3] = ', '4'])
160
161         self.runCmd("type format delete int")
162
163         self.runCmd("n")
164
165         self.expect("frame variable text_list",
166                     substrs=['size=0',
167                              '{}'])
168
169         lldbutil.run_break_set_by_file_and_line(
170             self, "main.cpp", self.final_line, num_expected_locations=-1)
171
172         self.runCmd("c", RUN_SUCCEEDED)
173
174         # The stop reason of the thread should be breakpoint.
175         self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
176                     substrs=['stopped',
177                              'stop reason = breakpoint'])
178
179         self.expect("frame variable text_list",
180                     substrs=['size=4',
181                              '[0]', 'goofy',
182                              '[1]', 'is',
183                              '[2]', 'smart',
184                              '[3]', '!!!'])
185
186         self.expect("p text_list",
187                     substrs=['size=4',
188                              '\"goofy\"',
189                              '\"is\"',
190                              '\"smart\"',
191                              '\"!!!\"'])
192
193         # check access-by-index
194         self.expect("frame variable text_list[0]",
195                     substrs=['goofy'])
196         self.expect("frame variable text_list[3]",
197                     substrs=['!!!'])
198
199         # but check that expression does not rely on us
200         self.expect("expression text_list[0]", matching=False, error=True,
201                     substrs=['goofy'])
202
203         # check that MightHaveChildren() gets it right
204         self.assertTrue(
205             self.frame().FindVariable("text_list").MightHaveChildren(),
206             "text_list.MightHaveChildren() says False for non empty!")