2 "API clients can register to receive events.
4 For example, check out the following output: ::
7 Event description: 0x103d0bb70 Event: broadcaster = 0x1009c8410, type = 0x00000001, data = { process = 0x1009c8400 (pid = 21528), state = running}
8 Event data flavor: Process::ProcessEventData
12 Event description: 0x103a700a0 Event: broadcaster = 0x1009c8410, type = 0x00000001, data = { process = 0x1009c8400 (pid = 21528), state = stopped}
13 Event data flavor: Process::ProcessEventData
14 Process state: stopped
17 Event description: 0x103d0d4a0 Event: broadcaster = 0x1009c8410, type = 0x00000001, data = { process = 0x1009c8400 (pid = 21528), state = exited}
18 Event data flavor: Process::ProcessEventData
22 timeout occurred waiting for event...
24 from test/python_api/event/TestEventspy: ::
26 def do_listen_for_and_print_event(self):
27 '''Create a listener and use SBEvent API to print the events received.'''
28 exe = os.path.join(os.getcwd(), 'a.out')
30 # Create a target by the debugger.
31 target = self.dbg.CreateTarget(exe)
32 self.assertTrue(target, VALID_TARGET)
34 # Now create a breakpoint on main.c by name 'c'.
35 breakpoint = target.BreakpointCreateByName('c', 'a.out')
37 # Now launch the process, and do not stop at the entry point.
38 process = target.LaunchSimple(None, None, os.getcwd())
39 self.assertTrue(process.GetState() == lldb.eStateStopped,
42 # Get a handle on the process's broadcaster.
43 broadcaster = process.GetBroadcaster()
45 # Create an empty event object.
46 event = lldb.SBEvent()
48 # Create a listener object and register with the broadcaster.
49 listener = lldb.SBListener('my listener')
50 rc = broadcaster.AddListener(listener, lldb.SBProcess.eBroadcastBitStateChanged)
51 self.assertTrue(rc, 'AddListener successfully retruns')
53 traceOn = self.TraceOn()
55 lldbutil.print_stacktraces(process)
57 # Create MyListeningThread class to wait for any kind of event.
59 class MyListeningThread(threading.Thread):
62 # Let's only try at most 4 times to retrieve any kind of event.
63 # After that, the thread exits.
66 print('Try wait for event...')
67 if listener.WaitForEventForBroadcasterWithType(5,
69 lldb.SBProcess.eBroadcastBitStateChanged,
72 desc = lldbutil.get_description(event))
73 print('Event description:', desc)
74 print('Event data flavor:', event.GetDataFlavor())
75 print('Process state:', lldbutil.state_type_to_str(process.GetState()))
79 print 'timeout occurred waiting for event...'
83 # Let's start the listening thread to retrieve the events.
84 my_thread = MyListeningThread()
87 # Use Python API to continue the process. The listening thread should be
88 # able to receive the state changed events.
91 # Use Python API to kill the process. The listening thread should be
92 # able to receive the state changed event, too.
95 # Wait until the 'MyListeningThread' terminates.
100 "__init__(self, int type, str data) -> SBEvent (make an event that contains a C string)"
101 ) lldb
::SBEvent
::SBEvent
;