blob: e597c07d2db27985f4334523f5738e1d9b614dde [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:
44 SBThread ();
45
46 SBThread (const lldb::SBThread &thread);
47
48 ~SBThread();
Jim Ingham4f465cf2012-10-10 18:32:14 +000049
50 static bool
51 EventIsThreadEvent (const SBEvent &event);
52
53 static SBFrame
54 GetStackFrameFromEvent (const SBEvent &event);
55
56 static SBThread
57 GetThreadFromEvent (const SBEvent &event);
Johnny Chen357033b2011-07-18 20:13:38 +000058
59 bool
60 IsValid() const;
61
62 void
63 Clear ();
64
65 lldb::StopReason
66 GetStopReason();
67
68 %feature("docstring", "
69 /// Get the number of words associated with the stop reason.
70 /// See also GetStopReasonDataAtIndex().
71 ") GetStopReasonDataCount;
72 size_t
73 GetStopReasonDataCount();
74
75 %feature("docstring", "
76 //--------------------------------------------------------------------------
77 /// Get information associated with a stop reason.
78 ///
79 /// Breakpoint stop reasons will have data that consists of pairs of
80 /// breakpoint IDs followed by the breakpoint location IDs (they always come
81 /// in pairs).
82 ///
83 /// Stop Reason Count Data Type
84 /// ======================== ===== =========================================
85 /// eStopReasonNone 0
86 /// eStopReasonTrace 0
87 /// eStopReasonBreakpoint N duple: {breakpoint id, location id}
Johnny Chen290fa412011-12-17 02:07:52 +000088 /// eStopReasonWatchpoint 1 watchpoint id
Johnny Chen357033b2011-07-18 20:13:38 +000089 /// eStopReasonSignal 1 unix signal number
90 /// eStopReasonException N exception data
Greg Clayton90ba8112012-12-05 00:16:59 +000091 /// eStopReasonExec 0
Johnny Chen357033b2011-07-18 20:13:38 +000092 /// eStopReasonPlanComplete 0
93 //--------------------------------------------------------------------------
94 ") GetStopReasonDataAtIndex;
95 uint64_t
96 GetStopReasonDataAtIndex(uint32_t idx);
97
Johnny Chencdd7e8b2011-12-19 19:38:09 +000098 %feature("autodoc", "
99 Pass only an (int)length and expect to get a Python string describing the
100 stop reason.
101 ") GetStopDescription;
Johnny Chen357033b2011-07-18 20:13:38 +0000102 size_t
103 GetStopDescription (char *dst, size_t dst_len);
104
Jim Ingham73ca05a2011-12-17 01:35:57 +0000105 SBValue
106 GetStopReturnValue ();
107
Johnny Chen357033b2011-07-18 20:13:38 +0000108 lldb::tid_t
109 GetThreadID () const;
110
111 uint32_t
112 GetIndexID () const;
113
114 const char *
115 GetName () const;
116
117 const char *
118 GetQueueName() const;
119
120 void
121 StepOver (lldb::RunMode stop_other_threads = lldb::eOnlyDuringStepping);
122
123 void
124 StepInto (lldb::RunMode stop_other_threads = lldb::eOnlyDuringStepping);
125
126 void
Jim Inghamc6276822012-12-12 19:58:40 +0000127 StepInto (const char *target_name, lldb::RunMode stop_other_threads = lldb::eOnlyDuringStepping);
128
129 void
Johnny Chen357033b2011-07-18 20:13:38 +0000130 StepOut ();
131
132 void
133 StepOutOfFrame (lldb::SBFrame &frame);
134
135 void
136 StepInstruction(bool step_over);
137
138 SBError
139 StepOverUntil (lldb::SBFrame &frame,
140 lldb::SBFileSpec &file_spec,
141 uint32_t line);
142
143 void
144 RunToAddress (lldb::addr_t addr);
145
Jim Ingham44137582012-09-12 00:40:39 +0000146 SBError
Jim Inghamcb640dd2012-09-14 02:14:15 +0000147 ReturnFromFrame (SBFrame &frame, SBValue &return_value);
Jim Ingham44137582012-09-12 00:40:39 +0000148
Johnny Chen357033b2011-07-18 20:13:38 +0000149 %feature("docstring", "
150 //--------------------------------------------------------------------------
151 /// LLDB currently supports process centric debugging which means when any
152 /// thread in a process stops, all other threads are stopped. The Suspend()
153 /// call here tells our process to suspend a thread and not let it run when
154 /// the other threads in a process are allowed to run. So when
155 /// SBProcess::Continue() is called, any threads that aren't suspended will
156 /// be allowed to run. If any of the SBThread functions for stepping are
157 /// called (StepOver, StepInto, StepOut, StepInstruction, RunToAddres), the
158 /// thread will now be allowed to run and these funtions will simply return.
159 ///
160 /// Eventually we plan to add support for thread centric debugging where
161 /// each thread is controlled individually and each thread would broadcast
162 /// its state, but we haven't implemented this yet.
163 ///
164 /// Likewise the SBThread::Resume() call will again allow the thread to run
165 /// when the process is continued.
166 ///
167 /// Suspend() and Resume() functions are not currently reference counted, if
168 /// anyone has the need for them to be reference counted, please let us
169 /// know.
170 //--------------------------------------------------------------------------
171 ") Suspend;
172 bool
173 Suspend();
174
175 bool
176 Resume ();
177
178 bool
179 IsSuspended();
180
181 uint32_t
182 GetNumFrames ();
183
184 lldb::SBFrame
185 GetFrameAtIndex (uint32_t idx);
186
187 lldb::SBFrame
188 GetSelectedFrame ();
189
190 lldb::SBFrame
191 SetSelectedFrame (uint32_t frame_idx);
192
193 lldb::SBProcess
194 GetProcess ();
195
196 bool
197 GetDescription (lldb::SBStream &description) const;
Greg Clayton13d19502012-01-29 06:07:39 +0000198
Jim Ingham4f465cf2012-10-10 18:32:14 +0000199 bool
200 GetStatus (lldb::SBStream &status) const;
201
Greg Clayton13d19502012-01-29 06:07:39 +0000202 %pythoncode %{
Greg Claytonb62bb8c2012-02-03 03:22:53 +0000203 class frames_access(object):
Greg Clayton6b2bd932012-02-01 08:09:32 +0000204 '''A helper object that will lazily hand out frames for a thread when supplied an index.'''
205 def __init__(self, sbthread):
206 self.sbthread = sbthread
207
208 def __len__(self):
209 if self.sbthread:
Filipe Cabecinhas1a96ef82012-05-11 20:39:42 +0000210 return int(self.sbthread.GetNumFrames())
Greg Clayton6b2bd932012-02-01 08:09:32 +0000211 return 0
212
213 def __getitem__(self, key):
214 if type(key) is int and key < self.sbthread.GetNumFrames():
215 return self.sbthread.GetFrameAtIndex(key)
216 return None
217
Greg Claytonb62bb8c2012-02-03 03:22:53 +0000218 def get_frames_access_object(self):
219 '''An accessor function that returns a frames_access() object which allows lazy frame access from a lldb.SBThread object.'''
220 return self.frames_access (self)
Greg Clayton6b2bd932012-02-01 08:09:32 +0000221
Greg Clayton24155862012-02-01 02:30:27 +0000222 def get_thread_frames(self):
Greg Claytonb62bb8c2012-02-03 03:22:53 +0000223 '''An accessor function that returns a list() that contains all frames in a lldb.SBThread object.'''
Greg Clayton24155862012-02-01 02:30:27 +0000224 frames = []
225 for frame in self:
226 frames.append(frame)
227 return frames
Greg Clayton6b2bd932012-02-01 08:09:32 +0000228
Greg Clayton13d19502012-01-29 06:07:39 +0000229 __swig_getmethods__["id"] = GetThreadID
Greg Clayton5ef31a92012-06-29 22:00:42 +0000230 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 +0000231
232 __swig_getmethods__["idx"] = GetIndexID
Greg Clayton5ef31a92012-06-29 22:00:42 +0000233 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 +0000234
235 __swig_getmethods__["return_value"] = GetStopReturnValue
Greg Clayton5ef31a92012-06-29 22:00:42 +0000236 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 +0000237
238 __swig_getmethods__["process"] = GetProcess
Greg Clayton5ef31a92012-06-29 22:00:42 +0000239 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 +0000240
241 __swig_getmethods__["num_frames"] = GetNumFrames
Greg Clayton5ef31a92012-06-29 22:00:42 +0000242 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 +0000243
Greg Clayton24155862012-02-01 02:30:27 +0000244 __swig_getmethods__["frames"] = get_thread_frames
Greg Clayton5ef31a92012-06-29 22:00:42 +0000245 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 +0000246
Greg Claytonb62bb8c2012-02-03 03:22:53 +0000247 __swig_getmethods__["frame"] = get_frames_access_object
Greg Clayton5ef31a92012-06-29 22:00:42 +0000248 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 +0000249
Greg Clayton13d19502012-01-29 06:07:39 +0000250 __swig_getmethods__["name"] = GetName
Greg Clayton5ef31a92012-06-29 22:00:42 +0000251 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 +0000252
253 __swig_getmethods__["queue"] = GetQueueName
Greg Clayton5ef31a92012-06-29 22:00:42 +0000254 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 +0000255
256 __swig_getmethods__["stop_reason"] = GetStopReason
Greg Clayton5ef31a92012-06-29 22:00:42 +0000257 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 +0000258
259 __swig_getmethods__["is_suspended"] = IsSuspended
Greg Clayton5ef31a92012-06-29 22:00:42 +0000260 if _newclass: is_suspended = property(IsSuspended, None, doc='''A read only property that returns a boolean value that indicates if this thread is suspended.''')
Greg Clayton13d19502012-01-29 06:07:39 +0000261 %}
262
Johnny Chen357033b2011-07-18 20:13:38 +0000263};
264
265} // namespace lldb