blob: a7ebb0a33c53300c06afe8b159e30eae734477db [file] [log] [blame]
Johnny Chenc3fba812011-07-18 20:13:38 +00001//===-- SWIG Interface for SBProcess ----------------------------*- 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
12%feature("docstring",
13"Represents the process associated with the target program.
14
15SBProcess supports thread iteration. For example (from test/lldbutil.py),
16
17# ==================================================
18# Utility functions related to Threads and Processes
19# ==================================================
20
21def get_stopped_threads(process, reason):
22 '''Returns the thread(s) with the specified stop reason in a list.
23
24 The list can be empty if no such thread exists.
25 '''
26 threads = []
27 for t in process:
28 if t.GetStopReason() == reason:
29 threads.append(t)
30 return threads
31
32...
33"
34) SBProcess;
35class SBProcess
36{
37public:
38 //------------------------------------------------------------------
39 /// Broadcaster event bits definitions.
40 //------------------------------------------------------------------
41 enum
42 {
43 eBroadcastBitStateChanged = (1 << 0),
44 eBroadcastBitInterrupt = (1 << 1),
45 eBroadcastBitSTDOUT = (1 << 2),
Han Ming Ongfb9cee62012-11-17 00:21:04 +000046 eBroadcastBitSTDERR = (1 << 3),
47 eBroadcastBitProfileData = (1 << 4)
Johnny Chenc3fba812011-07-18 20:13:38 +000048 };
49
50 SBProcess ();
51
52 SBProcess (const lldb::SBProcess& rhs);
53
54 ~SBProcess();
55
Jim Ingham5a15e692012-02-16 06:50:00 +000056 static const char *
57 GetBroadcasterClassName ();
58
Jim Inghamfee26ee2012-10-26 19:18:04 +000059 const char *
60 GetPluginName ();
61
62 const char *
63 GetShortPluginName ();
64
Johnny Chenc3fba812011-07-18 20:13:38 +000065 void
66 Clear ();
67
68 bool
69 IsValid() const;
70
71 lldb::SBTarget
72 GetTarget() const;
73
74 lldb::ByteOrder
75 GetByteOrder() const;
76
Johnny Chen23038b62011-11-28 21:39:07 +000077 %feature("autodoc", "
78 Writes data into the current process's stdin. API client specifies a Python
79 string as the only argument.
80 ") PutSTDIN;
Johnny Chenc3fba812011-07-18 20:13:38 +000081 size_t
82 PutSTDIN (const char *src, size_t src_len);
83
Johnny Chen609b9ce2011-11-28 19:12:25 +000084 %feature("autodoc", "
85 Reads data from the current process's stdout stream. API client specifies
86 the size of the buffer to read data into. It returns the byte buffer in a
87 Python string.
88 ") GetSTDOUT;
Johnny Chenc3fba812011-07-18 20:13:38 +000089 size_t
90 GetSTDOUT (char *dst, size_t dst_len) const;
91
Johnny Chen609b9ce2011-11-28 19:12:25 +000092 %feature("autodoc", "
93 Reads data from the current process's stderr stream. API client specifies
94 the size of the buffer to read data into. It returns the byte buffer in a
95 Python string.
96 ") GetSTDERR;
Johnny Chenc3fba812011-07-18 20:13:38 +000097 size_t
98 GetSTDERR (char *dst, size_t dst_len) const;
99
Han Ming Ongfb9cee62012-11-17 00:21:04 +0000100 size_t
101 GetAsyncProfileData(char *dst, size_t dst_len) const;
102
Johnny Chenc3fba812011-07-18 20:13:38 +0000103 void
104 ReportEventState (const lldb::SBEvent &event, FILE *out) const;
105
106 void
107 AppendEventStateReport (const lldb::SBEvent &event, lldb::SBCommandReturnObject &result);
108
109 %feature("docstring", "
110 //------------------------------------------------------------------
111 /// Remote connection related functions. These will fail if the
112 /// process is not in eStateConnected. They are intended for use
113 /// when connecting to an externally managed debugserver instance.
114 //------------------------------------------------------------------
115 ") RemoteAttachToProcessWithID;
116 bool
117 RemoteAttachToProcessWithID (lldb::pid_t pid,
118 lldb::SBError& error);
119
120 %feature("docstring",
121 "See SBTarget.Launch for argument description and usage."
122 ) RemoteLaunch;
123 bool
124 RemoteLaunch (char const **argv,
125 char const **envp,
126 const char *stdin_path,
127 const char *stdout_path,
128 const char *stderr_path,
129 const char *working_directory,
130 uint32_t launch_flags,
131 bool stop_at_entry,
132 lldb::SBError& error);
133
134 //------------------------------------------------------------------
135 // Thread related functions
136 //------------------------------------------------------------------
137 uint32_t
138 GetNumThreads ();
139
Jim Inghamefbdd222012-07-13 20:18:18 +0000140 %feature("autodoc", "
141 Returns the INDEX'th thread from the list of current threads. The index
142 of a thread is only valid for the current stop. For a persistent thread
143 identifier use either the thread ID or the IndexID. See help on SBThread
144 for more details.
145 ") GetThreadAtIndex;
Johnny Chenc3fba812011-07-18 20:13:38 +0000146 lldb::SBThread
147 GetThreadAtIndex (size_t index);
148
Jim Inghamefbdd222012-07-13 20:18:18 +0000149 %feature("autodoc", "
150 Returns the thread with the given thread ID.
151 ") GetThreadByID;
Johnny Chenc3fba812011-07-18 20:13:38 +0000152 lldb::SBThread
153 GetThreadByID (lldb::tid_t sb_thread_id);
Jim Inghamefbdd222012-07-13 20:18:18 +0000154
155 %feature("autodoc", "
156 Returns the thread with the given thread IndexID.
157 ") GetThreadByIndexID;
158 lldb::SBThread
159 GetThreadByIndexID (uint32_t index_id);
Johnny Chenc3fba812011-07-18 20:13:38 +0000160
Jim Inghamefbdd222012-07-13 20:18:18 +0000161 %feature("autodoc", "
162 Returns the currently selected thread.
163 ") GetSelectedThread;
Johnny Chenc3fba812011-07-18 20:13:38 +0000164 lldb::SBThread
165 GetSelectedThread () const;
166
167 bool
168 SetSelectedThread (const lldb::SBThread &thread);
169
170 bool
Greg Clayton82560f22012-10-12 23:32:11 +0000171 SetSelectedThreadByID (lldb::tid_t tid);
Johnny Chenc3fba812011-07-18 20:13:38 +0000172
Jim Inghamefbdd222012-07-13 20:18:18 +0000173 bool
174 SetSelectedThreadByIndexID (uint32_t index_id);
175
Johnny Chenc3fba812011-07-18 20:13:38 +0000176 //------------------------------------------------------------------
177 // Stepping related functions
178 //------------------------------------------------------------------
179
180 lldb::StateType
181 GetState ();
182
183 int
184 GetExitStatus ();
185
186 const char *
187 GetExitDescription ();
188
189 lldb::pid_t
190 GetProcessID ();
191
192 uint32_t
193 GetAddressByteSize() const;
194
195 %feature("docstring", "
196 Kills the process and shuts down all threads that were spawned to
197 track and monitor process.
198 ") Destroy;
199 lldb::SBError
200 Destroy ();
201
202 lldb::SBError
203 Continue ();
204
205 lldb::SBError
206 Stop ();
207
208 %feature("docstring", "Same as Destroy(self).") Destroy;
209 lldb::SBError
210 Kill ();
211
212 lldb::SBError
213 Detach ();
214
215 %feature("docstring", "Sends the process a unix signal.") Signal;
216 lldb::SBError
217 Signal (int signal);
218
Jim Ingham0e3b98e2013-01-08 23:22:42 +0000219 %feature("docstring", "
220 Returns a stop id that will increase every time the process executes. If
221 include_expression_stops is true, then stops caused by expression evaluation
222 will cause the returned value to increase, otherwise the counter returned will
223 only increase when execution is continued explicitly by the user. Note, the value
224 will always increase, but may increase by more than one per stop.
225 ") GetStopID;
226 uint32_t
227 GetStopID(bool include_expression_stops = false);
228
Jim Ingham5d90ade2012-07-27 23:57:19 +0000229 void
230 SendAsyncInterrupt();
231
Johnny Chenc3fba812011-07-18 20:13:38 +0000232 %feature("autodoc", "
233 Reads memory from the current process's address space and removes any
234 traps that may have been inserted into the memory. It returns the byte
235 buffer in a Python string. Example:
236
237 # Read 4 bytes from address 'addr' and assume error.Success() is True.
238 content = process.ReadMemory(addr, 4, error)
239 # Use 'ascii' encoding as each byte of 'content' is within [0..255].
240 new_bytes = bytearray(content, 'ascii')
241 ") ReadMemory;
242 size_t
243 ReadMemory (addr_t addr, void *buf, size_t size, lldb::SBError &error);
244
245 %feature("autodoc", "
246 Writes memory to the current process's address space and maintains any
247 traps that might be present due to software breakpoints. Example:
248
249 # Create a Python string from the byte array.
250 new_value = str(bytes)
251 result = process.WriteMemory(addr, new_value, error)
252 if not error.Success() or result != len(bytes):
253 print 'SBProcess.WriteMemory() failed!'
254 ") WriteMemory;
255 size_t
256 WriteMemory (addr_t addr, const void *buf, size_t size, lldb::SBError &error);
257
Greg Clayton4a2e3372011-12-15 03:14:23 +0000258 %feature("autodoc", "
259 Reads a NULL terminated C string from the current process's address space.
260 It returns a python string of the exact length, or truncates the string if
261 the maximum character limit is reached. Example:
262
263 # Read a C string of at most 256 bytes from address '0x1000'
264 error = lldb.SBError()
Johnny Chen08413862011-12-15 22:34:59 +0000265 cstring = process.ReadCStringFromMemory(0x1000, 256, error)
Greg Clayton4a2e3372011-12-15 03:14:23 +0000266 if error.Success():
267 print 'cstring: ', cstring
268 else
269 print 'error: ', error
270 ") ReadCStringFromMemory;
271
272 size_t
273 ReadCStringFromMemory (addr_t addr, void *buf, size_t size, lldb::SBError &error);
274
275 %feature("autodoc", "
276 Reads an unsigned integer from memory given a byte size and an address.
277 Returns the unsigned integer that was read. Example:
278
279 # Read a 4 byte unsigned integer from address 0x1000
280 error = lldb.SBError()
281 uint = ReadUnsignedFromMemory(0x1000, 4, error)
282 if error.Success():
283 print 'integer: %u' % uint
284 else
285 print 'error: ', error
286
287 ") ReadUnsignedFromMemory;
288
289 uint64_t
290 ReadUnsignedFromMemory (addr_t addr, uint32_t byte_size, lldb::SBError &error);
291
292 %feature("autodoc", "
293 Reads a pointer from memory from an address and returns the value. Example:
294
295 # Read a pointer from address 0x1000
296 error = lldb.SBError()
297 ptr = ReadPointerFromMemory(0x1000, error)
298 if error.Success():
299 print 'pointer: 0x%x' % ptr
300 else
301 print 'error: ', error
302
303 ") ReadPointerFromMemory;
304
305 lldb::addr_t
306 ReadPointerFromMemory (addr_t addr, lldb::SBError &error);
307
308
Johnny Chenc3fba812011-07-18 20:13:38 +0000309 // Events
310 static lldb::StateType
311 GetStateFromEvent (const lldb::SBEvent &event);
312
313 static bool
314 GetRestartedFromEvent (const lldb::SBEvent &event);
315
316 static lldb::SBProcess
317 GetProcessFromEvent (const lldb::SBEvent &event);
318
Jim Ingham28e23862012-02-08 05:23:15 +0000319 static bool
320 EventIsProcessEvent (const lldb::SBEvent &event);
321
Johnny Chenc3fba812011-07-18 20:13:38 +0000322 lldb::SBBroadcaster
323 GetBroadcaster () const;
324
325 bool
326 GetDescription (lldb::SBStream &description);
327
328 uint32_t
Johnny Chen191343e2012-05-23 22:34:34 +0000329 GetNumSupportedHardwareWatchpoints (lldb::SBError &error) const;
330
331 uint32_t
Johnny Chenc3fba812011-07-18 20:13:38 +0000332 LoadImage (lldb::SBFileSpec &image_spec, lldb::SBError &error);
333
334 lldb::SBError
335 UnloadImage (uint32_t image_token);
Johnny Chen9f074f02012-01-06 00:46:12 +0000336
Greg Clayton1b925202012-01-29 06:07:39 +0000337 %pythoncode %{
Greg Claytonb302dff2012-02-01 08:09:32 +0000338 def __get_is_alive__(self):
339 '''Returns "True" if the process is currently alive, "False" otherwise'''
340 s = self.GetState()
341 if (s == eStateAttaching or
342 s == eStateLaunching or
343 s == eStateStopped or
344 s == eStateRunning or
345 s == eStateStepping or
346 s == eStateCrashed or
347 s == eStateSuspended):
348 return True
349 return False
350
351 def __get_is_running__(self):
352 '''Returns "True" if the process is currently running, "False" otherwise'''
353 state = self.GetState()
354 if state == eStateRunning or state == eStateStepping:
355 return True
356 return False
357
358 def __get_is_running__(self):
359 '''Returns "True" if the process is currently stopped, "False" otherwise'''
360 state = self.GetState()
361 if state == eStateStopped or state == eStateCrashed or state == eStateSuspended:
362 return True
363 return False
364
Greg Claytonb6a5ba62012-02-03 03:22:53 +0000365 class threads_access(object):
Greg Claytonb302dff2012-02-01 08:09:32 +0000366 '''A helper object that will lazily hand out thread for a process when supplied an index.'''
367 def __init__(self, sbprocess):
368 self.sbprocess = sbprocess
369
370 def __len__(self):
Filipe Cabecinhas3cae38b2012-05-11 20:39:42 +0000371 if self.sbprocess:
372 return int(self.sbprocess.GetNumThreads())
Greg Claytonb302dff2012-02-01 08:09:32 +0000373 return 0
374
375 def __getitem__(self, key):
376 if type(key) is int and key < len(self):
377 return self.sbprocess.GetThreadAtIndex(key)
378 return None
379
Greg Claytonb6a5ba62012-02-03 03:22:53 +0000380 def get_threads_access_object(self):
381 '''An accessor function that returns a modules_access() object which allows lazy thread access from a lldb.SBProcess object.'''
382 return self.threads_access (self)
Greg Claytonb302dff2012-02-01 08:09:32 +0000383
384 def get_process_thread_list(self):
Greg Claytonb6a5ba62012-02-03 03:22:53 +0000385 '''An accessor function that returns a list() that contains all threads in a lldb.SBProcess object.'''
Greg Claytonb302dff2012-02-01 08:09:32 +0000386 threads = []
Enrico Granata2cb02032012-10-08 19:06:11 +0000387 accessor = self.get_threads_access_object()
388 for idx in range(len(accessor)):
389 threads.append(accessor[idx])
Greg Claytonb302dff2012-02-01 08:09:32 +0000390 return threads
391
392 __swig_getmethods__["threads"] = get_process_thread_list
Greg Clayton2a94be12012-06-29 22:00:42 +0000393 if _newclass: threads = property(get_process_thread_list, None, doc='''A read only property that returns a list() of lldb.SBThread objects for this process.''')
Greg Claytonb302dff2012-02-01 08:09:32 +0000394
Greg Claytonb6a5ba62012-02-03 03:22:53 +0000395 __swig_getmethods__["thread"] = get_threads_access_object
Greg Clayton2a94be12012-06-29 22:00:42 +0000396 if _newclass: thread = property(get_threads_access_object, None, doc='''A read only property that returns an object that can access threads by thread index (thread = lldb.process.thread[12]).''')
Greg Claytonb302dff2012-02-01 08:09:32 +0000397
398 __swig_getmethods__["is_alive"] = __get_is_alive__
Greg Clayton2a94be12012-06-29 22:00:42 +0000399 if _newclass: is_alive = property(__get_is_alive__, None, doc='''A read only property that returns a boolean value that indicates if this process is currently alive.''')
Greg Claytonb302dff2012-02-01 08:09:32 +0000400
401 __swig_getmethods__["is_running"] = __get_is_running__
Greg Clayton2a94be12012-06-29 22:00:42 +0000402 if _newclass: is_running = property(__get_is_running__, None, doc='''A read only property that returns a boolean value that indicates if this process is currently running.''')
Greg Claytonb302dff2012-02-01 08:09:32 +0000403
404 __swig_getmethods__["is_stopped"] = __get_is_running__
Greg Clayton2a94be12012-06-29 22:00:42 +0000405 if _newclass: is_stopped = property(__get_is_running__, None, doc='''A read only property that returns a boolean value that indicates if this process is currently stopped.''')
Greg Claytonb302dff2012-02-01 08:09:32 +0000406
Greg Clayton1b925202012-01-29 06:07:39 +0000407 __swig_getmethods__["id"] = GetProcessID
Greg Clayton2a94be12012-06-29 22:00:42 +0000408 if _newclass: id = property(GetProcessID, None, doc='''A read only property that returns the process ID as an integer.''')
Greg Clayton1b925202012-01-29 06:07:39 +0000409
410 __swig_getmethods__["target"] = GetTarget
Greg Clayton2a94be12012-06-29 22:00:42 +0000411 if _newclass: target = property(GetTarget, None, doc='''A read only property that an lldb object that represents the target (lldb.SBTarget) that owns this process.''')
Greg Clayton1b925202012-01-29 06:07:39 +0000412
413 __swig_getmethods__["num_threads"] = GetNumThreads
Greg Clayton2a94be12012-06-29 22:00:42 +0000414 if _newclass: num_threads = property(GetNumThreads, None, doc='''A read only property that returns the number of threads in this process as an integer.''')
Greg Clayton1b925202012-01-29 06:07:39 +0000415
416 __swig_getmethods__["selected_thread"] = GetSelectedThread
417 __swig_setmethods__["selected_thread"] = SetSelectedThread
Greg Clayton2a94be12012-06-29 22:00:42 +0000418 if _newclass: selected_thread = property(GetSelectedThread, SetSelectedThread, doc='''A read/write property that gets/sets the currently selected thread in this process. The getter returns a lldb.SBThread object and the setter takes an lldb.SBThread object.''')
Greg Clayton1b925202012-01-29 06:07:39 +0000419
420 __swig_getmethods__["state"] = GetState
Greg Clayton2a94be12012-06-29 22:00:42 +0000421 if _newclass: state = property(GetState, None, doc='''A read only property that returns an lldb enumeration value (see enumerations that start with "lldb.eState") that represents the current state of this process (running, stopped, exited, etc.).''')
Greg Clayton1b925202012-01-29 06:07:39 +0000422
423 __swig_getmethods__["exit_state"] = GetExitStatus
Greg Clayton2a94be12012-06-29 22:00:42 +0000424 if _newclass: exit_state = property(GetExitStatus, None, doc='''A read only property that returns an exit status as an integer of this process when the process state is lldb.eStateExited.''')
Greg Clayton1b925202012-01-29 06:07:39 +0000425
426 __swig_getmethods__["exit_description"] = GetExitDescription
Greg Clayton2a94be12012-06-29 22:00:42 +0000427 if _newclass: exit_description = property(GetExitDescription, None, doc='''A read only property that returns an exit description as a string of this process when the process state is lldb.eStateExited.''')
Greg Clayton1b925202012-01-29 06:07:39 +0000428
429 __swig_getmethods__["broadcaster"] = GetBroadcaster
Greg Clayton2a94be12012-06-29 22:00:42 +0000430 if _newclass: broadcaster = property(GetBroadcaster, None, doc='''A read only property that an lldb object that represents the broadcaster (lldb.SBBroadcaster) for this process.''')
Greg Clayton1b925202012-01-29 06:07:39 +0000431 %}
432
Johnny Chenc3fba812011-07-18 20:13:38 +0000433};
434
435} // namespace lldb