TestRealDefinition.py revision 9a530a652e519c5f99f7f13ab5512e2a040339a6
1"""Test that types defined in shared libraries work correctly."""
2
3import os, time
4import unittest2
5import lldb
6from lldbtest import *
7
8class TestRealDefinition(TestBase):
9
10    mydir = os.path.join("lang", "objc", "real-definition")
11
12    def test_expr_with_dsym(self):
13        """Test that we can find the implementation for an objective C type"""
14        self.buildDsym()
15        self.stop_at_interface()
16
17    def test_expr_with_dwarf(self):
18        """Test that we can find the implementation for an objective C type"""
19        self.buildDwarf()
20        self.stop_at_interface()
21
22    def test_frame_variable_with_dsym(self):
23        """Test that we can find the implementation for an objective C type"""
24        self.buildDsym()
25        self.stop_at_implementation()
26
27    def test_frame_variable_with_dwarf(self):
28        """Test that we can find the implementation for an objective C type"""
29        self.buildDwarf()
30        self.stop_at_implementation()
31
32    def setUp(self):
33        # Call super's setUp().
34        TestBase.setUp(self)
35
36    def common_setup(self):
37        exe = os.path.join(os.getcwd(), "a.out")
38        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
39
40        # Break inside the foo function which takes a bar_ptr argument.
41        self.expect("breakpoint set -f main.m -l %d" % line_number('main.m', '// Set breakpoint in main'), BREAKPOINT_CREATED, startstr = "Breakpoint created")
42
43    def stop_at_interface(self):
44        """Test that we can find the implementation for an objective C type when we stop in the interface"""
45        self.common_setup()
46
47        self.expect("breakpoint set -f Foo.m -l %d" % line_number('Foo.m', '// Set breakpoint where Bar is an interface'), BREAKPOINT_CREATED, startstr = "Breakpoint created")
48
49        self.runCmd("run", RUN_SUCCEEDED)
50
51        # The stop reason of the thread should be breakpoint.
52        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
53            substrs = ['stopped',
54                       'stop reason = breakpoint'])
55
56        # Run and stop at Foo
57        self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
58            substrs = [' resolved, hit count = 1'])
59
60        self.runCmd("continue", RUN_SUCCEEDED)
61
62        # Run at stop at main
63        self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
64            substrs = [' resolved, hit count = 1'])
65
66        # This should display correctly.
67        self.expect("frame variable foo->_bar->_hidden_ivar", VARIABLES_DISPLAYED_CORRECTLY,
68            substrs = ["(NSString *)", "foo->_bar->_hidden_ivar = 0x"])
69
70    def stop_at_implementation(self):
71        """Test that we can find the implementation for an objective C type when we stop in the implementation"""
72        self.common_setup()
73
74        self.expect("breakpoint set -f Bar.m -l %d" % line_number('Bar.m', '// Set breakpoint where Bar is an implementation'), BREAKPOINT_CREATED, startstr = "Breakpoint created")
75
76        self.runCmd("run", RUN_SUCCEEDED)
77
78        # The stop reason of the thread should be breakpoint.
79        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
80            substrs = ['stopped',
81                       'stop reason = breakpoint'])
82
83        # Run and stop at Foo
84        self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
85            substrs = [' resolved, hit count = 1'])
86
87        self.runCmd("continue", RUN_SUCCEEDED)
88
89        # Run at stop at main
90        self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
91            substrs = [' resolved, hit count = 1'])
92
93        # This should display correctly.
94        self.expect("frame variable foo->_bar->_hidden_ivar", VARIABLES_DISPLAYED_CORRECTLY,
95            substrs = ["(NSString *)", "foo->_bar->_hidden_ivar = 0x"])
96
97
98if __name__ == '__main__':
99    import atexit
100    lldb.SBDebugger.Initialize()
101    atexit.register(lambda: lldb.SBDebugger.Terminate())
102    unittest2.main()
103