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