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