1 //===-- SBThread.h ----------------------------------------------*- 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 #ifndef LLDB_SBThread_h_ 11 #define LLDB_SBThread_h_ 12 13 #include "lldb/API/SBDefines.h" 14 15 #include <stdio.h> 16 17 namespace lldb { 18 19 class SBFrame; 20 21 class LLDB_API SBThread 22 { 23 public: 24 enum 25 { 26 eBroadcastBitStackChanged = (1 << 0), 27 eBroadcastBitThreadSuspended = (1 << 1), 28 eBroadcastBitThreadResumed = (1 << 2), 29 eBroadcastBitSelectedFrameChanged = (1 << 3), 30 eBroadcastBitThreadSelected = (1 << 4) 31 }; 32 33 static const char * 34 GetBroadcasterClassName (); 35 36 SBThread (); 37 38 SBThread (const lldb::SBThread &thread); 39 40 SBThread (const lldb::ThreadSP& lldb_object_sp); 41 42 ~SBThread(); 43 44 lldb::SBQueue 45 GetQueue () const; 46 47 bool 48 IsValid() const; 49 50 void 51 Clear (); 52 53 lldb::StopReason 54 GetStopReason(); 55 56 /// Get the number of words associated with the stop reason. 57 /// See also GetStopReasonDataAtIndex(). 58 size_t 59 GetStopReasonDataCount(); 60 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} 73 /// eStopReasonWatchpoint 1 watchpoint id 74 /// eStopReasonSignal 1 unix signal number 75 /// eStopReasonException N exception data 76 /// eStopReasonExec 0 77 /// eStopReasonPlanComplete 0 78 //-------------------------------------------------------------------------- 79 uint64_t 80 GetStopReasonDataAtIndex(uint32_t idx); 81 82 bool 83 GetStopReasonExtendedInfoAsJSON (lldb::SBStream &stream); 84 85 size_t 86 GetStopDescription (char *dst, size_t dst_len); 87 88 SBValue 89 GetStopReturnValue (); 90 91 lldb::tid_t 92 GetThreadID () const; 93 94 uint32_t 95 GetIndexID () const; 96 97 const char * 98 GetName () const; 99 100 const char * 101 GetQueueName() const; 102 103 lldb::queue_id_t 104 GetQueueID() const; 105 106 bool 107 GetInfoItemByPathAsString ( const char *path, SBStream &strm); 108 109 void 110 StepOver (lldb::RunMode stop_other_threads = lldb::eOnlyDuringStepping); 111 112 void 113 StepInto (lldb::RunMode stop_other_threads = lldb::eOnlyDuringStepping); 114 115 void 116 StepInto (const char *target_name, lldb::RunMode stop_other_threads = lldb::eOnlyDuringStepping); 117 118 void 119 StepOut (); 120 121 void 122 StepOutOfFrame (lldb::SBFrame &frame); 123 124 void 125 StepInstruction(bool step_over); 126 127 SBError 128 StepOverUntil (lldb::SBFrame &frame, 129 lldb::SBFileSpec &file_spec, 130 uint32_t line); 131 132 SBError 133 StepUsingScriptedThreadPlan (const char *script_class_name); 134 135 SBError 136 JumpToLine (lldb::SBFileSpec &file_spec, uint32_t line); 137 138 void 139 RunToAddress (lldb::addr_t addr); 140 141 SBError 142 ReturnFromFrame (SBFrame &frame, SBValue &return_value); 143 144 //-------------------------------------------------------------------------- 145 /// LLDB currently supports process centric debugging which means when any 146 /// thread in a process stops, all other threads are stopped. The Suspend() 147 /// call here tells our process to suspend a thread and not let it run when 148 /// the other threads in a process are allowed to run. So when 149 /// SBProcess::Continue() is called, any threads that aren't suspended will 150 /// be allowed to run. If any of the SBThread functions for stepping are 151 /// called (StepOver, StepInto, StepOut, StepInstruction, RunToAddress), the 152 /// thread will not be allowed to run and these functions will simply return. 153 /// 154 /// Eventually we plan to add support for thread centric debugging where 155 /// each thread is controlled individually and each thread would broadcast 156 /// its state, but we haven't implemented this yet. 157 /// 158 /// Likewise the SBThread::Resume() call will again allow the thread to run 159 /// when the process is continued. 160 /// 161 /// Suspend() and Resume() functions are not currently reference counted, if 162 /// anyone has the need for them to be reference counted, please let us 163 /// know. 164 //-------------------------------------------------------------------------- 165 bool 166 Suspend(); 167 168 bool 169 Resume (); 170 171 bool 172 IsSuspended(); 173 174 bool 175 IsStopped(); 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 static bool 190 EventIsThreadEvent (const SBEvent &event); 191 192 static SBFrame 193 GetStackFrameFromEvent (const SBEvent &event); 194 195 static SBThread 196 GetThreadFromEvent (const SBEvent &event); 197 198 lldb::SBProcess 199 GetProcess (); 200 201 const lldb::SBThread & 202 operator = (const lldb::SBThread &rhs); 203 204 bool 205 operator == (const lldb::SBThread &rhs) const; 206 207 bool 208 operator != (const lldb::SBThread &rhs) const; 209 210 bool 211 GetDescription (lldb::SBStream &description) const; 212 213 bool 214 GetStatus (lldb::SBStream &status) const; 215 216 SBThread 217 GetExtendedBacktraceThread (const char *type); 218 219 uint32_t 220 GetExtendedBacktraceOriginatingIndexID (); 221 222 bool 223 SafeToCallFunctions (); 224 225 #ifndef SWIG 226 lldb_private::Thread * 227 operator->(); 228 229 lldb_private::Thread * 230 get(); 231 232 #endif 233 234 protected: 235 friend class SBBreakpoint; 236 friend class SBBreakpointLocation; 237 friend class SBExecutionContext; 238 friend class SBFrame; 239 friend class SBProcess; 240 friend class SBDebugger; 241 friend class SBValue; 242 friend class lldb_private::QueueImpl; 243 friend class SBQueueItem; 244 245 void 246 SetThread (const lldb::ThreadSP& lldb_object_sp); 247 248 #ifndef SWIG 249 SBError 250 ResumeNewPlan (lldb_private::ExecutionContext &exe_ctx, lldb_private::ThreadPlan *new_plan); 251 #endif 252 253 private: 254 lldb::ExecutionContextRefSP m_opaque_sp; 255 }; 256 257 } // namespace lldb 258 259 #endif // LLDB_SBThread_h_ 260