blob: 76a014a6ecaaaac64c05d85d314ba2af92f8eccc [file] [log] [blame]
Johnny Chenc3fba812011-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 Inghamefbdd222012-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 Chenc3fba812011-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 Ingham94a5d0d2012-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 Chenc3fba812011-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 Chenbcbefa82011-12-17 02:07:52 +000088 /// eStopReasonWatchpoint 1 watchpoint id
Johnny Chenc3fba812011-07-18 20:13:38 +000089 /// eStopReasonSignal 1 unix signal number
90 /// eStopReasonException N exception data
91 /// eStopReasonPlanComplete 0
92 //--------------------------------------------------------------------------
93 ") GetStopReasonDataAtIndex;
94 uint64_t
95 GetStopReasonDataAtIndex(uint32_t idx);
96
Johnny Chen65f4fb02011-12-19 19:38:09 +000097 %feature("autodoc", "
98 Pass only an (int)length and expect to get a Python string describing the
99 stop reason.
100 ") GetStopDescription;
Johnny Chenc3fba812011-07-18 20:13:38 +0000101 size_t
102 GetStopDescription (char *dst, size_t dst_len);
103
Jim Ingham1586d972011-12-17 01:35:57 +0000104 SBValue
105 GetStopReturnValue ();
106
Johnny Chenc3fba812011-07-18 20:13:38 +0000107 lldb::tid_t
108 GetThreadID () const;
109
110 uint32_t
111 GetIndexID () const;
112
113 const char *
114 GetName () const;
115
116 const char *
117 GetQueueName() const;
118
119 void
120 StepOver (lldb::RunMode stop_other_threads = lldb::eOnlyDuringStepping);
121
122 void
123 StepInto (lldb::RunMode stop_other_threads = lldb::eOnlyDuringStepping);
124
125 void
126 StepOut ();
127
128 void
129 StepOutOfFrame (lldb::SBFrame &frame);
130
131 void
132 StepInstruction(bool step_over);
133
134 SBError
135 StepOverUntil (lldb::SBFrame &frame,
136 lldb::SBFileSpec &file_spec,
137 uint32_t line);
138
139 void
140 RunToAddress (lldb::addr_t addr);
141
Jim Inghama17a81a2012-09-12 00:40:39 +0000142 SBError
Jim Inghamf59388a2012-09-14 02:14:15 +0000143 ReturnFromFrame (SBFrame &frame, SBValue &return_value);
Jim Inghama17a81a2012-09-12 00:40:39 +0000144
Johnny Chenc3fba812011-07-18 20:13:38 +0000145 %feature("docstring", "
146 //--------------------------------------------------------------------------
147 /// LLDB currently supports process centric debugging which means when any
148 /// thread in a process stops, all other threads are stopped. The Suspend()
149 /// call here tells our process to suspend a thread and not let it run when
150 /// the other threads in a process are allowed to run. So when
151 /// SBProcess::Continue() is called, any threads that aren't suspended will
152 /// be allowed to run. If any of the SBThread functions for stepping are
153 /// called (StepOver, StepInto, StepOut, StepInstruction, RunToAddres), the
154 /// thread will now be allowed to run and these funtions will simply return.
155 ///
156 /// Eventually we plan to add support for thread centric debugging where
157 /// each thread is controlled individually and each thread would broadcast
158 /// its state, but we haven't implemented this yet.
159 ///
160 /// Likewise the SBThread::Resume() call will again allow the thread to run
161 /// when the process is continued.
162 ///
163 /// Suspend() and Resume() functions are not currently reference counted, if
164 /// anyone has the need for them to be reference counted, please let us
165 /// know.
166 //--------------------------------------------------------------------------
167 ") Suspend;
168 bool
169 Suspend();
170
171 bool
172 Resume ();
173
174 bool
175 IsSuspended();
176
177 uint32_t
178 GetNumFrames ();
179
180 lldb::SBFrame
181 GetFrameAtIndex (uint32_t idx);
182
183 lldb::SBFrame
184 GetSelectedFrame ();
185
186 lldb::SBFrame
187 SetSelectedFrame (uint32_t frame_idx);
188
189 lldb::SBProcess
190 GetProcess ();
191
192 bool
193 GetDescription (lldb::SBStream &description) const;
Greg Clayton1b925202012-01-29 06:07:39 +0000194
Jim Ingham94a5d0d2012-10-10 18:32:14 +0000195 bool
196 GetStatus (lldb::SBStream &status) const;
197
Greg Clayton1b925202012-01-29 06:07:39 +0000198 %pythoncode %{
Greg Claytonb6a5ba62012-02-03 03:22:53 +0000199 class frames_access(object):
Greg Claytonb302dff2012-02-01 08:09:32 +0000200 '''A helper object that will lazily hand out frames for a thread when supplied an index.'''
201 def __init__(self, sbthread):
202 self.sbthread = sbthread
203
204 def __len__(self):
205 if self.sbthread:
Filipe Cabecinhas3cae38b2012-05-11 20:39:42 +0000206 return int(self.sbthread.GetNumFrames())
Greg Claytonb302dff2012-02-01 08:09:32 +0000207 return 0
208
209 def __getitem__(self, key):
210 if type(key) is int and key < self.sbthread.GetNumFrames():
211 return self.sbthread.GetFrameAtIndex(key)
212 return None
213
Greg Claytonb6a5ba62012-02-03 03:22:53 +0000214 def get_frames_access_object(self):
215 '''An accessor function that returns a frames_access() object which allows lazy frame access from a lldb.SBThread object.'''
216 return self.frames_access (self)
Greg Claytonb302dff2012-02-01 08:09:32 +0000217
Greg Clayton394da8e2012-02-01 02:30:27 +0000218 def get_thread_frames(self):
Greg Claytonb6a5ba62012-02-03 03:22:53 +0000219 '''An accessor function that returns a list() that contains all frames in a lldb.SBThread object.'''
Greg Clayton394da8e2012-02-01 02:30:27 +0000220 frames = []
221 for frame in self:
222 frames.append(frame)
223 return frames
Greg Claytonb302dff2012-02-01 08:09:32 +0000224
Greg Clayton1b925202012-01-29 06:07:39 +0000225 __swig_getmethods__["id"] = GetThreadID
Greg Clayton2a94be12012-06-29 22:00:42 +0000226 if _newclass: id = property(GetThreadID, None, doc='''A read only property that returns the thread ID as an integer.''')
Greg Clayton1b925202012-01-29 06:07:39 +0000227
228 __swig_getmethods__["idx"] = GetIndexID
Greg Clayton2a94be12012-06-29 22:00:42 +0000229 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 Clayton1b925202012-01-29 06:07:39 +0000230
231 __swig_getmethods__["return_value"] = GetStopReturnValue
Greg Clayton2a94be12012-06-29 22:00:42 +0000232 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 Clayton1b925202012-01-29 06:07:39 +0000233
234 __swig_getmethods__["process"] = GetProcess
Greg Clayton2a94be12012-06-29 22:00:42 +0000235 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 Clayton1b925202012-01-29 06:07:39 +0000236
237 __swig_getmethods__["num_frames"] = GetNumFrames
Greg Clayton2a94be12012-06-29 22:00:42 +0000238 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 Clayton1b925202012-01-29 06:07:39 +0000239
Greg Clayton394da8e2012-02-01 02:30:27 +0000240 __swig_getmethods__["frames"] = get_thread_frames
Greg Clayton2a94be12012-06-29 22:00:42 +0000241 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 Clayton394da8e2012-02-01 02:30:27 +0000242
Greg Claytonb6a5ba62012-02-03 03:22:53 +0000243 __swig_getmethods__["frame"] = get_frames_access_object
Greg Clayton2a94be12012-06-29 22:00:42 +0000244 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 Claytonb302dff2012-02-01 08:09:32 +0000245
Greg Clayton1b925202012-01-29 06:07:39 +0000246 __swig_getmethods__["name"] = GetName
Greg Clayton2a94be12012-06-29 22:00:42 +0000247 if _newclass: name = property(GetName, None, doc='''A read only property that returns the name of this thread as a string.''')
Greg Clayton1b925202012-01-29 06:07:39 +0000248
249 __swig_getmethods__["queue"] = GetQueueName
Greg Clayton2a94be12012-06-29 22:00:42 +0000250 if _newclass: queue = property(GetQueueName, None, doc='''A read only property that returns the dispatch queue name of this thread as a string.''')
Greg Clayton1b925202012-01-29 06:07:39 +0000251
252 __swig_getmethods__["stop_reason"] = GetStopReason
Greg Clayton2a94be12012-06-29 22:00:42 +0000253 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 Clayton1b925202012-01-29 06:07:39 +0000254
255 __swig_getmethods__["is_suspended"] = IsSuspended
Greg Clayton2a94be12012-06-29 22:00:42 +0000256 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 Clayton1b925202012-01-29 06:07:39 +0000257 %}
258
Johnny Chenc3fba812011-07-18 20:13:38 +0000259};
260
261} // namespace lldb