blob: 66963ea903c97c613bb18a6f2f4164e0d1328d99 [file] [log] [blame]
Johnny Chen6cf1bc32011-07-18 22:11:53 +00001//===-- SWIG Interface for SBEvent ------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10namespace lldb {
11
12class SBBroadcaster;
13
14%feature("docstring",
15"API clients can register to receive events.
16
17For example, check out the following output:
18
19Try wait for event...
20Event description: 0x103d0bb70 Event: broadcaster = 0x1009c8410, type = 0x00000001, data = { process = 0x1009c8400 (pid = 21528), state = running}
21Event data flavor: Process::ProcessEventData
22Process state: running
23
24Try wait for event...
25Event description: 0x103a700a0 Event: broadcaster = 0x1009c8410, type = 0x00000001, data = { process = 0x1009c8400 (pid = 21528), state = stopped}
26Event data flavor: Process::ProcessEventData
27Process state: stopped
28
29Try wait for event...
30Event description: 0x103d0d4a0 Event: broadcaster = 0x1009c8410, type = 0x00000001, data = { process = 0x1009c8400 (pid = 21528), state = exited}
31Event data flavor: Process::ProcessEventData
32Process state: exited
33
34Try wait for event...
35timeout occurred waiting for event...
36
37from test/python_api/event/TestEventspy:
38
39 def do_listen_for_and_print_event(self):
40 '''Create a listener and use SBEvent API to print the events received.'''
41 exe = os.path.join(os.getcwd(), 'a.out')
42
43 # Create a target by the debugger.
44 target = self.dbg.CreateTarget(exe)
45 self.assertTrue(target, VALID_TARGET)
46
47 # Now create a breakpoint on main.c by name 'c'.
48 breakpoint = target.BreakpointCreateByName('c', 'a.out')
49
50 # Now launch the process, and do not stop at the entry point.
51 process = target.LaunchSimple(None, None, os.getcwd())
52 self.assertTrue(process.GetState() == lldb.eStateStopped,
53 PROCESS_STOPPED)
54
55 # Get a handle on the process's broadcaster.
56 broadcaster = process.GetBroadcaster()
57
58 # Create an empty event object.
59 event = lldb.SBEvent()
60
61 # Create a listener object and register with the broadcaster.
62 listener = lldb.SBListener('my listener')
63 rc = broadcaster.AddListener(listener, lldb.SBProcess.eBroadcastBitStateChanged)
64 self.assertTrue(rc, 'AddListener successfully retruns')
65
66 traceOn = self.TraceOn()
67 if traceOn:
68 lldbutil.print_stacktraces(process)
69
70 # Create MyListeningThread class to wait for any kind of event.
71 import threading
72 class MyListeningThread(threading.Thread):
73 def run(self):
74 count = 0
75 # Let's only try at most 4 times to retrieve any kind of event.
76 # After that, the thread exits.
77 while not count > 3:
78 if traceOn:
79 print 'Try wait for event...'
80 if listener.WaitForEventForBroadcasterWithType(5,
81 broadcaster,
82 lldb.SBProcess.eBroadcastBitStateChanged,
83 event):
84 if traceOn:
85 desc = lldbutil.get_description(event)
86 print 'Event description:', desc
87 print 'Event data flavor:', event.GetDataFlavor()
88 print 'Process state:', lldbutil.state_type_to_str(process.GetState())
89 print
90 else:
91 if traceOn:
92 print 'timeout occurred waiting for event...'
93 count = count + 1
94 return
95
96 # Let's start the listening thread to retrieve the events.
97 my_thread = MyListeningThread()
98 my_thread.start()
99
100 # Use Python API to continue the process. The listening thread should be
101 # able to receive the state changed events.
102 process.Continue()
103
104 # Use Python API to kill the process. The listening thread should be
105 # able to receive the state changed event, too.
106 process.Kill()
107
108 # Wait until the 'MyListeningThread' terminates.
109 my_thread.join()
110") SBEvent;
111class SBEvent
112{
113public:
114 SBEvent();
115
116 SBEvent (const lldb::SBEvent &rhs);
117
118 %feature("autodoc",
119 "__init__(self, int type, str data) -> SBEvent (make an event that contains a C string)"
120 ) SBEvent;
121 SBEvent (uint32_t event, const char *cstr, uint32_t cstr_len);
122
123 ~SBEvent();
124
125 bool
126 IsValid() const;
127
128 const char *
129 GetDataFlavor ();
130
131 uint32_t
132 GetType () const;
133
134 lldb::SBBroadcaster
135 GetBroadcaster () const;
136
137 bool
138 BroadcasterMatchesRef (const lldb::SBBroadcaster &broadcaster);
139
140 void
141 Clear();
142
143 static const char *
144 GetCStringFromEvent (const lldb::SBEvent &event);
145
146 bool
147 GetDescription (lldb::SBStream &description) const;
148};
149
150} // namespace lldb