2 Test lldb data formatter subsystem.
8 from lldbsuite.test.decorators import *
9 from lldbsuite.test.lldbtest import *
10 from lldbsuite.test import lldbutil
13 class LibcxxVectorDataFormatterTestCase(TestBase):
15 mydir = TestBase.compute_mydir(__file__)
17 def check_numbers(self, var_name):
18 self.expect("frame variable " + var_name,
19 substrs=[var_name + ' = size=7',
29 self.expect("p " + var_name,
30 substrs=['$', 'size=7',
40 # check access-by-index
41 self.expect("frame variable " + var_name + "[0]",
43 self.expect("frame variable " + var_name + "[1]",
45 self.expect("frame variable " + var_name + "[2]",
47 self.expect("frame variable " + var_name + "[3]",
50 @add_test_categories(["libc++"])
51 def test_with_run_command(self):
52 """Test that that file and class static variables display correctly."""
54 (self.target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(
55 self, "break here", lldb.SBFileSpec("main.cpp", False))
57 # This is the function to remove the custom formats in order to have a
58 # clean slate for the next test case.
60 self.runCmd('type format clear', check=False)
61 self.runCmd('type summary clear', check=False)
62 self.runCmd('type filter clear', check=False)
63 self.runCmd('type synth clear', check=False)
65 "settings set target.max-children-count 256",
68 # Execute the cleanup function during test case tear down.
69 self.addTearDownHook(cleanup)
71 # empty vectors (and storage pointers SHOULD BOTH BE NULL..)
72 self.expect("frame variable numbers",
73 substrs=['numbers = size=0'])
75 lldbutil.continue_to_breakpoint(process, bkpt)
78 self.expect("frame variable numbers",
79 substrs=['numbers = size=1',
84 lldbutil.continue_to_breakpoint(process, bkpt)
86 self.expect("frame variable numbers",
87 substrs=['numbers = size=4',
94 self.expect("p numbers",
95 substrs=['$', 'size=4',
102 # check access to synthetic children
104 "type summary add --summary-string \"item 0 is ${var[0]}\" std::int_vect int_vect")
105 self.expect('frame variable numbers',
106 substrs=['item 0 is 1'])
109 "type summary add --summary-string \"item 0 is ${svar[0]}\" std::int_vect int_vect")
110 self.expect('frame variable numbers',
111 substrs=['item 0 is 1'])
112 # move on with synths
113 self.runCmd("type summary delete std::int_vect")
114 self.runCmd("type summary delete int_vect")
117 lldbutil.continue_to_breakpoint(process, bkpt)
119 self.check_numbers("numbers")
121 # clear out the vector and see that we do the right thing once again
122 lldbutil.continue_to_breakpoint(process, bkpt)
124 self.expect("frame variable numbers",
125 substrs=['numbers = size=0'])
127 lldbutil.continue_to_breakpoint(process, bkpt)
130 self.expect("frame variable numbers",
131 substrs=['numbers = size=1',
135 # check if we can display strings
136 self.expect("frame variable strings",
141 self.expect("p strings",
146 # test summaries based on synthetic children
148 "type summary add std::string_vect string_vect --summary-string \"vector has ${svar%#} items\" -e")
149 self.expect("frame variable strings",
150 substrs=['vector has 3 items',
155 self.expect("p strings",
156 substrs=['vector has 3 items',
161 lldbutil.continue_to_breakpoint(process, bkpt)
163 self.expect("frame variable strings",
164 substrs=['vector has 4 items'])
166 # check access-by-index
167 self.expect("frame variable strings[0]",
169 self.expect("frame variable strings[1]",
172 lldbutil.continue_to_breakpoint(process, bkpt)
174 self.expect("frame variable strings",
175 substrs=['vector has 0 items'])
177 @add_test_categories(["libc++"])
178 def test_ref_and_ptr(self):
179 """Test that that file and class static variables display correctly."""
181 (self.target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(
182 self, "Stop here to check by ref", lldb.SBFileSpec("main.cpp", False))
184 # The reference should display the same was as the value did
185 self.check_numbers("ref")
187 # The pointer should just show the right number of elements:
189 self.expect("frame variable ptr", substrs=['ptr =', ' size=7'])
191 self.expect("p ptr", substrs=['$', 'size=7'])