TestUniversal.py revision c113489c350d0535a9e6e7d19335ba7efb4f52c6
1"""Test aspects of lldb commands on universal binaries."""
2
3import os, time
4import unittest2
5import lldb
6from lldbtest import *
7
8class UniversalTestCase(TestBase):
9
10    mydir = os.path.join("macosx", "universal")
11
12    def setUp(self):
13        # Call super's setUp().
14        TestBase.setUp(self)
15        # Find the line number to break inside main().
16        self.line = line_number('main.c', '// Set break point at this line.')
17
18    # rdar://problem/8972204 AddressByteSize of 32-bit process should be 4, got 8 instead.
19    @unittest2.skipUnless(sys.platform.startswith("darwin") and os.uname()[4]=='i386',
20                          "requires Darwin & i386")
21    def test_process_launch_for_universal(self):
22        """Test process launch of a universal binary."""
23
24        # Invoke the default build rule.
25        self.buildDefault()
26
27        # Note that "testit" is a universal binary.
28        exe = os.path.join(os.getcwd(), "testit")
29
30        # By default, x86_64 is assumed if no architecture is specified.
31        self.expect("file " + exe, CURRENT_EXECUTABLE_SET,
32            startstr = "Current executable set to ",
33            substrs = ["testit' (x86_64)."])
34
35        # Break inside the main.
36        self.expect("breakpoint set -f main.c -l %d" % self.line,
37                    BREAKPOINT_CREATED,
38            startstr = "Breakpoint created: 1: file ='main.c', line = %d, locations = 1" %
39                        self.line)
40
41        # We should be able to launch the x86_64 executable.
42        self.runCmd("run", RUN_SUCCEEDED)
43
44        # Check whether we have a 64-bit process launched.
45        target = self.dbg.GetSelectedTarget()
46        process = target.GetProcess()
47        self.assertTrue(target.IsValid() and process.IsValid() and
48                        self.invoke(process, 'GetAddressByteSize') == 8,
49                        "64-bit process launched")
50
51        self.runCmd("continue")
52
53        # Now specify i386 as the architecture for "testit".
54        self.expect("file " + exe + " -a i386", CURRENT_EXECUTABLE_SET,
55            startstr = "Current executable set to ",
56            substrs = ["testit' (i386)."])
57
58        # Break inside the main.
59        self.expect("breakpoint set -f main.c -l %d" % self.line,
60                    BREAKPOINT_CREATED,
61            startstr = "Breakpoint created: 1: file ='main.c', line = %d, locations = 1" %
62                        self.line)
63
64        # We should be able to launch the i386 executable as well.
65        self.runCmd("run", RUN_SUCCEEDED)
66
67        # Check whether we have a 32-bit process launched.
68        target = self.dbg.GetSelectedTarget()
69        process = target.GetProcess()
70        self.assertTrue(target.IsValid() and process.IsValid(),
71                        "32-bit process launched")
72
73        pointerSize = self.invoke(process, 'GetAddressByteSize')
74        self.assertTrue(pointerSize == 4,
75                        "AddressByteSize of 32-bit process should be 4, got %d instead." % pointerSize)
76
77        self.runCmd("continue")
78
79
80if __name__ == '__main__':
81    import atexit
82    lldb.SBDebugger.Initialize()
83    atexit.register(lambda: lldb.SBDebugger.Terminate())
84    unittest2.main()
85