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 LibcxxListDataFormatterTestCase(TestBase):
15 mydir = TestBase.compute_mydir(__file__)
18 # Call super's setUp().
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.')
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."""
35 self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
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)
46 self.runCmd("run", RUN_SUCCEEDED)
48 lldbutil.skip_if_library_missing(
49 self, self.target(), lldbutil.PrintableRegex("libc\+\+"))
51 # The stop reason of the thread should be breakpoint.
52 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
54 'stop reason = breakpoint'])
56 # This is the function to remove the custom formats in order to have a
57 # clean slate for the next test case.
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)
64 "settings set target.max-children-count 256",
67 # Execute the cleanup function during test case tear down.
68 self.addTearDownHook(cleanup)
70 self.runCmd("frame variable numbers_list --show-types")
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")
75 self.expect("frame variable numbers_list --raw", matching=False,
76 substrs=['list has 0 items',
79 self.expect("frame variable numbers_list",
80 substrs=['list has 0 items',
83 self.expect("p numbers_list",
84 substrs=['list has 0 items',
87 self.runCmd("n") # This gets up past the printf
88 self.runCmd("n") # Now advance over the first push_back.
90 self.expect("frame variable numbers_list",
91 substrs=['list has 1 items',
99 self.expect("frame variable numbers_list",
100 substrs=['list has 4 items',
113 self.expect("frame variable numbers_list",
114 substrs=['list has 6 items',
125 self.expect("p numbers_list",
126 substrs=['list has 6 items',
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'])
145 self.expect("frame variable numbers_list",
146 substrs=['list has 0 items',
154 self.expect("frame variable numbers_list",
155 substrs=['list has 4 items',
161 ListPtr = self.frame().FindVariable("list_ptr")
162 self.assertTrue(ListPtr.GetChildAtIndex(
163 0).GetValueAsUnsigned(0) == 1, "[0] = 1")
165 # check that MightHaveChildren() gets it right
167 self.frame().FindVariable("numbers_list").MightHaveChildren(),
168 "numbers_list.MightHaveChildren() says False for non empty!")
170 self.runCmd("type format delete int")
174 self.expect("frame variable text_list",
175 substrs=['list has 3 items',
180 # check that MightHaveChildren() gets it right
182 self.frame().FindVariable("text_list").MightHaveChildren(),
183 "text_list.MightHaveChildren() says False for non empty!")
185 self.expect("p text_list",
186 substrs=['list has 3 items',
191 self.runCmd("n") # This gets us past the printf
195 # check access-by-index
196 self.expect("frame variable text_list[0]",
198 self.expect("frame variable text_list[3]",
201 self.runCmd("continue")
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)
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")
213 self.runCmd("continue")
216 countingList.GetChildAtIndex(0).GetValueAsUnsigned(0) == 3141,
217 "uniqued list[0] == 3141")
219 countingList.GetChildAtIndex(1).GetValueAsUnsigned(0) == 3142,
220 "uniqued list[1] == 3142")