blob: 538482143521001eecf1842f00979931d77bcdde [file] [log] [blame]
Johnny Chen357033b2011-07-18 20:13:38 +00001//===-- SWIG Interface for SBThread -----------------------------*- 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 a thread of execution. SBProcess contains SBThread(s).
14
Jim Ingham18b46892012-07-13 20:18:18 +000015SBThreads can be referred to by their ID, which maps to the system specific thread
16identifier, or by IndexID. The ID may or may not be unique depending on whether the
17system reuses its thread identifiers. The IndexID is a monotonically increasing identifier
18that will always uniquely reference a particular thread, and when that thread goes
19away it will not be reused.
20
Johnny Chen357033b2011-07-18 20:13:38 +000021SBThread supports frame iteration. For example (from test/python_api/
22lldbutil/iter/TestLLDBIterator.py),
23
24 from lldbutil import print_stacktrace
25 stopped_due_to_breakpoint = False
26 for thread in process:
27 if self.TraceOn():
28 print_stacktrace(thread)
29 ID = thread.GetThreadID()
30 if thread.GetStopReason() == lldb.eStopReasonBreakpoint:
31 stopped_due_to_breakpoint = True
32 for frame in thread:
33 self.assertTrue(frame.GetThread().GetThreadID() == ID)
34 if self.TraceOn():
35 print frame
36
37 self.assertTrue(stopped_due_to_breakpoint)
38
39See also SBProcess and SBFrame."
40) SBThread;
41class SBThread
42{
43public:
Daniel Malea54e14612013-10-03 22:21:09 +000044 //------------------------------------------------------------------
45 // Broadcaster bits.
46 //------------------------------------------------------------------
47 enum
48 {
49 eBroadcastBitStackChanged = (1 << 0),
50 eBroadcastBitThreadSuspended = (1 << 1),
51 eBroadcastBitThreadResumed = (1 << 2),
52 eBroadcastBitSelectedFrameChanged = (1 << 3),
53 eBroadcastBitThreadSelected = (1 << 4)
54 };
55
56
Johnny Chen357033b2011-07-18 20:13:38 +000057 SBThread ();
58
59 SBThread (const lldb::SBThread &thread);
60
61 ~SBThread();
Daniel Malea54e14612013-10-03 22:21:09 +000062
63 static const char *
64 GetBroadcasterClassName ();
Jim Ingham4f465cf2012-10-10 18:32:14 +000065
66 static bool
67 EventIsThreadEvent (const SBEvent &event);
68
69 static SBFrame
70 GetStackFrameFromEvent (const SBEvent &event);
71
72 static SBThread
73 GetThreadFromEvent (const SBEvent &event);
Johnny Chen357033b2011-07-18 20:13:38 +000074
75 bool
76 IsValid() const;
77
78 void
79 Clear ();
80
81 lldb::StopReason
82 GetStopReason();
83
84 %feature("docstring", "
85 /// Get the number of words associated with the stop reason.
86 /// See also GetStopReasonDataAtIndex().
87 ") GetStopReasonDataCount;
88 size_t
89 GetStopReasonDataCount();
90
91 %feature("docstring", "
92 //--------------------------------------------------------------------------
93 /// Get information associated with a stop reason.
94 ///
95 /// Breakpoint stop reasons will have data that consists of pairs of
96 /// breakpoint IDs followed by the breakpoint location IDs (they always come
97 /// in pairs).
98 ///
99 /// Stop Reason Count Data Type
100 /// ======================== ===== =========================================
101 /// eStopReasonNone 0
102 /// eStopReasonTrace 0
103 /// eStopReasonBreakpoint N duple: {breakpoint id, location id}
Johnny Chen290fa412011-12-17 02:07:52 +0000104 /// eStopReasonWatchpoint 1 watchpoint id
Johnny Chen357033b2011-07-18 20:13:38 +0000105 /// eStopReasonSignal 1 unix signal number
106 /// eStopReasonException N exception data
Greg Clayton90ba8112012-12-05 00:16:59 +0000107 /// eStopReasonExec 0
Johnny Chen357033b2011-07-18 20:13:38 +0000108 /// eStopReasonPlanComplete 0
109 //--------------------------------------------------------------------------
110 ") GetStopReasonDataAtIndex;
111 uint64_t
112 GetStopReasonDataAtIndex(uint32_t idx);
Kuba Breckaafdf8422014-10-10 23:43:03 +0000113
114 %feature("autodoc", "
115 Collects a thread's stop reason extended information dictionary and prints it
116 into the SBStream in a JSON format. The format of this JSON dictionary depends
117 on the stop reason and is currently used only for instrumentation plugins.
118 ") GetStopReasonExtendedInfoAsJSON;
119 bool
120 GetStopReasonExtendedInfoAsJSON (lldb::SBStream &stream);
Johnny Chen357033b2011-07-18 20:13:38 +0000121
Johnny Chencdd7e8b2011-12-19 19:38:09 +0000122 %feature("autodoc", "
123 Pass only an (int)length and expect to get a Python string describing the
124 stop reason.
125 ") GetStopDescription;
Johnny Chen357033b2011-07-18 20:13:38 +0000126 size_t
127 GetStopDescription (char *dst, size_t dst_len);
128
Jim Ingham73ca05a2011-12-17 01:35:57 +0000129 SBValue
130 GetStopReturnValue ();
131
Jason Molenda2fd83352014-02-05 05:44:54 +0000132 %feature("autodoc", "
133 Returns a unique thread identifier (type lldb::tid_t, typically a 64-bit type)
134 for the current SBThread that will remain constant throughout the thread's
135 lifetime in this process and will not be reused by another thread during this
136 process lifetime. On Mac OS X systems, this is a system-wide unique thread
137 identifier; this identifier is also used by other tools like sample which helps
138 to associate data from those tools with lldb. See related GetIndexID.
139 ")
140 GetThreadID;
Johnny Chen357033b2011-07-18 20:13:38 +0000141 lldb::tid_t
142 GetThreadID () const;
143
Jason Molenda2fd83352014-02-05 05:44:54 +0000144 %feature("autodoc", "
145 Return the index number for this SBThread. The index number is the same thing
146 that a user gives as an argument to 'thread select' in the command line lldb.
147 These numbers start at 1 (for the first thread lldb sees in a debug session)
148 and increments up throughout the process lifetime. An index number will not be
149 reused for a different thread later in a process - thread 1 will always be
150 associated with the same thread. See related GetThreadID.
151 This method returns a uint32_t index number, takes no arguments.
152 ")
153 GetIndexID;
Johnny Chen357033b2011-07-18 20:13:38 +0000154 uint32_t
155 GetIndexID () const;
156
157 const char *
158 GetName () const;
159
Jason Molenda8c713372013-11-05 11:00:35 +0000160 %feature("autodoc", "
161 Return the queue name associated with this thread, if any, as a str.
162 For example, with a libdispatch (aka Grand Central Dispatch) queue.
163 ") GetQueueName;
164
Johnny Chen357033b2011-07-18 20:13:38 +0000165 const char *
166 GetQueueName() const;
167
Jason Molenda8c713372013-11-05 11:00:35 +0000168 %feature("autodoc", "
169 Return the dispatch_queue_id for this thread, if any, as a lldb::queue_id_t.
170 For example, with a libdispatch (aka Grand Central Dispatch) queue.
171 ") GetQueueID;
172
Jason Molenda4fdb5862013-10-21 23:52:54 +0000173 lldb::queue_id_t
174 GetQueueID() const;
175
Jason Molendab9ffa982014-04-25 00:01:15 +0000176 %feature("autodoc", "
Jason Molenda705b1802014-06-13 02:37:02 +0000177 Takes a path string and a SBStream reference as parameters, returns a bool.
178 Collects the thread's 'info' dictionary from the remote system, uses the path
179 argument to descend into the dictionary to an item of interest, and prints
180 it into the SBStream in a natural format. Return bool is to indicate if
181 anything was printed into the stream (true) or not (false).
182 ") GetInfoItemByPathAsString;
183
184 bool
185 GetInfoItemByPathAsString (const char *path, lldb::SBStream &strm);
186
187 %feature("autodoc", "
Jason Molendab9ffa982014-04-25 00:01:15 +0000188 Return the SBQueue for this thread. If this thread is not currently associated
189 with a libdispatch queue, the SBQueue object's IsValid() method will return false.
190 If this SBThread is actually a HistoryThread, we may be able to provide QueueID
191 and QueueName, but not provide an SBQueue. Those individual attributes may have
192 been saved for the HistoryThread without enough information to reconstitute the
193 entire SBQueue at that time.
194 This method takes no arguments, returns an SBQueue.
195 ") GetQueue;
196
197 lldb::SBQueue
198 GetQueue () const;
199
Johnny Chen357033b2011-07-18 20:13:38 +0000200 void
201 StepOver (lldb::RunMode stop_other_threads = lldb::eOnlyDuringStepping);
202
203 void
204 StepInto (lldb::RunMode stop_other_threads = lldb::eOnlyDuringStepping);
205
206 void
Jim Inghamc6276822012-12-12 19:58:40 +0000207 StepInto (const char *target_name, lldb::RunMode stop_other_threads = lldb::eOnlyDuringStepping);
208
209 void
Johnny Chen357033b2011-07-18 20:13:38 +0000210 StepOut ();
211
212 void
213 StepOutOfFrame (lldb::SBFrame &frame);
214
215 void
216 StepInstruction(bool step_over);
217
218 SBError
Richard Mittonf86248d2013-09-12 02:20:34 +0000219 StepOverUntil (lldb::SBFrame &frame,
220 lldb::SBFileSpec &file_spec,
Johnny Chen357033b2011-07-18 20:13:38 +0000221 uint32_t line);
222
Richard Mittonf86248d2013-09-12 02:20:34 +0000223 SBError
Jim Ingham2bdbfd52014-09-29 23:17:18 +0000224 StepUsingScriptedThreadPlan (const char *script_class_name);
225
226 SBError
Richard Mittonf86248d2013-09-12 02:20:34 +0000227 JumpToLine (lldb::SBFileSpec &file_spec, uint32_t line);
228
Johnny Chen357033b2011-07-18 20:13:38 +0000229 void
230 RunToAddress (lldb::addr_t addr);
231
Jim Ingham44137582012-09-12 00:40:39 +0000232 SBError
Jim Inghamcb640dd2012-09-14 02:14:15 +0000233 ReturnFromFrame (SBFrame &frame, SBValue &return_value);
Jim Ingham44137582012-09-12 00:40:39 +0000234
Johnny Chen357033b2011-07-18 20:13:38 +0000235 %feature("docstring", "
236 //--------------------------------------------------------------------------
237 /// LLDB currently supports process centric debugging which means when any
238 /// thread in a process stops, all other threads are stopped. The Suspend()
239 /// call here tells our process to suspend a thread and not let it run when
240 /// the other threads in a process are allowed to run. So when
241 /// SBProcess::Continue() is called, any threads that aren't suspended will
242 /// be allowed to run. If any of the SBThread functions for stepping are
243 /// called (StepOver, StepInto, StepOut, StepInstruction, RunToAddres), the
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +0000244 /// thread will now be allowed to run and these functions will simply return.
Johnny Chen357033b2011-07-18 20:13:38 +0000245 ///
246 /// Eventually we plan to add support for thread centric debugging where
247 /// each thread is controlled individually and each thread would broadcast
248 /// its state, but we haven't implemented this yet.
249 ///
250 /// Likewise the SBThread::Resume() call will again allow the thread to run
251 /// when the process is continued.
252 ///
253 /// Suspend() and Resume() functions are not currently reference counted, if
254 /// anyone has the need for them to be reference counted, please let us
255 /// know.
256 //--------------------------------------------------------------------------
257 ") Suspend;
258 bool
259 Suspend();
260
261 bool
262 Resume ();
263
264 bool
265 IsSuspended();
266
Andrew Kaylora75418d2013-04-15 23:33:53 +0000267 bool
268 IsStopped();
269
Johnny Chen357033b2011-07-18 20:13:38 +0000270 uint32_t
271 GetNumFrames ();
272
273 lldb::SBFrame
274 GetFrameAtIndex (uint32_t idx);
275
276 lldb::SBFrame
277 GetSelectedFrame ();
278
279 lldb::SBFrame
280 SetSelectedFrame (uint32_t frame_idx);
281
282 lldb::SBProcess
283 GetProcess ();
284
285 bool
286 GetDescription (lldb::SBStream &description) const;
Greg Clayton13d19502012-01-29 06:07:39 +0000287
Jim Ingham4f465cf2012-10-10 18:32:14 +0000288 bool
289 GetStatus (lldb::SBStream &status) const;
290
Enrico Granatac3387332013-05-03 01:29:27 +0000291 bool
292 operator == (const lldb::SBThread &rhs) const;
293
294 bool
295 operator != (const lldb::SBThread &rhs) const;
Jason Molenda8ee9cb52013-11-16 01:24:22 +0000296
Jason Molenda5dd49162013-11-06 00:04:44 +0000297 %feature("autodoc","
298 Given an argument of str to specify the type of thread-origin extended
299 backtrace to retrieve, query whether the origin of this thread is
300 available. An SBThread is retured; SBThread.IsValid will return true
301 if an extended backtrace was available. The returned SBThread is not
302 a part of the SBProcess' thread list and it cannot be manipulated like
303 normal threads -- you cannot step or resume it, for instance -- it is
304 intended to used primarily for generating a backtrace. You may request
305 the returned thread's own thread origin in turn.
Jason Molenda008c45f2013-11-12 23:33:32 +0000306 ") GetExtendedBacktraceThread;
Jason Molenda5dd49162013-11-06 00:04:44 +0000307 lldb::SBThread
Jason Molenda008c45f2013-11-12 23:33:32 +0000308 GetExtendedBacktraceThread (const char *type);
Jason Molenda5dd49162013-11-06 00:04:44 +0000309
Jason Molenda8ee9cb52013-11-16 01:24:22 +0000310 %feature("autodoc","
311 Takes no arguments, returns a uint32_t.
312 If this SBThread is an ExtendedBacktrace thread, get the IndexID of the
313 original thread that this ExtendedBacktrace thread represents, if
314 available. The thread that was running this backtrace in the past may
315 not have been registered with lldb's thread index (if it was created,
316 did its work, and was destroyed without lldb ever stopping execution).
317 In that case, this ExtendedBacktrace thread's IndexID will be returned.
318 ") GetExtendedBacktraceOriginatingIndexID;
319 uint32_t
320 GetExtendedBacktraceOriginatingIndexID();
321
Jason Molendab4892cd2014-05-13 22:02:48 +0000322 %feature("autodoc","
323 Takes no arguments, returns a bool.
324 lldb may be able to detect that function calls should not be executed
325 on a given thread at a particular point in time. It is recommended that
326 this is checked before performing an inferior function call on a given
327 thread.
328 ") SafeToCallFunctions;
329 bool
330 SafeToCallFunctions ();
331
Greg Clayton13d19502012-01-29 06:07:39 +0000332 %pythoncode %{
Greg Claytonb62bb8c2012-02-03 03:22:53 +0000333 class frames_access(object):
Greg Clayton6b2bd932012-02-01 08:09:32 +0000334 '''A helper object that will lazily hand out frames for a thread when supplied an index.'''
335 def __init__(self, sbthread):
336 self.sbthread = sbthread
337
338 def __len__(self):
339 if self.sbthread:
Filipe Cabecinhas1a96ef82012-05-11 20:39:42 +0000340 return int(self.sbthread.GetNumFrames())
Greg Clayton6b2bd932012-02-01 08:09:32 +0000341 return 0
342
343 def __getitem__(self, key):
344 if type(key) is int and key < self.sbthread.GetNumFrames():
345 return self.sbthread.GetFrameAtIndex(key)
346 return None
347
Greg Claytonb62bb8c2012-02-03 03:22:53 +0000348 def get_frames_access_object(self):
349 '''An accessor function that returns a frames_access() object which allows lazy frame access from a lldb.SBThread object.'''
350 return self.frames_access (self)
Greg Clayton6b2bd932012-02-01 08:09:32 +0000351
Greg Clayton24155862012-02-01 02:30:27 +0000352 def get_thread_frames(self):
Greg Claytonb62bb8c2012-02-03 03:22:53 +0000353 '''An accessor function that returns a list() that contains all frames in a lldb.SBThread object.'''
Greg Clayton24155862012-02-01 02:30:27 +0000354 frames = []
355 for frame in self:
356 frames.append(frame)
357 return frames
Greg Clayton6b2bd932012-02-01 08:09:32 +0000358
Greg Clayton13d19502012-01-29 06:07:39 +0000359 __swig_getmethods__["id"] = GetThreadID
Greg Clayton5ef31a92012-06-29 22:00:42 +0000360 if _newclass: id = property(GetThreadID, None, doc='''A read only property that returns the thread ID as an integer.''')
Greg Clayton13d19502012-01-29 06:07:39 +0000361
362 __swig_getmethods__["idx"] = GetIndexID
Greg Clayton5ef31a92012-06-29 22:00:42 +0000363 if _newclass: idx = property(GetIndexID, None, doc='''A read only property that returns the thread index ID as an integer. Thread index ID values start at 1 and increment as threads come and go and can be used to uniquely identify threads.''')
Greg Clayton13d19502012-01-29 06:07:39 +0000364
365 __swig_getmethods__["return_value"] = GetStopReturnValue
Greg Clayton5ef31a92012-06-29 22:00:42 +0000366 if _newclass: return_value = property(GetStopReturnValue, None, doc='''A read only property that returns an lldb object that represents the return value from the last stop (lldb.SBValue) if we just stopped due to stepping out of a function.''')
Greg Clayton13d19502012-01-29 06:07:39 +0000367
368 __swig_getmethods__["process"] = GetProcess
Greg Clayton5ef31a92012-06-29 22:00:42 +0000369 if _newclass: process = property(GetProcess, None, doc='''A read only property that returns an lldb object that represents the process (lldb.SBProcess) that owns this thread.''')
Greg Clayton13d19502012-01-29 06:07:39 +0000370
371 __swig_getmethods__["num_frames"] = GetNumFrames
Greg Clayton5ef31a92012-06-29 22:00:42 +0000372 if _newclass: num_frames = property(GetNumFrames, None, doc='''A read only property that returns the number of stack frames in this thread as an integer.''')
Greg Clayton13d19502012-01-29 06:07:39 +0000373
Greg Clayton24155862012-02-01 02:30:27 +0000374 __swig_getmethods__["frames"] = get_thread_frames
Greg Clayton5ef31a92012-06-29 22:00:42 +0000375 if _newclass: frames = property(get_thread_frames, None, doc='''A read only property that returns a list() of lldb.SBFrame objects for all frames in this thread.''')
Greg Clayton24155862012-02-01 02:30:27 +0000376
Greg Claytonb62bb8c2012-02-03 03:22:53 +0000377 __swig_getmethods__["frame"] = get_frames_access_object
Greg Clayton5ef31a92012-06-29 22:00:42 +0000378 if _newclass: frame = property(get_frames_access_object, None, doc='''A read only property that returns an object that can be used to access frames as an array ("frame_12 = lldb.thread.frame[12]").''')
Greg Clayton6b2bd932012-02-01 08:09:32 +0000379
Greg Clayton13d19502012-01-29 06:07:39 +0000380 __swig_getmethods__["name"] = GetName
Greg Clayton5ef31a92012-06-29 22:00:42 +0000381 if _newclass: name = property(GetName, None, doc='''A read only property that returns the name of this thread as a string.''')
Greg Clayton13d19502012-01-29 06:07:39 +0000382
383 __swig_getmethods__["queue"] = GetQueueName
Greg Clayton5ef31a92012-06-29 22:00:42 +0000384 if _newclass: queue = property(GetQueueName, None, doc='''A read only property that returns the dispatch queue name of this thread as a string.''')
Greg Clayton13d19502012-01-29 06:07:39 +0000385
Jason Molenda4fdb5862013-10-21 23:52:54 +0000386 __swig_getmethods__["queue_id"] = GetQueueID
Jason Molenda5e873db2013-10-22 01:37:18 +0000387 if _newclass: queue_id = property(GetQueueID, None, doc='''A read only property that returns the dispatch queue id of this thread as an integer.''')
Jason Molenda4fdb5862013-10-21 23:52:54 +0000388
Greg Clayton13d19502012-01-29 06:07:39 +0000389 __swig_getmethods__["stop_reason"] = GetStopReason
Greg Clayton5ef31a92012-06-29 22:00:42 +0000390 if _newclass: stop_reason = property(GetStopReason, None, doc='''A read only property that returns an lldb enumeration value (see enumerations that start with "lldb.eStopReason") that represents the reason this thread stopped.''')
Greg Clayton13d19502012-01-29 06:07:39 +0000391
392 __swig_getmethods__["is_suspended"] = IsSuspended
Greg Clayton5ef31a92012-06-29 22:00:42 +0000393 if _newclass: is_suspended = property(IsSuspended, None, doc='''A read only property that returns a boolean value that indicates if this thread is suspended.''')
Andrew Kaylora75418d2013-04-15 23:33:53 +0000394
395 __swig_getmethods__["is_stopped"] = IsStopped
396 if _newclass: is_stopped = property(IsStopped, None, doc='''A read only property that returns a boolean value that indicates if this thread is stopped but not exited.''')
Greg Clayton13d19502012-01-29 06:07:39 +0000397 %}
398
Johnny Chen357033b2011-07-18 20:13:38 +0000399};
400
401} // namespace lldb