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