blob: d023b2472ccc977a1dfdb348eff39e9406b55ddf [file] [log] [blame]
Johnny Chen357033b2011-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 Ongab3b8b22012-11-17 00:21:04 +000046 eBroadcastBitSTDERR = (1 << 3),
47 eBroadcastBitProfileData = (1 << 4)
Johnny Chen357033b2011-07-18 20:13:38 +000048 };
49
50 SBProcess ();
51
52 SBProcess (const lldb::SBProcess& rhs);
53
54 ~SBProcess();
55
Jim Ingham4bddaeb2012-02-16 06:50:00 +000056 static const char *
57 GetBroadcasterClassName ();
58
Jim Inghamd7b30ef2012-10-26 19:18:04 +000059 const char *
60 GetPluginName ();
61
62 const char *
63 GetShortPluginName ();
64
Johnny Chen357033b2011-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 Chen49cb85d2011-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 Chen357033b2011-07-18 20:13:38 +000081 size_t
82 PutSTDIN (const char *src, size_t src_len);
83
Johnny Chend80e5e92011-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 Chen357033b2011-07-18 20:13:38 +000089 size_t
90 GetSTDOUT (char *dst, size_t dst_len) const;
91
Johnny Chend80e5e92011-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 Chen357033b2011-07-18 20:13:38 +000097 size_t
98 GetSTDERR (char *dst, size_t dst_len) const;
99
Han Ming Ongab3b8b22012-11-17 00:21:04 +0000100 size_t
101 GetAsyncProfileData(char *dst, size_t dst_len) const;
102
Johnny Chen357033b2011-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 Ingham18b46892012-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 Chen357033b2011-07-18 20:13:38 +0000146 lldb::SBThread
147 GetThreadAtIndex (size_t index);
148
Jim Ingham18b46892012-07-13 20:18:18 +0000149 %feature("autodoc", "
150 Returns the thread with the given thread ID.
151 ") GetThreadByID;
Johnny Chen357033b2011-07-18 20:13:38 +0000152 lldb::SBThread
153 GetThreadByID (lldb::tid_t sb_thread_id);
Jim Ingham18b46892012-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 Chen357033b2011-07-18 20:13:38 +0000160
Jim Ingham18b46892012-07-13 20:18:18 +0000161 %feature("autodoc", "
162 Returns the currently selected thread.
163 ") GetSelectedThread;
Johnny Chen357033b2011-07-18 20:13:38 +0000164 lldb::SBThread
165 GetSelectedThread () const;
166
Greg Claytona4d87472013-01-18 23:41:08 +0000167 %feature("autodoc", "
168 Lazily create a thread on demand through the current OperatingSystem plug-in, if the current OperatingSystem plug-in supports it.
169 ") CreateOSPluginThread;
170 lldb::SBThread
171 CreateOSPluginThread (lldb::tid_t tid, lldb::addr_t context);
172
Johnny Chen357033b2011-07-18 20:13:38 +0000173 bool
174 SetSelectedThread (const lldb::SBThread &thread);
175
176 bool
Greg Claytonea561dc2012-10-12 23:32:11 +0000177 SetSelectedThreadByID (lldb::tid_t tid);
Johnny Chen357033b2011-07-18 20:13:38 +0000178
Jim Ingham18b46892012-07-13 20:18:18 +0000179 bool
180 SetSelectedThreadByIndexID (uint32_t index_id);
181
Johnny Chen357033b2011-07-18 20:13:38 +0000182 //------------------------------------------------------------------
Jason Molenda5e8dce42013-12-13 00:29:16 +0000183 // Queue related functions
184 //------------------------------------------------------------------
185 uint32_t
186 GetNumQueues ();
187
188 lldb::SBQueue
189 GetQueueAtIndex (uint32_t index);
190
191 //------------------------------------------------------------------
Johnny Chen357033b2011-07-18 20:13:38 +0000192 // Stepping related functions
193 //------------------------------------------------------------------
194
195 lldb::StateType
196 GetState ();
197
198 int
199 GetExitStatus ();
200
201 const char *
202 GetExitDescription ();
203
Greg Clayton949e8222013-01-16 17:29:04 +0000204 %feature("autodoc", "
205 Returns the process ID of the process.
206 ") GetProcessID;
Johnny Chen357033b2011-07-18 20:13:38 +0000207 lldb::pid_t
208 GetProcessID ();
Greg Clayton949e8222013-01-16 17:29:04 +0000209
210 %feature("autodoc", "
211 Returns an integer ID that is guaranteed to be unique across all process instances. This is not the process ID, just a unique integer for comparison and caching purposes.
212 ") GetUniqueID;
213 uint32_t
214 GetUniqueID();
Johnny Chen357033b2011-07-18 20:13:38 +0000215
216 uint32_t
217 GetAddressByteSize() const;
218
219 %feature("docstring", "
220 Kills the process and shuts down all threads that were spawned to
221 track and monitor process.
222 ") Destroy;
223 lldb::SBError
224 Destroy ();
225
226 lldb::SBError
227 Continue ();
228
229 lldb::SBError
230 Stop ();
231
232 %feature("docstring", "Same as Destroy(self).") Destroy;
233 lldb::SBError
234 Kill ();
235
236 lldb::SBError
237 Detach ();
238
239 %feature("docstring", "Sends the process a unix signal.") Signal;
240 lldb::SBError
241 Signal (int signal);
242
Jim Inghambf2956a22013-01-08 23:22:42 +0000243 %feature("docstring", "
244 Returns a stop id that will increase every time the process executes. If
245 include_expression_stops is true, then stops caused by expression evaluation
246 will cause the returned value to increase, otherwise the counter returned will
247 only increase when execution is continued explicitly by the user. Note, the value
248 will always increase, but may increase by more than one per stop.
249 ") GetStopID;
250 uint32_t
251 GetStopID(bool include_expression_stops = false);
252
Jim Inghamcfc09352012-07-27 23:57:19 +0000253 void
254 SendAsyncInterrupt();
255
Johnny Chen357033b2011-07-18 20:13:38 +0000256 %feature("autodoc", "
257 Reads memory from the current process's address space and removes any
258 traps that may have been inserted into the memory. It returns the byte
259 buffer in a Python string. Example:
260
261 # Read 4 bytes from address 'addr' and assume error.Success() is True.
262 content = process.ReadMemory(addr, 4, error)
Jason Molendac7e828e2013-08-24 00:16:19 +0000263 new_bytes = bytearray(content)
Johnny Chen357033b2011-07-18 20:13:38 +0000264 ") ReadMemory;
265 size_t
266 ReadMemory (addr_t addr, void *buf, size_t size, lldb::SBError &error);
267
268 %feature("autodoc", "
269 Writes memory to the current process's address space and maintains any
270 traps that might be present due to software breakpoints. Example:
271
272 # Create a Python string from the byte array.
273 new_value = str(bytes)
274 result = process.WriteMemory(addr, new_value, error)
275 if not error.Success() or result != len(bytes):
276 print 'SBProcess.WriteMemory() failed!'
277 ") WriteMemory;
278 size_t
279 WriteMemory (addr_t addr, const void *buf, size_t size, lldb::SBError &error);
280
Greg Claytone91b7952011-12-15 03:14:23 +0000281 %feature("autodoc", "
282 Reads a NULL terminated C string from the current process's address space.
283 It returns a python string of the exact length, or truncates the string if
284 the maximum character limit is reached. Example:
285
286 # Read a C string of at most 256 bytes from address '0x1000'
287 error = lldb.SBError()
Johnny Chen80e3e842011-12-15 22:34:59 +0000288 cstring = process.ReadCStringFromMemory(0x1000, 256, error)
Greg Claytone91b7952011-12-15 03:14:23 +0000289 if error.Success():
290 print 'cstring: ', cstring
291 else
292 print 'error: ', error
293 ") ReadCStringFromMemory;
294
295 size_t
296 ReadCStringFromMemory (addr_t addr, void *buf, size_t size, lldb::SBError &error);
297
298 %feature("autodoc", "
299 Reads an unsigned integer from memory given a byte size and an address.
300 Returns the unsigned integer that was read. Example:
301
302 # Read a 4 byte unsigned integer from address 0x1000
303 error = lldb.SBError()
304 uint = ReadUnsignedFromMemory(0x1000, 4, error)
305 if error.Success():
306 print 'integer: %u' % uint
307 else
308 print 'error: ', error
309
310 ") ReadUnsignedFromMemory;
311
312 uint64_t
313 ReadUnsignedFromMemory (addr_t addr, uint32_t byte_size, lldb::SBError &error);
314
315 %feature("autodoc", "
316 Reads a pointer from memory from an address and returns the value. Example:
317
318 # Read a pointer from address 0x1000
319 error = lldb.SBError()
320 ptr = ReadPointerFromMemory(0x1000, error)
321 if error.Success():
322 print 'pointer: 0x%x' % ptr
323 else
324 print 'error: ', error
325
326 ") ReadPointerFromMemory;
327
328 lldb::addr_t
329 ReadPointerFromMemory (addr_t addr, lldb::SBError &error);
330
331
Johnny Chen357033b2011-07-18 20:13:38 +0000332 // Events
333 static lldb::StateType
334 GetStateFromEvent (const lldb::SBEvent &event);
335
336 static bool
337 GetRestartedFromEvent (const lldb::SBEvent &event);
338
Jim Ingham0161b492013-02-09 01:29:05 +0000339 static size_t
340 GetNumRestartedReasonsFromEvent (const lldb::SBEvent &event);
341
342 static const char *
343 GetRestartedReasonAtIndexFromEvent (const lldb::SBEvent &event, size_t idx);
344
Johnny Chen357033b2011-07-18 20:13:38 +0000345 static lldb::SBProcess
346 GetProcessFromEvent (const lldb::SBEvent &event);
347
Jim Inghame6bc6cb2012-02-08 05:23:15 +0000348 static bool
349 EventIsProcessEvent (const lldb::SBEvent &event);
350
Johnny Chen357033b2011-07-18 20:13:38 +0000351 lldb::SBBroadcaster
352 GetBroadcaster () const;
353
354 bool
355 GetDescription (lldb::SBStream &description);
356
357 uint32_t
Johnny Chenf9ef60d2012-05-23 22:34:34 +0000358 GetNumSupportedHardwareWatchpoints (lldb::SBError &error) const;
359
360 uint32_t
Johnny Chen357033b2011-07-18 20:13:38 +0000361 LoadImage (lldb::SBFileSpec &image_spec, lldb::SBError &error);
362
363 lldb::SBError
364 UnloadImage (uint32_t image_token);
Jason Molendaa3329782014-03-29 18:54:20 +0000365
366 lldb::SBError
367 SendEventData (const char *event_data);
Johnny Chen39c6d0f2012-01-06 00:46:12 +0000368
Jason Molenda8c713372013-11-05 11:00:35 +0000369 %feature("autodoc", "
370 Return the number of different thread-origin extended backtraces
371 this process can support as a uint32_t.
372 When the process is stopped and you have an SBThread, lldb may be
373 able to show a backtrace of when that thread was originally created,
374 or the work item was enqueued to it (in the case of a libdispatch
375 queue).
Jason Molenda95d005c2013-11-06 03:07:33 +0000376 ") GetNumExtendedBacktraceTypes;
Jason Molenda8c713372013-11-05 11:00:35 +0000377
378 uint32_t
Jason Molenda95d005c2013-11-06 03:07:33 +0000379 GetNumExtendedBacktraceTypes ();
Jason Molenda8c713372013-11-05 11:00:35 +0000380
381 %feature("autodoc", "
382 Takes an index argument, returns the name of one of the thread-origin
383 extended backtrace methods as a str.
Jason Molenda95d005c2013-11-06 03:07:33 +0000384 ") GetExtendedBacktraceTypeAtIndex;
Jason Molenda8c713372013-11-05 11:00:35 +0000385
386 const char *
Jason Molenda95d005c2013-11-06 03:07:33 +0000387 GetExtendedBacktraceTypeAtIndex (uint32_t idx);
Jason Molenda8c713372013-11-05 11:00:35 +0000388
Greg Clayton13d19502012-01-29 06:07:39 +0000389 %pythoncode %{
Greg Clayton6b2bd932012-02-01 08:09:32 +0000390 def __get_is_alive__(self):
391 '''Returns "True" if the process is currently alive, "False" otherwise'''
392 s = self.GetState()
393 if (s == eStateAttaching or
394 s == eStateLaunching or
395 s == eStateStopped or
396 s == eStateRunning or
397 s == eStateStepping or
398 s == eStateCrashed or
399 s == eStateSuspended):
400 return True
401 return False
402
403 def __get_is_running__(self):
404 '''Returns "True" if the process is currently running, "False" otherwise'''
405 state = self.GetState()
406 if state == eStateRunning or state == eStateStepping:
407 return True
408 return False
409
410 def __get_is_running__(self):
411 '''Returns "True" if the process is currently stopped, "False" otherwise'''
412 state = self.GetState()
413 if state == eStateStopped or state == eStateCrashed or state == eStateSuspended:
414 return True
415 return False
416
Greg Claytonb62bb8c2012-02-03 03:22:53 +0000417 class threads_access(object):
Greg Clayton6b2bd932012-02-01 08:09:32 +0000418 '''A helper object that will lazily hand out thread for a process when supplied an index.'''
419 def __init__(self, sbprocess):
420 self.sbprocess = sbprocess
421
422 def __len__(self):
Filipe Cabecinhas1a96ef82012-05-11 20:39:42 +0000423 if self.sbprocess:
424 return int(self.sbprocess.GetNumThreads())
Greg Clayton6b2bd932012-02-01 08:09:32 +0000425 return 0
426
427 def __getitem__(self, key):
428 if type(key) is int and key < len(self):
429 return self.sbprocess.GetThreadAtIndex(key)
430 return None
431
Greg Claytonb62bb8c2012-02-03 03:22:53 +0000432 def get_threads_access_object(self):
433 '''An accessor function that returns a modules_access() object which allows lazy thread access from a lldb.SBProcess object.'''
434 return self.threads_access (self)
Greg Clayton6b2bd932012-02-01 08:09:32 +0000435
436 def get_process_thread_list(self):
Greg Claytonb62bb8c2012-02-03 03:22:53 +0000437 '''An accessor function that returns a list() that contains all threads in a lldb.SBProcess object.'''
Greg Clayton6b2bd932012-02-01 08:09:32 +0000438 threads = []
Enrico Granatabeea93c2012-10-08 19:06:11 +0000439 accessor = self.get_threads_access_object()
440 for idx in range(len(accessor)):
441 threads.append(accessor[idx])
Greg Clayton6b2bd932012-02-01 08:09:32 +0000442 return threads
443
444 __swig_getmethods__["threads"] = get_process_thread_list
Greg Clayton5ef31a92012-06-29 22:00:42 +0000445 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 Clayton6b2bd932012-02-01 08:09:32 +0000446
Greg Claytonb62bb8c2012-02-03 03:22:53 +0000447 __swig_getmethods__["thread"] = get_threads_access_object
Greg Clayton5ef31a92012-06-29 22:00:42 +0000448 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 Clayton6b2bd932012-02-01 08:09:32 +0000449
450 __swig_getmethods__["is_alive"] = __get_is_alive__
Greg Clayton5ef31a92012-06-29 22:00:42 +0000451 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 Clayton6b2bd932012-02-01 08:09:32 +0000452
453 __swig_getmethods__["is_running"] = __get_is_running__
Greg Clayton5ef31a92012-06-29 22:00:42 +0000454 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 Clayton6b2bd932012-02-01 08:09:32 +0000455
456 __swig_getmethods__["is_stopped"] = __get_is_running__
Greg Clayton5ef31a92012-06-29 22:00:42 +0000457 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 Clayton6b2bd932012-02-01 08:09:32 +0000458
Greg Clayton13d19502012-01-29 06:07:39 +0000459 __swig_getmethods__["id"] = GetProcessID
Greg Clayton5ef31a92012-06-29 22:00:42 +0000460 if _newclass: id = property(GetProcessID, None, doc='''A read only property that returns the process ID as an integer.''')
Greg Clayton13d19502012-01-29 06:07:39 +0000461
462 __swig_getmethods__["target"] = GetTarget
Greg Clayton5ef31a92012-06-29 22:00:42 +0000463 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 Clayton13d19502012-01-29 06:07:39 +0000464
465 __swig_getmethods__["num_threads"] = GetNumThreads
Greg Clayton5ef31a92012-06-29 22:00:42 +0000466 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 Clayton13d19502012-01-29 06:07:39 +0000467
468 __swig_getmethods__["selected_thread"] = GetSelectedThread
469 __swig_setmethods__["selected_thread"] = SetSelectedThread
Greg Clayton5ef31a92012-06-29 22:00:42 +0000470 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 Clayton13d19502012-01-29 06:07:39 +0000471
472 __swig_getmethods__["state"] = GetState
Greg Clayton5ef31a92012-06-29 22:00:42 +0000473 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 Clayton13d19502012-01-29 06:07:39 +0000474
475 __swig_getmethods__["exit_state"] = GetExitStatus
Greg Clayton5ef31a92012-06-29 22:00:42 +0000476 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 Clayton13d19502012-01-29 06:07:39 +0000477
478 __swig_getmethods__["exit_description"] = GetExitDescription
Greg Clayton5ef31a92012-06-29 22:00:42 +0000479 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 Clayton13d19502012-01-29 06:07:39 +0000480
481 __swig_getmethods__["broadcaster"] = GetBroadcaster
Greg Clayton5ef31a92012-06-29 22:00:42 +0000482 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 Clayton13d19502012-01-29 06:07:39 +0000483 %}
484
Johnny Chen357033b2011-07-18 20:13:38 +0000485};
486
487} // namespace lldb