• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1"""Test that hidden ivars in a shared library are visible from the main executable."""
2
3import os, time
4import unittest2
5import lldb
6from lldbtest import *
7import lldbutil
8
9class HiddenIvarsTestCase(TestBase):
10
11    mydir = os.path.join("lang", "objc", "hidden-ivars")
12
13    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
14    @dsym_test
15    def test_expr_with_dsym(self):
16        if self.getArchitecture() == 'i386':
17            self.skipTest("requires modern objc runtime")
18        self.buildDsym()
19        self.expr()
20
21    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
22    @dwarf_test
23    def test_expr_with_dwarf(self):
24        if self.getArchitecture() == 'i386':
25            self.skipTest("requires modern objc runtime")
26        self.buildDwarf()
27        self.expr()
28
29    @unittest2.expectedFailure
30    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
31    @dsym_test
32    def test_frame_variable_with_dsym(self):
33        if self.getArchitecture() == 'i386':
34            self.skipTest("requires modern objc runtime")
35        self.buildDsym()
36        self.frame_var()
37
38    @unittest2.expectedFailure
39    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
40    @dwarf_test
41    def test_frame_variable_with_dwarf(self):
42        if self.getArchitecture() == 'i386':
43            self.skipTest("requires modern objc runtime")
44        self.buildDwarf()
45        self.frame_var()
46
47    def setUp(self):
48        # Call super's setUp().
49        TestBase.setUp(self)
50        # Find the line number to break inside main().
51        self.line = line_number('main.m', '// Set breakpoint 0 here.')
52
53    def common_setup(self):
54        exe = os.path.join(os.getcwd(), "a.out")
55        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
56
57        # Break inside the foo function which takes a bar_ptr argument.
58        lldbutil.run_break_set_by_file_and_line (self, "main.m", self.line, num_expected_locations=1, loc_exact=True)
59
60        self.runCmd("run", RUN_SUCCEEDED)
61
62        # The stop reason of the thread should be breakpoint.
63        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
64            substrs = ['stopped',
65                       'stop reason = breakpoint'])
66
67        # The breakpoint should have a hit count of 1.
68        self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
69            substrs = [' resolved, hit count = 1'])
70
71    def expr(self):
72        self.common_setup()
73
74        # This should display correctly.
75        self.expect("expression (j->_definer->foo)", VARIABLES_DISPLAYED_CORRECTLY,
76            substrs = ["= 4"])
77
78        self.expect("expression (j->_definer->bar)", VARIABLES_DISPLAYED_CORRECTLY,
79            substrs = ["= 5"])
80
81        self.expect("expression *(j->_definer)", VARIABLES_DISPLAYED_CORRECTLY,
82            substrs = ["foo = 4", "bar = 5"])
83
84        self.expect("expression (k->foo)", VARIABLES_DISPLAYED_CORRECTLY,
85            substrs = ["= 2"])
86
87        self.expect("expression (k->bar)", VARIABLES_DISPLAYED_CORRECTLY,
88            substrs = ["= 3"])
89
90        self.expect("expression *(k)", VARIABLES_DISPLAYED_CORRECTLY,
91            substrs = ["foo = 2", "bar = 3"])
92
93    def frame_var(self):
94        self.common_setup()
95
96        # This should display correctly.
97        self.expect("frame variable j->_definer->foo", VARIABLES_DISPLAYED_CORRECTLY,
98            substrs = ["= 4"])
99
100        self.expect("frame variable j->_definer->bar", VARIABLES_DISPLAYED_CORRECTLY,
101            substrs = ["= 5"])
102
103        self.expect("frame variable *j->_definer", VARIABLES_DISPLAYED_CORRECTLY,
104            substrs = ["foo = 4", "bar = 5"])
105
106        self.expect("frame variable k->foo", VARIABLES_DISPLAYED_CORRECTLY,
107            substrs = ["= 2"])
108
109        self.expect("frame variable k->bar", VARIABLES_DISPLAYED_CORRECTLY,
110            substrs = ["= 3"])
111
112        self.expect("frame variable *k", VARIABLES_DISPLAYED_CORRECTLY,
113            substrs = ["foo = 2", "bar = 3"])
114
115if __name__ == '__main__':
116    import atexit
117    lldb.SBDebugger.Initialize()
118    atexit.register(lambda: lldb.SBDebugger.Terminate())
119    unittest2.main()
120