File: TestRequireHWBreakpoints.py

package info (click to toggle)
llvm-toolchain-19 1%3A19.1.7-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 1,998,520 kB
  • sloc: cpp: 6,951,680; ansic: 1,486,157; asm: 913,598; python: 232,024; f90: 80,126; objc: 75,281; lisp: 37,276; pascal: 16,990; sh: 10,009; ml: 5,058; perl: 4,724; awk: 3,523; makefile: 3,167; javascript: 2,504; xml: 892; fortran: 664; cs: 573
file content (112 lines) | stat: -rw-r--r-- 3,891 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
"""
Test require hardware breakpoints.

Some of these tests require a target that does not have hardware breakpoints.
So that we can check we fail when required to use them.
"""


import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil

from functionalities.breakpoint.hardware_breakpoints.base import *


class BreakpointLocationsTestCase(HardwareBreakpointTestBase):
    def test_breakpoint(self):
        """Test regular breakpoints when hardware breakpoints are required."""
        self.build()
        exe = self.getBuildArtifact("a.out")
        target = self.dbg.CreateTarget(exe)

        self.runCmd("settings set target.require-hardware-breakpoint true")

        breakpoint = target.BreakpointCreateByLocation("main.c", 1)
        self.assertTrue(breakpoint.IsHardware())

    @skipTestIfFn(HardwareBreakpointTestBase.supports_hw_breakpoints)
    def test_step_range(self):
        """Test stepping when hardware breakpoints are required."""
        self.build()

        _, _, thread, _ = lldbutil.run_to_line_breakpoint(
            self, lldb.SBFileSpec("main.c"), 1
        )

        self.runCmd("settings set target.require-hardware-breakpoint true")

        # Ensure we fail in the interpreter.
        self.expect("thread step-in")
        self.expect("thread step-in", error=True)

        # Ensure we fail when stepping through the API.
        error = lldb.SBError()
        thread.StepInto("", 4, error)
        self.assertTrue(error.Fail())
        self.assertIn(
            "Could not create hardware breakpoint for thread plan", error.GetCString()
        )

    @skipTestIfFn(HardwareBreakpointTestBase.supports_hw_breakpoints)
    def test_step_out(self):
        """Test stepping out when hardware breakpoints are required."""
        self.build()

        _, _, thread, _ = lldbutil.run_to_line_breakpoint(
            self, lldb.SBFileSpec("main.c"), 1
        )

        self.runCmd("settings set target.require-hardware-breakpoint true")

        # Ensure this fails in the command interpreter.
        self.expect("thread step-out", error=True)

        # Ensure we fail when stepping through the API.
        error = lldb.SBError()
        thread.StepOut(error)
        self.assertTrue(error.Fail())
        self.assertIn(
            "Could not create hardware breakpoint for thread plan", error.GetCString()
        )

    @skipTestIfFn(HardwareBreakpointTestBase.supports_hw_breakpoints)
    def test_step_over(self):
        """Test stepping over when hardware breakpoints are required."""
        self.build()

        _, _, thread, _ = lldbutil.run_to_line_breakpoint(
            self, lldb.SBFileSpec("main.c"), 7
        )

        self.runCmd("settings set target.require-hardware-breakpoint true")

        # Step over doesn't fail immediately but fails later on.
        self.expect(
            "thread step-over",
            error=True,
            substrs=["error: Could not create hardware breakpoint for thread plan."],
        )

    # Was reported to sometimes pass on certain hardware.
    @skipIf(oslist=["linux"], archs=["arm"])
    @skipTestIfFn(HardwareBreakpointTestBase.supports_hw_breakpoints)
    def test_step_until(self):
        """Test stepping until when hardware breakpoints are required."""
        self.build()

        _, _, thread, _ = lldbutil.run_to_line_breakpoint(
            self, lldb.SBFileSpec("main.c"), 7
        )

        self.runCmd("settings set target.require-hardware-breakpoint true")

        self.expect("thread until 5", error=True)

        # Ensure we fail when stepping through the API.
        error = thread.StepOverUntil(lldb.SBFrame(), lldb.SBFileSpec(), 5)
        self.assertTrue(error.Fail())
        self.assertIn(
            "Could not create hardware breakpoint for thread plan", error.GetCString()
        )