TestUniversal.py revision ff4e1d8e276b6e330f78ac145712274a7c36a484
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 = "macosx/universal"
11
12    @unittest2.skipUnless(sys.platform.startswith("darwin") and os.uname()[4]=='i386',
13                          "requires Darwin & i386")
14    def test_process_launch_for_universal(self):
15        """Test process launch of a universal binary."""
16
17        # Invoke the default build rule.
18        self.buildDefault()
19
20        # Note that "testit" is a universal binary.
21        exe = os.path.join(os.getcwd(), "testit")
22
23        # By default, x86_64 is assumed if no architecture is specified.
24        self.expect("file " + exe, CURRENT_EXECUTABLE_SET,
25            startstr = "Current executable set to ",
26            substrs = ["testit' (x86_64)."])
27
28        # Break inside the main.
29        self.expect("breakpoint set -f main.c -l 5", BREAKPOINT_CREATED,
30            startstr = "Breakpoint created: 1: file ='main.c', line = 5, locations = 1")
31
32        # We should be able to launch the x86_64 executable.
33        self.runCmd("run", RUN_SUCCEEDED)
34
35        # Check whether we have a 64-bit process launched.
36        target = self.dbg.GetSelectedTarget()
37        process = target.GetProcess()
38        self.assertTrue(target.IsValid() and process.IsValid() and
39                        self.invoke(process, 'GetAddressByteSize') == 8,
40                        "64-bit process launched")
41
42        self.runCmd("continue")
43
44        # Now specify i386 as the architecture for "testit".
45        self.expect("file " + exe + " -a i386", CURRENT_EXECUTABLE_SET,
46            startstr = "Current executable set to ",
47            substrs = ["testit' (i386)."])
48
49        # Break inside the main.
50        self.expect("breakpoint set -f main.c -l 5", BREAKPOINT_CREATED,
51            startstr = "Breakpoint created: 1: file ='main.c', line = 5, locations = 1")
52
53        # We should be able to launch the i386 executable as well.
54        self.runCmd("run", RUN_SUCCEEDED)
55
56        # Check whether we have a 32-bit process launched.
57        target = self.dbg.GetSelectedTarget()
58        process = target.GetProcess()
59        self.assertTrue(target.IsValid() and process.IsValid() and
60                        self.invoke(process, 'GetAddressByteSize') == 4,
61                        "32-bit process launched")
62
63        self.runCmd("continue")
64
65
66if __name__ == '__main__':
67    import atexit
68    lldb.SBDebugger.Initialize()
69    atexit.register(lambda: lldb.SBDebugger.Terminate())
70    unittest2.main()
71