Johnny Chen | c3fba81 | 2011-07-18 20:13:38 +0000 | [diff] [blame] | 1 | //===-- 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 | |
| 10 | namespace lldb { |
| 11 | |
| 12 | %feature("docstring", |
| 13 | "Represents a thread of execution. SBProcess contains SBThread(s). |
| 14 | |
Jim Ingham | efbdd22 | 2012-07-13 20:18:18 +0000 | [diff] [blame] | 15 | SBThreads can be referred to by their ID, which maps to the system specific thread |
| 16 | identifier, or by IndexID. The ID may or may not be unique depending on whether the |
| 17 | system reuses its thread identifiers. The IndexID is a monotonically increasing identifier |
| 18 | that will always uniquely reference a particular thread, and when that thread goes |
| 19 | away it will not be reused. |
| 20 | |
Johnny Chen | c3fba81 | 2011-07-18 20:13:38 +0000 | [diff] [blame] | 21 | SBThread supports frame iteration. For example (from test/python_api/ |
| 22 | lldbutil/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 | |
| 39 | See also SBProcess and SBFrame." |
| 40 | ) SBThread; |
| 41 | class SBThread |
| 42 | { |
| 43 | public: |
| 44 | SBThread (); |
| 45 | |
| 46 | SBThread (const lldb::SBThread &thread); |
| 47 | |
| 48 | ~SBThread(); |
| 49 | |
| 50 | bool |
| 51 | IsValid() const; |
| 52 | |
| 53 | void |
| 54 | Clear (); |
| 55 | |
| 56 | lldb::StopReason |
| 57 | GetStopReason(); |
| 58 | |
| 59 | %feature("docstring", " |
| 60 | /// Get the number of words associated with the stop reason. |
| 61 | /// See also GetStopReasonDataAtIndex(). |
| 62 | ") GetStopReasonDataCount; |
| 63 | size_t |
| 64 | GetStopReasonDataCount(); |
| 65 | |
| 66 | %feature("docstring", " |
| 67 | //-------------------------------------------------------------------------- |
| 68 | /// Get information associated with a stop reason. |
| 69 | /// |
| 70 | /// Breakpoint stop reasons will have data that consists of pairs of |
| 71 | /// breakpoint IDs followed by the breakpoint location IDs (they always come |
| 72 | /// in pairs). |
| 73 | /// |
| 74 | /// Stop Reason Count Data Type |
| 75 | /// ======================== ===== ========================================= |
| 76 | /// eStopReasonNone 0 |
| 77 | /// eStopReasonTrace 0 |
| 78 | /// eStopReasonBreakpoint N duple: {breakpoint id, location id} |
Johnny Chen | bcbefa8 | 2011-12-17 02:07:52 +0000 | [diff] [blame] | 79 | /// eStopReasonWatchpoint 1 watchpoint id |
Johnny Chen | c3fba81 | 2011-07-18 20:13:38 +0000 | [diff] [blame] | 80 | /// eStopReasonSignal 1 unix signal number |
| 81 | /// eStopReasonException N exception data |
| 82 | /// eStopReasonPlanComplete 0 |
| 83 | //-------------------------------------------------------------------------- |
| 84 | ") GetStopReasonDataAtIndex; |
| 85 | uint64_t |
| 86 | GetStopReasonDataAtIndex(uint32_t idx); |
| 87 | |
Johnny Chen | 65f4fb0 | 2011-12-19 19:38:09 +0000 | [diff] [blame] | 88 | %feature("autodoc", " |
| 89 | Pass only an (int)length and expect to get a Python string describing the |
| 90 | stop reason. |
| 91 | ") GetStopDescription; |
Johnny Chen | c3fba81 | 2011-07-18 20:13:38 +0000 | [diff] [blame] | 92 | size_t |
| 93 | GetStopDescription (char *dst, size_t dst_len); |
| 94 | |
Jim Ingham | 1586d97 | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 95 | SBValue |
| 96 | GetStopReturnValue (); |
| 97 | |
Johnny Chen | c3fba81 | 2011-07-18 20:13:38 +0000 | [diff] [blame] | 98 | lldb::tid_t |
| 99 | GetThreadID () const; |
| 100 | |
| 101 | uint32_t |
| 102 | GetIndexID () const; |
| 103 | |
| 104 | const char * |
| 105 | GetName () const; |
| 106 | |
| 107 | const char * |
| 108 | GetQueueName() const; |
| 109 | |
| 110 | void |
| 111 | StepOver (lldb::RunMode stop_other_threads = lldb::eOnlyDuringStepping); |
| 112 | |
| 113 | void |
| 114 | StepInto (lldb::RunMode stop_other_threads = lldb::eOnlyDuringStepping); |
| 115 | |
| 116 | void |
| 117 | StepOut (); |
| 118 | |
| 119 | void |
| 120 | StepOutOfFrame (lldb::SBFrame &frame); |
| 121 | |
| 122 | void |
| 123 | StepInstruction(bool step_over); |
| 124 | |
| 125 | SBError |
| 126 | StepOverUntil (lldb::SBFrame &frame, |
| 127 | lldb::SBFileSpec &file_spec, |
| 128 | uint32_t line); |
| 129 | |
| 130 | void |
| 131 | RunToAddress (lldb::addr_t addr); |
| 132 | |
Jim Ingham | a17a81a | 2012-09-12 00:40:39 +0000 | [diff] [blame] | 133 | SBError |
| 134 | ReturnToFrame (SBFrame &frame, SBValue &return_value); |
| 135 | |
Johnny Chen | c3fba81 | 2011-07-18 20:13:38 +0000 | [diff] [blame] | 136 | %feature("docstring", " |
| 137 | //-------------------------------------------------------------------------- |
| 138 | /// LLDB currently supports process centric debugging which means when any |
| 139 | /// thread in a process stops, all other threads are stopped. The Suspend() |
| 140 | /// call here tells our process to suspend a thread and not let it run when |
| 141 | /// the other threads in a process are allowed to run. So when |
| 142 | /// SBProcess::Continue() is called, any threads that aren't suspended will |
| 143 | /// be allowed to run. If any of the SBThread functions for stepping are |
| 144 | /// called (StepOver, StepInto, StepOut, StepInstruction, RunToAddres), the |
| 145 | /// thread will now be allowed to run and these funtions will simply return. |
| 146 | /// |
| 147 | /// Eventually we plan to add support for thread centric debugging where |
| 148 | /// each thread is controlled individually and each thread would broadcast |
| 149 | /// its state, but we haven't implemented this yet. |
| 150 | /// |
| 151 | /// Likewise the SBThread::Resume() call will again allow the thread to run |
| 152 | /// when the process is continued. |
| 153 | /// |
| 154 | /// Suspend() and Resume() functions are not currently reference counted, if |
| 155 | /// anyone has the need for them to be reference counted, please let us |
| 156 | /// know. |
| 157 | //-------------------------------------------------------------------------- |
| 158 | ") Suspend; |
| 159 | bool |
| 160 | Suspend(); |
| 161 | |
| 162 | bool |
| 163 | Resume (); |
| 164 | |
| 165 | bool |
| 166 | IsSuspended(); |
| 167 | |
| 168 | uint32_t |
| 169 | GetNumFrames (); |
| 170 | |
| 171 | lldb::SBFrame |
| 172 | GetFrameAtIndex (uint32_t idx); |
| 173 | |
| 174 | lldb::SBFrame |
| 175 | GetSelectedFrame (); |
| 176 | |
| 177 | lldb::SBFrame |
| 178 | SetSelectedFrame (uint32_t frame_idx); |
| 179 | |
| 180 | lldb::SBProcess |
| 181 | GetProcess (); |
| 182 | |
| 183 | bool |
| 184 | GetDescription (lldb::SBStream &description) const; |
Greg Clayton | 1b92520 | 2012-01-29 06:07:39 +0000 | [diff] [blame] | 185 | |
| 186 | %pythoncode %{ |
Greg Clayton | b6a5ba6 | 2012-02-03 03:22:53 +0000 | [diff] [blame] | 187 | class frames_access(object): |
Greg Clayton | b302dff | 2012-02-01 08:09:32 +0000 | [diff] [blame] | 188 | '''A helper object that will lazily hand out frames for a thread when supplied an index.''' |
| 189 | def __init__(self, sbthread): |
| 190 | self.sbthread = sbthread |
| 191 | |
| 192 | def __len__(self): |
| 193 | if self.sbthread: |
Filipe Cabecinhas | 3cae38b | 2012-05-11 20:39:42 +0000 | [diff] [blame] | 194 | return int(self.sbthread.GetNumFrames()) |
Greg Clayton | b302dff | 2012-02-01 08:09:32 +0000 | [diff] [blame] | 195 | return 0 |
| 196 | |
| 197 | def __getitem__(self, key): |
| 198 | if type(key) is int and key < self.sbthread.GetNumFrames(): |
| 199 | return self.sbthread.GetFrameAtIndex(key) |
| 200 | return None |
| 201 | |
Greg Clayton | b6a5ba6 | 2012-02-03 03:22:53 +0000 | [diff] [blame] | 202 | def get_frames_access_object(self): |
| 203 | '''An accessor function that returns a frames_access() object which allows lazy frame access from a lldb.SBThread object.''' |
| 204 | return self.frames_access (self) |
Greg Clayton | b302dff | 2012-02-01 08:09:32 +0000 | [diff] [blame] | 205 | |
Greg Clayton | 394da8e | 2012-02-01 02:30:27 +0000 | [diff] [blame] | 206 | def get_thread_frames(self): |
Greg Clayton | b6a5ba6 | 2012-02-03 03:22:53 +0000 | [diff] [blame] | 207 | '''An accessor function that returns a list() that contains all frames in a lldb.SBThread object.''' |
Greg Clayton | 394da8e | 2012-02-01 02:30:27 +0000 | [diff] [blame] | 208 | frames = [] |
| 209 | for frame in self: |
| 210 | frames.append(frame) |
| 211 | return frames |
Greg Clayton | b302dff | 2012-02-01 08:09:32 +0000 | [diff] [blame] | 212 | |
Greg Clayton | 1b92520 | 2012-01-29 06:07:39 +0000 | [diff] [blame] | 213 | __swig_getmethods__["id"] = GetThreadID |
Greg Clayton | 2a94be1 | 2012-06-29 22:00:42 +0000 | [diff] [blame] | 214 | if _newclass: id = property(GetThreadID, None, doc='''A read only property that returns the thread ID as an integer.''') |
Greg Clayton | 1b92520 | 2012-01-29 06:07:39 +0000 | [diff] [blame] | 215 | |
| 216 | __swig_getmethods__["idx"] = GetIndexID |
Greg Clayton | 2a94be1 | 2012-06-29 22:00:42 +0000 | [diff] [blame] | 217 | 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 Clayton | 1b92520 | 2012-01-29 06:07:39 +0000 | [diff] [blame] | 218 | |
| 219 | __swig_getmethods__["return_value"] = GetStopReturnValue |
Greg Clayton | 2a94be1 | 2012-06-29 22:00:42 +0000 | [diff] [blame] | 220 | 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 Clayton | 1b92520 | 2012-01-29 06:07:39 +0000 | [diff] [blame] | 221 | |
| 222 | __swig_getmethods__["process"] = GetProcess |
Greg Clayton | 2a94be1 | 2012-06-29 22:00:42 +0000 | [diff] [blame] | 223 | 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 Clayton | 1b92520 | 2012-01-29 06:07:39 +0000 | [diff] [blame] | 224 | |
| 225 | __swig_getmethods__["num_frames"] = GetNumFrames |
Greg Clayton | 2a94be1 | 2012-06-29 22:00:42 +0000 | [diff] [blame] | 226 | 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 Clayton | 1b92520 | 2012-01-29 06:07:39 +0000 | [diff] [blame] | 227 | |
Greg Clayton | 394da8e | 2012-02-01 02:30:27 +0000 | [diff] [blame] | 228 | __swig_getmethods__["frames"] = get_thread_frames |
Greg Clayton | 2a94be1 | 2012-06-29 22:00:42 +0000 | [diff] [blame] | 229 | 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 Clayton | 394da8e | 2012-02-01 02:30:27 +0000 | [diff] [blame] | 230 | |
Greg Clayton | b6a5ba6 | 2012-02-03 03:22:53 +0000 | [diff] [blame] | 231 | __swig_getmethods__["frame"] = get_frames_access_object |
Greg Clayton | 2a94be1 | 2012-06-29 22:00:42 +0000 | [diff] [blame] | 232 | 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 Clayton | b302dff | 2012-02-01 08:09:32 +0000 | [diff] [blame] | 233 | |
Greg Clayton | 1b92520 | 2012-01-29 06:07:39 +0000 | [diff] [blame] | 234 | __swig_getmethods__["name"] = GetName |
Greg Clayton | 2a94be1 | 2012-06-29 22:00:42 +0000 | [diff] [blame] | 235 | if _newclass: name = property(GetName, None, doc='''A read only property that returns the name of this thread as a string.''') |
Greg Clayton | 1b92520 | 2012-01-29 06:07:39 +0000 | [diff] [blame] | 236 | |
| 237 | __swig_getmethods__["queue"] = GetQueueName |
Greg Clayton | 2a94be1 | 2012-06-29 22:00:42 +0000 | [diff] [blame] | 238 | if _newclass: queue = property(GetQueueName, None, doc='''A read only property that returns the dispatch queue name of this thread as a string.''') |
Greg Clayton | 1b92520 | 2012-01-29 06:07:39 +0000 | [diff] [blame] | 239 | |
| 240 | __swig_getmethods__["stop_reason"] = GetStopReason |
Greg Clayton | 2a94be1 | 2012-06-29 22:00:42 +0000 | [diff] [blame] | 241 | 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 Clayton | 1b92520 | 2012-01-29 06:07:39 +0000 | [diff] [blame] | 242 | |
| 243 | __swig_getmethods__["is_suspended"] = IsSuspended |
Greg Clayton | 2a94be1 | 2012-06-29 22:00:42 +0000 | [diff] [blame] | 244 | 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 Clayton | 1b92520 | 2012-01-29 06:07:39 +0000 | [diff] [blame] | 245 | %} |
| 246 | |
Johnny Chen | c3fba81 | 2011-07-18 20:13:38 +0000 | [diff] [blame] | 247 | }; |
| 248 | |
| 249 | } // namespace lldb |