3a2d006c7de56083743de8a542347e20e114ca4a
[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 LibcxxListDataFormatterTestCase(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 number to break at.
21         self.line = line_number('main.cpp', '// Set break point at this line.')
22         self.line2 = line_number('main.cpp',
23                                  '// Set second break point at this line.')
24         self.line3 = line_number('main.cpp',
25                                  '// Set third break point at this line.')
26         self.line4 = line_number('main.cpp',
27                                  '// Set fourth break point at this line.')
28
29     @add_test_categories(["libc++"])
30     @skipIf(debug_info="gmodules",
31             bugnumber="https://bugs.llvm.org/show_bug.cgi?id=36048")
32     def test_with_run_command(self):
33         """Test that that file and class static variables display correctly."""
34         self.build()
35         self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
36
37         lldbutil.run_break_set_by_file_and_line(
38             self, "main.cpp", self.line, num_expected_locations=-1)
39         lldbutil.run_break_set_by_file_and_line(
40             self, "main.cpp", self.line2, num_expected_locations=-1)
41         lldbutil.run_break_set_by_file_and_line(
42             self, "main.cpp", self.line3, num_expected_locations=-1)
43         lldbutil.run_break_set_by_file_and_line(
44             self, "main.cpp", self.line4, num_expected_locations=-1)
45
46         self.runCmd("run", RUN_SUCCEEDED)
47
48         lldbutil.skip_if_library_missing(
49             self, self.target(), lldbutil.PrintableRegex("libc\+\+"))
50
51         # The stop reason of the thread should be breakpoint.
52         self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
53                     substrs=['stopped',
54                              'stop reason = breakpoint'])
55
56         # This is the function to remove the custom formats in order to have a
57         # clean slate for the next test case.
58         def cleanup():
59             self.runCmd('type format clear', check=False)
60             self.runCmd('type summary clear', check=False)
61             self.runCmd('type filter clear', check=False)
62             self.runCmd('type synth clear', check=False)
63             self.runCmd(
64                 "settings set target.max-children-count 256",
65                 check=False)
66
67         # Execute the cleanup function during test case tear down.
68         self.addTearDownHook(cleanup)
69
70         self.runCmd("frame variable numbers_list --show-types")
71         self.runCmd(
72             "type summary add std::int_list std::string_list int_list string_list --summary-string \"list has ${svar%#} items\" -e")
73         self.runCmd("type format add -f hex int")
74
75         self.expect("frame variable numbers_list --raw", matching=False,
76                     substrs=['list has 0 items',
77                              '{}'])
78
79         self.expect("frame variable numbers_list",
80                     substrs=['list has 0 items',
81                              '{}'])
82
83         self.expect("p numbers_list",
84                     substrs=['list has 0 items',
85                              '{}'])
86
87         self.runCmd("n") # This gets up past the printf
88         self.runCmd("n") # Now advance over the first push_back.
89
90         self.expect("frame variable numbers_list",
91                     substrs=['list has 1 items',
92                              '[0] = ',
93                              '0x12345678'])
94
95         self.runCmd("n")
96         self.runCmd("n")
97         self.runCmd("n")
98
99         self.expect("frame variable numbers_list",
100                     substrs=['list has 4 items',
101                              '[0] = ',
102                              '0x12345678',
103                              '[1] =',
104                              '0x11223344',
105                              '[2] =',
106                              '0xbeeffeed',
107                              '[3] =',
108                              '0x00abba00'])
109
110         self.runCmd("n")
111         self.runCmd("n")
112
113         self.expect("frame variable numbers_list",
114                     substrs=['list has 6 items',
115                              '[0] = ',
116                              '0x12345678',
117                              '0x11223344',
118                              '0xbeeffeed',
119                              '0x00abba00',
120                              '[4] =',
121                              '0x0abcdef0',
122                              '[5] =',
123                              '0x0cab0cab'])
124
125         self.expect("p numbers_list",
126                     substrs=['list has 6 items',
127                              '[0] = ',
128                              '0x12345678',
129                              '0x11223344',
130                              '0xbeeffeed',
131                              '0x00abba00',
132                              '[4] =',
133                              '0x0abcdef0',
134                              '[5] =',
135                              '0x0cab0cab'])
136
137         # check access-by-index
138         self.expect("frame variable numbers_list[0]",
139                     substrs=['0x12345678'])
140         self.expect("frame variable numbers_list[1]",
141                     substrs=['0x11223344'])
142
143         self.runCmd("n")
144
145         self.expect("frame variable numbers_list",
146                     substrs=['list has 0 items',
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=['list has 4 items',
156                              '[0] = ', '1',
157                              '[1] = ', '2',
158                              '[2] = ', '3',
159                              '[3] = ', '4'])
160
161         ListPtr = self.frame().FindVariable("list_ptr")
162         self.assertTrue(ListPtr.GetChildAtIndex(
163             0).GetValueAsUnsigned(0) == 1, "[0] = 1")
164
165         # check that MightHaveChildren() gets it right
166         self.assertTrue(
167             self.frame().FindVariable("numbers_list").MightHaveChildren(),
168             "numbers_list.MightHaveChildren() says False for non empty!")
169
170         self.runCmd("type format delete int")
171
172         self.runCmd("c")
173
174         self.expect("frame variable text_list",
175                     substrs=['list has 3 items',
176                              '[0]', 'goofy',
177                              '[1]', 'is',
178                              '[2]', 'smart'])
179
180         # check that MightHaveChildren() gets it right
181         self.assertTrue(
182             self.frame().FindVariable("text_list").MightHaveChildren(),
183             "text_list.MightHaveChildren() says False for non empty!")
184
185         self.expect("p text_list",
186                     substrs=['list has 3 items',
187                              '\"goofy\"',
188                              '\"is\"',
189                              '\"smart\"'])
190
191         self.runCmd("n") # This gets us past the printf
192         self.runCmd("n")
193         self.runCmd("n")
194
195         # check access-by-index
196         self.expect("frame variable text_list[0]",
197                     substrs=['goofy'])
198         self.expect("frame variable text_list[3]",
199                     substrs=['!!!'])
200
201         self.runCmd("continue")
202
203         # check that the list provider correctly updates if elements move
204         countingList = self.frame().FindVariable("countingList")
205         countingList.SetPreferDynamicValue(True)
206         countingList.SetPreferSyntheticValue(True)
207
208         self.assertTrue(countingList.GetChildAtIndex(
209             0).GetValueAsUnsigned(0) == 3141, "list[0] == 3141")
210         self.assertTrue(countingList.GetChildAtIndex(
211             1).GetValueAsUnsigned(0) == 3141, "list[1] == 3141")
212
213         self.runCmd("continue")
214
215         self.assertTrue(
216             countingList.GetChildAtIndex(0).GetValueAsUnsigned(0) == 3141,
217             "uniqued list[0] == 3141")
218         self.assertTrue(
219             countingList.GetChildAtIndex(1).GetValueAsUnsigned(0) == 3142,
220             "uniqued list[1] == 3142")