1a03dc8c9SPavel Labath""" 2a03dc8c9SPavel LabathTest completing types using information from other shared libraries. 3a03dc8c9SPavel Labath""" 4a03dc8c9SPavel Labath 5a03dc8c9SPavel Labathimport os 6a03dc8c9SPavel Labathimport lldb 7a03dc8c9SPavel Labathfrom lldbsuite.test.decorators import * 8a03dc8c9SPavel Labathfrom lldbsuite.test.lldbtest import * 9a03dc8c9SPavel Labathfrom lldbsuite.test import lldbutil 10a03dc8c9SPavel Labath 11a03dc8c9SPavel Labath 12a03dc8c9SPavel Labathclass LimitDebugInfoTestCase(TestBase): 13a03dc8c9SPavel Labath 14a03dc8c9SPavel Labath def _check_type(self, target, name): 15a03dc8c9SPavel Labath exe = target.FindModule(lldb.SBFileSpec("a.out")) 16a03dc8c9SPavel Labath type_ = exe.FindFirstType(name) 17a03dc8c9SPavel Labath self.trace("type_: %s"%type_) 18a03dc8c9SPavel Labath self.assertTrue(type_) 19a03dc8c9SPavel Labath base = type_.GetDirectBaseClassAtIndex(0).GetType() 20a03dc8c9SPavel Labath self.trace("base:%s"%base) 21a03dc8c9SPavel Labath self.assertTrue(base) 22a03dc8c9SPavel Labath self.assertEquals(base.GetNumberOfFields(), 0) 23a03dc8c9SPavel Labath 24a03dc8c9SPavel Labath def _check_debug_info_is_limited(self, target): 25a03dc8c9SPavel Labath # Without other shared libraries we should only see the member declared 26a03dc8c9SPavel Labath # in the derived class. This serves as a sanity check that we are truly 27a03dc8c9SPavel Labath # building with limited debug info. 28a03dc8c9SPavel Labath self._check_type(target, "InheritsFromOne") 29a03dc8c9SPavel Labath self._check_type(target, "InheritsFromTwo") 30a03dc8c9SPavel Labath 31a03dc8c9SPavel Labath @skipIf(bugnumber="pr46284", debug_info="gmodules") 32d6343e60SPavel Labath @skipIfWindows # Clang emits type info even with -flimit-debug-info 33*1265f05cSRaphael Isemann # Requires DW_CC_pass_by_* attributes from Clang 7 to correctly call 34*1265f05cSRaphael Isemann # by-value functions. 35*1265f05cSRaphael Isemann @skipIf(compiler="clang", compiler_version=['<', '7.0']) 36a03dc8c9SPavel Labath def test_one_and_two_debug(self): 37a03dc8c9SPavel Labath self.build() 38a03dc8c9SPavel Labath target = self.dbg.CreateTarget(self.getBuildArtifact("a.out")) 39a03dc8c9SPavel Labath 40a03dc8c9SPavel Labath self._check_debug_info_is_limited(target) 41a03dc8c9SPavel Labath 421956cf10SPavel Labath lldbutil.run_to_name_breakpoint(self, "main", 431956cf10SPavel Labath extra_images=["one", "two"]) 44a03dc8c9SPavel Labath 45a03dc8c9SPavel Labath # But when other shared libraries are loaded, we should be able to see 46a03dc8c9SPavel Labath # all members. 47a03dc8c9SPavel Labath self.expect_expr("inherits_from_one.member", result_value="47") 48a03dc8c9SPavel Labath self.expect_expr("inherits_from_one.one", result_value="142") 49a03dc8c9SPavel Labath self.expect_expr("inherits_from_two.member", result_value="47") 50a03dc8c9SPavel Labath self.expect_expr("inherits_from_two.one", result_value="142") 51a03dc8c9SPavel Labath self.expect_expr("inherits_from_two.two", result_value="242") 52a03dc8c9SPavel Labath 53b3b95287SPavel Labath self.expect_expr("one_as_member.member", result_value="47") 54b3b95287SPavel Labath self.expect_expr("one_as_member.one.member", result_value="147") 55b3b95287SPavel Labath self.expect_expr("two_as_member.member", result_value="47") 56b3b95287SPavel Labath self.expect_expr("two_as_member.two.one.member", result_value="147") 57b3b95287SPavel Labath self.expect_expr("two_as_member.two.member", result_value="247") 58b3b95287SPavel Labath 59b65d4b23SPavel Labath self.expect_expr("array_of_one[2].member", result_value="174") 60b65d4b23SPavel Labath self.expect_expr("array_of_two[2].one[2].member", result_value="174") 61b65d4b23SPavel Labath self.expect_expr("array_of_two[2].member", result_value="274") 62b65d4b23SPavel Labath 631956cf10SPavel Labath self.expect_expr("get_one().member", result_value="124") 641956cf10SPavel Labath self.expect_expr("get_two().one().member", result_value="124") 651956cf10SPavel Labath self.expect_expr("get_two().member", result_value="224") 661956cf10SPavel Labath 67fdc6aea3SPavel Labath self.expect_expr("shadowed_one.member", result_value="47") 68fdc6aea3SPavel Labath self.expect_expr("shadowed_one.one", result_value="142") 69fdc6aea3SPavel Labath 70a03dc8c9SPavel Labath @skipIf(bugnumber="pr46284", debug_info="gmodules") 71d6343e60SPavel Labath @skipIfWindows # Clang emits type info even with -flimit-debug-info 72*1265f05cSRaphael Isemann # Requires DW_CC_pass_by_* attributes from Clang 7 to correctly call 73*1265f05cSRaphael Isemann # by-value functions. 74*1265f05cSRaphael Isemann @skipIf(compiler="clang", compiler_version=['<', '7.0']) 75a03dc8c9SPavel Labath def test_two_debug(self): 76a03dc8c9SPavel Labath self.build(dictionary=dict(STRIP_ONE="1")) 77a03dc8c9SPavel Labath target = self.dbg.CreateTarget(self.getBuildArtifact("a.out")) 78a03dc8c9SPavel Labath 79a03dc8c9SPavel Labath self._check_debug_info_is_limited(target) 80a03dc8c9SPavel Labath 811956cf10SPavel Labath lldbutil.run_to_name_breakpoint(self, "main", 821956cf10SPavel Labath extra_images=["one", "two"]) 83a03dc8c9SPavel Labath 84a03dc8c9SPavel Labath # This time, we should only see the members from the second library. 85a03dc8c9SPavel Labath self.expect_expr("inherits_from_one.member", result_value="47") 86a03dc8c9SPavel Labath self.expect("expr inherits_from_one.one", error=True, 87a03dc8c9SPavel Labath substrs=["no member named 'one' in 'InheritsFromOne'"]) 88a03dc8c9SPavel Labath self.expect_expr("inherits_from_two.member", result_value="47") 89a03dc8c9SPavel Labath self.expect("expr inherits_from_two.one", error=True, 90a03dc8c9SPavel Labath substrs=["no member named 'one' in 'InheritsFromTwo'"]) 91a03dc8c9SPavel Labath self.expect_expr("inherits_from_two.two", result_value="242") 92a03dc8c9SPavel Labath 93b3b95287SPavel Labath self.expect_expr("one_as_member.member", result_value="47") 94b3b95287SPavel Labath self.expect("expr one_as_member.one.member", error=True, 95b3b95287SPavel Labath substrs=["no member named 'member' in 'member::One'"]) 96b3b95287SPavel Labath self.expect_expr("two_as_member.member", result_value="47") 97b3b95287SPavel Labath self.expect("expr two_as_member.two.one.member", error=True, 98b3b95287SPavel Labath substrs=["no member named 'member' in 'member::One'"]) 99b3b95287SPavel Labath self.expect_expr("two_as_member.two.member", result_value="247") 100b3b95287SPavel Labath 101b65d4b23SPavel Labath self.expect("expr array_of_one[2].member", error=True, 102b65d4b23SPavel Labath substrs=["no member named 'member' in 'array::One'"]) 103b65d4b23SPavel Labath self.expect("expr array_of_two[2].one[2].member", error=True, 104b65d4b23SPavel Labath substrs=["no member named 'member' in 'array::One'"]) 105b65d4b23SPavel Labath self.expect_expr("array_of_two[2].member", result_value="274") 106b65d4b23SPavel Labath 1071956cf10SPavel Labath self.expect("expr get_one().member", error=True, 1081956cf10SPavel Labath substrs=["calling 'get_one' with incomplete return type 'result::One'"]) 1091956cf10SPavel Labath self.expect("expr get_two().one().member", error=True, 1101956cf10SPavel Labath substrs=["calling 'one' with incomplete return type 'result::One'"]) 1111956cf10SPavel Labath self.expect_expr("get_two().member", result_value="224") 1121956cf10SPavel Labath 113a03dc8c9SPavel Labath @skipIf(bugnumber="pr46284", debug_info="gmodules") 114d6343e60SPavel Labath @skipIfWindows # Clang emits type info even with -flimit-debug-info 115*1265f05cSRaphael Isemann # Requires DW_CC_pass_by_* attributes from Clang 7 to correctly call 116*1265f05cSRaphael Isemann # by-value functions. 117*1265f05cSRaphael Isemann @skipIf(compiler="clang", compiler_version=['<', '7.0']) 118a03dc8c9SPavel Labath def test_one_debug(self): 119a03dc8c9SPavel Labath self.build(dictionary=dict(STRIP_TWO="1")) 120a03dc8c9SPavel Labath target = self.dbg.CreateTarget(self.getBuildArtifact("a.out")) 121a03dc8c9SPavel Labath 122a03dc8c9SPavel Labath self._check_debug_info_is_limited(target) 123a03dc8c9SPavel Labath 1241956cf10SPavel Labath lldbutil.run_to_name_breakpoint(self, "main", 1251956cf10SPavel Labath extra_images=["one", "two"]) 126a03dc8c9SPavel Labath 127a03dc8c9SPavel Labath # In this case we should only see the members from the second library. 128a03dc8c9SPavel Labath # Note that we cannot see inherits_from_two.one because without debug 129a03dc8c9SPavel Labath # info for "Two", we cannot determine that it in fact inherits from 130a03dc8c9SPavel Labath # "One". 131a03dc8c9SPavel Labath self.expect_expr("inherits_from_one.member", result_value="47") 132a03dc8c9SPavel Labath self.expect_expr("inherits_from_one.one", result_value="142") 133a03dc8c9SPavel Labath self.expect_expr("inherits_from_two.member", result_value="47") 134a03dc8c9SPavel Labath self.expect("expr inherits_from_two.one", error=True, 135a03dc8c9SPavel Labath substrs=["no member named 'one' in 'InheritsFromTwo'"]) 136a03dc8c9SPavel Labath self.expect("expr inherits_from_two.two", error=True, 137a03dc8c9SPavel Labath substrs=["no member named 'two' in 'InheritsFromTwo'"]) 138b3b95287SPavel Labath 139b3b95287SPavel Labath self.expect_expr("one_as_member.member", result_value="47") 140b3b95287SPavel Labath self.expect_expr("one_as_member.one.member", result_value="147") 141b3b95287SPavel Labath self.expect_expr("two_as_member.member", result_value="47") 142b3b95287SPavel Labath self.expect("expr two_as_member.two.one.member", error=True, 143b3b95287SPavel Labath substrs=["no member named 'one' in 'member::Two'"]) 144b3b95287SPavel Labath self.expect("expr two_as_member.two.member", error=True, 145b3b95287SPavel Labath substrs=["no member named 'member' in 'member::Two'"]) 146b65d4b23SPavel Labath 147b65d4b23SPavel Labath self.expect_expr("array_of_one[2].member", result_value="174") 148b65d4b23SPavel Labath self.expect("expr array_of_two[2].one[2].member", error=True, 149b65d4b23SPavel Labath substrs=["no member named 'one' in 'array::Two'"]) 150b65d4b23SPavel Labath self.expect("expr array_of_two[2].member", error=True, 151b65d4b23SPavel Labath substrs=["no member named 'member' in 'array::Two'"]) 1521956cf10SPavel Labath 1531956cf10SPavel Labath self.expect_expr("get_one().member", result_value="124") 1541956cf10SPavel Labath self.expect("expr get_two().one().member", error=True, 1551956cf10SPavel Labath substrs=["calling 'get_two' with incomplete return type 'result::Two'"]) 1561956cf10SPavel Labath self.expect("expr get_two().member", error=True, 1571956cf10SPavel Labath substrs=["calling 'get_two' with incomplete return type 'result::Two'"]) 158