TestObjCStepping.py revision c94765e60759ece7681561f91ca70bc41ab6cbdc
1"""Test stepping through ObjC method dispatch in various forms.""" 2 3import os, time 4import unittest2 5import lldb 6import lldbutil 7from lldbtest import * 8 9class TestObjCStepping(TestBase): 10 11 mydir = os.path.join("lang", "objc", "objc-stepping") 12 13 # rdar://problem/10986147 14 @unittest2.expectedFailure 15 @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") 16 @python_api_test 17 def test_with_dsym_and_python_api(self): 18 """Test stepping through ObjC method dispatch in various forms.""" 19 self.buildDsym() 20 self.objc_stepping() 21 22 # rdar://problem/10986147 23 @unittest2.expectedFailure 24 @python_api_test 25 def test_with_dwarf_and_python_api(self): 26 """Test stepping through ObjC method dispatch in various forms.""" 27 self.buildDwarf() 28 self.objc_stepping() 29 30 def setUp(self): 31 # Call super's setUp(). 32 TestBase.setUp(self) 33 # Find the line numbers that we will step to in main: 34 self.main_source = "stepping-tests.m" 35 self.source_randomMethod_line = line_number (self.main_source, '// Source randomMethod start line.') 36 self.sourceBase_randomMethod_line = line_number (self.main_source, '// SourceBase randomMethod start line.') 37 self.source_returnsStruct_start_line = line_number (self.main_source, '// Source returnsStruct start line.') 38 self.sourceBase_returnsStruct_start_line = line_number (self.main_source, '// SourceBase returnsStruct start line.') 39 40 def objc_stepping(self): 41 """Use Python APIs to test stepping into ObjC methods.""" 42 exe = os.path.join(os.getcwd(), "a.out") 43 44 target = self.dbg.CreateTarget(exe) 45 self.assertTrue(target, VALID_TARGET) 46 47 self.main_source_spec = lldb.SBFileSpec (self.main_source) 48 break1 = target.BreakpointCreateBySourceRegex ("// Set first breakpoint here.", self.main_source_spec) 49 self.assertTrue(break1, VALID_BREAKPOINT) 50 51 break2 = target.BreakpointCreateBySourceRegex ("// Set second breakpoint here.", self.main_source_spec) 52 self.assertTrue(break2, VALID_BREAKPOINT) 53 54 break3 = target.BreakpointCreateBySourceRegex ('// Set third breakpoint here.', self.main_source_spec) 55 self.assertTrue(break3, VALID_BREAKPOINT) 56 57 break4 = target.BreakpointCreateBySourceRegex ('// Set fourth breakpoint here.', self.main_source_spec) 58 self.assertTrue(break4, VALID_BREAKPOINT) 59 60 break5 = target.BreakpointCreateBySourceRegex ('// Set fifth breakpoint here.', self.main_source_spec) 61 self.assertTrue(break5, VALID_BREAKPOINT) 62 63 break_returnStruct_call_super = target.BreakpointCreateBySourceRegex ('// Source returnsStruct call line.', self.main_source_spec) 64 self.assertTrue(break_returnStruct_call_super, VALID_BREAKPOINT) 65 66 # Now launch the process, and do not stop at entry point. 67 process = target.LaunchSimple (None, None, os.getcwd()) 68 69 self.assertTrue(process, PROCESS_IS_VALID) 70 71 # The stop reason of the thread should be breakpoint. 72 threads = lldbutil.get_threads_stopped_at_breakpoint (process, break1) 73 if len(threads) != 1: 74 self.fail ("Failed to stop at breakpoint 1.") 75 76 thread = threads[0] 77 78 mySource = thread.GetFrameAtIndex(0).FindVariable("mySource") 79 self.assertTrue(mySource, "Found mySource local variable.") 80 mySource_isa = mySource.GetChildMemberWithName ("isa") 81 self.assertTrue(mySource_isa, "Found mySource->isa local variable.") 82 mySource_isa.GetValue () 83 84 # Lets delete mySource so we can check that after stepping a child variable 85 # with no parent persists and is useful. 86 del (mySource) 87 88 # Now step in, that should leave us in the Source randomMethod: 89 thread.StepInto() 90 line_number = thread.GetFrameAtIndex(0).GetLineEntry().GetLine() 91 self.assertTrue (line_number == self.source_randomMethod_line, "Stepped into Source randomMethod.") 92 93 # Now step in again, through the super call, and that should leave us in the SourceBase randomMethod: 94 thread.StepInto() 95 line_number = thread.GetFrameAtIndex(0).GetLineEntry().GetLine() 96 self.assertTrue (line_number == self.sourceBase_randomMethod_line, "Stepped through super into SourceBase randomMethod.") 97 98 threads = lldbutil.continue_to_breakpoint (process, break2) 99 self.assertTrue (len(threads) == 1, "Continued to second breakpoint in main.") 100 101 # Again, step in twice gets us to a stret method and a stret super call: 102 thread = threads[0] 103 thread.StepInto() 104 line_number = thread.GetFrameAtIndex(0).GetLineEntry().GetLine() 105 self.assertTrue (line_number == self.source_returnsStruct_start_line, "Stepped into Source returnsStruct.") 106 107 threads = lldbutil.continue_to_breakpoint (process, break_returnStruct_call_super) 108 self.assertTrue (len(threads) == 1, "Stepped to the call super line in Source returnsStruct.") 109 thread = threads[0] 110 111 thread.StepInto() 112 line_number = thread.GetFrameAtIndex(0).GetLineEntry().GetLine() 113 self.assertTrue (line_number == self.sourceBase_returnsStruct_start_line, "Stepped through super into SourceBase returnsStruct.") 114 115 # Cool now continue to get past the call that intializes the Observer, and then do our steps in again to see that 116 # we can find our way when we're stepping through a KVO swizzled object. 117 118 threads = lldbutil.continue_to_breakpoint (process, break3) 119 self.assertTrue (len(threads) == 1, "Continued to third breakpoint in main, our object should now be swizzled.") 120 121 mySource_isa.GetValue () 122 did_change = mySource_isa.GetValueDidChange () 123 124 self.assertTrue (did_change, "The isa did indeed change, swizzled!") 125 126 # Now step in, that should leave us in the Source randomMethod: 127 thread = threads[0] 128 thread.StepInto() 129 line_number = thread.GetFrameAtIndex(0).GetLineEntry().GetLine() 130 self.assertTrue (line_number == self.source_randomMethod_line, "Stepped into Source randomMethod in swizzled object.") 131 132 # Now step in again, through the super call, and that should leave us in the SourceBase randomMethod: 133 thread.StepInto() 134 line_number = thread.GetFrameAtIndex(0).GetLineEntry().GetLine() 135 self.assertTrue (line_number == self.sourceBase_randomMethod_line, "Stepped through super into SourceBase randomMethod in swizzled object.") 136 137 threads = lldbutil.continue_to_breakpoint (process, break4) 138 self.assertTrue (len(threads) == 1, "Continued to fourth breakpoint in main.") 139 thread = threads[0] 140 141 # Again, step in twice gets us to a stret method and a stret super call: 142 thread.StepInto() 143 line_number = thread.GetFrameAtIndex(0).GetLineEntry().GetLine() 144 self.assertTrue (line_number == self.source_returnsStruct_start_line, "Stepped into Source returnsStruct in swizzled object.") 145 146 threads = lldbutil.continue_to_breakpoint(process, break_returnStruct_call_super) 147 self.assertTrue (len(threads) == 1, "Stepped to the call super line in Source returnsStruct - second time.") 148 thread = threads[0] 149 150 thread.StepInto() 151 line_number = thread.GetFrameAtIndex(0).GetLineEntry().GetLine() 152 self.assertTrue (line_number == self.sourceBase_returnsStruct_start_line, "Stepped through super into SourceBase returnsStruct in swizzled object.") 153 154 155if __name__ == '__main__': 156 import atexit 157 lldb.SBDebugger.Initialize() 158 atexit.register(lambda: lldb.SBDebugger.Terminate()) 159 unittest2.main() 160