6b42b51d16a899d30b2692485c254d990666e9b4
[openbsd] /
1 """
2 Test address breakpoints set with shared library of SBAddress work correctly.
3 """
4
5
6
7 import lldb
8 import lldbsuite.test.lldbutil as lldbutil
9 from lldbsuite.test.lldbtest import *
10
11
12 class 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         launch_info.SetLaunchFlags(flags)
60
61         error = lldb.SBError()
62
63         process = target.Launch(launch_info, error)
64         self.assertTrue(process, PROCESS_IS_VALID)
65
66         # Did we hit our breakpoint?
67         from lldbsuite.test.lldbutil import get_threads_stopped_at_breakpoint
68         threads = get_threads_stopped_at_breakpoint(process, breakpoint)
69         self.assertTrue(
70             len(threads) == 1,
71             "There should be a thread stopped at our breakpoint")
72
73         # The hit count for the breakpoint should be 1.
74         self.assertTrue(breakpoint.GetHitCount() == 1)
75
76         process.Kill()
77
78         # Now re-launch and see that we hit the breakpoint again:
79         launch_info.Clear()
80         launch_info.SetLaunchFlags(flags)
81
82         process = target.Launch(launch_info, error)
83         self.assertTrue(process, PROCESS_IS_VALID)
84
85         thread = get_threads_stopped_at_breakpoint(process, breakpoint)
86         self.assertTrue(
87             len(threads) == 1,
88             "There should be a thread stopped at our breakpoint")
89
90         # The hit count for the breakpoint should now be 2.
91         self.assertTrue(breakpoint.GetHitCount() == 2)