File: TestStepOverWatchpoint.py

package info (click to toggle)
llvm-toolchain-18 1%3A18.1.8-18
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,908,340 kB
  • sloc: cpp: 6,667,937; ansic: 1,440,452; asm: 883,619; python: 230,549; objc: 76,880; f90: 74,238; lisp: 35,989; pascal: 16,571; sh: 10,229; perl: 7,459; ml: 5,047; awk: 3,523; makefile: 2,987; javascript: 2,149; xml: 892; fortran: 649; cs: 573
file content (124 lines) | stat: -rw-r--r-- 4,955 bytes parent folder | download
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
113
114
115
116
117
118
119
120
121
122
123
124
"""Test stepping over watchpoints and instruction stepping past watchpoints."""


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


class TestStepOverWatchpoint(TestBase):
    NO_DEBUG_INFO_TESTCASE = True

    def get_to_start(self, bkpt_text):
        """Test stepping over watchpoints and instruction stepping past watchpoints.."""
        self.build()
        target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
            self, bkpt_text, lldb.SBFileSpec("main.c")
        )
        return (target, process, thread, frame, read_watchpoint)

    @add_test_categories(["basic_process"])
    @expectedFailureAll(
        oslist=["ios", "watchos", "tvos", "bridgeos", "macosx"],
        archs=["aarch64", "arm"],
        bugnumber="<rdar://problem/106868647>",
    )
    def test_step_over_read_watchpoint(self):
        self.build()
        target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
            self, "break here for read watchpoints", lldb.SBFileSpec("main.c")
        )

        frame = thread.GetFrameAtIndex(0)
        self.assertTrue(frame.IsValid(), "Failed to get frame.")

        read_value = frame.FindValue("g_watch_me_read", lldb.eValueTypeVariableGlobal)
        self.assertTrue(read_value.IsValid(), "Failed to find read value.")

        error = lldb.SBError()

        # resolve_location=True, read=True, write=False
        read_watchpoint = read_value.Watch(True, True, False, error)
        self.assertSuccess(error, "Error while setting watchpoint")
        self.assertTrue(read_watchpoint, "Failed to set read watchpoint.")

        # Disable the breakpoint we hit so we don't muddy the waters with
        # stepping off from the breakpoint:
        bkpt.SetEnabled(False)

        thread.StepOver()
        self.assertStopReason(
            thread.GetStopReason(),
            lldb.eStopReasonWatchpoint,
            STOPPED_DUE_TO_WATCHPOINT,
        )
        self.assertEquals(thread.GetStopDescription(20), "watchpoint 1")

        process.Continue()
        self.assertState(process.GetState(), lldb.eStateStopped, PROCESS_STOPPED)
        self.assertEquals(thread.GetStopDescription(20), "step over")

        self.step_inst_for_watchpoint(1)

    @add_test_categories(["basic_process"])
    @expectedFailureAll(
        oslist=["ios", "watchos", "tvos", "bridgeos", "macosx"],
        archs=["aarch64", "arm"],
        bugnumber="<rdar://problem/106868647>",
    )
    def test_step_over_write_watchpoint(self):
        self.build()
        target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
            self, "break here for modify watchpoints", lldb.SBFileSpec("main.c")
        )

        # Disable the breakpoint we hit so we don't muddy the waters with
        # stepping off from the breakpoint:
        bkpt.SetEnabled(False)

        frame = thread.GetFrameAtIndex(0)
        self.assertTrue(frame.IsValid(), "Failed to get frame.")

        write_value = frame.FindValue("g_watch_me_write", lldb.eValueTypeVariableGlobal)
        self.assertTrue(write_value, "Failed to find write value.")

        error = lldb.SBError()
        # resolve_location=True, read=False, modify=True
        write_watchpoint = write_value.Watch(True, False, True, error)
        self.assertTrue(write_watchpoint, "Failed to set write watchpoint.")
        self.assertSuccess(error, "Error while setting watchpoint")

        thread.StepOver()
        self.assertStopReason(
            thread.GetStopReason(),
            lldb.eStopReasonWatchpoint,
            STOPPED_DUE_TO_WATCHPOINT,
        )
        self.assertEquals(thread.GetStopDescription(20), "watchpoint 1")

        process.Continue()
        self.assertState(process.GetState(), lldb.eStateStopped, PROCESS_STOPPED)
        self.assertEquals(thread.GetStopDescription(20), "step over")

        self.step_inst_for_watchpoint(1)

    def step_inst_for_watchpoint(self, wp_id):
        watchpoint_hit = False
        current_line = self.frame().GetLineEntry().GetLine()
        while self.frame().GetLineEntry().GetLine() == current_line:
            self.thread().StepInstruction(False)  # step_over=False
            stop_reason = self.thread().GetStopReason()
            if stop_reason == lldb.eStopReasonWatchpoint:
                self.assertFalse(watchpoint_hit, "Watchpoint already hit.")
                expected_stop_desc = "watchpoint %d" % wp_id
                actual_stop_desc = self.thread().GetStopDescription(20)
                self.assertEquals(
                    actual_stop_desc, expected_stop_desc, "Watchpoint ID didn't match."
                )
                watchpoint_hit = True
            else:
                self.assertStopReason(
                    stop_reason, lldb.eStopReasonPlanComplete, STOPPED_DUE_TO_STEP_IN
                )
        self.assertTrue(watchpoint_hit, "Watchpoint never hit.")