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