]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_events/TestWatchpointEvents.py
Vendor import of lldb trunk r256945:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / functionalities / watchpoint / watchpoint_events / TestWatchpointEvents.py
1 """Test that adding, deleting and modifying watchpoints sends the appropriate events."""
2
3 from __future__ import print_function
4
5
6
7 import os, time
8 import lldb
9 import lldbsuite.test.lldbutil as lldbutil
10 from lldbsuite.test.lldbtest import *
11
12 class TestWatchpointEvents (TestBase):
13
14     mydir = TestBase.compute_mydir(__file__)
15
16     def setUp(self):
17         # Call super's setUp().
18         TestBase.setUp(self)
19         # Find the line numbers that we will step to in main:
20         self.main_source = "main.c"
21
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."""
27         self.build()
28         
29         exe = os.path.join(os.getcwd(), "a.out")
30
31         target = self.dbg.CreateTarget(exe)
32         self.assertTrue(target, VALID_TARGET)
33
34         self.main_source_spec = lldb.SBFileSpec (self.main_source)
35
36         break_in_main = target.BreakpointCreateBySourceRegex ('// Put a breakpoint here.', self.main_source_spec)
37         self.assertTrue(break_in_main, VALID_BREAKPOINT)
38
39         # Now launch the process, and do not stop at entry point.
40         process = target.LaunchSimple (None, None, self.get_process_working_directory())
41
42         self.assertTrue(process, PROCESS_IS_VALID)
43
44         # The stop reason of the thread should be breakpoint.
45         threads = lldbutil.get_threads_stopped_at_breakpoint (process, break_in_main)
46
47         if len(threads) != 1:
48             self.fail ("Failed to stop at first breakpoint in main.")
49
50         thread = threads[0]
51         frame = thread.GetFrameAtIndex(0)
52         local_var = frame.FindVariable ("local_var")
53         self.assertTrue (local_var.IsValid())
54
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)
59
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()))
64
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)
69
70         local_watch.SetIgnoreCount(10)
71         self.GetWatchpointEvent (lldb.eWatchpointEventTypeIgnoreChanged)
72
73         local_watch.SetCondition ("1 == 2")
74         self.GetWatchpointEvent (lldb.eWatchpointEventTypeConditionChanged)
75
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)
86         if found_event:
87             print("Found an event I didn't expect: ", event)
88
89         self.assertTrue (not found_event, "Only one event per change.")