27cdf1e73ac5c0d3abdb4fc62a103854f67c8112
[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 StdVectorDataFormatterTestCase(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
23     @add_test_categories(["libstdcxx"])
24     def test_with_run_command(self):
25         """Test that that file and class static variables display correctly."""
26         self.build()
27         self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
28
29         lldbutil.run_break_set_by_source_regexp(
30             self, "Set break point at this line.")
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         # This is the function to remove the custom formats in order to have a
40         # clean slate for the next test case.
41         def cleanup():
42             self.runCmd('type format clear', check=False)
43             self.runCmd('type summary clear', check=False)
44             self.runCmd('type filter clear', check=False)
45             self.runCmd('type synth clear', check=False)
46             self.runCmd(
47                 "settings set target.max-children-count 256",
48                 check=False)
49
50         # Execute the cleanup function during test case tear down.
51         self.addTearDownHook(cleanup)
52
53         # empty vectors (and storage pointers SHOULD BOTH BE NULL..)
54         self.expect("frame variable numbers",
55                     substrs=['numbers = size=0'])
56
57         self.runCmd("c")
58
59         # first value added
60         self.expect("frame variable numbers",
61                     substrs=['numbers = size=1',
62                              '[0] = 1',
63                              '}'])
64
65         # add some more data
66         self.runCmd("c")
67
68         self.expect("frame variable numbers",
69                     substrs=['numbers = size=4',
70                              '[0] = 1',
71                              '[1] = 12',
72                              '[2] = 123',
73                              '[3] = 1234',
74                              '}'])
75
76         self.expect("p numbers",
77                     substrs=['$', 'size=4',
78                              '[0] = 1',
79                              '[1] = 12',
80                              '[2] = 123',
81                              '[3] = 1234',
82                              '}'])
83
84         # check access to synthetic children
85         self.runCmd(
86             "type summary add --summary-string \"item 0 is ${var[0]}\" std::int_vect int_vect")
87         self.expect('frame variable numbers',
88                     substrs=['item 0 is 1'])
89
90         self.runCmd(
91             "type summary add --summary-string \"item 0 is ${svar[0]}\" std::int_vect int_vect")
92         #import time
93         # time.sleep(19)
94         self.expect('frame variable numbers',
95                     substrs=['item 0 is 1'])
96         # move on with synths
97         self.runCmd("type summary delete std::int_vect")
98         self.runCmd("type summary delete int_vect")
99
100         # add some more data
101         self.runCmd("c")
102
103         self.expect("frame variable numbers",
104                     substrs=['numbers = size=7',
105                              '[0] = 1',
106                              '[1] = 12',
107                              '[2] = 123',
108                              '[3] = 1234',
109                              '[4] = 12345',
110                              '[5] = 123456',
111                              '[6] = 1234567',
112                              '}'])
113
114         self.expect("p numbers",
115                     substrs=['$', 'size=7',
116                              '[0] = 1',
117                              '[1] = 12',
118                              '[2] = 123',
119                              '[3] = 1234',
120                              '[4] = 12345',
121                              '[5] = 123456',
122                              '[6] = 1234567',
123                              '}'])
124
125         # check access-by-index
126         self.expect("frame variable numbers[0]",
127                     substrs=['1'])
128         self.expect("frame variable numbers[1]",
129                     substrs=['12'])
130         self.expect("frame variable numbers[2]",
131                     substrs=['123'])
132         self.expect("frame variable numbers[3]",
133                     substrs=['1234'])
134
135         # but check that expression does not rely on us
136         # (when expression gets to call into STL code correctly, we will have to find
137         # another way to check this)
138         self.expect("expression numbers[6]", matching=False, error=True,
139                     substrs=['1234567'])
140
141         # check that MightHaveChildren() gets it right
142         self.assertTrue(
143             self.frame().FindVariable("numbers").MightHaveChildren(),
144             "numbers.MightHaveChildren() says False for non empty!")
145
146         # clear out the vector and see that we do the right thing once again
147         self.runCmd("c")
148
149         self.expect("frame variable numbers",
150                     substrs=['numbers = size=0'])
151
152         self.runCmd("c")
153
154         # first value added
155         self.expect("frame variable numbers",
156                     substrs=['numbers = size=1',
157                              '[0] = 7',
158                              '}'])
159
160         # check if we can display strings
161         self.runCmd("c")
162
163         self.expect("frame variable strings",
164                     substrs=['goofy',
165                              'is',
166                              'smart'])
167
168         self.expect("p strings",
169                     substrs=['goofy',
170                              'is',
171                              'smart'])
172
173         # test summaries based on synthetic children
174         self.runCmd(
175             "type summary add std::string_vect string_vect --summary-string \"vector has ${svar%#} items\" -e")
176         self.expect("frame variable strings",
177                     substrs=['vector has 3 items',
178                              'goofy',
179                              'is',
180                              'smart'])
181
182         self.expect("p strings",
183                     substrs=['vector has 3 items',
184                              'goofy',
185                              'is',
186                              'smart'])
187
188         self.runCmd("c")
189
190         self.expect("frame variable strings",
191                     substrs=['vector has 4 items'])
192
193         # check access-by-index
194         self.expect("frame variable strings[0]",
195                     substrs=['goofy'])
196         self.expect("frame variable strings[1]",
197                     substrs=['is'])
198
199         # but check that expression does not rely on us
200         # (when expression gets to call into STL code correctly, we will have to find
201         # another way to check this)
202         self.expect("expression strings[0]", matching=False, error=True,
203                     substrs=['goofy'])
204
205         # check that MightHaveChildren() gets it right
206         self.assertTrue(
207             self.frame().FindVariable("strings").MightHaveChildren(),
208             "strings.MightHaveChildren() says False for non empty!")
209
210         self.runCmd("c")
211
212         self.expect("frame variable strings",
213                     substrs=['vector has 0 items'])