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
95
97
98 uint32_t GetIndexID() const;
99
100 const char *GetName() const;
101
102 const char *GetQueueName() const;
103
105
106 bool GetInfoItemByPathAsString(const char *path, SBStream &strm);
107
108 void StepOver(lldb::RunMode stop_other_threads = lldb::eOnlyDuringStepping);
109
110 void StepOver(lldb::RunMode stop_other_threads, SBError &error);
111
112 void StepInto(lldb::RunMode stop_other_threads = lldb::eOnlyDuringStepping);
113
114 void StepInto(const char *target_name,
115 lldb::RunMode stop_other_threads = lldb::eOnlyDuringStepping);
116
117 void StepInto(const char *target_name, uint32_t end_line, SBError &error,
118 lldb::RunMode stop_other_threads = lldb::eOnlyDuringStepping);
119
120 void StepOut();
121
122 void StepOut(SBError &error);
123
124 void StepOutOfFrame(SBFrame &frame);
125
126 void StepOutOfFrame(SBFrame &frame, SBError &error);
127
128 void StepInstruction(bool step_over);
129
130 void StepInstruction(bool step_over, SBError &error);
131
133 uint32_t line);
134
135 SBError StepUsingScriptedThreadPlan(const char *script_class_name);
136
137 SBError StepUsingScriptedThreadPlan(const char *script_class_name,
138 bool resume_immediately);
139
140 SBError StepUsingScriptedThreadPlan(const char *script_class_name,
141 lldb::SBStructuredData &args_data,
142 bool resume_immediately);
143
144 SBError JumpToLine(lldb::SBFileSpec &file_spec, uint32_t line);
145
146 void RunToAddress(lldb::addr_t addr);
147
149
150 SBError ReturnFromFrame(SBFrame &frame, SBValue &return_value);
151
153
154 /// LLDB currently supports process centric debugging which means when any
155 /// thread in a process stops, all other threads are stopped. The Suspend()
156 /// call here tells our process to suspend a thread and not let it run when
157 /// the other threads in a process are allowed to run. So when
158 /// SBProcess::Continue() is called, any threads that aren't suspended will
159 /// be allowed to run. If any of the SBThread functions for stepping are
160 /// called (StepOver, StepInto, StepOut, StepInstruction, RunToAddress), the
161 /// thread will not be allowed to run and these functions will simply return.
162 ///
163 /// Eventually we plan to add support for thread centric debugging where
164 /// each thread is controlled individually and each thread would broadcast
165 /// its state, but we haven't implemented this yet.
166 ///
167 /// Likewise the SBThread::Resume() call will again allow the thread to run
168 /// when the process is continued.
169 ///
170 /// Suspend() and Resume() functions are not currently reference counted, if
171 /// anyone has the need for them to be reference counted, please let us
172 /// know.
173 bool Suspend();
174
175 bool Suspend(SBError &error);
176
177 bool Resume();
178
179 bool Resume(SBError &error);
180
181 bool IsSuspended();
182
183 bool IsStopped();
184
185 uint32_t GetNumFrames();
186
187 lldb::SBFrame GetFrameAtIndex(uint32_t idx);
188
190
192
193 lldb::SBFrame SetSelectedFrame(uint32_t frame_idx);
194
195 static bool EventIsThreadEvent(const SBEvent &event);
196
197 static SBFrame GetStackFrameFromEvent(const SBEvent &event);
198
199 static SBThread GetThreadFromEvent(const SBEvent &event);
200
202
203 const lldb::SBThread &operator=(const lldb::SBThread &rhs);
204
205 bool operator==(const lldb::SBThread &rhs) const;
206
207 bool operator!=(const lldb::SBThread &rhs) const;
208
209 bool GetDescription(lldb::SBStream &description) const;
210
211 bool GetDescription(lldb::SBStream &description, bool stop_format) const;
212
213 /// Similar to \a GetDescription() but the format of the description can be
214 /// configured via the \p format parameter. See
215 /// https://lldb.llvm.org/use/formatting.html for more information on format
216 /// strings.
217 ///
218 /// \param[in] format
219 /// The format to use for generating the description.
220 ///
221 /// \param[out] output
222 /// The stream where the description will be written to.
223 ///
224 /// \return
225 /// An error object with an error message in case of failures.
226 SBError GetDescriptionWithFormat(const SBFormat &format, SBStream &output);
227
228 bool GetStatus(lldb::SBStream &status) const;
229
230 SBThread GetExtendedBacktraceThread(const char *type);
231
233
235
237
238 bool SafeToCallFunctions();
239
241
242private:
243 friend class SBBreakpoint;
246 friend class SBSaveCoreOptions;
247 friend class SBExecutionContext;
248 friend class SBFrame;
249 friend class SBFrameList;
250 friend class SBProcess;
251 friend class SBDebugger;
252 friend class SBValue;
254 friend class SBQueueItem;
255 friend class SBThreadCollection;
256 friend class SBThreadPlan;
257 friend class SBTrace;
258
260 friend class lldb_private::python::SWIGBridge;
261
262 SBThread(const lldb::ThreadSP &lldb_object_sp);
263
264 void SetThread(const lldb::ThreadSP &lldb_object_sp);
265
266 lldb::ThreadSP GetSP() const;
267
269
271
273};
274
275} // namespace lldb
276
277#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:502
bool Suspend()
LLDB currently supports process centric debugging which means when any thread in a process stops,...
Definition SBThread.cpp:967
bool GetStopDescription(lldb::SBStream &stream) const
Gets a human-readable description of why the thread stopped.
Definition SBThread.cpp:243
const lldb::SBThread & operator=(const lldb::SBThread &rhs)
Definition SBThread.cpp:78
friend class SBBreakpointCallbackBaton
Definition SBThread.h:245
lldb::SBFrame SetSelectedFrame(uint32_t frame_idx)
SBError UnwindInnermostExpression()
Definition SBThread.cpp:947
friend class SBThreadCollection
Definition SBThread.h:255
bool IsValid() const
Definition SBThread.cpp:111
uint32_t GetNumFrames()
friend class SBProcess
Definition SBThread.h:250
const char * GetQueueName() const
Definition SBThread.cpp:353
friend class SBSaveCoreOptions
Definition SBThread.h:246
friend class SBQueueItem
Definition SBThread.h:254
SBValue GetSiginfo()
uint32_t GetIndexID() const
Definition SBThread.cpp:328
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:251
void StepOutOfFrame(SBFrame &frame)
Definition SBThread.cpp:610
friend class SBBreakpoint
Definition SBThread.h:243
bool GetStatus(lldb::SBStream &status) const
friend class SBValue
Definition SBThread.h:252
static SBFrame GetStackFrameFromEvent(const SBEvent &event)
lldb::queue_id_t GetQueueID() const
Definition SBThread.cpp:369
bool GetInfoItemByPathAsString(const char *path, SBStream &strm)
Definition SBThread.cpp:387
lldb::SBFrame GetSelectedFrame()
friend class SBExecutionContext
Definition SBThread.h:247
friend class SBFrameList
Definition SBThread.h:249
bool operator!=(const lldb::SBThread &rhs) const
friend class SBTrace
Definition SBThread.h:257
SBError StepUsingScriptedThreadPlan(const char *script_class_name)
Definition SBThread.cpp:851
lldb::tid_t GetThreadID() const
Definition SBThread.cpp:319
friend class SBThreadPlan
Definition SBThread.h:256
lldb::SBFrame GetFrameAtIndex(uint32_t idx)
uint32_t GetExtendedBacktraceOriginatingIndexID()
lldb::SBQueue GetQueue() const
Definition SBThread.cpp:89
lldb::SBFrameList GetFrames()
bool SafeToCallFunctions()
lldb::SBProcess GetProcess()
size_t GetStopReasonDataCount()
Get the number of words associated with the stop reason.
Definition SBThread.cpp:153
void StepInstruction(bool step_over)
Definition SBThread.cpp:658
SBThread GetCurrentExceptionBacktrace()
friend class SBFrame
Definition SBThread.h:248
static SBThread GetThreadFromEvent(const SBEvent &event)
bool GetStopReasonExtendedInfoAsJSON(lldb::SBStream &stream)
Definition SBThread.cpp:190
lldb::StopReason GetStopReason()
Definition SBThread.cpp:136
SBValue GetStopReturnValue()
Definition SBThread.cpp:294
void StepOver(lldb::RunMode stop_other_threads=lldb::eOnlyDuringStepping)
Definition SBThread.cpp:459
SBError JumpToLine(lldb::SBFileSpec &file_spec, uint32_t line)
Definition SBThread.cpp:906
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:244
SBThreadCollection GetStopReasonExtendedBacktraces(InstrumentationRuntimeType type)
Definition SBThread.cpp:216
SBValue GetCurrentException()
void SetThread(const lldb::ThreadSP &lldb_object_sp)
Definition SBThread.cpp:315
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:268
void RunToAddress(lldb::addr_t addr)
Definition SBThread.cpp:691
uint64_t GetStopReasonDataAtIndex(uint32_t idx)
Get information associated with a stop reason.
Definition SBThread.cpp:171
SBError ReturnFromFrame(SBFrame &frame, SBValue &return_value)
Definition SBThread.cpp:928
bool operator==(const lldb::SBThread &rhs) const
SBError StepOverUntil(lldb::SBFrame &frame, lldb::SBFileSpec &file_spec, uint32_t line)
Definition SBThread.cpp:730
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:84
uint64_t queue_id_t
Definition lldb-types.h:90
std::shared_ptr< lldb_private::ExecutionContextRef > ExecutionContextRefSP