1 """Test stepping over watchpoints."""
6 from lldbsuite.test.decorators import *
7 from lldbsuite.test.lldbtest import *
8 from lldbsuite.test import lldbutil
11 class TestStepOverWatchpoint(TestBase):
13 mydir = TestBase.compute_mydir(__file__)
14 NO_DEBUG_INFO_TESTCASE = True
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"])
27 """Test stepping over watchpoints."""
29 exe = self.getBuildArtifact("a.out")
31 target = self.dbg.CreateTarget(exe)
32 self.assertTrue(self.target, VALID_TARGET)
34 lldbutil.run_break_set_by_symbol(self, 'main')
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,
42 thread = lldbutil.get_stopped_thread(process,
43 lldb.eStopReasonBreakpoint)
44 self.assertTrue(thread.IsValid(), "Failed to get thread.")
46 frame = thread.GetFrameAtIndex(0)
47 self.assertTrue(frame.IsValid(), "Failed to get frame.")
49 read_value = frame.FindValue('g_watch_me_read',
50 lldb.eValueTypeVariableGlobal)
51 self.assertTrue(read_value.IsValid(), "Failed to find read value.")
53 error = lldb.SBError()
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" %
60 self.assertTrue(read_watchpoint, "Failed to set read watchpoint.")
63 self.assertTrue(thread.GetStopReason() == lldb.eStopReasonWatchpoint,
64 STOPPED_DUE_TO_WATCHPOINT)
65 self.assertTrue(thread.GetStopDescription(20) == 'watchpoint 1')
68 self.assertTrue(process.GetState() == lldb.eStateStopped,
70 self.assertTrue(thread.GetStopDescription(20) == 'step over')
72 self.step_inst_for_watchpoint(1)
74 write_value = frame.FindValue('g_watch_me_write',
75 lldb.eValueTypeVariableGlobal)
76 self.assertTrue(write_value, "Failed to find write value.")
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")
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" %
92 self.assertTrue(thread.GetStopReason() == lldb.eStopReasonWatchpoint,
93 STOPPED_DUE_TO_WATCHPOINT)
94 self.assertTrue(thread.GetStopDescription(20) == 'watchpoint 2')
97 self.assertTrue(process.GetState() == lldb.eStateStopped,
99 self.assertTrue(thread.GetStopDescription(20) == 'step over')
101 self.step_inst_for_watchpoint(2)
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
117 self.assertTrue(stop_reason == lldb.eStopReasonPlanComplete,
118 STOPPED_DUE_TO_STEP_IN)
119 self.assertTrue(watchpoint_hit, "Watchpoint never hit.")