blob: da8a28f209ab581f7f75562bc1f6317995ab684b [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);
283};
284
285} // namespace lldb