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