1"""
2Test completing types using information from other shared libraries.
3"""
4
5import os
6import lldb
7from lldbsuite.test.decorators import *
8from lldbsuite.test.lldbtest import *
9from lldbsuite.test import lldbutil
10
11
12class LimitDebugInfoTestCase(TestBase):
13
14    mydir = TestBase.compute_mydir(__file__)
15
16    def _check_type(self, target, name):
17        exe = target.FindModule(lldb.SBFileSpec("a.out"))
18        type_ = exe.FindFirstType(name)
19        self.trace("type_: %s"%type_)
20        self.assertTrue(type_)
21        base = type_.GetDirectBaseClassAtIndex(0).GetType()
22        self.trace("base:%s"%base)
23        self.assertTrue(base)
24        self.assertEquals(base.GetNumberOfFields(), 0)
25
26    def _check_debug_info_is_limited(self, target):
27        # Without other shared libraries we should only see the member declared
28        # in the derived class. This serves as a sanity check that we are truly
29        # building with limited debug info.
30        self._check_type(target, "InheritsFromOne")
31        self._check_type(target, "InheritsFromTwo")
32
33    @skipIf(bugnumber="pr46284", debug_info="gmodules")
34    def test_one_and_two_debug(self):
35        self.build()
36        target = self.dbg.CreateTarget(self.getBuildArtifact("a.out"))
37
38        self._check_debug_info_is_limited(target)
39
40        self.registerSharedLibrariesWithTarget(target, ["one", "two"])
41
42        # But when other shared libraries are loaded, we should be able to see
43        # all members.
44        self.expect_expr("inherits_from_one.member", result_value="47")
45        self.expect_expr("inherits_from_one.one", result_value="142")
46
47        self.expect_expr("inherits_from_two.member", result_value="47")
48        self.expect_expr("inherits_from_two.one", result_value="142")
49        self.expect_expr("inherits_from_two.two", result_value="242")
50
51    @skipIf(bugnumber="pr46284", debug_info="gmodules")
52    def test_two_debug(self):
53        self.build(dictionary=dict(STRIP_ONE="1"))
54        target = self.dbg.CreateTarget(self.getBuildArtifact("a.out"))
55
56        self._check_debug_info_is_limited(target)
57
58        self.registerSharedLibrariesWithTarget(target, ["one", "two"])
59
60        # This time, we should only see the members from the second library.
61        self.expect_expr("inherits_from_one.member", result_value="47")
62        self.expect("expr inherits_from_one.one", error=True,
63            substrs=["no member named 'one' in 'InheritsFromOne'"])
64
65        self.expect_expr("inherits_from_two.member", result_value="47")
66        self.expect("expr inherits_from_two.one", error=True,
67            substrs=["no member named 'one' in 'InheritsFromTwo'"])
68        self.expect_expr("inherits_from_two.two", result_value="242")
69
70    @skipIf(bugnumber="pr46284", debug_info="gmodules")
71    def test_one_debug(self):
72        self.build(dictionary=dict(STRIP_TWO="1"))
73        target = self.dbg.CreateTarget(self.getBuildArtifact("a.out"))
74
75        self._check_debug_info_is_limited(target)
76
77        self.registerSharedLibrariesWithTarget(target, ["one", "two"])
78
79        # In this case we should only see the members from the second library.
80        # Note that we cannot see inherits_from_two.one because without debug
81        # info for "Two", we cannot determine that it in fact inherits from
82        # "One".
83        self.expect_expr("inherits_from_one.member", result_value="47")
84        self.expect_expr("inherits_from_one.one", result_value="142")
85
86        self.expect_expr("inherits_from_two.member", result_value="47")
87        self.expect("expr inherits_from_two.one", error=True,
88            substrs=["no member named 'one' in 'InheritsFromTwo'"])
89        self.expect("expr inherits_from_two.two", error=True,
90            substrs=["no member named 'two' in 'InheritsFromTwo'"])
91