xref: /freebsd/contrib/llvm-project/lldb/bindings/interface/SBEventDocstrings.i (revision 06c3fb2749bda94cb5201f81ffdb8fa6c3161b2e)
1*06c3fb27SDimitry Andric %feature("docstring",
2*06c3fb27SDimitry Andric "API clients can register to receive events.
3*06c3fb27SDimitry Andric 
4*06c3fb27SDimitry Andric For example, check out the following output: ::
5*06c3fb27SDimitry Andric 
6*06c3fb27SDimitry Andric     Try wait for event...
7*06c3fb27SDimitry Andric     Event description: 0x103d0bb70 Event: broadcaster = 0x1009c8410, type = 0x00000001, data = { process = 0x1009c8400 (pid = 21528), state = running}
8*06c3fb27SDimitry Andric     Event data flavor: Process::ProcessEventData
9*06c3fb27SDimitry Andric     Process state: running
10*06c3fb27SDimitry Andric 
11*06c3fb27SDimitry Andric     Try wait for event...
12*06c3fb27SDimitry Andric     Event description: 0x103a700a0 Event: broadcaster = 0x1009c8410, type = 0x00000001, data = { process = 0x1009c8400 (pid = 21528), state = stopped}
13*06c3fb27SDimitry Andric     Event data flavor: Process::ProcessEventData
14*06c3fb27SDimitry Andric     Process state: stopped
15*06c3fb27SDimitry Andric 
16*06c3fb27SDimitry Andric     Try wait for event...
17*06c3fb27SDimitry Andric     Event description: 0x103d0d4a0 Event: broadcaster = 0x1009c8410, type = 0x00000001, data = { process = 0x1009c8400 (pid = 21528), state = exited}
18*06c3fb27SDimitry Andric     Event data flavor: Process::ProcessEventData
19*06c3fb27SDimitry Andric     Process state: exited
20*06c3fb27SDimitry Andric 
21*06c3fb27SDimitry Andric     Try wait for event...
22*06c3fb27SDimitry Andric     timeout occurred waiting for event...
23*06c3fb27SDimitry Andric 
24*06c3fb27SDimitry Andric from test/python_api/event/TestEventspy: ::
25*06c3fb27SDimitry Andric 
26*06c3fb27SDimitry Andric     def do_listen_for_and_print_event(self):
27*06c3fb27SDimitry Andric         '''Create a listener and use SBEvent API to print the events received.'''
28*06c3fb27SDimitry Andric         exe = os.path.join(os.getcwd(), 'a.out')
29*06c3fb27SDimitry Andric 
30*06c3fb27SDimitry Andric         # Create a target by the debugger.
31*06c3fb27SDimitry Andric         target = self.dbg.CreateTarget(exe)
32*06c3fb27SDimitry Andric         self.assertTrue(target, VALID_TARGET)
33*06c3fb27SDimitry Andric 
34*06c3fb27SDimitry Andric         # Now create a breakpoint on main.c by name 'c'.
35*06c3fb27SDimitry Andric         breakpoint = target.BreakpointCreateByName('c', 'a.out')
36*06c3fb27SDimitry Andric 
37*06c3fb27SDimitry Andric         # Now launch the process, and do not stop at the entry point.
38*06c3fb27SDimitry Andric         process = target.LaunchSimple(None, None, os.getcwd())
39*06c3fb27SDimitry Andric         self.assertTrue(process.GetState() == lldb.eStateStopped,
40*06c3fb27SDimitry Andric                         PROCESS_STOPPED)
41*06c3fb27SDimitry Andric 
42*06c3fb27SDimitry Andric         # Get a handle on the process's broadcaster.
43*06c3fb27SDimitry Andric         broadcaster = process.GetBroadcaster()
44*06c3fb27SDimitry Andric 
45*06c3fb27SDimitry Andric         # Create an empty event object.
46*06c3fb27SDimitry Andric         event = lldb.SBEvent()
47*06c3fb27SDimitry Andric 
48*06c3fb27SDimitry Andric         # Create a listener object and register with the broadcaster.
49*06c3fb27SDimitry Andric         listener = lldb.SBListener('my listener')
50*06c3fb27SDimitry Andric         rc = broadcaster.AddListener(listener, lldb.SBProcess.eBroadcastBitStateChanged)
51*06c3fb27SDimitry Andric         self.assertTrue(rc, 'AddListener successfully retruns')
52*06c3fb27SDimitry Andric 
53*06c3fb27SDimitry Andric         traceOn = self.TraceOn()
54*06c3fb27SDimitry Andric         if traceOn:
55*06c3fb27SDimitry Andric             lldbutil.print_stacktraces(process)
56*06c3fb27SDimitry Andric 
57*06c3fb27SDimitry Andric         # Create MyListeningThread class to wait for any kind of event.
58*06c3fb27SDimitry Andric         import threading
59*06c3fb27SDimitry Andric         class MyListeningThread(threading.Thread):
60*06c3fb27SDimitry Andric             def run(self):
61*06c3fb27SDimitry Andric                 count = 0
62*06c3fb27SDimitry Andric                 # Let's only try at most 4 times to retrieve any kind of event.
63*06c3fb27SDimitry Andric                 # After that, the thread exits.
64*06c3fb27SDimitry Andric                 while not count > 3:
65*06c3fb27SDimitry Andric                     if traceOn:
66*06c3fb27SDimitry Andric                         print('Try wait for event...')
67*06c3fb27SDimitry Andric                     if listener.WaitForEventForBroadcasterWithType(5,
68*06c3fb27SDimitry Andric                                                                    broadcaster,
69*06c3fb27SDimitry Andric                                                                    lldb.SBProcess.eBroadcastBitStateChanged,
70*06c3fb27SDimitry Andric                                                                    event):
71*06c3fb27SDimitry Andric                         if traceOn:
72*06c3fb27SDimitry Andric                             desc = lldbutil.get_description(event))
73*06c3fb27SDimitry Andric                             print('Event description:', desc)
74*06c3fb27SDimitry Andric                             print('Event data flavor:', event.GetDataFlavor())
75*06c3fb27SDimitry Andric                             print('Process state:', lldbutil.state_type_to_str(process.GetState()))
76*06c3fb27SDimitry Andric                             print()
77*06c3fb27SDimitry Andric                     else:
78*06c3fb27SDimitry Andric                         if traceOn:
79*06c3fb27SDimitry Andric                             print 'timeout occurred waiting for event...'
80*06c3fb27SDimitry Andric                     count = count + 1
81*06c3fb27SDimitry Andric                 return
82*06c3fb27SDimitry Andric 
83*06c3fb27SDimitry Andric         # Let's start the listening thread to retrieve the events.
84*06c3fb27SDimitry Andric         my_thread = MyListeningThread()
85*06c3fb27SDimitry Andric         my_thread.start()
86*06c3fb27SDimitry Andric 
87*06c3fb27SDimitry Andric         # Use Python API to continue the process.  The listening thread should be
88*06c3fb27SDimitry Andric         # able to receive the state changed events.
89*06c3fb27SDimitry Andric         process.Continue()
90*06c3fb27SDimitry Andric 
91*06c3fb27SDimitry Andric         # Use Python API to kill the process.  The listening thread should be
92*06c3fb27SDimitry Andric         # able to receive the state changed event, too.
93*06c3fb27SDimitry Andric         process.Kill()
94*06c3fb27SDimitry Andric 
95*06c3fb27SDimitry Andric         # Wait until the 'MyListeningThread' terminates.
96*06c3fb27SDimitry Andric         my_thread.join()"
97*06c3fb27SDimitry Andric ) lldb::SBEvent;
98*06c3fb27SDimitry Andric 
99*06c3fb27SDimitry Andric %feature("autodoc",
100*06c3fb27SDimitry Andric "__init__(self, int type, str data) -> SBEvent (make an event that contains a C string)"
101*06c3fb27SDimitry Andric ) lldb::SBEvent::SBEvent;
102