1""" 2Test address breakpoints set with shared library of SBAddress work correctly. 3""" 4 5 6 7import lldb 8import lldbsuite.test.lldbutil as lldbutil 9from lldbsuite.test.lldbtest import * 10 11 12class AddressBreakpointTestCase(TestBase): 13 14 NO_DEBUG_INFO_TESTCASE = True 15 16 def test_address_breakpoints(self): 17 """Test address breakpoints set with shared library of SBAddress work correctly.""" 18 self.build() 19 self.address_breakpoints() 20 21 def address_breakpoints(self): 22 """Test address breakpoints set with shared library of SBAddress work correctly.""" 23 target = self.createTestTarget() 24 25 # Now create a breakpoint on main.c by name 'c'. 26 breakpoint = target.BreakpointCreateBySourceRegex( 27 "Set a breakpoint here", lldb.SBFileSpec("main.c")) 28 self.assertTrue(breakpoint and 29 breakpoint.GetNumLocations() >= 1, 30 VALID_BREAKPOINT) 31 32 # Get the breakpoint location from breakpoint after we verified that, 33 # indeed, it has one location. 34 location = breakpoint.GetLocationAtIndex(0) 35 self.assertTrue(location and 36 location.IsEnabled(), 37 VALID_BREAKPOINT_LOCATION) 38 39 # Next get the address from the location, and create an address breakpoint using 40 # that address: 41 42 address = location.GetAddress() 43 target.BreakpointDelete(breakpoint.GetID()) 44 45 breakpoint = target.BreakpointCreateBySBAddress(address) 46 47 # Disable ASLR. This will allow us to actually test (on platforms that support this flag) 48 # that the breakpoint was able to track the module. 49 50 launch_info = lldb.SBLaunchInfo(None) 51 flags = launch_info.GetLaunchFlags() 52 flags &= ~lldb.eLaunchFlagDisableASLR 53 flags &= lldb.eLaunchFlagInheritTCCFromParent 54 launch_info.SetLaunchFlags(flags) 55 56 error = lldb.SBError() 57 58 process = target.Launch(launch_info, error) 59 self.assertTrue(process, PROCESS_IS_VALID) 60 61 # Did we hit our breakpoint? 62 from lldbsuite.test.lldbutil import get_threads_stopped_at_breakpoint 63 threads = get_threads_stopped_at_breakpoint(process, breakpoint) 64 self.assertEqual( 65 len(threads), 1, 66 "There should be a thread stopped at our breakpoint") 67 68 # The hit count for the breakpoint should be 1. 69 self.assertEquals(breakpoint.GetHitCount(), 1) 70 71 process.Kill() 72 73 # Now re-launch and see that we hit the breakpoint again: 74 launch_info.Clear() 75 launch_info.SetLaunchFlags(flags) 76 77 process = target.Launch(launch_info, error) 78 self.assertTrue(process, PROCESS_IS_VALID) 79 80 thread = get_threads_stopped_at_breakpoint(process, breakpoint) 81 self.assertEqual( 82 len(threads), 1, 83 "There should be a thread stopped at our breakpoint") 84 85 # The hit count for the breakpoint should now be 2. 86 self.assertEquals(breakpoint.GetHitCount(), 2) 87