• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1"""Test that types defined in shared libraries work correctly."""
2
3import os, time
4import unittest2
5import lldb
6from lldbtest import *
7import lldbutil
8
9class TestRealDefinition(TestBase):
10
11    mydir = os.path.join("lang", "objc", "real-definition")
12
13    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
14    @dsym_test
15    def test_frame_var_after_stop_at_interface_with_dsym(self):
16        """Test that we can find the implementation for an objective C type"""
17        if self.getArchitecture() == 'i386':
18            self.skipTest("requires modern objc runtime")
19        self.buildDsym()
20        self.stop_at_interface()
21
22    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
23    @dwarf_test
24    def test_frame_var_after_stop_at_interface_with_dwarf(self):
25        """Test that we can find the implementation for an objective C type"""
26        if self.getArchitecture() == 'i386':
27            self.skipTest("requires modern objc runtime")
28        self.buildDwarf()
29        self.stop_at_interface()
30
31    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
32    @dsym_test
33    def test_frame_var_after_stop_at_implementation_with_dsym(self):
34        """Test that we can find the implementation for an objective C type"""
35        if self.getArchitecture() == 'i386':
36            self.skipTest("requires modern objc runtime")
37        self.buildDsym()
38        self.stop_at_implementation()
39
40    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
41    @dwarf_test
42    def test_frame_var_after_stop_at_implementation_with_dwarf(self):
43        """Test that we can find the implementation for an objective C type"""
44        if self.getArchitecture() == 'i386':
45            self.skipTest("requires modern objc runtime")
46        self.buildDwarf()
47        self.stop_at_implementation()
48
49    def setUp(self):
50        # Call super's setUp().
51        TestBase.setUp(self)
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        line = line_number('main.m', '// Set breakpoint in main')
59        lldbutil.run_break_set_by_file_and_line (self, "main.m", line, num_expected_locations=1, loc_exact=True)
60
61    def stop_at_interface(self):
62        """Test that we can find the implementation for an objective C type when we stop in the interface"""
63        self.common_setup()
64
65        line = line_number('Foo.m', '// Set breakpoint where Bar is an interface')
66        lldbutil.run_break_set_by_file_and_line (self, 'Foo.m', line, num_expected_locations=1, loc_exact=True);
67
68        self.runCmd("run", RUN_SUCCEEDED)
69
70        # The stop reason of the thread should be breakpoint.
71        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
72            substrs = ['stopped',
73                       'stop reason = breakpoint'])
74
75        # Run and stop at Foo
76        self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
77            substrs = [' resolved, hit count = 1'])
78
79        self.runCmd("continue", RUN_SUCCEEDED)
80
81        # Run at stop at main
82        self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
83            substrs = [' resolved, hit count = 1'])
84
85        # This should display correctly.
86        self.expect("frame variable foo->_bar->_hidden_ivar", VARIABLES_DISPLAYED_CORRECTLY,
87            substrs = ["(NSString *)", "foo->_bar->_hidden_ivar = 0x"])
88
89    def stop_at_implementation(self):
90        """Test that we can find the implementation for an objective C type when we stop in the implementation"""
91        self.common_setup()
92
93        line = line_number('Bar.m', '// Set breakpoint where Bar is an implementation')
94        lldbutil.run_break_set_by_file_and_line (self, 'Bar.m', line, num_expected_locations=1, loc_exact=True)
95
96        self.runCmd("run", RUN_SUCCEEDED)
97
98        # The stop reason of the thread should be breakpoint.
99        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
100            substrs = ['stopped',
101                       'stop reason = breakpoint'])
102
103        # Run and stop at Foo
104        self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
105            substrs = [' resolved, hit count = 1'])
106
107        self.runCmd("continue", RUN_SUCCEEDED)
108
109        # Run at stop at main
110        self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
111            substrs = [' resolved, hit count = 1'])
112
113        # This should display correctly.
114        self.expect("frame variable foo->_bar->_hidden_ivar", VARIABLES_DISPLAYED_CORRECTLY,
115            substrs = ["(NSString *)", "foo->_bar->_hidden_ivar = 0x"])
116
117
118if __name__ == '__main__':
119    import atexit
120    lldb.SBDebugger.Initialize()
121    atexit.register(lambda: lldb.SBDebugger.Terminate())
122    unittest2.main()
123