1 """Test that adding, deleting and modifying watchpoints sends the appropriate events."""
3 from __future__ import print_function
9 import lldbsuite.test.lldbutil as lldbutil
10 from lldbsuite.test.lldbtest import *
12 class TestWatchpointEvents (TestBase):
14 mydir = TestBase.compute_mydir(__file__)
17 # Call super's setUp().
19 # Find the line numbers that we will step to in main:
20 self.main_source = "main.c"
22 @add_test_categories(['pyapi'])
23 @expectedFailureAndroid(archs=['arm', 'aarch64']) # Watchpoints not supported
24 @expectedFailureWindows("llvm.org/pr24446") # WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows
25 def test_with_python_api(self):
26 """Test that adding, deleting and modifying watchpoints sends the appropriate events."""
29 exe = os.path.join(os.getcwd(), "a.out")
31 target = self.dbg.CreateTarget(exe)
32 self.assertTrue(target, VALID_TARGET)
34 self.main_source_spec = lldb.SBFileSpec (self.main_source)
36 break_in_main = target.BreakpointCreateBySourceRegex ('// Put a breakpoint here.', self.main_source_spec)
37 self.assertTrue(break_in_main, VALID_BREAKPOINT)
39 # Now launch the process, and do not stop at entry point.
40 process = target.LaunchSimple (None, None, self.get_process_working_directory())
42 self.assertTrue(process, PROCESS_IS_VALID)
44 # The stop reason of the thread should be breakpoint.
45 threads = lldbutil.get_threads_stopped_at_breakpoint (process, break_in_main)
48 self.fail ("Failed to stop at first breakpoint in main.")
51 frame = thread.GetFrameAtIndex(0)
52 local_var = frame.FindVariable ("local_var")
53 self.assertTrue (local_var.IsValid())
55 self.listener = lldb.SBListener("com.lldb.testsuite_listener")
56 self.target_bcast = target.GetBroadcaster()
57 self.target_bcast.AddListener (self.listener, lldb.SBTarget.eBroadcastBitWatchpointChanged)
58 self.listener.StartListeningForEvents (self.target_bcast, lldb.SBTarget.eBroadcastBitWatchpointChanged)
60 error = lldb.SBError()
61 local_watch = local_var.Watch(True, True, True, error)
62 if not error.Success():
63 self.fail ("Failed to make watchpoint for local_var: %s"%(error.GetCString()))
65 self.GetWatchpointEvent (lldb.eWatchpointEventTypeAdded)
66 # Now change some of the features of this watchpoint and make sure we get events:
67 local_watch.SetEnabled(False)
68 self.GetWatchpointEvent (lldb.eWatchpointEventTypeDisabled)
70 local_watch.SetIgnoreCount(10)
71 self.GetWatchpointEvent (lldb.eWatchpointEventTypeIgnoreChanged)
73 local_watch.SetCondition ("1 == 2")
74 self.GetWatchpointEvent (lldb.eWatchpointEventTypeConditionChanged)
76 def GetWatchpointEvent (self, event_type):
77 # We added a watchpoint so we should get a watchpoint added event.
78 event = lldb.SBEvent()
79 success = self.listener.WaitForEvent (1, event)
80 self.assertTrue(success == True, "Successfully got watchpoint event")
81 self.assertTrue (lldb.SBWatchpoint.EventIsWatchpointEvent(event), "Event is a watchpoint event.")
82 found_type = lldb.SBWatchpoint.GetWatchpointEventTypeFromEvent (event)
83 self.assertTrue (found_type == event_type, "Event is not correct type, expected: %d, found: %d"%(event_type, found_type))
84 # There shouldn't be another event waiting around:
85 found_event = self.listener.PeekAtNextEventForBroadcasterWithType (self.target_bcast, lldb.SBTarget.eBroadcastBitBreakpointChanged, event)
87 print("Found an event I didn't expect: ", event)
89 self.assertTrue (not found_event, "Only one event per change.")