TestUniversal.py revision a8b3cdd691771ec347420ed625d7306574eedd4f
1"""Test aspects of lldb commands on universal binaries."""
2
3import os, time
4import unittest2
5import lldb
6from lldbtest import *
7
8class TestUniversal(TestBase):
9
10    mydir = "macosx/universal"
11
12    def test_process_launch_for_universal(self):
13        """Test process launch of a universal binary."""
14
15        # Note that "testit" is a universal binary.
16        exe = os.path.join(os.getcwd(), "testit")
17
18        # By default, x86_64 is assumed if no architecture is specified.
19        self.expect("file " + exe, CURRENT_EXECUTABLE_SET,
20            startstr = "Current executable set to ",
21            substrs = ["testit' (x86_64)."])
22
23        # Break inside the main.
24        self.expect("breakpoint set -f main.c -l 5", BREAKPOINT_CREATED,
25            startstr = "Breakpoint created: 1: file ='main.c', line = 5, locations = 1")
26
27        # We should be able to launch the x86_64 executable.
28        self.runCmd("run", RUN_STOPPED)
29
30        # Check whether we have a 64-bit process launched.
31        target = self.dbg.GetCurrentTarget()
32        process = target.GetProcess()
33        self.assertTrue(target.IsValid() and process.IsValid() and
34                        self.invoke(process, 'GetAddressByteSize') == 8,
35                        "64-bit process launched")
36
37        self.runCmd("continue")
38
39        # Now specify i386 as the architecture for "testit".
40        self.expect("file " + exe + " -a i386", CURRENT_EXECUTABLE_SET,
41            startstr = "Current executable set to ",
42            substrs = ["testit' (i386)."])
43
44        # Break inside the main.
45        self.expect("breakpoint set -f main.c -l 5", BREAKPOINT_CREATED,
46            startstr = "Breakpoint created: 1: file ='main.c', line = 5, locations = 1")
47
48        # We should be able to launch the i386 executable as well.
49        self.runCmd("run", RUN_STOPPED)
50
51        # Check whether we have a 32-bit process launched.
52        target = self.dbg.GetCurrentTarget()
53        process = target.GetProcess()
54        self.assertTrue(target.IsValid() and process.IsValid() and
55                        self.invoke(process, 'GetAddressByteSize') == 4,
56                        "32-bit process launched")
57
58        self.runCmd("continue")
59
60
61if __name__ == '__main__':
62    import atexit
63    lldb.SBDebugger.Initialize()
64    atexit.register(lambda: lldb.SBDebugger.Terminate())
65    unittest2.main()
66