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