• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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        exe = self.getBuildArtifact("a.out")
26
27        # Create a target by the debugger.
28        target = self.dbg.CreateTarget(exe)
29        self.assertTrue(target, VALID_TARGET)
30
31        # Now create a breakpoint on main.c by name 'c'.
32        breakpoint = target.BreakpointCreateBySourceRegex(
33            "Set a breakpoint here", lldb.SBFileSpec("main.c"))
34        self.assertTrue(breakpoint and
35                        breakpoint.GetNumLocations() >= 1,
36                        VALID_BREAKPOINT)
37
38        # Get the breakpoint location from breakpoint after we verified that,
39        # indeed, it has one location.
40        location = breakpoint.GetLocationAtIndex(0)
41        self.assertTrue(location and
42                        location.IsEnabled(),
43                        VALID_BREAKPOINT_LOCATION)
44
45        # Next get the address from the location, and create an address breakpoint using
46        # that address:
47
48        address = location.GetAddress()
49        target.BreakpointDelete(breakpoint.GetID())
50
51        breakpoint = target.BreakpointCreateBySBAddress(address)
52
53        # Disable ASLR.  This will allow us to actually test (on platforms that support this flag)
54        # that the breakpoint was able to track the module.
55
56        launch_info = lldb.SBLaunchInfo(None)
57        flags = launch_info.GetLaunchFlags()
58        flags &= ~lldb.eLaunchFlagDisableASLR
59        flags &= lldb.eLaunchFlagInheritTCCFromParent
60        launch_info.SetLaunchFlags(flags)
61
62        error = lldb.SBError()
63
64        process = target.Launch(launch_info, error)
65        self.assertTrue(process, PROCESS_IS_VALID)
66
67        # Did we hit our breakpoint?
68        from lldbsuite.test.lldbutil import get_threads_stopped_at_breakpoint
69        threads = get_threads_stopped_at_breakpoint(process, breakpoint)
70        self.assertTrue(
71            len(threads) == 1,
72            "There should be a thread stopped at our breakpoint")
73
74        # The hit count for the breakpoint should be 1.
75        self.assertEquals(breakpoint.GetHitCount(), 1)
76
77        process.Kill()
78
79        # Now re-launch and see that we hit the breakpoint again:
80        launch_info.Clear()
81        launch_info.SetLaunchFlags(flags)
82
83        process = target.Launch(launch_info, error)
84        self.assertTrue(process, PROCESS_IS_VALID)
85
86        thread = get_threads_stopped_at_breakpoint(process, breakpoint)
87        self.assertTrue(
88            len(threads) == 1,
89            "There should be a thread stopped at our breakpoint")
90
91        # The hit count for the breakpoint should now be 2.
92        self.assertEquals(breakpoint.GetHitCount(), 2)
93