TestUniversal.py revision 4386675ff4485cc67173f590b0f7daa5ba83fc33
15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)"""Test aspects of lldb commands on universal binaries."""
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)import os, time
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)import unittest2
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)import lldb
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)from lldbtest import *
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class UniversalTestCase(TestBase):
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    mydir = os.path.join("macosx", "universal")
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    def setUp(self):
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        # Call super's setUp().
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        TestBase.setUp(self)
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        # Find the line number to break inside main().
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        self.line = line_number('main.c', '// Set break point at this line.')
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    # rdar://problem/8972204 AddressByteSize of 32-bit process should be 4, got 8 instead.
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    @unittest2.skipUnless(sys.platform.startswith("darwin") and os.uname()[4] in ['i386', 'x86_64'],
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                          "requires Darwin & i386")
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    def test_process_launch_for_universal(self):
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        """Test process launch of a universal binary."""
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        from lldbutil import print_registers
24
25        # Invoke the default build rule.
26        self.buildDefault()
27
28        # Note that "testit" is a universal binary.
29        exe = os.path.join(os.getcwd(), "testit")
30
31        # By default, x86_64 is assumed if no architecture is specified.
32        self.expect("file " + exe, CURRENT_EXECUTABLE_SET,
33            startstr = "Current executable set to ",
34            substrs = ["testit' (x86_64)."])
35
36        # Break inside the main.
37        self.expect("breakpoint set -f main.c -l %d" % self.line,
38                    BREAKPOINT_CREATED,
39            startstr = "Breakpoint created: 1: file ='main.c', line = %d, locations = 1" %
40                        self.line)
41
42        # We should be able to launch the x86_64 executable.
43        self.runCmd("run", RUN_SUCCEEDED)
44
45        # Check whether we have a 64-bit process launched.
46        target = self.dbg.GetSelectedTarget()
47        process = target.GetProcess()
48        self.assertTrue(target and process and
49                        self.invoke(process, 'GetAddressByteSize') == 8,
50                        "64-bit process launched")
51
52        frame = process.GetThreadAtIndex(0).GetFrameAtIndex(0)
53        registers = print_registers(frame, string_buffer=True)
54        self.expect(registers, exe=False,
55            substrs = ['Name: rax'])
56
57        self.runCmd("continue")
58
59        # Now specify i386 as the architecture for "testit".
60        self.expect("file " + exe + " -a i386", CURRENT_EXECUTABLE_SET,
61            startstr = "Current executable set to ",
62            substrs = ["testit' (i386)."])
63
64        # Break inside the main.
65        self.expect("breakpoint set -f main.c -l %d" % self.line,
66                    BREAKPOINT_CREATED,
67            startstr = "Breakpoint created: 1: file ='main.c', line = %d, locations = 1" %
68                        self.line)
69
70        # We should be able to launch the i386 executable as well.
71        self.runCmd("run", RUN_SUCCEEDED)
72
73        # Check whether we have a 32-bit process launched.
74        target = self.dbg.GetSelectedTarget()
75        process = target.GetProcess()
76        self.assertTrue(target and process,
77                        "32-bit process launched")
78
79        pointerSize = self.invoke(process, 'GetAddressByteSize')
80        self.assertTrue(pointerSize == 4,
81                        "AddressByteSize of 32-bit process should be 4, got %d instead." % pointerSize)
82
83        frame = process.GetThreadAtIndex(0).GetFrameAtIndex(0)
84        registers = print_registers(frame, string_buffer=True)
85        self.expect(registers, exe=False,
86            substrs = ['Name: eax'])
87
88        self.runCmd("continue")
89
90
91if __name__ == '__main__':
92    import atexit
93    lldb.SBDebugger.Initialize()
94    atexit.register(lambda: lldb.SBDebugger.Terminate())
95    unittest2.main()
96