1"""
2Test require hardware breakpoints.
3"""
4
5
6import lldb
7from lldbsuite.test.decorators import *
8from lldbsuite.test.lldbtest import *
9from lldbsuite.test import lldbutil
10
11from functionalities.breakpoint.hardware_breakpoints.base import *
12
13class BreakpointLocationsTestCase(HardwareBreakpointTestBase):
14
15    @skipIf(oslist=["linux"], archs=["arm"])
16    def supports_hw_breakpoints(self):
17        return super().supports_hw_breakpoints()
18
19    def test_breakpoint(self):
20        """Test regular breakpoints when hardware breakpoints are required."""
21        self.build()
22        exe = self.getBuildArtifact("a.out")
23        target = self.dbg.CreateTarget(exe)
24
25        self.runCmd("settings set target.require-hardware-breakpoint true")
26
27        breakpoint = target.BreakpointCreateByLocation("main.c", 1)
28        self.assertTrue(breakpoint.IsHardware())
29
30    @expectedFailureIfFn(supports_hw_breakpoints)
31    def test_step_range(self):
32        """Test stepping when hardware breakpoints are required."""
33        self.build()
34
35        _, _, thread, _ = lldbutil.run_to_line_breakpoint(
36            self, lldb.SBFileSpec("main.c"), 1)
37
38        self.runCmd("settings set target.require-hardware-breakpoint true")
39
40        # Ensure we fail in the interpreter.
41        self.expect("thread step-in")
42        self.expect("thread step-in", error=True)
43
44        # Ensure we fail when stepping through the API.
45        error = lldb.SBError()
46        thread.StepInto('', 4, error)
47        self.assertTrue(error.Fail())
48        self.assertTrue("Could not create hardware breakpoint for thread plan"
49                        in error.GetCString())
50
51    @expectedFailureIfFn(supports_hw_breakpoints)
52    def test_step_out(self):
53        """Test stepping out when hardware breakpoints are required."""
54        self.build()
55
56        _, _, thread, _ = lldbutil.run_to_line_breakpoint(
57            self, lldb.SBFileSpec("main.c"), 1)
58
59        self.runCmd("settings set target.require-hardware-breakpoint true")
60
61        # Ensure this fails in the command interpreter.
62        self.expect("thread step-out", error=True)
63
64        # Ensure we fail when stepping through the API.
65        error = lldb.SBError()
66        thread.StepOut(error)
67        self.assertTrue(error.Fail())
68        self.assertTrue("Could not create hardware breakpoint for thread plan"
69                        in error.GetCString())
70
71    @expectedFailureIfFn(supports_hw_breakpoints)
72    def test_step_over(self):
73        """Test stepping over when hardware breakpoints are required."""
74        self.build()
75
76        _, _, thread, _ = lldbutil.run_to_line_breakpoint(
77            self, lldb.SBFileSpec("main.c"), 7)
78
79        self.runCmd("settings set target.require-hardware-breakpoint true")
80
81        # Step over doesn't fail immediately but fails later on.
82        self.expect(
83            "thread step-over",
84            error=True,
85            substrs=[
86                'error: Could not create hardware breakpoint for thread plan.'
87            ])
88
89    @expectedFailureIfFn(supports_hw_breakpoints)
90    def test_step_until(self):
91        """Test stepping until when hardware breakpoints are required."""
92        self.build()
93
94        _, _, thread, _ = lldbutil.run_to_line_breakpoint(
95            self, lldb.SBFileSpec("main.c"), 7)
96
97        self.runCmd("settings set target.require-hardware-breakpoint true")
98
99        self.expect("thread until 5", error=True)
100
101        # Ensure we fail when stepping through the API.
102        error = thread.StepOverUntil(lldb.SBFrame(), lldb.SBFileSpec(), 5)
103        self.assertTrue(error.Fail())
104        self.assertTrue("Could not create hardware breakpoint for thread plan"
105                        in error.GetCString())
106