xref: /llvm-project/lldb/test/API/python_api/breakpoint/TestBreakpointAPI.py (revision 2238dcc39358353cac21df75c3c3286ab20b8f53)
199451b44SJordan Rupprecht"""
299451b44SJordan RupprechtTest SBBreakpoint APIs.
399451b44SJordan Rupprecht"""
499451b44SJordan Rupprecht
599451b44SJordan Rupprechtimport lldb
699451b44SJordan Rupprechtfrom lldbsuite.test.decorators import *
799451b44SJordan Rupprechtfrom lldbsuite.test.lldbtest import *
899451b44SJordan Rupprechtfrom lldbsuite.test import lldbutil
999451b44SJordan Rupprecht
1099451b44SJordan Rupprecht
1199451b44SJordan Rupprechtclass BreakpointAPITestCase(TestBase):
1299451b44SJordan Rupprecht    NO_DEBUG_INFO_TESTCASE = True
1399451b44SJordan Rupprecht
1499451b44SJordan Rupprecht    def test_breakpoint_is_valid(self):
1599451b44SJordan Rupprecht        """Make sure that if an SBBreakpoint gets deleted its IsValid returns false."""
1699451b44SJordan Rupprecht        self.build()
1799451b44SJordan Rupprecht        exe = self.getBuildArtifact("a.out")
1899451b44SJordan Rupprecht
1999451b44SJordan Rupprecht        # Create a target by the debugger.
2099451b44SJordan Rupprecht        target = self.dbg.CreateTarget(exe)
2199451b44SJordan Rupprecht        self.assertTrue(target, VALID_TARGET)
2299451b44SJordan Rupprecht
2399451b44SJordan Rupprecht        # Now create a breakpoint on main.c by name 'AFunction'.
24*2238dcc3SJonas Devlieghere        breakpoint = target.BreakpointCreateByName("AFunction", "a.out")
25b321b429SJonas Devlieghere        self.trace("breakpoint:", breakpoint)
26*2238dcc3SJonas Devlieghere        self.assertTrue(
27*2238dcc3SJonas Devlieghere            breakpoint and breakpoint.GetNumLocations() == 1, VALID_BREAKPOINT
28*2238dcc3SJonas Devlieghere        )
2999451b44SJordan Rupprecht
3099451b44SJordan Rupprecht        # Now delete it:
3199451b44SJordan Rupprecht        did_delete = target.BreakpointDelete(breakpoint.GetID())
32*2238dcc3SJonas Devlieghere        self.assertTrue(did_delete, "Did delete the breakpoint we just created.")
3399451b44SJordan Rupprecht
3499451b44SJordan Rupprecht        # Make sure we can't find it:
3599451b44SJordan Rupprecht        del_bkpt = target.FindBreakpointByID(breakpoint.GetID())
3699451b44SJordan Rupprecht        self.assertTrue(not del_bkpt, "We did delete the breakpoint.")
3799451b44SJordan Rupprecht
3899451b44SJordan Rupprecht        # Finally make sure the original breakpoint is no longer valid.
39*2238dcc3SJonas Devlieghere        self.assertTrue(not breakpoint, "Breakpoint we deleted is no longer valid.")
4099451b44SJordan Rupprecht
4199451b44SJordan Rupprecht    def test_target_delete(self):
4299451b44SJordan Rupprecht        """Make sure that if an SBTarget gets deleted the associated
4399451b44SJordan Rupprecht        Breakpoint's IsValid returns false."""
4499451b44SJordan Rupprecht
4599451b44SJordan Rupprecht        self.build()
4699451b44SJordan Rupprecht        exe = self.getBuildArtifact("a.out")
4799451b44SJordan Rupprecht
4899451b44SJordan Rupprecht        # Create a target by the debugger.
4999451b44SJordan Rupprecht        target = self.dbg.CreateTarget(exe)
5099451b44SJordan Rupprecht        self.assertTrue(target, VALID_TARGET)
5199451b44SJordan Rupprecht
5299451b44SJordan Rupprecht        # Now create a breakpoint on main.c by name 'AFunction'.
53*2238dcc3SJonas Devlieghere        breakpoint = target.BreakpointCreateByName("AFunction", "a.out")
54b321b429SJonas Devlieghere        self.trace("breakpoint:", breakpoint)
55*2238dcc3SJonas Devlieghere        self.assertTrue(
56*2238dcc3SJonas Devlieghere            breakpoint and breakpoint.GetNumLocations() == 1, VALID_BREAKPOINT
57*2238dcc3SJonas Devlieghere        )
5899451b44SJordan Rupprecht        location = breakpoint.GetLocationAtIndex(0)
5999451b44SJordan Rupprecht        self.assertTrue(location.IsValid())
6099451b44SJordan Rupprecht
613ff63672SDave Lee        # Test negative index access.
623ff63672SDave Lee        self.assertTrue(breakpoint.location[-1].IsValid())
633ff63672SDave Lee
646754caa9SJim Ingham        # Make sure the breakpoint's target is right:
65*2238dcc3SJonas Devlieghere        self.assertEqual(
66*2238dcc3SJonas Devlieghere            target, breakpoint.GetTarget(), "Breakpoint reports its target correctly"
67*2238dcc3SJonas Devlieghere        )
686754caa9SJim Ingham
6999451b44SJordan Rupprecht        self.assertTrue(self.dbg.DeleteTarget(target))
7099451b44SJordan Rupprecht        self.assertFalse(breakpoint.IsValid())
7199451b44SJordan Rupprecht        self.assertFalse(location.IsValid())
72