2b8bbbca9e290273ae8d45c0c52a936c4faadddb
[openbsd] /
1 """Test stepping over watchpoints."""
2
3
4
5 import lldb
6 from lldbsuite.test.decorators import *
7 from lldbsuite.test.lldbtest import *
8 from lldbsuite.test import lldbutil
9
10
11 class TestStepOverWatchpoint(TestBase):
12
13     mydir = TestBase.compute_mydir(__file__)
14     NO_DEBUG_INFO_TESTCASE = True
15
16     @expectedFailureAll(
17         oslist=["linux"],
18         archs=[
19             'aarch64',
20             'arm'],
21         bugnumber="llvm.org/pr26031")
22     # Read-write watchpoints not supported on SystemZ
23     @expectedFailureAll(archs=['s390x'])
24     @expectedFailureAll(oslist=["ios", "watchos", "tvos", "bridgeos"], bugnumber="<rdar://problem/34027183>")  # watchpoint tests aren't working on arm64
25     @add_test_categories(["basic_process"])
26     def test(self):
27         """Test stepping over watchpoints."""
28         self.build()
29         exe = self.getBuildArtifact("a.out")
30
31         target = self.dbg.CreateTarget(exe)
32         self.assertTrue(self.target, VALID_TARGET)
33
34         lldbutil.run_break_set_by_symbol(self, 'main')
35
36         process = target.LaunchSimple(None, None,
37                                       self.get_process_working_directory())
38         self.assertTrue(process.IsValid(), PROCESS_IS_VALID)
39         self.assertTrue(process.GetState() == lldb.eStateStopped,
40                         PROCESS_STOPPED)
41
42         thread = lldbutil.get_stopped_thread(process,
43                                              lldb.eStopReasonBreakpoint)
44         self.assertTrue(thread.IsValid(), "Failed to get thread.")
45
46         frame = thread.GetFrameAtIndex(0)
47         self.assertTrue(frame.IsValid(), "Failed to get frame.")
48
49         read_value = frame.FindValue('g_watch_me_read',
50                                      lldb.eValueTypeVariableGlobal)
51         self.assertTrue(read_value.IsValid(), "Failed to find read value.")
52
53         error = lldb.SBError()
54
55         # resolve_location=True, read=True, write=False
56         read_watchpoint = read_value.Watch(True, True, False, error)
57         self.assertTrue(error.Success(),
58                         "Error while setting watchpoint: %s" %
59                         error.GetCString())
60         self.assertTrue(read_watchpoint, "Failed to set read watchpoint.")
61
62         thread.StepOver()
63         self.assertTrue(thread.GetStopReason() == lldb.eStopReasonWatchpoint,
64                         STOPPED_DUE_TO_WATCHPOINT)
65         self.assertTrue(thread.GetStopDescription(20) == 'watchpoint 1')
66
67         process.Continue()
68         self.assertTrue(process.GetState() == lldb.eStateStopped,
69                         PROCESS_STOPPED)
70         self.assertTrue(thread.GetStopDescription(20) == 'step over')
71
72         self.step_inst_for_watchpoint(1)
73
74         write_value = frame.FindValue('g_watch_me_write',
75                                       lldb.eValueTypeVariableGlobal)
76         self.assertTrue(write_value, "Failed to find write value.")
77
78         # Most of the MIPS boards provide only one H/W watchpoints, and S/W
79         # watchpoints are not supported yet
80         arch = self.getArchitecture()
81         if re.match("^mips", arch) or re.match("powerpc64le", arch):
82             self.runCmd("watchpoint delete 1")
83
84         # resolve_location=True, read=False, write=True
85         write_watchpoint = write_value.Watch(True, False, True, error)
86         self.assertTrue(write_watchpoint, "Failed to set write watchpoint.")
87         self.assertTrue(error.Success(),
88                         "Error while setting watchpoint: %s" %
89                         error.GetCString())
90
91         thread.StepOver()
92         self.assertTrue(thread.GetStopReason() == lldb.eStopReasonWatchpoint,
93                         STOPPED_DUE_TO_WATCHPOINT)
94         self.assertTrue(thread.GetStopDescription(20) == 'watchpoint 2')
95
96         process.Continue()
97         self.assertTrue(process.GetState() == lldb.eStateStopped,
98                         PROCESS_STOPPED)
99         self.assertTrue(thread.GetStopDescription(20) == 'step over')
100
101         self.step_inst_for_watchpoint(2)
102
103     def step_inst_for_watchpoint(self, wp_id):
104         watchpoint_hit = False
105         current_line = self.frame().GetLineEntry().GetLine()
106         while self.frame().GetLineEntry().GetLine() == current_line:
107             self.thread().StepInstruction(False)  # step_over=False
108             stop_reason = self.thread().GetStopReason()
109             if stop_reason == lldb.eStopReasonWatchpoint:
110                 self.assertFalse(watchpoint_hit, "Watchpoint already hit.")
111                 expected_stop_desc = "watchpoint %d" % wp_id
112                 actual_stop_desc = self.thread().GetStopDescription(20)
113                 self.assertTrue(actual_stop_desc == expected_stop_desc,
114                                 "Watchpoint ID didn't match.")
115                 watchpoint_hit = True
116             else:
117                 self.assertTrue(stop_reason == lldb.eStopReasonPlanComplete,
118                                 STOPPED_DUE_TO_STEP_IN)
119         self.assertTrue(watchpoint_hit, "Watchpoint never hit.")