199451b44SJordan Rupprecht""" 299451b44SJordan RupprechtTest that breakpoints set on a bad address say they are bad. 399451b44SJordan Rupprecht""" 499451b44SJordan Rupprecht 599451b44SJordan Rupprecht 699451b44SJordan Rupprechtimport lldb 799451b44SJordan Rupprechtimport lldbsuite.test.lldbutil as lldbutil 899451b44SJordan Rupprechtfrom lldbsuite.test.lldbtest import * 999451b44SJordan Rupprecht 1099451b44SJordan Rupprecht 1199451b44SJordan Rupprechtclass BadAddressBreakpointTestCase(TestBase): 1299451b44SJordan Rupprecht NO_DEBUG_INFO_TESTCASE = True 1399451b44SJordan Rupprecht 1499451b44SJordan Rupprecht def test_bad_address_breakpoints(self): 1599451b44SJordan Rupprecht """Test that breakpoints set on a bad address say they are bad.""" 1699451b44SJordan Rupprecht self.build() 1799451b44SJordan Rupprecht self.address_breakpoints() 1899451b44SJordan Rupprecht 1999451b44SJordan Rupprecht def address_breakpoints(self): 2099451b44SJordan Rupprecht """Test that breakpoints set on a bad address say they are bad.""" 212238dcc3SJonas Devlieghere target, process, thread, bkpt = lldbutil.run_to_source_breakpoint( 222238dcc3SJonas Devlieghere self, "Set a breakpoint here", lldb.SBFileSpec("main.c") 232238dcc3SJonas Devlieghere ) 2499451b44SJordan Rupprecht 2584b9985fSWill Hawkins # illegal_address will hold (optionally) an address that, if 2684b9985fSWill Hawkins # used as a breakpoint, will generate an unresolved breakpoint. 2784b9985fSWill Hawkins illegal_address = None 2884b9985fSWill Hawkins 2984b9985fSWill Hawkins # Walk through all the memory regions in the process and 3084b9985fSWill Hawkins # find an address that is invalid. 3184b9985fSWill Hawkins regions = process.GetMemoryRegions() 3284b9985fSWill Hawkins for region_idx in range(regions.GetSize()): 3384b9985fSWill Hawkins region = lldb.SBMemoryRegionInfo() 3484b9985fSWill Hawkins regions.GetMemoryRegionAtIndex(region_idx, region) 35*58611451SEisuke Kawashima if illegal_address is None or region.GetRegionEnd() > illegal_address: 3684b9985fSWill Hawkins illegal_address = region.GetRegionEnd() 3784b9985fSWill Hawkins 3884b9985fSWill Hawkins if illegal_address is not None: 3984b9985fSWill Hawkins # Now, set a breakpoint at the address we know is illegal. 4084b9985fSWill Hawkins bkpt = target.BreakpointCreateByAddress(illegal_address) 4184b9985fSWill Hawkins # Verify that breakpoint is not resolved. 4299451b44SJordan Rupprecht for bp_loc in bkpt: 431eeeab82SJordan Rupprecht self.assertFalse(bp_loc.IsResolved()) 4499451b44SJordan Rupprecht else: 4599451b44SJordan Rupprecht self.fail( 462238dcc3SJonas Devlieghere "Could not find an illegal address at which to set a bad breakpoint." 472238dcc3SJonas Devlieghere ) 48