blob: 453f98ffe200937c0555f0a16de9645972150aff [file] [log] [blame]
Johnny Chen357033b2011-07-18 20:13:38 +00001//===-- SWIG Interface for SBProcess ----------------------------*- C++ -*-===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Johnny Chen357033b2011-07-18 20:13:38 +00006//
7//===----------------------------------------------------------------------===//
8
9namespace lldb {
10
11%feature("docstring",
12"Represents the process associated with the target program.
13
14SBProcess supports thread iteration. For example (from test/lldbutil.py),
15
16# ==================================================
17# Utility functions related to Threads and Processes
18# ==================================================
19
20def get_stopped_threads(process, reason):
21 '''Returns the thread(s) with the specified stop reason in a list.
22
23 The list can be empty if no such thread exists.
24 '''
25 threads = []
26 for t in process:
27 if t.GetStopReason() == reason:
28 threads.append(t)
29 return threads
30
31...
32"
33) SBProcess;
34class SBProcess
35{
36public:
Johnny Chen357033b2011-07-18 20:13:38 +000037 enum
38 {
39 eBroadcastBitStateChanged = (1 << 0),
40 eBroadcastBitInterrupt = (1 << 1),
41 eBroadcastBitSTDOUT = (1 << 2),
Han Ming Ongab3b8b22012-11-17 00:21:04 +000042 eBroadcastBitSTDERR = (1 << 3),
Todd Fiala75930012016-08-19 04:21:48 +000043 eBroadcastBitProfileData = (1 << 4),
44 eBroadcastBitStructuredData = (1 << 5)
Johnny Chen357033b2011-07-18 20:13:38 +000045 };
46
47 SBProcess ();
48
49 SBProcess (const lldb::SBProcess& rhs);
50
51 ~SBProcess();
52
Jim Ingham4bddaeb2012-02-16 06:50:00 +000053 static const char *
54 GetBroadcasterClassName ();
55
Jim Inghamd7b30ef2012-10-26 19:18:04 +000056 const char *
57 GetPluginName ();
Pavel Labatheba97422019-04-18 16:23:33 +000058
Jim Inghamd7b30ef2012-10-26 19:18:04 +000059 const char *
60 GetShortPluginName ();
Pavel Labatheba97422019-04-18 16:23:33 +000061
Johnny Chen357033b2011-07-18 20:13:38 +000062 void
63 Clear ();
64
65 bool
66 IsValid() const;
67
Pavel Labath7f5237b2019-03-11 13:58:46 +000068 explicit operator bool() const;
69
Johnny Chen357033b2011-07-18 20:13:38 +000070 lldb::SBTarget
71 GetTarget() const;
72
73 lldb::ByteOrder
74 GetByteOrder() const;
75
Johnny Chen49cb85d2011-11-28 21:39:07 +000076 %feature("autodoc", "
77 Writes data into the current process's stdin. API client specifies a Python
Pavel Labatheba97422019-04-18 16:23:33 +000078 string as the only argument.") PutSTDIN;
Johnny Chen357033b2011-07-18 20:13:38 +000079 size_t
80 PutSTDIN (const char *src, size_t src_len);
81
Johnny Chend80e5e92011-11-28 19:12:25 +000082 %feature("autodoc", "
83 Reads data from the current process's stdout stream. API client specifies
84 the size of the buffer to read data into. It returns the byte buffer in a
Pavel Labatheba97422019-04-18 16:23:33 +000085 Python string.") GetSTDOUT;
Johnny Chen357033b2011-07-18 20:13:38 +000086 size_t
87 GetSTDOUT (char *dst, size_t dst_len) const;
88
Johnny Chend80e5e92011-11-28 19:12:25 +000089 %feature("autodoc", "
90 Reads data from the current process's stderr stream. API client specifies
91 the size of the buffer to read data into. It returns the byte buffer in a
Pavel Labatheba97422019-04-18 16:23:33 +000092 Python string.") GetSTDERR;
Johnny Chen357033b2011-07-18 20:13:38 +000093 size_t
94 GetSTDERR (char *dst, size_t dst_len) const;
95
Han Ming Ongab3b8b22012-11-17 00:21:04 +000096 size_t
97 GetAsyncProfileData(char *dst, size_t dst_len) const;
Pavel Labatheba97422019-04-18 16:23:33 +000098
Johnny Chen357033b2011-07-18 20:13:38 +000099 void
Lawrence D'Anna322f12a2019-10-14 20:15:28 +0000100 ReportEventState (const lldb::SBEvent &event, SBFile out) const;
101
102 void
103 ReportEventState (const lldb::SBEvent &event, FileSP BORROWED) const;
Johnny Chen357033b2011-07-18 20:13:38 +0000104
105 void
106 AppendEventStateReport (const lldb::SBEvent &event, lldb::SBCommandReturnObject &result);
107
108 %feature("docstring", "
Pavel Labatheba97422019-04-18 16:23:33 +0000109 Remote connection related functions. These will fail if the
110 process is not in eStateConnected. They are intended for use
111 when connecting to an externally managed debugserver instance.") RemoteAttachToProcessWithID;
Johnny Chen357033b2011-07-18 20:13:38 +0000112 bool
113 RemoteAttachToProcessWithID (lldb::pid_t pid,
114 lldb::SBError& error);
Pavel Labatheba97422019-04-18 16:23:33 +0000115
Johnny Chen357033b2011-07-18 20:13:38 +0000116 %feature("docstring",
117 "See SBTarget.Launch for argument description and usage."
118 ) RemoteLaunch;
119 bool
120 RemoteLaunch (char const **argv,
121 char const **envp,
122 const char *stdin_path,
123 const char *stdout_path,
124 const char *stderr_path,
125 const char *working_directory,
126 uint32_t launch_flags,
127 bool stop_at_entry,
128 lldb::SBError& error);
Pavel Labatheba97422019-04-18 16:23:33 +0000129
Johnny Chen357033b2011-07-18 20:13:38 +0000130 //------------------------------------------------------------------
131 // Thread related functions
132 //------------------------------------------------------------------
133 uint32_t
134 GetNumThreads ();
135
Jim Ingham18b46892012-07-13 20:18:18 +0000136 %feature("autodoc", "
137 Returns the INDEX'th thread from the list of current threads. The index
138 of a thread is only valid for the current stop. For a persistent thread
139 identifier use either the thread ID or the IndexID. See help on SBThread
Pavel Labatheba97422019-04-18 16:23:33 +0000140 for more details.") GetThreadAtIndex;
Johnny Chen357033b2011-07-18 20:13:38 +0000141 lldb::SBThread
142 GetThreadAtIndex (size_t index);
143
Jim Ingham18b46892012-07-13 20:18:18 +0000144 %feature("autodoc", "
Pavel Labatheba97422019-04-18 16:23:33 +0000145 Returns the thread with the given thread ID.") GetThreadByID;
Johnny Chen357033b2011-07-18 20:13:38 +0000146 lldb::SBThread
147 GetThreadByID (lldb::tid_t sb_thread_id);
Pavel Labatheba97422019-04-18 16:23:33 +0000148
Jim Ingham18b46892012-07-13 20:18:18 +0000149 %feature("autodoc", "
Pavel Labatheba97422019-04-18 16:23:33 +0000150 Returns the thread with the given thread IndexID.") GetThreadByIndexID;
Jim Ingham18b46892012-07-13 20:18:18 +0000151 lldb::SBThread
152 GetThreadByIndexID (uint32_t index_id);
Johnny Chen357033b2011-07-18 20:13:38 +0000153
Jim Ingham18b46892012-07-13 20:18:18 +0000154 %feature("autodoc", "
Pavel Labatheba97422019-04-18 16:23:33 +0000155 Returns the currently selected thread.") GetSelectedThread;
Johnny Chen357033b2011-07-18 20:13:38 +0000156 lldb::SBThread
157 GetSelectedThread () const;
158
Greg Claytona4d87472013-01-18 23:41:08 +0000159 %feature("autodoc", "
Pavel Labatheba97422019-04-18 16:23:33 +0000160 Lazily create a thread on demand through the current OperatingSystem plug-in, if the current OperatingSystem plug-in supports it.") CreateOSPluginThread;
Greg Claytona4d87472013-01-18 23:41:08 +0000161 lldb::SBThread
162 CreateOSPluginThread (lldb::tid_t tid, lldb::addr_t context);
163
Johnny Chen357033b2011-07-18 20:13:38 +0000164 bool
165 SetSelectedThread (const lldb::SBThread &thread);
166
167 bool
Greg Claytonea561dc2012-10-12 23:32:11 +0000168 SetSelectedThreadByID (lldb::tid_t tid);
Johnny Chen357033b2011-07-18 20:13:38 +0000169
Jim Ingham18b46892012-07-13 20:18:18 +0000170 bool
171 SetSelectedThreadByIndexID (uint32_t index_id);
Pavel Labatheba97422019-04-18 16:23:33 +0000172
Johnny Chen357033b2011-07-18 20:13:38 +0000173 //------------------------------------------------------------------
Jason Molenda5e8dce42013-12-13 00:29:16 +0000174 // Queue related functions
175 //------------------------------------------------------------------
176 uint32_t
177 GetNumQueues ();
178
179 lldb::SBQueue
180 GetQueueAtIndex (uint32_t index);
181
182 //------------------------------------------------------------------
Johnny Chen357033b2011-07-18 20:13:38 +0000183 // Stepping related functions
184 //------------------------------------------------------------------
185
186 lldb::StateType
187 GetState ();
188
189 int
190 GetExitStatus ();
191
192 const char *
193 GetExitDescription ();
194
Greg Clayton949e8222013-01-16 17:29:04 +0000195 %feature("autodoc", "
Pavel Labatheba97422019-04-18 16:23:33 +0000196 Returns the process ID of the process.") GetProcessID;
Johnny Chen357033b2011-07-18 20:13:38 +0000197 lldb::pid_t
198 GetProcessID ();
Pavel Labatheba97422019-04-18 16:23:33 +0000199
Greg Clayton949e8222013-01-16 17:29:04 +0000200 %feature("autodoc", "
Pavel Labatheba97422019-04-18 16:23:33 +0000201 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.") GetUniqueID;
Greg Clayton949e8222013-01-16 17:29:04 +0000202 uint32_t
203 GetUniqueID();
Johnny Chen357033b2011-07-18 20:13:38 +0000204
205 uint32_t
206 GetAddressByteSize() const;
207
208 %feature("docstring", "
209 Kills the process and shuts down all threads that were spawned to
Pavel Labatheba97422019-04-18 16:23:33 +0000210 track and monitor process.") Destroy;
Johnny Chen357033b2011-07-18 20:13:38 +0000211 lldb::SBError
212 Destroy ();
213
214 lldb::SBError
215 Continue ();
216
217 lldb::SBError
218 Stop ();
219
220 %feature("docstring", "Same as Destroy(self).") Destroy;
221 lldb::SBError
222 Kill ();
223
224 lldb::SBError
225 Detach ();
226
227 %feature("docstring", "Sends the process a unix signal.") Signal;
228 lldb::SBError
229 Signal (int signal);
230
Todd Fiala802dc4022014-06-23 19:30:49 +0000231 lldb::SBUnixSignals
232 GetUnixSignals();
233
Jim Inghambf2956a22013-01-08 23:22:42 +0000234 %feature("docstring", "
235 Returns a stop id that will increase every time the process executes. If
236 include_expression_stops is true, then stops caused by expression evaluation
237 will cause the returned value to increase, otherwise the counter returned will
238 only increase when execution is continued explicitly by the user. Note, the value
Pavel Labatheba97422019-04-18 16:23:33 +0000239 will always increase, but may increase by more than one per stop.") GetStopID;
Jim Inghambf2956a22013-01-08 23:22:42 +0000240 uint32_t
241 GetStopID(bool include_expression_stops = false);
Pavel Labatheba97422019-04-18 16:23:33 +0000242
Jim Inghamcfc09352012-07-27 23:57:19 +0000243 void
244 SendAsyncInterrupt();
Pavel Labatheba97422019-04-18 16:23:33 +0000245
Johnny Chen357033b2011-07-18 20:13:38 +0000246 %feature("autodoc", "
247 Reads memory from the current process's address space and removes any
248 traps that may have been inserted into the memory. It returns the byte
249 buffer in a Python string. Example:
250
251 # Read 4 bytes from address 'addr' and assume error.Success() is True.
252 content = process.ReadMemory(addr, 4, error)
Pavel Labatheba97422019-04-18 16:23:33 +0000253 new_bytes = bytearray(content)") ReadMemory;
Johnny Chen357033b2011-07-18 20:13:38 +0000254 size_t
255 ReadMemory (addr_t addr, void *buf, size_t size, lldb::SBError &error);
256
257 %feature("autodoc", "
258 Writes memory to the current process's address space and maintains any
259 traps that might be present due to software breakpoints. Example:
260
261 # Create a Python string from the byte array.
262 new_value = str(bytes)
263 result = process.WriteMemory(addr, new_value, error)
264 if not error.Success() or result != len(bytes):
Pavel Labatheba97422019-04-18 16:23:33 +0000265 print('SBProcess.WriteMemory() failed!')") WriteMemory;
Johnny Chen357033b2011-07-18 20:13:38 +0000266 size_t
267 WriteMemory (addr_t addr, const void *buf, size_t size, lldb::SBError &error);
268
Greg Claytone91b7952011-12-15 03:14:23 +0000269 %feature("autodoc", "
270 Reads a NULL terminated C string from the current process's address space.
271 It returns a python string of the exact length, or truncates the string if
272 the maximum character limit is reached. Example:
Pavel Labatheba97422019-04-18 16:23:33 +0000273
274 # Read a C string of at most 256 bytes from address '0x1000'
Greg Claytone91b7952011-12-15 03:14:23 +0000275 error = lldb.SBError()
Johnny Chen80e3e842011-12-15 22:34:59 +0000276 cstring = process.ReadCStringFromMemory(0x1000, 256, error)
Greg Claytone91b7952011-12-15 03:14:23 +0000277 if error.Success():
Zachary Turner5f3fd802015-10-16 17:52:32 +0000278 print('cstring: ', cstring)
Greg Claytone91b7952011-12-15 03:14:23 +0000279 else
Pavel Labatheba97422019-04-18 16:23:33 +0000280 print('error: ', error)") ReadCStringFromMemory;
Greg Claytone91b7952011-12-15 03:14:23 +0000281
282 size_t
Zachary Turner44073962016-01-25 23:21:18 +0000283 ReadCStringFromMemory (addr_t addr, void *char_buf, size_t size, lldb::SBError &error);
Greg Claytone91b7952011-12-15 03:14:23 +0000284
285 %feature("autodoc", "
Pavel Labatheba97422019-04-18 16:23:33 +0000286 Reads an unsigned integer from memory given a byte size and an address.
Greg Claytone91b7952011-12-15 03:14:23 +0000287 Returns the unsigned integer that was read. Example:
Pavel Labatheba97422019-04-18 16:23:33 +0000288
Greg Claytone91b7952011-12-15 03:14:23 +0000289 # Read a 4 byte unsigned integer from address 0x1000
290 error = lldb.SBError()
291 uint = ReadUnsignedFromMemory(0x1000, 4, error)
292 if error.Success():
Zachary Turner5f3fd802015-10-16 17:52:32 +0000293 print('integer: %u' % uint)
Greg Claytone91b7952011-12-15 03:14:23 +0000294 else
Pavel Labath27e9d982019-04-21 12:48:53 +0000295 print('error: ', error)") ReadUnsignedFromMemory;
Greg Claytone91b7952011-12-15 03:14:23 +0000296
297 uint64_t
298 ReadUnsignedFromMemory (addr_t addr, uint32_t byte_size, lldb::SBError &error);
Pavel Labatheba97422019-04-18 16:23:33 +0000299
Greg Claytone91b7952011-12-15 03:14:23 +0000300 %feature("autodoc", "
301 Reads a pointer from memory from an address and returns the value. Example:
Pavel Labatheba97422019-04-18 16:23:33 +0000302
Greg Claytone91b7952011-12-15 03:14:23 +0000303 # Read a pointer from address 0x1000
304 error = lldb.SBError()
305 ptr = ReadPointerFromMemory(0x1000, error)
306 if error.Success():
Zachary Turner5f3fd802015-10-16 17:52:32 +0000307 print('pointer: 0x%x' % ptr)
Greg Claytone91b7952011-12-15 03:14:23 +0000308 else
Pavel Labath27e9d982019-04-21 12:48:53 +0000309 print('error: ', error)") ReadPointerFromMemory;
Pavel Labatheba97422019-04-18 16:23:33 +0000310
Greg Claytone91b7952011-12-15 03:14:23 +0000311 lldb::addr_t
312 ReadPointerFromMemory (addr_t addr, lldb::SBError &error);
Pavel Labatheba97422019-04-18 16:23:33 +0000313
Greg Claytone91b7952011-12-15 03:14:23 +0000314
Johnny Chen357033b2011-07-18 20:13:38 +0000315 // Events
316 static lldb::StateType
317 GetStateFromEvent (const lldb::SBEvent &event);
318
319 static bool
320 GetRestartedFromEvent (const lldb::SBEvent &event);
321
Jim Ingham0161b492013-02-09 01:29:05 +0000322 static size_t
323 GetNumRestartedReasonsFromEvent (const lldb::SBEvent &event);
Pavel Labatheba97422019-04-18 16:23:33 +0000324
Jim Ingham0161b492013-02-09 01:29:05 +0000325 static const char *
326 GetRestartedReasonAtIndexFromEvent (const lldb::SBEvent &event, size_t idx);
327
Johnny Chen357033b2011-07-18 20:13:38 +0000328 static lldb::SBProcess
329 GetProcessFromEvent (const lldb::SBEvent &event);
330
Jim Inghame6bc6cb2012-02-08 05:23:15 +0000331 static bool
Ilia K06d28552015-05-15 09:29:09 +0000332 GetInterruptedFromEvent (const lldb::SBEvent &event);
333
Todd Fiala75930012016-08-19 04:21:48 +0000334 static lldb::SBStructuredData
335 GetStructuredDataFromEvent (const lldb::SBEvent &event);
336
Ilia K06d28552015-05-15 09:29:09 +0000337 static bool
Jim Inghame6bc6cb2012-02-08 05:23:15 +0000338 EventIsProcessEvent (const lldb::SBEvent &event);
339
Todd Fiala75930012016-08-19 04:21:48 +0000340 static bool
341 EventIsStructuredDataEvent (const lldb::SBEvent &event);
342
Johnny Chen357033b2011-07-18 20:13:38 +0000343 lldb::SBBroadcaster
344 GetBroadcaster () const;
345
346 bool
347 GetDescription (lldb::SBStream &description);
348
349 uint32_t
Johnny Chenf9ef60d2012-05-23 22:34:34 +0000350 GetNumSupportedHardwareWatchpoints (lldb::SBError &error) const;
351
352 uint32_t
Johnny Chen357033b2011-07-18 20:13:38 +0000353 LoadImage (lldb::SBFileSpec &image_spec, lldb::SBError &error);
Pavel Labatheba97422019-04-18 16:23:33 +0000354
Jim Ingham0d231f72018-06-28 20:02:11 +0000355 %feature("autodoc", "
356 Load the library whose filename is given by image_spec looking in all the
357 paths supplied in the paths argument. If successful, return a token that
358 can be passed to UnloadImage and fill loaded_path with the path that was
Pavel Labatheba97422019-04-18 16:23:33 +0000359 successfully loaded. On failure, return
360 lldb.LLDB_INVALID_IMAGE_TOKEN.") LoadImageUsingPaths;
361 uint32_t
Jim Ingham0d231f72018-06-28 20:02:11 +0000362 LoadImageUsingPaths(const lldb::SBFileSpec &image_spec,
363 SBStringList &paths,
Pavel Labatheba97422019-04-18 16:23:33 +0000364 lldb::SBFileSpec &loaded_path,
Jim Ingham0d231f72018-06-28 20:02:11 +0000365 SBError &error);
366
Johnny Chen357033b2011-07-18 20:13:38 +0000367 lldb::SBError
368 UnloadImage (uint32_t image_token);
Pavel Labatheba97422019-04-18 16:23:33 +0000369
Jason Molendaa3329782014-03-29 18:54:20 +0000370 lldb::SBError
371 SendEventData (const char *event_data);
Johnny Chen39c6d0f2012-01-06 00:46:12 +0000372
Jason Molenda8c713372013-11-05 11:00:35 +0000373 %feature("autodoc", "
374 Return the number of different thread-origin extended backtraces
375 this process can support as a uint32_t.
376 When the process is stopped and you have an SBThread, lldb may be
377 able to show a backtrace of when that thread was originally created,
Pavel Labatheba97422019-04-18 16:23:33 +0000378 or the work item was enqueued to it (in the case of a libdispatch
379 queue).") GetNumExtendedBacktraceTypes;
380
Jason Molenda8c713372013-11-05 11:00:35 +0000381 uint32_t
Jason Molenda95d005c2013-11-06 03:07:33 +0000382 GetNumExtendedBacktraceTypes ();
Jason Molenda8c713372013-11-05 11:00:35 +0000383
384 %feature("autodoc", "
Pavel Labatheba97422019-04-18 16:23:33 +0000385 Takes an index argument, returns the name of one of the thread-origin
386 extended backtrace methods as a str.") GetExtendedBacktraceTypeAtIndex;
Jason Molenda8c713372013-11-05 11:00:35 +0000387
388 const char *
Jason Molenda95d005c2013-11-06 03:07:33 +0000389 GetExtendedBacktraceTypeAtIndex (uint32_t idx);
Jason Molenda8c713372013-11-05 11:00:35 +0000390
Kuba Breckaa51ea382014-09-06 01:33:13 +0000391 lldb::SBThreadCollection
392 GetHistoryThreads (addr_t addr);
Pavel Labatheba97422019-04-18 16:23:33 +0000393
Kuba Brecka63927542014-10-11 01:59:32 +0000394 bool
395 IsInstrumentationRuntimePresent(lldb::InstrumentationRuntimeType type);
Kuba Breckaa51ea382014-09-06 01:33:13 +0000396
Adrian McCarthyf7d18932015-11-20 23:09:11 +0000397 lldb::SBError
398 SaveCore(const char *file_name);
399
Ravitheja Addepallyd5d8d912017-04-26 08:48:50 +0000400 lldb::SBTrace
401 StartTrace(SBTraceOptions &options, lldb::SBError &error);
402
Greg Clayton4d32eb62016-06-24 23:40:35 +0000403 lldb::SBError
404 GetMemoryRegionInfo(lldb::addr_t load_addr, lldb::SBMemoryRegionInfo &region_info);
405
406 lldb::SBMemoryRegionInfoList
407 GetMemoryRegions();
408
Vadim Macagon141a6262017-08-01 07:34:26 +0000409 %feature("autodoc", "
410 Get information about the process.
411 Valid process info will only be returned when the process is alive,
412 use IsValid() to check if the info returned is valid.
413
414 process_info = process.GetProcessInfo()
415 if process_info.IsValid():
Pavel Labatheba97422019-04-18 16:23:33 +0000416 process_info.GetProcessID()") GetProcessInfo;
Vadim Macagon141a6262017-08-01 07:34:26 +0000417 lldb::SBProcessInfo
418 GetProcessInfo();
419
Greg Clayton13d19502012-01-29 06:07:39 +0000420 %pythoncode %{
Greg Clayton6b2bd932012-02-01 08:09:32 +0000421 def __get_is_alive__(self):
422 '''Returns "True" if the process is currently alive, "False" otherwise'''
423 s = self.GetState()
Pavel Labatheba97422019-04-18 16:23:33 +0000424 if (s == eStateAttaching or
425 s == eStateLaunching or
426 s == eStateStopped or
427 s == eStateRunning or
428 s == eStateStepping or
429 s == eStateCrashed or
Greg Clayton6b2bd932012-02-01 08:09:32 +0000430 s == eStateSuspended):
431 return True
432 return False
433
434 def __get_is_running__(self):
435 '''Returns "True" if the process is currently running, "False" otherwise'''
436 state = self.GetState()
437 if state == eStateRunning or state == eStateStepping:
438 return True
439 return False
440
Greg Claytond458c4d2016-07-05 18:19:43 +0000441 def __get_is_stopped__(self):
Greg Clayton6b2bd932012-02-01 08:09:32 +0000442 '''Returns "True" if the process is currently stopped, "False" otherwise'''
443 state = self.GetState()
444 if state == eStateStopped or state == eStateCrashed or state == eStateSuspended:
445 return True
446 return False
447
Greg Claytonb62bb8c2012-02-03 03:22:53 +0000448 class threads_access(object):
Greg Clayton6b2bd932012-02-01 08:09:32 +0000449 '''A helper object that will lazily hand out thread for a process when supplied an index.'''
450 def __init__(self, sbprocess):
451 self.sbprocess = sbprocess
Pavel Labatheba97422019-04-18 16:23:33 +0000452
Greg Clayton6b2bd932012-02-01 08:09:32 +0000453 def __len__(self):
Filipe Cabecinhas1a96ef82012-05-11 20:39:42 +0000454 if self.sbprocess:
455 return int(self.sbprocess.GetNumThreads())
Greg Clayton6b2bd932012-02-01 08:09:32 +0000456 return 0
Pavel Labatheba97422019-04-18 16:23:33 +0000457
Greg Clayton6b2bd932012-02-01 08:09:32 +0000458 def __getitem__(self, key):
459 if type(key) is int and key < len(self):
460 return self.sbprocess.GetThreadAtIndex(key)
461 return None
Pavel Labatheba97422019-04-18 16:23:33 +0000462
Greg Claytonb62bb8c2012-02-03 03:22:53 +0000463 def get_threads_access_object(self):
464 '''An accessor function that returns a modules_access() object which allows lazy thread access from a lldb.SBProcess object.'''
465 return self.threads_access (self)
Pavel Labatheba97422019-04-18 16:23:33 +0000466
Greg Clayton6b2bd932012-02-01 08:09:32 +0000467 def get_process_thread_list(self):
Greg Claytonb62bb8c2012-02-03 03:22:53 +0000468 '''An accessor function that returns a list() that contains all threads in a lldb.SBProcess object.'''
Greg Clayton6b2bd932012-02-01 08:09:32 +0000469 threads = []
Enrico Granatabeea93c2012-10-08 19:06:11 +0000470 accessor = self.get_threads_access_object()
471 for idx in range(len(accessor)):
472 threads.append(accessor[idx])
Greg Clayton6b2bd932012-02-01 08:09:32 +0000473 return threads
Pavel Labath4da5a1d2019-04-03 11:48:38 +0000474
475 def __iter__(self):
476 '''Iterate over all threads in a lldb.SBProcess object.'''
477 return lldb_iter(self, 'GetNumThreads', 'GetThreadAtIndex')
Pavel Labatheba97422019-04-18 16:23:33 +0000478
Pavel Labath4da5a1d2019-04-03 11:48:38 +0000479 def __len__(self):
480 '''Return the number of threads in a lldb.SBProcess object.'''
481 return self.GetNumThreads()
482
Pavel Labatheba97422019-04-18 16:23:33 +0000483
Jonas Devlieghere89b65842019-07-02 22:18:35 +0000484 threads = property(get_process_thread_list, None, doc='''A read only property that returns a list() of lldb.SBThread objects for this process.''')
485 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]).''')
486 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.''')
487 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.''')
488 is_stopped = property(__get_is_stopped__, None, doc='''A read only property that returns a boolean value that indicates if this process is currently stopped.''')
489 id = property(GetProcessID, None, doc='''A read only property that returns the process ID as an integer.''')
490 target = property(GetTarget, None, doc='''A read only property that an lldb object that represents the target (lldb.SBTarget) that owns this process.''')
491 num_threads = property(GetNumThreads, None, doc='''A read only property that returns the number of threads in this process as an integer.''')
492 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.''')
493 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.).''')
494 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.''')
495 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.''')
496 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 +0000497 %}
498
Johnny Chen357033b2011-07-18 20:13:38 +0000499};
500
501} // namespace lldb