LLDB mainline
SBThread.h
Go to the documentation of this file.
1//===-- SBThread.h ----------------------------------------------*- C++ -*-===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLDB_API_SBTHREAD_H
10#define LLDB_API_SBTHREAD_H
11
12#include "lldb/API/SBDefines.h"
13
14#include <cstdio>
15
16namespace lldb_private {
17namespace python {
18class SWIGBridge;
19}
20} // namespace lldb_private
21
22namespace lldb {
23
24class SBFrame;
25
27public:
28 enum {
34 };
35
36 static const char *GetBroadcasterClassName();
37
38 SBThread();
39
40 SBThread(const lldb::SBThread &thread);
41
43
44 lldb::SBQueue GetQueue() const;
45
46 explicit operator bool() const;
47
48 bool IsValid() const;
49
50 void Clear();
51
53
54 /// Get the number of words associated with the stop reason.
55 /// See also GetStopReasonDataAtIndex().
57
58 /// Get information associated with a stop reason.
59 ///
60 /// Breakpoint stop reasons will have data that consists of pairs of
61 /// breakpoint IDs followed by the breakpoint location IDs (they always come
62 /// in pairs).
63 ///
64 /// Stop Reason Count Data Type
65 /// ======================== ===== =========================================
66 /// eStopReasonNone 0
67 /// eStopReasonTrace 0
68 /// eStopReasonBreakpoint N duple: {breakpoint id, location id}
69 /// eStopReasonWatchpoint 1 watchpoint id
70 /// eStopReasonSignal 1 unix signal number
71 /// eStopReasonException N exception data
72 /// eStopReasonExec 0
73 /// eStopReasonFork 1 pid of the child process
74 /// eStopReasonVFork 1 pid of the child process
75 /// eStopReasonVForkDone 0
76 /// eStopReasonPlanComplete 0
77 uint64_t GetStopReasonDataAtIndex(uint32_t idx);
78
80
83
84 /// Gets a human-readable description of why the thread stopped.
85 ///
86 /// \param stream Output stream to receive the stop description text
87 /// \return
88 /// true if obtained and written to the stream,
89 // false if there was an error retrieving the description.
90 bool GetStopDescription(lldb::SBStream &stream) const;
91
92 size_t GetStopDescription(char *dst_or_null, size_t dst_len);
93
94 /// Get the value the function returned, if the thread stopped because it
95 /// stepped out of a function. Invalid if the function threw an error
96 /// instead. See GetStopErrorValue.
98
99 /// Get the error the function threw, if the thread stopped because it
100 /// stepped out of a function that threw instead of returning. Only
101 /// languages whose runtime can find thrown errors, such as Swift, report
102 /// one.
104
105 lldb::tid_t GetThreadID() const;
106
107 uint32_t GetIndexID() const;
108
109 const char *GetName() const;
110
111 const char *GetQueueName() const;
112
114
115 bool GetInfoItemByPathAsString(const char *path, SBStream &strm);
116
117 void StepOver(lldb::RunMode stop_other_threads = lldb::eOnlyDuringStepping);
118
119 void StepOver(lldb::RunMode stop_other_threads, SBError &error);
120
121 void StepInto(lldb::RunMode stop_other_threads = lldb::eOnlyDuringStepping);
122
123 void StepInto(const char *target_name,
124 lldb::RunMode stop_other_threads = lldb::eOnlyDuringStepping);
125
126 void StepInto(const char *target_name, uint32_t end_line, SBError &error,
127 lldb::RunMode stop_other_threads = lldb::eOnlyDuringStepping);
128
129 void StepOut();
130
131 void StepOut(SBError &error);
132
133 void StepOutOfFrame(SBFrame &frame);
134
135 void StepOutOfFrame(SBFrame &frame, SBError &error);
136
137 void StepInstruction(bool step_over);
138
139 void StepInstruction(bool step_over, SBError &error);
140
142 uint32_t line);
143
144 SBError StepUsingScriptedThreadPlan(const char *script_class_name);
145
146 SBError StepUsingScriptedThreadPlan(const char *script_class_name,
147 bool resume_immediately);
148
149 SBError StepUsingScriptedThreadPlan(const char *script_class_name,
150 lldb::SBStructuredData &args_data,
151 bool resume_immediately);
152
153 SBError JumpToLine(lldb::SBFileSpec &file_spec, uint32_t line);
154
155 void RunToAddress(lldb::addr_t addr);
156
158
159 SBError ReturnFromFrame(SBFrame &frame, SBValue &return_value);
160
162
163 /// LLDB currently supports process centric debugging which means when any
164 /// thread in a process stops, all other threads are stopped. The Suspend()
165 /// call here tells our process to suspend a thread and not let it run when
166 /// the other threads in a process are allowed to run. So when
167 /// SBProcess::Continue() is called, any threads that aren't suspended will
168 /// be allowed to run. If any of the SBThread functions for stepping are
169 /// called (StepOver, StepInto, StepOut, StepInstruction, RunToAddress), the
170 /// thread will not be allowed to run and these functions will simply return.
171 ///
172 /// Eventually we plan to add support for thread centric debugging where
173 /// each thread is controlled individually and each thread would broadcast
174 /// its state, but we haven't implemented this yet.
175 ///
176 /// Likewise the SBThread::Resume() call will again allow the thread to run
177 /// when the process is continued.
178 ///
179 /// Suspend() and Resume() functions are not currently reference counted, if
180 /// anyone has the need for them to be reference counted, please let us
181 /// know.
182 bool Suspend();
183
184 bool Suspend(SBError &error);
185
186 bool Resume();
187
188 bool Resume(SBError &error);
189
190 bool IsSuspended();
191
192 bool IsStopped();
193
194 uint32_t GetNumFrames();
195
196 lldb::SBFrame GetFrameAtIndex(uint32_t idx);
197
199
201
202 lldb::SBFrame SetSelectedFrame(uint32_t frame_idx);
203
204 static bool EventIsThreadEvent(const SBEvent &event);
205
206 static SBFrame GetStackFrameFromEvent(const SBEvent &event);
207
208 static SBThread GetThreadFromEvent(const SBEvent &event);
209
211
212 const lldb::SBThread &operator=(const lldb::SBThread &rhs);
213
214 bool operator==(const lldb::SBThread &rhs) const;
215
216 bool operator!=(const lldb::SBThread &rhs) const;
217
218 bool GetDescription(lldb::SBStream &description) const;
219
220 bool GetDescription(lldb::SBStream &description, bool stop_format) const;
221
222 /// Similar to \a GetDescription() but the format of the description can be
223 /// configured via the \p format parameter. See
224 /// \lldbformatting for more information on format
225 /// strings.
226 ///
227 /// \param[in] format
228 /// The format to use for generating the description.
229 ///
230 /// \param[out] output
231 /// The stream where the description will be written to.
232 ///
233 /// \return
234 /// An error object with an error message in case of failures.
235 SBError GetDescriptionWithFormat(const SBFormat &format, SBStream &output);
236
237 bool GetStatus(lldb::SBStream &status) const;
238
239 SBThread GetExtendedBacktraceThread(const char *type);
240
242
244
246
247 bool SafeToCallFunctions();
248
250
251private:
252 friend class SBBreakpoint;
255 friend class SBSaveCoreOptions;
256 friend class SBExecutionContext;
257 friend class SBFrame;
258 friend class SBFrameList;
259 friend class SBProcess;
260 friend class SBDebugger;
261 friend class SBValue;
263 friend class SBQueueItem;
264 friend class SBThreadCollection;
265 friend class SBThreadPlan;
266 friend class SBTrace;
267
270
271 SBThread(const lldb::ThreadSP &lldb_object_sp);
272
273 void SetThread(const lldb::ThreadSP &lldb_object_sp);
274
275 lldb::ThreadSP GetSP() const;
276
278
280
282};
283
284} // namespace lldb
285
286#endif // LLDB_API_SBTHREAD_H
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_API
Definition SBDefines.h:28
static llvm::StringRef GetName(XcodeSDK::Type type)
Definition XcodeSDK.cpp:21
Class that represents a format string that can be used to generate descriptions of objects like frame...
Definition SBFormat.h:28
Represents a list of SBFrame objects.
Definition SBFrameList.h:31
void StepInto(lldb::RunMode stop_other_threads=lldb::eOnlyDuringStepping)
Definition SBThread.cpp:557
bool Suspend()
LLDB currently supports process centric debugging which means when any thread in a process stops,...
bool GetStopDescription(lldb::SBStream &stream) const
Gets a human-readable description of why the thread stopped.
Definition SBThread.cpp:245
const lldb::SBThread & operator=(const lldb::SBThread &rhs)
Definition SBThread.cpp:80
friend class SBBreakpointCallbackBaton
Definition SBThread.h:254
lldb::SBFrame SetSelectedFrame(uint32_t frame_idx)
SBError UnwindInnermostExpression()
friend class SBThreadCollection
Definition SBThread.h:264
bool IsValid() const
Definition SBThread.cpp:113
uint32_t GetNumFrames()
friend class SBProcess
Definition SBThread.h:259
const char * GetQueueName() const
Definition SBThread.cpp:385
friend class SBSaveCoreOptions
Definition SBThread.h:255
friend class SBQueueItem
Definition SBThread.h:263
SBValue GetSiginfo()
uint32_t GetIndexID() const
Definition SBThread.cpp:352
bool GetDescription(lldb::SBStream &description) const
static bool EventIsThreadEvent(const SBEvent &event)
lldb_private::Thread * operator->()
lldb_private::Thread * get()
friend class SBDebugger
Definition SBThread.h:260
void StepOutOfFrame(SBFrame &frame)
Definition SBThread.cpp:711
friend class SBBreakpoint
Definition SBThread.h:252
bool GetStatus(lldb::SBStream &status) const
friend class SBValue
Definition SBThread.h:261
static SBFrame GetStackFrameFromEvent(const SBEvent &event)
lldb::queue_id_t GetQueueID() const
Definition SBThread.cpp:402
lldb::SBFrameList GetFrames() const
bool GetInfoItemByPathAsString(const char *path, SBStream &strm)
Definition SBThread.cpp:420
lldb::SBFrame GetSelectedFrame()
friend class SBExecutionContext
Definition SBThread.h:256
friend class SBFrameList
Definition SBThread.h:258
bool operator!=(const lldb::SBThread &rhs) const
friend class SBTrace
Definition SBThread.h:266
SBError StepUsingScriptedThreadPlan(const char *script_class_name)
Definition SBThread.cpp:934
lldb::tid_t GetThreadID() const
Definition SBThread.cpp:336
friend class SBThreadPlan
Definition SBThread.h:265
lldb::SBFrame GetFrameAtIndex(uint32_t idx)
uint32_t GetExtendedBacktraceOriginatingIndexID()
lldb::SBQueue GetQueue() const
Definition SBThread.cpp:91
bool SafeToCallFunctions()
lldb::SBProcess GetProcess()
size_t GetStopReasonDataCount()
Get the number of words associated with the stop reason.
Definition SBThread.cpp:155
void StepInstruction(bool step_over)
Definition SBThread.cpp:759
SBThread GetCurrentExceptionBacktrace()
friend class SBFrame
Definition SBThread.h:257
static SBThread GetThreadFromEvent(const SBEvent &event)
bool GetStopReasonExtendedInfoAsJSON(lldb::SBStream &stream)
Definition SBThread.cpp:192
lldb::StopReason GetStopReason()
Definition SBThread.cpp:138
SBValue GetStopReturnValue()
Get the value the function returned, if the thread stopped because it stepped out of a function.
Definition SBThread.cpp:314
void StepOver(lldb::RunMode stop_other_threads=lldb::eOnlyDuringStepping)
Definition SBThread.cpp:493
SBError JumpToLine(lldb::SBFileSpec &file_spec, uint32_t line)
Definition SBThread.cpp:994
SBError GetDescriptionWithFormat(const SBFormat &format, SBStream &output)
Similar to GetDescription() but the format of the description can be configured via the format parame...
friend class SBBreakpointLocation
Definition SBThread.h:253
SBThreadCollection GetStopReasonExtendedBacktraces(InstrumentationRuntimeType type)
Definition SBThread.cpp:218
SBValue GetCurrentException()
void SetThread(const lldb::ThreadSP &lldb_object_sp)
Definition SBThread.cpp:332
lldb::ThreadSP GetSP() const
@ eBroadcastBitThreadSuspended
Definition SBThread.h:30
@ eBroadcastBitSelectedFrameChanged
Definition SBThread.h:32
@ eBroadcastBitThreadResumed
Definition SBThread.h:31
@ eBroadcastBitStackChanged
Definition SBThread.h:29
@ eBroadcastBitThreadSelected
Definition SBThread.h:33
SBThread GetExtendedBacktraceThread(const char *type)
lldb::ExecutionContextRefSP m_opaque_sp
Definition SBThread.h:277
void RunToAddress(lldb::addr_t addr)
Definition SBThread.cpp:811
SBValue GetStopErrorValue()
Get the error the function threw, if the thread stopped because it stepped out of a function that thr...
Definition SBThread.cpp:323
uint64_t GetStopReasonDataAtIndex(uint32_t idx)
Get information associated with a stop reason.
Definition SBThread.cpp:173
SBError ReturnFromFrame(SBFrame &frame, SBValue &return_value)
bool operator==(const lldb::SBThread &rhs) const
SBError StepOverUntil(lldb::SBFrame &frame, lldb::SBFileSpec &file_spec, uint32_t line)
Definition SBThread.cpp:850
Unwraps the opaque internal object held by an SB (public API) instance, for scripting-language plugin...
A class that represents a running process on the host machine.
std::shared_ptr< lldb_private::Thread > ThreadSP
InstrumentationRuntimeType
uint64_t addr_t
Definition lldb-types.h:80
StopReason
Thread stop reasons.
RunMode
Thread Run Modes.
@ eOnlyDuringStepping
uint64_t tid_t
Definition lldb-types.h:85
uint64_t queue_id_t
Definition lldb-types.h:92
std::shared_ptr< lldb_private::ExecutionContextRef > ExecutionContextRefSP