1"""Test aspects of lldb commands on universal binaries.""" 2 3import os, time 4import unittest2 5import lldb 6from lldbtest import * 7import lldbutil 8 9class UniversalTestCase(TestBase): 10 11 mydir = os.path.join("macosx", "universal") 12 13 def setUp(self): 14 # Call super's setUp(). 15 TestBase.setUp(self) 16 # Find the line number to break inside main(). 17 self.line = line_number('main.c', '// Set break point at this line.') 18 19 @python_api_test 20 @unittest2.skipUnless(sys.platform.startswith("darwin") and os.uname()[4] in ['i386', 'x86_64'], 21 "requires Darwin & i386") 22 def test_sbdebugger_create_target_with_file_and_target_triple(self): 23 """Test the SBDebugger.CreateTargetWithFileAndTargetTriple() API.""" 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 # Create a target by the debugger. 31 target = self.dbg.CreateTargetWithFileAndTargetTriple(exe, "i386-apple-macosx") 32 self.assertTrue(target, VALID_TARGET) 33 34 # Now launch the process, and do not stop at entry point. 35 process = target.LaunchSimple(None, None, os.getcwd()) 36 self.assertTrue(process, PROCESS_IS_VALID) 37 38 # rdar://problem/8972204 AddressByteSize of 32-bit process should be 4, got 8 instead. 39 @unittest2.skipUnless(sys.platform.startswith("darwin") and os.uname()[4] in ['i386', 'x86_64'], 40 "requires Darwin & i386") 41 def test_process_launch_for_universal(self): 42 """Test process launch of a universal binary.""" 43 from lldbutil import print_registers 44 45 # Invoke the default build rule. 46 self.buildDefault() 47 48 # Note that "testit" is a universal binary. 49 exe = os.path.join(os.getcwd(), "testit") 50 51 # By default, x86_64 is assumed if no architecture is specified. 52 self.expect("file " + exe, CURRENT_EXECUTABLE_SET, 53 startstr = "Current executable set to ", 54 substrs = ["testit' (x86_64)."]) 55 56 # Break inside the main. 57 lldbutil.run_break_set_by_file_and_line (self, "main.c", self.line, num_expected_locations=1, loc_exact=True) 58 59 # We should be able to launch the x86_64 executable. 60 self.runCmd("run", RUN_SUCCEEDED) 61 62 # Check whether we have a 64-bit process launched. 63 target = self.dbg.GetSelectedTarget() 64 process = target.GetProcess() 65 self.assertTrue(target and process and 66 self.invoke(process, 'GetAddressByteSize') == 8, 67 "64-bit process launched") 68 69 frame = process.GetThreadAtIndex(0).GetFrameAtIndex(0) 70 registers = print_registers(frame, string_buffer=True) 71 self.expect(registers, exe=False, 72 substrs = ['Name: rax']) 73 74 self.runCmd("continue") 75 76 # Now specify i386 as the architecture for "testit". 77 self.expect("file " + exe + " -a i386", CURRENT_EXECUTABLE_SET, 78 startstr = "Current executable set to ", 79 substrs = ["testit' (i386)."]) 80 81 # Break inside the main. 82 lldbutil.run_break_set_by_file_and_line (self, "main.c", self.line, num_expected_locations=1, loc_exact=True) 83 84 # We should be able to launch the i386 executable as well. 85 self.runCmd("run", RUN_SUCCEEDED) 86 87 # Check whether we have a 32-bit process launched. 88 target = self.dbg.GetSelectedTarget() 89 process = target.GetProcess() 90 self.assertTrue(target and process, 91 "32-bit process launched") 92 93 pointerSize = self.invoke(process, 'GetAddressByteSize') 94 self.assertTrue(pointerSize == 4, 95 "AddressByteSize of 32-bit process should be 4, got %d instead." % pointerSize) 96 97 frame = process.GetThreadAtIndex(0).GetFrameAtIndex(0) 98 registers = print_registers(frame, string_buffer=True) 99 self.expect(registers, exe=False, 100 substrs = ['Name: eax']) 101 102 self.runCmd("continue") 103 104 105if __name__ == '__main__': 106 import atexit 107 lldb.SBDebugger.Initialize() 108 atexit.register(lambda: lldb.SBDebugger.Terminate()) 109 unittest2.main() 110