1 """Test stepping over watchpoints."""
3 from __future__ import print_function
7 from lldbsuite.test.decorators import *
8 from lldbsuite.test.lldbtest import *
9 from lldbsuite.test import lldbutil
12 class TestStepOverWatchpoint(TestBase):
14 mydir = TestBase.compute_mydir(__file__)
21 bugnumber="llvm.org/pr26031")
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"])
30 """Test stepping over watchpoints."""
32 exe = self.getBuildArtifact("a.out")
34 target = self.dbg.CreateTarget(exe)
35 self.assertTrue(self.target, VALID_TARGET)
37 lldbutil.run_break_set_by_symbol(self, 'main')
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,
45 thread = lldbutil.get_stopped_thread(process,
46 lldb.eStopReasonBreakpoint)
47 self.assertTrue(thread.IsValid(), "Failed to get thread.")
49 frame = thread.GetFrameAtIndex(0)
50 self.assertTrue(frame.IsValid(), "Failed to get frame.")
52 read_value = frame.FindValue('g_watch_me_read',
53 lldb.eValueTypeVariableGlobal)
54 self.assertTrue(read_value.IsValid(), "Failed to find read value.")
56 error = lldb.SBError()
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" %
63 self.assertTrue(read_watchpoint, "Failed to set read watchpoint.")
66 self.assertTrue(thread.GetStopReason() == lldb.eStopReasonWatchpoint,
67 STOPPED_DUE_TO_WATCHPOINT)
68 self.assertTrue(thread.GetStopDescription(20) == 'watchpoint 1')
71 self.assertTrue(process.GetState() == lldb.eStateStopped,
73 self.assertTrue(thread.GetStopDescription(20) == 'step over')
75 self.step_inst_for_watchpoint(1)
77 write_value = frame.FindValue('g_watch_me_write',
78 lldb.eValueTypeVariableGlobal)
79 self.assertTrue(write_value, "Failed to find write value.")
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")
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" %
95 self.assertTrue(thread.GetStopReason() == lldb.eStopReasonWatchpoint,
96 STOPPED_DUE_TO_WATCHPOINT)
97 self.assertTrue(thread.GetStopDescription(20) == 'watchpoint 2')
100 self.assertTrue(process.GetState() == lldb.eStateStopped,
102 self.assertTrue(thread.GetStopDescription(20) == 'step over')
104 self.step_inst_for_watchpoint(2)
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
120 self.assertTrue(stop_reason == lldb.eStopReasonPlanComplete,
121 STOPPED_DUE_TO_STEP_IN)
122 self.assertTrue(watchpoint_hit, "Watchpoint never hit.")