1b8338983SRaphael Isemann""" 2b8338983SRaphael IsemannTest basic std::array functionality. 3b8338983SRaphael Isemann""" 4b8338983SRaphael Isemann 5b8338983SRaphael Isemannfrom lldbsuite.test.decorators import * 6b8338983SRaphael Isemannfrom lldbsuite.test.lldbtest import * 7b8338983SRaphael Isemannfrom lldbsuite.test import lldbutil 8b8338983SRaphael Isemann 9b8338983SRaphael Isemann 10b8338983SRaphael Isemannclass TestCase(TestBase): 11b8338983SRaphael Isemann @add_test_categories(["libc++"]) 12b8338983SRaphael Isemann @skipIf(compiler=no_match("clang")) 13b8338983SRaphael Isemann def test(self): 14b8338983SRaphael Isemann self.build() 15b8338983SRaphael Isemann 16*2238dcc3SJonas Devlieghere lldbutil.run_to_source_breakpoint( 17*2238dcc3SJonas Devlieghere self, "// Set break point at this line.", lldb.SBFileSpec("main.cpp") 18*2238dcc3SJonas Devlieghere ) 19b8338983SRaphael Isemann 20b8338983SRaphael Isemann self.runCmd("settings set target.import-std-module true") 21b8338983SRaphael Isemann 2215f3cd6bSMatheus Izvekov size_type = "size_type" 2315f3cd6bSMatheus Izvekov value_type = "value_type" 2415f3cd6bSMatheus Izvekov iterator = "iterator" 2515f3cd6bSMatheus Izvekov riterator = "reverse_iterator" 26b8338983SRaphael Isemann 27b8338983SRaphael Isemann # Test inspecting an array of integers. 28b8338983SRaphael Isemann array_type = "std::array<int, 3>" 29*2238dcc3SJonas Devlieghere self.expect_expr( 30*2238dcc3SJonas Devlieghere "a", 31b8338983SRaphael Isemann result_type=array_type, 32b8338983SRaphael Isemann result_children=[ 33*2238dcc3SJonas Devlieghere ValueCheck( 34*2238dcc3SJonas Devlieghere name="__elems_", 35*2238dcc3SJonas Devlieghere children=[ 36b8338983SRaphael Isemann ValueCheck(value="3"), 37b8338983SRaphael Isemann ValueCheck(value="1"), 38b8338983SRaphael Isemann ValueCheck(value="2"), 39*2238dcc3SJonas Devlieghere ], 40*2238dcc3SJonas Devlieghere ) 41*2238dcc3SJonas Devlieghere ], 42*2238dcc3SJonas Devlieghere ) 43b8338983SRaphael Isemann self.expect_expr("a.size()", result_type=size_type, result_value="3") 44b8338983SRaphael Isemann self.expect_expr("a.front()", result_type=value_type, result_value="3") 45b8338983SRaphael Isemann self.expect_expr("a[1]", result_type=value_type, result_value="1") 46b8338983SRaphael Isemann self.expect_expr("a.back()", result_type=value_type, result_value="2") 47b8338983SRaphael Isemann 48b8338983SRaphael Isemann # Both are just pointers to the underlying elements. 49b8338983SRaphael Isemann self.expect_expr("a.begin()", result_type=iterator) 50b8338983SRaphael Isemann self.expect_expr("a.rbegin()", result_type=riterator) 51b8338983SRaphael Isemann 52b8338983SRaphael Isemann self.expect_expr("*a.begin()", result_type=value_type, result_value="3") 53b8338983SRaphael Isemann self.expect_expr("*a.rbegin()", result_type="int", result_value="2") 54b8338983SRaphael Isemann 55b8338983SRaphael Isemann self.expect_expr("a.at(0)", result_type=value_type, result_value="3") 56b8338983SRaphael Isemann 57b8338983SRaphael Isemann # Same again with an array that has an element type from debug info. 58b8338983SRaphael Isemann array_type = "std::array<DbgInfo, 1>" 59b8338983SRaphael Isemann 60b8338983SRaphael Isemann dbg_info_elem_children = [ValueCheck(value="4")] 61b8338983SRaphael Isemann dbg_info_elem = [ValueCheck(children=dbg_info_elem_children)] 62b8338983SRaphael Isemann 63*2238dcc3SJonas Devlieghere self.expect_expr( 64*2238dcc3SJonas Devlieghere "b", 65b8338983SRaphael Isemann result_type=array_type, 66*2238dcc3SJonas Devlieghere result_children=[ValueCheck(name="__elems_", children=dbg_info_elem)], 67*2238dcc3SJonas Devlieghere ) 68b8338983SRaphael Isemann self.expect_expr("b.size()", result_type=size_type, result_value="1") 69*2238dcc3SJonas Devlieghere self.expect_expr( 70*2238dcc3SJonas Devlieghere "b.front()", result_type=value_type, result_children=dbg_info_elem_children 71*2238dcc3SJonas Devlieghere ) 72*2238dcc3SJonas Devlieghere self.expect_expr( 73*2238dcc3SJonas Devlieghere "b[0]", result_type=value_type, result_children=dbg_info_elem_children 74*2238dcc3SJonas Devlieghere ) 75*2238dcc3SJonas Devlieghere self.expect_expr( 76*2238dcc3SJonas Devlieghere "b.back()", result_type=value_type, result_children=dbg_info_elem_children 77*2238dcc3SJonas Devlieghere ) 78b8338983SRaphael Isemann 79b8338983SRaphael Isemann # Both are just pointers to the underlying elements. 80b8338983SRaphael Isemann self.expect_expr("b.begin()", result_type=iterator) 81b8338983SRaphael Isemann self.expect_expr("b.rbegin()", result_type=riterator) 82b8338983SRaphael Isemann 83*2238dcc3SJonas Devlieghere self.expect_expr( 84*2238dcc3SJonas Devlieghere "*b.begin()", result_type=value_type, result_children=dbg_info_elem_children 85*2238dcc3SJonas Devlieghere ) 86*2238dcc3SJonas Devlieghere self.expect_expr( 87*2238dcc3SJonas Devlieghere "*b.rbegin()", result_type="DbgInfo", result_children=dbg_info_elem_children 88*2238dcc3SJonas Devlieghere ) 89b8338983SRaphael Isemann 90*2238dcc3SJonas Devlieghere self.expect_expr( 91*2238dcc3SJonas Devlieghere "b.at(0)", result_type=value_type, result_children=dbg_info_elem_children 92*2238dcc3SJonas Devlieghere ) 93