1 //===-- SBThread.h ----------------------------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #ifndef LLDB_SBThread_h_
10 #define LLDB_SBThread_h_
12 #include "lldb/API/SBDefines.h"
20 class LLDB_API SBThread {
23 eBroadcastBitStackChanged = (1 << 0),
24 eBroadcastBitThreadSuspended = (1 << 1),
25 eBroadcastBitThreadResumed = (1 << 2),
26 eBroadcastBitSelectedFrameChanged = (1 << 3),
27 eBroadcastBitThreadSelected = (1 << 4)
30 static const char *GetBroadcasterClassName();
34 SBThread(const lldb::SBThread &thread);
36 SBThread(const lldb::ThreadSP &lldb_object_sp);
40 lldb::SBQueue GetQueue() const;
42 explicit operator bool() const;
48 lldb::StopReason GetStopReason();
50 /// Get the number of words associated with the stop reason.
51 /// See also GetStopReasonDataAtIndex().
52 size_t GetStopReasonDataCount();
54 /// Get information associated with a stop reason.
56 /// Breakpoint stop reasons will have data that consists of pairs of
57 /// breakpoint IDs followed by the breakpoint location IDs (they always come
60 /// Stop Reason Count Data Type
61 /// ======================== ===== =========================================
63 /// eStopReasonTrace 0
64 /// eStopReasonBreakpoint N duple: {breakpoint id, location id}
65 /// eStopReasonWatchpoint 1 watchpoint id
66 /// eStopReasonSignal 1 unix signal number
67 /// eStopReasonException N exception data
69 /// eStopReasonPlanComplete 0
70 uint64_t GetStopReasonDataAtIndex(uint32_t idx);
72 bool GetStopReasonExtendedInfoAsJSON(lldb::SBStream &stream);
75 GetStopReasonExtendedBacktraces(InstrumentationRuntimeType type);
77 size_t GetStopDescription(char *dst, size_t dst_len);
79 SBValue GetStopReturnValue();
81 lldb::tid_t GetThreadID() const;
83 uint32_t GetIndexID() const;
85 const char *GetName() const;
87 const char *GetQueueName() const;
89 lldb::queue_id_t GetQueueID() const;
91 bool GetInfoItemByPathAsString(const char *path, SBStream &strm);
93 void StepOver(lldb::RunMode stop_other_threads = lldb::eOnlyDuringStepping);
95 void StepOver(lldb::RunMode stop_other_threads, SBError &error);
97 void StepInto(lldb::RunMode stop_other_threads = lldb::eOnlyDuringStepping);
99 void StepInto(const char *target_name,
100 lldb::RunMode stop_other_threads = lldb::eOnlyDuringStepping);
102 void StepInto(const char *target_name, uint32_t end_line, SBError &error,
103 lldb::RunMode stop_other_threads = lldb::eOnlyDuringStepping);
107 void StepOut(SBError &error);
109 void StepOutOfFrame(SBFrame &frame);
111 void StepOutOfFrame(SBFrame &frame, SBError &error);
113 void StepInstruction(bool step_over);
115 void StepInstruction(bool step_over, SBError &error);
117 SBError StepOverUntil(lldb::SBFrame &frame, lldb::SBFileSpec &file_spec,
120 SBError StepUsingScriptedThreadPlan(const char *script_class_name);
122 SBError StepUsingScriptedThreadPlan(const char *script_class_name,
123 bool resume_immediately);
125 SBError StepUsingScriptedThreadPlan(const char *script_class_name,
126 lldb::SBStructuredData &args_data,
127 bool resume_immediately);
129 SBError JumpToLine(lldb::SBFileSpec &file_spec, uint32_t line);
131 void RunToAddress(lldb::addr_t addr);
133 void RunToAddress(lldb::addr_t addr, SBError &error);
135 SBError ReturnFromFrame(SBFrame &frame, SBValue &return_value);
137 SBError UnwindInnermostExpression();
139 /// LLDB currently supports process centric debugging which means when any
140 /// thread in a process stops, all other threads are stopped. The Suspend()
141 /// call here tells our process to suspend a thread and not let it run when
142 /// the other threads in a process are allowed to run. So when
143 /// SBProcess::Continue() is called, any threads that aren't suspended will
144 /// be allowed to run. If any of the SBThread functions for stepping are
145 /// called (StepOver, StepInto, StepOut, StepInstruction, RunToAddress), the
146 /// thread will not be allowed to run and these functions will simply return.
148 /// Eventually we plan to add support for thread centric debugging where
149 /// each thread is controlled individually and each thread would broadcast
150 /// its state, but we haven't implemented this yet.
152 /// Likewise the SBThread::Resume() call will again allow the thread to run
153 /// when the process is continued.
155 /// Suspend() and Resume() functions are not currently reference counted, if
156 /// anyone has the need for them to be reference counted, please let us
160 bool Suspend(SBError &error);
164 bool Resume(SBError &error);
170 uint32_t GetNumFrames();
172 lldb::SBFrame GetFrameAtIndex(uint32_t idx);
174 lldb::SBFrame GetSelectedFrame();
176 lldb::SBFrame SetSelectedFrame(uint32_t frame_idx);
178 static bool EventIsThreadEvent(const SBEvent &event);
180 static SBFrame GetStackFrameFromEvent(const SBEvent &event);
182 static SBThread GetThreadFromEvent(const SBEvent &event);
184 lldb::SBProcess GetProcess();
186 const lldb::SBThread &operator=(const lldb::SBThread &rhs);
188 bool operator==(const lldb::SBThread &rhs) const;
190 bool operator!=(const lldb::SBThread &rhs) const;
192 bool GetDescription(lldb::SBStream &description) const;
194 bool GetDescription(lldb::SBStream &description, bool stop_format) const;
196 bool GetStatus(lldb::SBStream &status) const;
198 SBThread GetExtendedBacktraceThread(const char *type);
200 uint32_t GetExtendedBacktraceOriginatingIndexID();
202 SBValue GetCurrentException();
204 SBThread GetCurrentExceptionBacktrace();
206 bool SafeToCallFunctions();
209 friend class SBBreakpoint;
210 friend class SBBreakpointLocation;
211 friend class SBBreakpointCallbackBaton;
212 friend class SBExecutionContext;
213 friend class SBFrame;
214 friend class SBProcess;
215 friend class SBDebugger;
216 friend class SBValue;
217 friend class lldb_private::QueueImpl;
218 friend class SBQueueItem;
219 friend class SBThreadPlan;
221 void SetThread(const lldb::ThreadSP &lldb_object_sp);
223 SBError ResumeNewPlan(lldb_private::ExecutionContext &exe_ctx,
224 lldb_private::ThreadPlan *new_plan);
226 lldb::ExecutionContextRefSP m_opaque_sp;
228 lldb_private::Thread *operator->();
230 lldb_private::Thread *get();
235 #endif // LLDB_SBThread_h_