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