48 lines · python
1"""2Test that breakpoints set on a bad address say they are bad.3"""4 5 6import lldb7import lldbsuite.test.lldbutil as lldbutil8from lldbsuite.test.lldbtest import *9 10 11class BadAddressBreakpointTestCase(TestBase):12 NO_DEBUG_INFO_TESTCASE = True13 14 def test_bad_address_breakpoints(self):15 """Test that breakpoints set on a bad address say they are bad."""16 self.build()17 self.address_breakpoints()18 19 def address_breakpoints(self):20 """Test that breakpoints set on a bad address say they are bad."""21 target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(22 self, "Set a breakpoint here", lldb.SBFileSpec("main.c")23 )24 25 # illegal_address will hold (optionally) an address that, if26 # used as a breakpoint, will generate an unresolved breakpoint.27 illegal_address = None28 29 # Walk through all the memory regions in the process and30 # find an address that is invalid.31 regions = process.GetMemoryRegions()32 for region_idx in range(regions.GetSize()):33 region = lldb.SBMemoryRegionInfo()34 regions.GetMemoryRegionAtIndex(region_idx, region)35 if illegal_address is None or region.GetRegionEnd() > illegal_address:36 illegal_address = region.GetRegionEnd()37 38 if illegal_address is not None:39 # Now, set a breakpoint at the address we know is illegal.40 bkpt = target.BreakpointCreateByAddress(illegal_address)41 # Verify that breakpoint is not resolved.42 for bp_loc in bkpt:43 self.assertFalse(bp_loc.IsResolved())44 else:45 self.fail(46 "Could not find an illegal address at which to set a bad breakpoint."47 )48