blob: df58f169aa9f048744b38c7dde5fbf6d0ae1db70 [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),
46 eBroadcastBitSTDERR = (1 << 3)
47 };
48
49 SBProcess ();
50
51 SBProcess (const lldb::SBProcess& rhs);
52
53 ~SBProcess();
54
55 void
56 Clear ();
57
58 bool
59 IsValid() const;
60
61 lldb::SBTarget
62 GetTarget() const;
63
64 lldb::ByteOrder
65 GetByteOrder() const;
66
Johnny Chen23038b62011-11-28 21:39:07 +000067 %feature("autodoc", "
68 Writes data into the current process's stdin. API client specifies a Python
69 string as the only argument.
70 ") PutSTDIN;
Johnny Chenc3fba812011-07-18 20:13:38 +000071 size_t
72 PutSTDIN (const char *src, size_t src_len);
73
Johnny Chen609b9ce2011-11-28 19:12:25 +000074 %feature("autodoc", "
75 Reads data from the current process's stdout stream. API client specifies
76 the size of the buffer to read data into. It returns the byte buffer in a
77 Python string.
78 ") GetSTDOUT;
Johnny Chenc3fba812011-07-18 20:13:38 +000079 size_t
80 GetSTDOUT (char *dst, size_t dst_len) const;
81
Johnny Chen609b9ce2011-11-28 19:12:25 +000082 %feature("autodoc", "
83 Reads data from the current process's stderr stream. API client specifies
84 the size of the buffer to read data into. It returns the byte buffer in a
85 Python string.
86 ") GetSTDERR;
Johnny Chenc3fba812011-07-18 20:13:38 +000087 size_t
88 GetSTDERR (char *dst, size_t dst_len) const;
89
90 void
91 ReportEventState (const lldb::SBEvent &event, FILE *out) const;
92
93 void
94 AppendEventStateReport (const lldb::SBEvent &event, lldb::SBCommandReturnObject &result);
95
96 %feature("docstring", "
97 //------------------------------------------------------------------
98 /// Remote connection related functions. These will fail if the
99 /// process is not in eStateConnected. They are intended for use
100 /// when connecting to an externally managed debugserver instance.
101 //------------------------------------------------------------------
102 ") RemoteAttachToProcessWithID;
103 bool
104 RemoteAttachToProcessWithID (lldb::pid_t pid,
105 lldb::SBError& error);
106
107 %feature("docstring",
108 "See SBTarget.Launch for argument description and usage."
109 ) RemoteLaunch;
110 bool
111 RemoteLaunch (char const **argv,
112 char const **envp,
113 const char *stdin_path,
114 const char *stdout_path,
115 const char *stderr_path,
116 const char *working_directory,
117 uint32_t launch_flags,
118 bool stop_at_entry,
119 lldb::SBError& error);
120
121 //------------------------------------------------------------------
122 // Thread related functions
123 //------------------------------------------------------------------
124 uint32_t
125 GetNumThreads ();
126
127 lldb::SBThread
128 GetThreadAtIndex (size_t index);
129
130 lldb::SBThread
131 GetThreadByID (lldb::tid_t sb_thread_id);
132
133 lldb::SBThread
134 GetSelectedThread () const;
135
136 bool
137 SetSelectedThread (const lldb::SBThread &thread);
138
139 bool
140 SetSelectedThreadByID (uint32_t tid);
141
142 //------------------------------------------------------------------
143 // Stepping related functions
144 //------------------------------------------------------------------
145
146 lldb::StateType
147 GetState ();
148
149 int
150 GetExitStatus ();
151
152 const char *
153 GetExitDescription ();
154
155 lldb::pid_t
156 GetProcessID ();
157
158 uint32_t
159 GetAddressByteSize() const;
160
161 %feature("docstring", "
162 Kills the process and shuts down all threads that were spawned to
163 track and monitor process.
164 ") Destroy;
165 lldb::SBError
166 Destroy ();
167
168 lldb::SBError
169 Continue ();
170
171 lldb::SBError
172 Stop ();
173
174 %feature("docstring", "Same as Destroy(self).") Destroy;
175 lldb::SBError
176 Kill ();
177
178 lldb::SBError
179 Detach ();
180
181 %feature("docstring", "Sends the process a unix signal.") Signal;
182 lldb::SBError
183 Signal (int signal);
184
185 %feature("autodoc", "
186 Reads memory from the current process's address space and removes any
187 traps that may have been inserted into the memory. It returns the byte
188 buffer in a Python string. Example:
189
190 # Read 4 bytes from address 'addr' and assume error.Success() is True.
191 content = process.ReadMemory(addr, 4, error)
192 # Use 'ascii' encoding as each byte of 'content' is within [0..255].
193 new_bytes = bytearray(content, 'ascii')
194 ") ReadMemory;
195 size_t
196 ReadMemory (addr_t addr, void *buf, size_t size, lldb::SBError &error);
197
198 %feature("autodoc", "
199 Writes memory to the current process's address space and maintains any
200 traps that might be present due to software breakpoints. Example:
201
202 # Create a Python string from the byte array.
203 new_value = str(bytes)
204 result = process.WriteMemory(addr, new_value, error)
205 if not error.Success() or result != len(bytes):
206 print 'SBProcess.WriteMemory() failed!'
207 ") WriteMemory;
208 size_t
209 WriteMemory (addr_t addr, const void *buf, size_t size, lldb::SBError &error);
210
Greg Clayton4a2e3372011-12-15 03:14:23 +0000211 %feature("autodoc", "
212 Reads a NULL terminated C string from the current process's address space.
213 It returns a python string of the exact length, or truncates the string if
214 the maximum character limit is reached. Example:
215
216 # Read a C string of at most 256 bytes from address '0x1000'
217 error = lldb.SBError()
Johnny Chen08413862011-12-15 22:34:59 +0000218 cstring = process.ReadCStringFromMemory(0x1000, 256, error)
Greg Clayton4a2e3372011-12-15 03:14:23 +0000219 if error.Success():
220 print 'cstring: ', cstring
221 else
222 print 'error: ', error
223 ") ReadCStringFromMemory;
224
225 size_t
226 ReadCStringFromMemory (addr_t addr, void *buf, size_t size, lldb::SBError &error);
227
228 %feature("autodoc", "
229 Reads an unsigned integer from memory given a byte size and an address.
230 Returns the unsigned integer that was read. Example:
231
232 # Read a 4 byte unsigned integer from address 0x1000
233 error = lldb.SBError()
234 uint = ReadUnsignedFromMemory(0x1000, 4, error)
235 if error.Success():
236 print 'integer: %u' % uint
237 else
238 print 'error: ', error
239
240 ") ReadUnsignedFromMemory;
241
242 uint64_t
243 ReadUnsignedFromMemory (addr_t addr, uint32_t byte_size, lldb::SBError &error);
244
245 %feature("autodoc", "
246 Reads a pointer from memory from an address and returns the value. Example:
247
248 # Read a pointer from address 0x1000
249 error = lldb.SBError()
250 ptr = ReadPointerFromMemory(0x1000, error)
251 if error.Success():
252 print 'pointer: 0x%x' % ptr
253 else
254 print 'error: ', error
255
256 ") ReadPointerFromMemory;
257
258 lldb::addr_t
259 ReadPointerFromMemory (addr_t addr, lldb::SBError &error);
260
261
Johnny Chenc3fba812011-07-18 20:13:38 +0000262 // Events
263 static lldb::StateType
264 GetStateFromEvent (const lldb::SBEvent &event);
265
266 static bool
267 GetRestartedFromEvent (const lldb::SBEvent &event);
268
269 static lldb::SBProcess
270 GetProcessFromEvent (const lldb::SBEvent &event);
271
272 lldb::SBBroadcaster
273 GetBroadcaster () const;
274
275 bool
276 GetDescription (lldb::SBStream &description);
277
278 uint32_t
279 LoadImage (lldb::SBFileSpec &image_spec, lldb::SBError &error);
280
281 lldb::SBError
282 UnloadImage (uint32_t image_token);
Johnny Chen9f074f02012-01-06 00:46:12 +0000283
Greg Clayton1b925202012-01-29 06:07:39 +0000284 %pythoncode %{
Greg Claytonb302dff2012-02-01 08:09:32 +0000285 def __get_is_alive__(self):
286 '''Returns "True" if the process is currently alive, "False" otherwise'''
287 s = self.GetState()
288 if (s == eStateAttaching or
289 s == eStateLaunching or
290 s == eStateStopped or
291 s == eStateRunning or
292 s == eStateStepping or
293 s == eStateCrashed or
294 s == eStateSuspended):
295 return True
296 return False
297
298 def __get_is_running__(self):
299 '''Returns "True" if the process is currently running, "False" otherwise'''
300 state = self.GetState()
301 if state == eStateRunning or state == eStateStepping:
302 return True
303 return False
304
305 def __get_is_running__(self):
306 '''Returns "True" if the process is currently stopped, "False" otherwise'''
307 state = self.GetState()
308 if state == eStateStopped or state == eStateCrashed or state == eStateSuspended:
309 return True
310 return False
311
Greg Claytonb6a5ba62012-02-03 03:22:53 +0000312 class threads_access(object):
Greg Claytonb302dff2012-02-01 08:09:32 +0000313 '''A helper object that will lazily hand out thread for a process when supplied an index.'''
314 def __init__(self, sbprocess):
315 self.sbprocess = sbprocess
316
317 def __len__(self):
318 if self.sbprocess: return self.sbprocess.GetNumThreads()
319 return 0
320
321 def __getitem__(self, key):
322 if type(key) is int and key < len(self):
323 return self.sbprocess.GetThreadAtIndex(key)
324 return None
325
Greg Claytonb6a5ba62012-02-03 03:22:53 +0000326 def get_threads_access_object(self):
327 '''An accessor function that returns a modules_access() object which allows lazy thread access from a lldb.SBProcess object.'''
328 return self.threads_access (self)
Greg Claytonb302dff2012-02-01 08:09:32 +0000329
330 def get_process_thread_list(self):
Greg Claytonb6a5ba62012-02-03 03:22:53 +0000331 '''An accessor function that returns a list() that contains all threads in a lldb.SBProcess object.'''
Greg Claytonb302dff2012-02-01 08:09:32 +0000332 threads = []
333 for idx in range(self.GetNumThreads()):
334 threads.append(GetThreadAtIndex(idx))
335 return threads
336
337 __swig_getmethods__["threads"] = get_process_thread_list
338 if _newclass: x = property(get_process_thread_list, None)
339
Greg Claytonb6a5ba62012-02-03 03:22:53 +0000340 __swig_getmethods__["thread"] = get_threads_access_object
341 if _newclass: x = property(get_threads_access_object, None)
Greg Claytonb302dff2012-02-01 08:09:32 +0000342
343 __swig_getmethods__["is_alive"] = __get_is_alive__
344 if _newclass: x = property(__get_is_alive__, None)
345
346 __swig_getmethods__["is_running"] = __get_is_running__
347 if _newclass: x = property(__get_is_running__, None)
348
349 __swig_getmethods__["is_stopped"] = __get_is_running__
350 if _newclass: x = property(__get_is_running__, None)
351
Greg Clayton1b925202012-01-29 06:07:39 +0000352 __swig_getmethods__["id"] = GetProcessID
353 if _newclass: x = property(GetProcessID, None)
354
355 __swig_getmethods__["target"] = GetTarget
356 if _newclass: x = property(GetTarget, None)
357
358 __swig_getmethods__["num_threads"] = GetNumThreads
359 if _newclass: x = property(GetNumThreads, None)
360
361 __swig_getmethods__["selected_thread"] = GetSelectedThread
362 __swig_setmethods__["selected_thread"] = SetSelectedThread
363 if _newclass: x = property(GetSelectedThread, SetSelectedThread)
364
365 __swig_getmethods__["state"] = GetState
366 if _newclass: x = property(GetState, None)
367
368 __swig_getmethods__["exit_state"] = GetExitStatus
369 if _newclass: x = property(GetExitStatus, None)
370
371 __swig_getmethods__["exit_description"] = GetExitDescription
372 if _newclass: x = property(GetExitDescription, None)
373
374 __swig_getmethods__["broadcaster"] = GetBroadcaster
375 if _newclass: x = property(GetBroadcaster, None)
376 %}
377
Johnny Chenc3fba812011-07-18 20:13:38 +0000378};
379
380} // namespace lldb