]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/functionalities/breakpoint/address_breakpoints/TestBadAddressBreakpoints.py
Vendor import of lldb trunk r290819:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / functionalities / breakpoint / address_breakpoints / TestBadAddressBreakpoints.py
1 """
2 Test that breakpoints set on a bad address say they are bad.
3 """
4
5 from __future__ import print_function
6
7
8 import os
9 import time
10 import re
11 import lldb
12 import lldbsuite.test.lldbutil as lldbutil
13 from lldbsuite.test.lldbtest import *
14
15
16 class BadAddressBreakpointTestCase(TestBase):
17
18     mydir = TestBase.compute_mydir(__file__)
19
20     NO_DEBUG_INFO_TESTCASE = True
21
22     def test_bad_address_breakpoints(self):
23         """Test that breakpoints set on a bad address say they are bad."""
24         self.build()
25         self.address_breakpoints()
26
27     def setUp(self):
28         # Call super's setUp().
29         TestBase.setUp(self)
30
31     def address_breakpoints(self):
32         """Test that breakpoints set on a bad address say they are bad."""
33         exe = os.path.join(os.getcwd(), "a.out")
34
35         # Create a target by the debugger.
36         target = self.dbg.CreateTarget(exe)
37         self.assertTrue(target, VALID_TARGET)
38
39         # Now create a breakpoint on main.c by name 'c'.
40         breakpoint = target.BreakpointCreateBySourceRegex(
41             "Set a breakpoint here", lldb.SBFileSpec("main.c"))
42         self.assertTrue(breakpoint and
43                         breakpoint.GetNumLocations() == 1,
44                         VALID_BREAKPOINT)
45
46         # Get the breakpoint location from breakpoint after we verified that,
47         # indeed, it has one location.
48         location = breakpoint.GetLocationAtIndex(0)
49         self.assertTrue(location and
50                         location.IsEnabled(),
51                         VALID_BREAKPOINT_LOCATION)
52
53         launch_info = lldb.SBLaunchInfo(None)
54
55         error = lldb.SBError()
56
57         process = target.Launch(launch_info, error)
58         self.assertTrue(process, PROCESS_IS_VALID)
59
60         # Did we hit our breakpoint?
61         from lldbsuite.test.lldbutil import get_threads_stopped_at_breakpoint
62         threads = get_threads_stopped_at_breakpoint(process, breakpoint)
63         self.assertTrue(
64             len(threads) == 1,
65             "There should be a thread stopped at our breakpoint")
66
67         # The hit count for the breakpoint should be 1.
68         self.assertTrue(breakpoint.GetHitCount() == 1)
69
70         # Now see if we can read from 0.  If I can't do that, I don't have a good way to know
71         # what an illegal address is...
72         error.Clear()
73
74         ptr = process.ReadPointerFromMemory(0x0, error)
75
76         if not error.Success():
77             bkpt = target.BreakpointCreateByAddress(0x0)
78             for bp_loc in bkpt:
79                 self.assertTrue(bp_loc.IsResolved() == False)
80         else:
81             self.fail(
82                 "Could not find an illegal address at which to set a bad breakpoint.")