2 Test lldb data formatter subsystem.
5 from __future__ import print_function
11 from lldbsuite.test.decorators import *
12 from lldbsuite.test.lldbtest import *
13 from lldbsuite.test import lldbutil
16 class StdVectorDataFormatterTestCase(TestBase):
18 mydir = TestBase.compute_mydir(__file__)
21 # Call super's setUp().
23 # Find the line number to break at.
24 self.line = line_number('main.cpp', '// Set break point at this line.')
27 @skipIfWindows # libstdcpp not ported to Windows
28 def test_with_run_command(self):
29 """Test that that file and class static variables display correctly."""
31 self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)
33 lldbutil.run_break_set_by_source_regexp(
34 self, "Set break point at this line.")
36 self.runCmd("run", RUN_SUCCEEDED)
38 # The stop reason of the thread should be breakpoint.
39 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
41 'stop reason = breakpoint'])
43 # This is the function to remove the custom formats in order to have a
44 # clean slate for the next test case.
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)
51 "settings set target.max-children-count 256",
54 # Execute the cleanup function during test case tear down.
55 self.addTearDownHook(cleanup)
57 # empty vectors (and storage pointers SHOULD BOTH BE NULL..)
58 self.expect("frame variable numbers",
59 substrs=['numbers = size=0'])
64 self.expect("frame variable numbers",
65 substrs=['numbers = size=1',
72 self.expect("frame variable numbers",
73 substrs=['numbers = size=4',
80 self.expect("p numbers",
81 substrs=['$', 'size=4',
88 # check access to synthetic children
90 "type summary add --summary-string \"item 0 is ${var[0]}\" std::int_vect int_vect")
91 self.expect('frame variable numbers',
92 substrs=['item 0 is 1'])
95 "type summary add --summary-string \"item 0 is ${svar[0]}\" std::int_vect int_vect")
98 self.expect('frame variable numbers',
99 substrs=['item 0 is 1'])
100 # move on with synths
101 self.runCmd("type summary delete std::int_vect")
102 self.runCmd("type summary delete int_vect")
107 self.expect("frame variable numbers",
108 substrs=['numbers = size=7',
118 self.expect("p numbers",
119 substrs=['$', 'size=7',
129 # check access-by-index
130 self.expect("frame variable numbers[0]",
132 self.expect("frame variable numbers[1]",
134 self.expect("frame variable numbers[2]",
136 self.expect("frame variable numbers[3]",
139 # but check that expression does not rely on us
140 # (when expression gets to call into STL code correctly, we will have to find
141 # another way to check this)
142 self.expect("expression numbers[6]", matching=False, error=True,
145 # check that MightHaveChildren() gets it right
147 self.frame().FindVariable("numbers").MightHaveChildren(),
148 "numbers.MightHaveChildren() says False for non empty!")
150 # clear out the vector and see that we do the right thing once again
153 self.expect("frame variable numbers",
154 substrs=['numbers = size=0'])
159 self.expect("frame variable numbers",
160 substrs=['numbers = size=1',
164 # check if we can display strings
167 self.expect("frame variable strings",
172 self.expect("p strings",
177 # test summaries based on synthetic children
179 "type summary add std::string_vect string_vect --summary-string \"vector has ${svar%#} items\" -e")
180 self.expect("frame variable strings",
181 substrs=['vector has 3 items',
186 self.expect("p strings",
187 substrs=['vector has 3 items',
194 self.expect("frame variable strings",
195 substrs=['vector has 4 items'])
197 # check access-by-index
198 self.expect("frame variable strings[0]",
200 self.expect("frame variable strings[1]",
203 # but check that expression does not rely on us
204 # (when expression gets to call into STL code correctly, we will have to find
205 # another way to check this)
206 self.expect("expression strings[0]", matching=False, error=True,
209 # check that MightHaveChildren() gets it right
211 self.frame().FindVariable("strings").MightHaveChildren(),
212 "strings.MightHaveChildren() says False for non empty!")
216 self.expect("frame variable strings",
217 substrs=['vector has 0 items'])