blob: ac6e699fcc610e1f5cfb42dc55da4c81fd02b620 [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
15SBThread supports frame iteration. For example (from test/python_api/
16lldbutil/iter/TestLLDBIterator.py),
17
18 from lldbutil import print_stacktrace
19 stopped_due_to_breakpoint = False
20 for thread in process:
21 if self.TraceOn():
22 print_stacktrace(thread)
23 ID = thread.GetThreadID()
24 if thread.GetStopReason() == lldb.eStopReasonBreakpoint:
25 stopped_due_to_breakpoint = True
26 for frame in thread:
27 self.assertTrue(frame.GetThread().GetThreadID() == ID)
28 if self.TraceOn():
29 print frame
30
31 self.assertTrue(stopped_due_to_breakpoint)
32
33See also SBProcess and SBFrame."
34) SBThread;
35class SBThread
36{
37public:
38 SBThread ();
39
40 SBThread (const lldb::SBThread &thread);
41
42 ~SBThread();
43
44 bool
45 IsValid() const;
46
47 void
48 Clear ();
49
50 lldb::StopReason
51 GetStopReason();
52
53 %feature("docstring", "
54 /// Get the number of words associated with the stop reason.
55 /// See also GetStopReasonDataAtIndex().
56 ") GetStopReasonDataCount;
57 size_t
58 GetStopReasonDataCount();
59
60 %feature("docstring", "
61 //--------------------------------------------------------------------------
62 /// Get information associated with a stop reason.
63 ///
64 /// Breakpoint stop reasons will have data that consists of pairs of
65 /// breakpoint IDs followed by the breakpoint location IDs (they always come
66 /// in pairs).
67 ///
68 /// Stop Reason Count Data Type
69 /// ======================== ===== =========================================
70 /// eStopReasonNone 0
71 /// eStopReasonTrace 0
72 /// eStopReasonBreakpoint N duple: {breakpoint id, location id}
Johnny Chenbcbefa82011-12-17 02:07:52 +000073 /// eStopReasonWatchpoint 1 watchpoint id
Johnny Chenc3fba812011-07-18 20:13:38 +000074 /// eStopReasonSignal 1 unix signal number
75 /// eStopReasonException N exception data
76 /// eStopReasonPlanComplete 0
77 //--------------------------------------------------------------------------
78 ") GetStopReasonDataAtIndex;
79 uint64_t
80 GetStopReasonDataAtIndex(uint32_t idx);
81
Johnny Chen65f4fb02011-12-19 19:38:09 +000082 %feature("autodoc", "
83 Pass only an (int)length and expect to get a Python string describing the
84 stop reason.
85 ") GetStopDescription;
Johnny Chenc3fba812011-07-18 20:13:38 +000086 size_t
87 GetStopDescription (char *dst, size_t dst_len);
88
Jim Ingham1586d972011-12-17 01:35:57 +000089 SBValue
90 GetStopReturnValue ();
91
Johnny Chenc3fba812011-07-18 20:13:38 +000092 lldb::tid_t
93 GetThreadID () const;
94
95 uint32_t
96 GetIndexID () const;
97
98 const char *
99 GetName () const;
100
101 const char *
102 GetQueueName() const;
103
104 void
105 StepOver (lldb::RunMode stop_other_threads = lldb::eOnlyDuringStepping);
106
107 void
108 StepInto (lldb::RunMode stop_other_threads = lldb::eOnlyDuringStepping);
109
110 void
111 StepOut ();
112
113 void
114 StepOutOfFrame (lldb::SBFrame &frame);
115
116 void
117 StepInstruction(bool step_over);
118
119 SBError
120 StepOverUntil (lldb::SBFrame &frame,
121 lldb::SBFileSpec &file_spec,
122 uint32_t line);
123
124 void
125 RunToAddress (lldb::addr_t addr);
126
127 %feature("docstring", "
128 //--------------------------------------------------------------------------
129 /// LLDB currently supports process centric debugging which means when any
130 /// thread in a process stops, all other threads are stopped. The Suspend()
131 /// call here tells our process to suspend a thread and not let it run when
132 /// the other threads in a process are allowed to run. So when
133 /// SBProcess::Continue() is called, any threads that aren't suspended will
134 /// be allowed to run. If any of the SBThread functions for stepping are
135 /// called (StepOver, StepInto, StepOut, StepInstruction, RunToAddres), the
136 /// thread will now be allowed to run and these funtions will simply return.
137 ///
138 /// Eventually we plan to add support for thread centric debugging where
139 /// each thread is controlled individually and each thread would broadcast
140 /// its state, but we haven't implemented this yet.
141 ///
142 /// Likewise the SBThread::Resume() call will again allow the thread to run
143 /// when the process is continued.
144 ///
145 /// Suspend() and Resume() functions are not currently reference counted, if
146 /// anyone has the need for them to be reference counted, please let us
147 /// know.
148 //--------------------------------------------------------------------------
149 ") Suspend;
150 bool
151 Suspend();
152
153 bool
154 Resume ();
155
156 bool
157 IsSuspended();
158
159 uint32_t
160 GetNumFrames ();
161
162 lldb::SBFrame
163 GetFrameAtIndex (uint32_t idx);
164
165 lldb::SBFrame
166 GetSelectedFrame ();
167
168 lldb::SBFrame
169 SetSelectedFrame (uint32_t frame_idx);
170
171 lldb::SBProcess
172 GetProcess ();
173
174 bool
175 GetDescription (lldb::SBStream &description) const;
Greg Clayton1b925202012-01-29 06:07:39 +0000176
177 %pythoncode %{
Greg Claytonb6a5ba62012-02-03 03:22:53 +0000178 class frames_access(object):
Greg Claytonb302dff2012-02-01 08:09:32 +0000179 '''A helper object that will lazily hand out frames for a thread when supplied an index.'''
180 def __init__(self, sbthread):
181 self.sbthread = sbthread
182
183 def __len__(self):
184 if self.sbthread:
Filipe Cabecinhas3cae38b2012-05-11 20:39:42 +0000185 return int(self.sbthread.GetNumFrames())
Greg Claytonb302dff2012-02-01 08:09:32 +0000186 return 0
187
188 def __getitem__(self, key):
189 if type(key) is int and key < self.sbthread.GetNumFrames():
190 return self.sbthread.GetFrameAtIndex(key)
191 return None
192
Greg Claytonb6a5ba62012-02-03 03:22:53 +0000193 def get_frames_access_object(self):
194 '''An accessor function that returns a frames_access() object which allows lazy frame access from a lldb.SBThread object.'''
195 return self.frames_access (self)
Greg Claytonb302dff2012-02-01 08:09:32 +0000196
Greg Clayton394da8e2012-02-01 02:30:27 +0000197 def get_thread_frames(self):
Greg Claytonb6a5ba62012-02-03 03:22:53 +0000198 '''An accessor function that returns a list() that contains all frames in a lldb.SBThread object.'''
Greg Clayton394da8e2012-02-01 02:30:27 +0000199 frames = []
200 for frame in self:
201 frames.append(frame)
202 return frames
Greg Claytonb302dff2012-02-01 08:09:32 +0000203
Greg Clayton1b925202012-01-29 06:07:39 +0000204 __swig_getmethods__["id"] = GetThreadID
Greg Clayton2a94be12012-06-29 22:00:42 +0000205 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 +0000206
207 __swig_getmethods__["idx"] = GetIndexID
Greg Clayton2a94be12012-06-29 22:00:42 +0000208 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 +0000209
210 __swig_getmethods__["return_value"] = GetStopReturnValue
Greg Clayton2a94be12012-06-29 22:00:42 +0000211 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 +0000212
213 __swig_getmethods__["process"] = GetProcess
Greg Clayton2a94be12012-06-29 22:00:42 +0000214 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 +0000215
216 __swig_getmethods__["num_frames"] = GetNumFrames
Greg Clayton2a94be12012-06-29 22:00:42 +0000217 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 +0000218
Greg Clayton394da8e2012-02-01 02:30:27 +0000219 __swig_getmethods__["frames"] = get_thread_frames
Greg Clayton2a94be12012-06-29 22:00:42 +0000220 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 +0000221
Greg Claytonb6a5ba62012-02-03 03:22:53 +0000222 __swig_getmethods__["frame"] = get_frames_access_object
Greg Clayton2a94be12012-06-29 22:00:42 +0000223 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 +0000224
Greg Clayton1b925202012-01-29 06:07:39 +0000225 __swig_getmethods__["name"] = GetName
Greg Clayton2a94be12012-06-29 22:00:42 +0000226 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 +0000227
228 __swig_getmethods__["queue"] = GetQueueName
Greg Clayton2a94be12012-06-29 22:00:42 +0000229 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 +0000230
231 __swig_getmethods__["stop_reason"] = GetStopReason
Greg Clayton2a94be12012-06-29 22:00:42 +0000232 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 +0000233
234 __swig_getmethods__["is_suspended"] = IsSuspended
Greg Clayton2a94be12012-06-29 22:00:42 +0000235 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 +0000236 %}
237
Johnny Chenc3fba812011-07-18 20:13:38 +0000238};
239
240} // namespace lldb