1 //===-- SBThread.cpp --------------------------------------------*- 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 #include "lldb/API/SBThread.h"
10 #include "SBReproducerPrivate.h"
12 #include "lldb/API/SBAddress.h"
13 #include "lldb/API/SBDebugger.h"
14 #include "lldb/API/SBEvent.h"
15 #include "lldb/API/SBFileSpec.h"
16 #include "lldb/API/SBFrame.h"
17 #include "lldb/API/SBProcess.h"
18 #include "lldb/API/SBStream.h"
19 #include "lldb/API/SBStructuredData.h"
20 #include "lldb/API/SBSymbolContext.h"
21 #include "lldb/API/SBThreadCollection.h"
22 #include "lldb/API/SBThreadPlan.h"
23 #include "lldb/API/SBValue.h"
24 #include "lldb/Breakpoint/BreakpointLocation.h"
25 #include "lldb/Core/Debugger.h"
26 #include "lldb/Core/StreamFile.h"
27 #include "lldb/Core/StructuredDataImpl.h"
28 #include "lldb/Core/ValueObject.h"
29 #include "lldb/Interpreter/CommandInterpreter.h"
30 #include "lldb/Symbol/CompileUnit.h"
31 #include "lldb/Symbol/SymbolContext.h"
32 #include "lldb/Target/Process.h"
33 #include "lldb/Target/Queue.h"
34 #include "lldb/Target/StopInfo.h"
35 #include "lldb/Target/SystemRuntime.h"
36 #include "lldb/Target/Target.h"
37 #include "lldb/Target/Thread.h"
38 #include "lldb/Target/ThreadPlan.h"
39 #include "lldb/Target/ThreadPlanStepInRange.h"
40 #include "lldb/Target/ThreadPlanStepInstruction.h"
41 #include "lldb/Target/ThreadPlanStepOut.h"
42 #include "lldb/Target/ThreadPlanStepRange.h"
43 #include "lldb/Target/UnixSignals.h"
44 #include "lldb/Utility/State.h"
45 #include "lldb/Utility/Stream.h"
46 #include "lldb/Utility/StructuredData.h"
47 #include "lldb/lldb-enumerations.h"
52 using namespace lldb_private
;
54 const char *SBThread::GetBroadcasterClassName() {
55 LLDB_RECORD_STATIC_METHOD_NO_ARGS(const char *, SBThread
,
56 GetBroadcasterClassName
);
58 return Thread::GetStaticBroadcasterClass().AsCString();
62 SBThread::SBThread() : m_opaque_sp(new ExecutionContextRef()) {
63 LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBThread
);
66 SBThread::SBThread(const ThreadSP
&lldb_object_sp
)
67 : m_opaque_sp(new ExecutionContextRef(lldb_object_sp
)) {
68 LLDB_RECORD_CONSTRUCTOR(SBThread
, (const lldb::ThreadSP
&), lldb_object_sp
);
71 SBThread::SBThread(const SBThread
&rhs
) : m_opaque_sp() {
72 LLDB_RECORD_CONSTRUCTOR(SBThread
, (const lldb::SBThread
&), rhs
);
74 m_opaque_sp
= clone(rhs
.m_opaque_sp
);
77 // Assignment operator
79 const lldb::SBThread
&SBThread::operator=(const SBThread
&rhs
) {
80 LLDB_RECORD_METHOD(const lldb::SBThread
&,
81 SBThread
, operator=,(const lldb::SBThread
&), rhs
);
84 m_opaque_sp
= clone(rhs
.m_opaque_sp
);
85 return LLDB_RECORD_RESULT(*this);
89 SBThread::~SBThread() {}
91 lldb::SBQueue
SBThread::GetQueue() const {
92 LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBQueue
, SBThread
, GetQueue
);
96 std::unique_lock
<std::recursive_mutex
> lock
;
97 ExecutionContext
exe_ctx(m_opaque_sp
.get(), lock
);
99 if (exe_ctx
.HasThreadScope()) {
100 Process::StopLocker stop_locker
;
101 if (stop_locker
.TryLock(&exe_ctx
.GetProcessPtr()->GetRunLock())) {
102 queue_sp
= exe_ctx
.GetThreadPtr()->GetQueue();
104 sb_queue
.SetQueue(queue_sp
);
109 return LLDB_RECORD_RESULT(sb_queue
);
112 bool SBThread::IsValid() const {
113 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBThread
, IsValid
);
114 return this->operator bool();
116 SBThread::operator bool() const {
117 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBThread
, operator bool);
119 std::unique_lock
<std::recursive_mutex
> lock
;
120 ExecutionContext
exe_ctx(m_opaque_sp
.get(), lock
);
122 Target
*target
= exe_ctx
.GetTargetPtr();
123 Process
*process
= exe_ctx
.GetProcessPtr();
124 if (target
&& process
) {
125 Process::StopLocker stop_locker
;
126 if (stop_locker
.TryLock(&process
->GetRunLock()))
127 return m_opaque_sp
->GetThreadSP().get() != nullptr;
129 // Without a valid target & process, this thread can't be valid.
133 void SBThread::Clear() {
134 LLDB_RECORD_METHOD_NO_ARGS(void, SBThread
, Clear
);
136 m_opaque_sp
->Clear();
139 StopReason
SBThread::GetStopReason() {
140 LLDB_RECORD_METHOD_NO_ARGS(lldb::StopReason
, SBThread
, GetStopReason
);
142 StopReason reason
= eStopReasonInvalid
;
143 std::unique_lock
<std::recursive_mutex
> lock
;
144 ExecutionContext
exe_ctx(m_opaque_sp
.get(), lock
);
146 if (exe_ctx
.HasThreadScope()) {
147 Process::StopLocker stop_locker
;
148 if (stop_locker
.TryLock(&exe_ctx
.GetProcessPtr()->GetRunLock())) {
149 return exe_ctx
.GetThreadPtr()->GetStopReason();
156 size_t SBThread::GetStopReasonDataCount() {
157 LLDB_RECORD_METHOD_NO_ARGS(size_t, SBThread
, GetStopReasonDataCount
);
159 std::unique_lock
<std::recursive_mutex
> lock
;
160 ExecutionContext
exe_ctx(m_opaque_sp
.get(), lock
);
162 if (exe_ctx
.HasThreadScope()) {
163 Process::StopLocker stop_locker
;
164 if (stop_locker
.TryLock(&exe_ctx
.GetProcessPtr()->GetRunLock())) {
165 StopInfoSP stop_info_sp
= exe_ctx
.GetThreadPtr()->GetStopInfo();
167 StopReason reason
= stop_info_sp
->GetStopReason();
169 case eStopReasonInvalid
:
170 case eStopReasonNone
:
171 case eStopReasonTrace
:
172 case eStopReasonExec
:
173 case eStopReasonPlanComplete
:
174 case eStopReasonThreadExiting
:
175 case eStopReasonInstrumentation
:
176 // There is no data for these stop reasons.
179 case eStopReasonBreakpoint
: {
180 break_id_t site_id
= stop_info_sp
->GetValue();
181 lldb::BreakpointSiteSP
bp_site_sp(
182 exe_ctx
.GetProcessPtr()->GetBreakpointSiteList().FindByID(
185 return bp_site_sp
->GetNumberOfOwners() * 2;
187 return 0; // Breakpoint must have cleared itself...
190 case eStopReasonWatchpoint
:
193 case eStopReasonSignal
:
196 case eStopReasonException
:
205 uint64_t SBThread::GetStopReasonDataAtIndex(uint32_t idx
) {
206 LLDB_RECORD_METHOD(uint64_t, SBThread
, GetStopReasonDataAtIndex
, (uint32_t),
209 std::unique_lock
<std::recursive_mutex
> lock
;
210 ExecutionContext
exe_ctx(m_opaque_sp
.get(), lock
);
212 if (exe_ctx
.HasThreadScope()) {
213 Process::StopLocker stop_locker
;
214 if (stop_locker
.TryLock(&exe_ctx
.GetProcessPtr()->GetRunLock())) {
215 Thread
*thread
= exe_ctx
.GetThreadPtr();
216 StopInfoSP stop_info_sp
= thread
->GetStopInfo();
218 StopReason reason
= stop_info_sp
->GetStopReason();
220 case eStopReasonInvalid
:
221 case eStopReasonNone
:
222 case eStopReasonTrace
:
223 case eStopReasonExec
:
224 case eStopReasonPlanComplete
:
225 case eStopReasonThreadExiting
:
226 case eStopReasonInstrumentation
:
227 // There is no data for these stop reasons.
230 case eStopReasonBreakpoint
: {
231 break_id_t site_id
= stop_info_sp
->GetValue();
232 lldb::BreakpointSiteSP
bp_site_sp(
233 exe_ctx
.GetProcessPtr()->GetBreakpointSiteList().FindByID(
236 uint32_t bp_index
= idx
/ 2;
237 BreakpointLocationSP
bp_loc_sp(
238 bp_site_sp
->GetOwnerAtIndex(bp_index
));
241 // Odd idx, return the breakpoint location ID
242 return bp_loc_sp
->GetID();
244 // Even idx, return the breakpoint ID
245 return bp_loc_sp
->GetBreakpoint().GetID();
249 return LLDB_INVALID_BREAK_ID
;
252 case eStopReasonWatchpoint
:
253 return stop_info_sp
->GetValue();
255 case eStopReasonSignal
:
256 return stop_info_sp
->GetValue();
258 case eStopReasonException
:
259 return stop_info_sp
->GetValue();
267 bool SBThread::GetStopReasonExtendedInfoAsJSON(lldb::SBStream
&stream
) {
268 LLDB_RECORD_METHOD(bool, SBThread
, GetStopReasonExtendedInfoAsJSON
,
269 (lldb::SBStream
&), stream
);
271 Stream
&strm
= stream
.ref();
273 std::unique_lock
<std::recursive_mutex
> lock
;
274 ExecutionContext
exe_ctx(m_opaque_sp
.get(), lock
);
276 if (!exe_ctx
.HasThreadScope())
279 StopInfoSP stop_info
= exe_ctx
.GetThreadPtr()->GetStopInfo();
280 StructuredData::ObjectSP info
= stop_info
->GetExtendedInfo();
290 SBThread::GetStopReasonExtendedBacktraces(InstrumentationRuntimeType type
) {
291 LLDB_RECORD_METHOD(lldb::SBThreadCollection
, SBThread
,
292 GetStopReasonExtendedBacktraces
,
293 (lldb::InstrumentationRuntimeType
), type
);
295 ThreadCollectionSP threads
;
296 threads
= std::make_shared
<ThreadCollection
>();
298 std::unique_lock
<std::recursive_mutex
> lock
;
299 ExecutionContext
exe_ctx(m_opaque_sp
.get(), lock
);
301 if (!exe_ctx
.HasThreadScope())
302 return LLDB_RECORD_RESULT(threads
);
304 ProcessSP process_sp
= exe_ctx
.GetProcessSP();
306 StopInfoSP stop_info
= exe_ctx
.GetThreadPtr()->GetStopInfo();
307 StructuredData::ObjectSP info
= stop_info
->GetExtendedInfo();
309 return LLDB_RECORD_RESULT(threads
);
311 return LLDB_RECORD_RESULT(process_sp
->GetInstrumentationRuntime(type
)
312 ->GetBacktracesFromExtendedStopInfo(info
));
315 size_t SBThread::GetStopDescription(char *dst
, size_t dst_len
) {
316 LLDB_RECORD_METHOD(size_t, SBThread
, GetStopDescription
, (char *, size_t),
319 std::unique_lock
<std::recursive_mutex
> lock
;
320 ExecutionContext
exe_ctx(m_opaque_sp
.get(), lock
);
322 if (exe_ctx
.HasThreadScope()) {
323 Process::StopLocker stop_locker
;
324 if (stop_locker
.TryLock(&exe_ctx
.GetProcessPtr()->GetRunLock())) {
326 StopInfoSP stop_info_sp
= exe_ctx
.GetThreadPtr()->GetStopInfo();
328 const char *stop_desc
= stop_info_sp
->GetDescription();
331 return ::snprintf(dst
, dst_len
, "%s", stop_desc
);
333 // NULL dst passed in, return the length needed to contain the
335 return ::strlen(stop_desc
) + 1; // Include the NULL byte for size
338 size_t stop_desc_len
= 0;
339 switch (stop_info_sp
->GetStopReason()) {
340 case eStopReasonTrace
:
341 case eStopReasonPlanComplete
: {
342 static char trace_desc
[] = "step";
343 stop_desc
= trace_desc
;
345 sizeof(trace_desc
); // Include the NULL byte for size
348 case eStopReasonBreakpoint
: {
349 static char bp_desc
[] = "breakpoint hit";
351 stop_desc_len
= sizeof(bp_desc
); // Include the NULL byte for size
354 case eStopReasonWatchpoint
: {
355 static char wp_desc
[] = "watchpoint hit";
357 stop_desc_len
= sizeof(wp_desc
); // Include the NULL byte for size
360 case eStopReasonSignal
: {
362 exe_ctx
.GetProcessPtr()->GetUnixSignals()->GetSignalAsCString(
363 stop_info_sp
->GetValue());
364 if (stop_desc
== nullptr || stop_desc
[0] == '\0') {
365 static char signal_desc
[] = "signal";
366 stop_desc
= signal_desc
;
368 sizeof(signal_desc
); // Include the NULL byte for size
372 case eStopReasonException
: {
373 char exc_desc
[] = "exception";
374 stop_desc
= exc_desc
;
375 stop_desc_len
= sizeof(exc_desc
); // Include the NULL byte for size
378 case eStopReasonExec
: {
379 char exc_desc
[] = "exec";
380 stop_desc
= exc_desc
;
381 stop_desc_len
= sizeof(exc_desc
); // Include the NULL byte for size
384 case eStopReasonThreadExiting
: {
385 char limbo_desc
[] = "thread exiting";
386 stop_desc
= limbo_desc
;
387 stop_desc_len
= sizeof(limbo_desc
);
393 if (stop_desc
&& stop_desc
[0]) {
395 return ::snprintf(dst
, dst_len
, "%s", stop_desc
) +
396 1; // Include the NULL byte
398 if (stop_desc_len
== 0)
399 stop_desc_len
= ::strlen(stop_desc
) + 1; // Include the NULL byte
401 return stop_desc_len
;
412 SBValue
SBThread::GetStopReturnValue() {
413 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBValue
, SBThread
, GetStopReturnValue
);
415 ValueObjectSP return_valobj_sp
;
416 std::unique_lock
<std::recursive_mutex
> lock
;
417 ExecutionContext
exe_ctx(m_opaque_sp
.get(), lock
);
419 if (exe_ctx
.HasThreadScope()) {
420 Process::StopLocker stop_locker
;
421 if (stop_locker
.TryLock(&exe_ctx
.GetProcessPtr()->GetRunLock())) {
422 StopInfoSP stop_info_sp
= exe_ctx
.GetThreadPtr()->GetStopInfo();
424 return_valobj_sp
= StopInfo::GetReturnValueObject(stop_info_sp
);
429 return LLDB_RECORD_RESULT(SBValue(return_valobj_sp
));
432 void SBThread::SetThread(const ThreadSP
&lldb_object_sp
) {
433 m_opaque_sp
->SetThreadSP(lldb_object_sp
);
436 lldb::tid_t
SBThread::GetThreadID() const {
437 LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::tid_t
, SBThread
, GetThreadID
);
439 ThreadSP
thread_sp(m_opaque_sp
->GetThreadSP());
441 return thread_sp
->GetID();
442 return LLDB_INVALID_THREAD_ID
;
445 uint32_t SBThread::GetIndexID() const {
446 LLDB_RECORD_METHOD_CONST_NO_ARGS(uint32_t, SBThread
, GetIndexID
);
448 ThreadSP
thread_sp(m_opaque_sp
->GetThreadSP());
450 return thread_sp
->GetIndexID();
451 return LLDB_INVALID_INDEX32
;
454 const char *SBThread::GetName() const {
455 LLDB_RECORD_METHOD_CONST_NO_ARGS(const char *, SBThread
, GetName
);
457 const char *name
= nullptr;
458 std::unique_lock
<std::recursive_mutex
> lock
;
459 ExecutionContext
exe_ctx(m_opaque_sp
.get(), lock
);
461 if (exe_ctx
.HasThreadScope()) {
462 Process::StopLocker stop_locker
;
463 if (stop_locker
.TryLock(&exe_ctx
.GetProcessPtr()->GetRunLock())) {
464 name
= exe_ctx
.GetThreadPtr()->GetName();
471 const char *SBThread::GetQueueName() const {
472 LLDB_RECORD_METHOD_CONST_NO_ARGS(const char *, SBThread
, GetQueueName
);
474 const char *name
= nullptr;
475 std::unique_lock
<std::recursive_mutex
> lock
;
476 ExecutionContext
exe_ctx(m_opaque_sp
.get(), lock
);
478 if (exe_ctx
.HasThreadScope()) {
479 Process::StopLocker stop_locker
;
480 if (stop_locker
.TryLock(&exe_ctx
.GetProcessPtr()->GetRunLock())) {
481 name
= exe_ctx
.GetThreadPtr()->GetQueueName();
488 lldb::queue_id_t
SBThread::GetQueueID() const {
489 LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::queue_id_t
, SBThread
, GetQueueID
);
491 queue_id_t id
= LLDB_INVALID_QUEUE_ID
;
492 std::unique_lock
<std::recursive_mutex
> lock
;
493 ExecutionContext
exe_ctx(m_opaque_sp
.get(), lock
);
495 if (exe_ctx
.HasThreadScope()) {
496 Process::StopLocker stop_locker
;
497 if (stop_locker
.TryLock(&exe_ctx
.GetProcessPtr()->GetRunLock())) {
498 id
= exe_ctx
.GetThreadPtr()->GetQueueID();
505 bool SBThread::GetInfoItemByPathAsString(const char *path
, SBStream
&strm
) {
506 LLDB_RECORD_METHOD(bool, SBThread
, GetInfoItemByPathAsString
,
507 (const char *, lldb::SBStream
&), path
, strm
);
509 bool success
= false;
510 std::unique_lock
<std::recursive_mutex
> lock
;
511 ExecutionContext
exe_ctx(m_opaque_sp
.get(), lock
);
513 if (exe_ctx
.HasThreadScope()) {
514 Process::StopLocker stop_locker
;
515 if (stop_locker
.TryLock(&exe_ctx
.GetProcessPtr()->GetRunLock())) {
516 Thread
*thread
= exe_ctx
.GetThreadPtr();
517 StructuredData::ObjectSP info_root_sp
= thread
->GetExtendedInfo();
519 StructuredData::ObjectSP node
=
520 info_root_sp
->GetObjectForDotSeparatedPath(path
);
522 if (node
->GetType() == eStructuredDataTypeString
) {
523 strm
.Printf("%s", node
->GetAsString()->GetValue().str().c_str());
526 if (node
->GetType() == eStructuredDataTypeInteger
) {
527 strm
.Printf("0x%" PRIx64
, node
->GetAsInteger()->GetValue());
530 if (node
->GetType() == eStructuredDataTypeFloat
) {
531 strm
.Printf("0x%f", node
->GetAsFloat()->GetValue());
534 if (node
->GetType() == eStructuredDataTypeBoolean
) {
535 if (node
->GetAsBoolean()->GetValue())
538 strm
.Printf("false");
541 if (node
->GetType() == eStructuredDataTypeNull
) {
553 SBError
SBThread::ResumeNewPlan(ExecutionContext
&exe_ctx
,
554 ThreadPlan
*new_plan
) {
557 Process
*process
= exe_ctx
.GetProcessPtr();
559 sb_error
.SetErrorString("No process in SBThread::ResumeNewPlan");
563 Thread
*thread
= exe_ctx
.GetThreadPtr();
565 sb_error
.SetErrorString("No thread in SBThread::ResumeNewPlan");
569 // User level plans should be Master Plans so they can be interrupted, other
570 // plans executed, and then a "continue" will resume the plan.
571 if (new_plan
!= nullptr) {
572 new_plan
->SetIsMasterPlan(true);
573 new_plan
->SetOkayToDiscard(false);
576 // Why do we need to set the current thread by ID here???
577 process
->GetThreadList().SetSelectedThreadByID(thread
->GetID());
579 if (process
->GetTarget().GetDebugger().GetAsyncExecution())
580 sb_error
.ref() = process
->Resume();
582 sb_error
.ref() = process
->ResumeSynchronous(nullptr);
587 void SBThread::StepOver(lldb::RunMode stop_other_threads
) {
588 LLDB_RECORD_METHOD(void, SBThread
, StepOver
, (lldb::RunMode
),
591 SBError error
; // Ignored
592 StepOver(stop_other_threads
, error
);
595 void SBThread::StepOver(lldb::RunMode stop_other_threads
, SBError
&error
) {
596 LLDB_RECORD_METHOD(void, SBThread
, StepOver
, (lldb::RunMode
, lldb::SBError
&),
597 stop_other_threads
, error
);
599 std::unique_lock
<std::recursive_mutex
> lock
;
600 ExecutionContext
exe_ctx(m_opaque_sp
.get(), lock
);
602 if (!exe_ctx
.HasThreadScope()) {
603 error
.SetErrorString("this SBThread object is invalid");
607 Thread
*thread
= exe_ctx
.GetThreadPtr();
608 bool abort_other_plans
= false;
609 StackFrameSP
frame_sp(thread
->GetStackFrameAtIndex(0));
611 Status new_plan_status
;
612 ThreadPlanSP new_plan_sp
;
614 if (frame_sp
->HasDebugInformation()) {
615 const LazyBool avoid_no_debug
= eLazyBoolCalculate
;
616 SymbolContext
sc(frame_sp
->GetSymbolContext(eSymbolContextEverything
));
617 new_plan_sp
= thread
->QueueThreadPlanForStepOverRange(
618 abort_other_plans
, sc
.line_entry
, sc
, stop_other_threads
,
619 new_plan_status
, avoid_no_debug
);
621 new_plan_sp
= thread
->QueueThreadPlanForStepSingleInstruction(
622 true, abort_other_plans
, stop_other_threads
, new_plan_status
);
625 error
= ResumeNewPlan(exe_ctx
, new_plan_sp
.get());
628 void SBThread::StepInto(lldb::RunMode stop_other_threads
) {
629 LLDB_RECORD_METHOD(void, SBThread
, StepInto
, (lldb::RunMode
),
632 StepInto(nullptr, stop_other_threads
);
635 void SBThread::StepInto(const char *target_name
,
636 lldb::RunMode stop_other_threads
) {
637 LLDB_RECORD_METHOD(void, SBThread
, StepInto
, (const char *, lldb::RunMode
),
638 target_name
, stop_other_threads
);
640 SBError error
; // Ignored
641 StepInto(target_name
, LLDB_INVALID_LINE_NUMBER
, error
, stop_other_threads
);
644 void SBThread::StepInto(const char *target_name
, uint32_t end_line
,
645 SBError
&error
, lldb::RunMode stop_other_threads
) {
646 LLDB_RECORD_METHOD(void, SBThread
, StepInto
,
647 (const char *, uint32_t, lldb::SBError
&, lldb::RunMode
),
648 target_name
, end_line
, error
, stop_other_threads
);
651 std::unique_lock
<std::recursive_mutex
> lock
;
652 ExecutionContext
exe_ctx(m_opaque_sp
.get(), lock
);
654 if (!exe_ctx
.HasThreadScope()) {
655 error
.SetErrorString("this SBThread object is invalid");
659 bool abort_other_plans
= false;
661 Thread
*thread
= exe_ctx
.GetThreadPtr();
662 StackFrameSP
frame_sp(thread
->GetStackFrameAtIndex(0));
663 ThreadPlanSP new_plan_sp
;
664 Status new_plan_status
;
666 if (frame_sp
&& frame_sp
->HasDebugInformation()) {
667 SymbolContext
sc(frame_sp
->GetSymbolContext(eSymbolContextEverything
));
669 if (end_line
== LLDB_INVALID_LINE_NUMBER
)
670 range
= sc
.line_entry
.range
;
672 if (!sc
.GetAddressRangeFromHereToEndLine(end_line
, range
, error
.ref()))
676 const LazyBool step_out_avoids_code_without_debug_info
=
678 const LazyBool step_in_avoids_code_without_debug_info
=
680 new_plan_sp
= thread
->QueueThreadPlanForStepInRange(
681 abort_other_plans
, range
, sc
, target_name
, stop_other_threads
,
682 new_plan_status
, step_in_avoids_code_without_debug_info
,
683 step_out_avoids_code_without_debug_info
);
685 new_plan_sp
= thread
->QueueThreadPlanForStepSingleInstruction(
686 false, abort_other_plans
, stop_other_threads
, new_plan_status
);
689 if (new_plan_status
.Success())
690 error
= ResumeNewPlan(exe_ctx
, new_plan_sp
.get());
692 error
.SetErrorString(new_plan_status
.AsCString());
695 void SBThread::StepOut() {
696 LLDB_RECORD_METHOD_NO_ARGS(void, SBThread
, StepOut
);
698 SBError error
; // Ignored
702 void SBThread::StepOut(SBError
&error
) {
703 LLDB_RECORD_METHOD(void, SBThread
, StepOut
, (lldb::SBError
&), error
);
705 std::unique_lock
<std::recursive_mutex
> lock
;
706 ExecutionContext
exe_ctx(m_opaque_sp
.get(), lock
);
708 if (!exe_ctx
.HasThreadScope()) {
709 error
.SetErrorString("this SBThread object is invalid");
713 bool abort_other_plans
= false;
714 bool stop_other_threads
= false;
716 Thread
*thread
= exe_ctx
.GetThreadPtr();
718 const LazyBool avoid_no_debug
= eLazyBoolCalculate
;
719 Status new_plan_status
;
720 ThreadPlanSP
new_plan_sp(thread
->QueueThreadPlanForStepOut(
721 abort_other_plans
, nullptr, false, stop_other_threads
, eVoteYes
,
722 eVoteNoOpinion
, 0, new_plan_status
, avoid_no_debug
));
724 if (new_plan_status
.Success())
725 error
= ResumeNewPlan(exe_ctx
, new_plan_sp
.get());
727 error
.SetErrorString(new_plan_status
.AsCString());
730 void SBThread::StepOutOfFrame(SBFrame
&sb_frame
) {
731 LLDB_RECORD_METHOD(void, SBThread
, StepOutOfFrame
, (lldb::SBFrame
&),
734 SBError error
; // Ignored
735 StepOutOfFrame(sb_frame
, error
);
738 void SBThread::StepOutOfFrame(SBFrame
&sb_frame
, SBError
&error
) {
739 LLDB_RECORD_METHOD(void, SBThread
, StepOutOfFrame
,
740 (lldb::SBFrame
&, lldb::SBError
&), sb_frame
, error
);
743 std::unique_lock
<std::recursive_mutex
> lock
;
744 ExecutionContext
exe_ctx(m_opaque_sp
.get(), lock
);
746 if (!sb_frame
.IsValid()) {
747 error
.SetErrorString("passed invalid SBFrame object");
751 StackFrameSP
frame_sp(sb_frame
.GetFrameSP());
753 if (!exe_ctx
.HasThreadScope()) {
754 error
.SetErrorString("this SBThread object is invalid");
758 bool abort_other_plans
= false;
759 bool stop_other_threads
= false;
760 Thread
*thread
= exe_ctx
.GetThreadPtr();
761 if (sb_frame
.GetThread().GetThreadID() != thread
->GetID()) {
762 error
.SetErrorString("passed a frame from another thread");
766 Status new_plan_status
;
767 ThreadPlanSP
new_plan_sp(thread
->QueueThreadPlanForStepOut(
768 abort_other_plans
, nullptr, false, stop_other_threads
, eVoteYes
,
769 eVoteNoOpinion
, frame_sp
->GetFrameIndex(), new_plan_status
));
771 if (new_plan_status
.Success())
772 error
= ResumeNewPlan(exe_ctx
, new_plan_sp
.get());
774 error
.SetErrorString(new_plan_status
.AsCString());
777 void SBThread::StepInstruction(bool step_over
) {
778 LLDB_RECORD_METHOD(void, SBThread
, StepInstruction
, (bool), step_over
);
780 SBError error
; // Ignored
781 StepInstruction(step_over
, error
);
784 void SBThread::StepInstruction(bool step_over
, SBError
&error
) {
785 LLDB_RECORD_METHOD(void, SBThread
, StepInstruction
, (bool, lldb::SBError
&),
788 std::unique_lock
<std::recursive_mutex
> lock
;
789 ExecutionContext
exe_ctx(m_opaque_sp
.get(), lock
);
791 if (!exe_ctx
.HasThreadScope()) {
792 error
.SetErrorString("this SBThread object is invalid");
796 Thread
*thread
= exe_ctx
.GetThreadPtr();
797 Status new_plan_status
;
798 ThreadPlanSP
new_plan_sp(thread
->QueueThreadPlanForStepSingleInstruction(
799 step_over
, true, true, new_plan_status
));
801 if (new_plan_status
.Success())
802 error
= ResumeNewPlan(exe_ctx
, new_plan_sp
.get());
804 error
.SetErrorString(new_plan_status
.AsCString());
807 void SBThread::RunToAddress(lldb::addr_t addr
) {
808 LLDB_RECORD_METHOD(void, SBThread
, RunToAddress
, (lldb::addr_t
), addr
);
810 SBError error
; // Ignored
811 RunToAddress(addr
, error
);
814 void SBThread::RunToAddress(lldb::addr_t addr
, SBError
&error
) {
815 LLDB_RECORD_METHOD(void, SBThread
, RunToAddress
,
816 (lldb::addr_t
, lldb::SBError
&), addr
, error
);
818 std::unique_lock
<std::recursive_mutex
> lock
;
819 ExecutionContext
exe_ctx(m_opaque_sp
.get(), lock
);
821 if (!exe_ctx
.HasThreadScope()) {
822 error
.SetErrorString("this SBThread object is invalid");
826 bool abort_other_plans
= false;
827 bool stop_other_threads
= true;
829 Address
target_addr(addr
);
831 Thread
*thread
= exe_ctx
.GetThreadPtr();
833 Status new_plan_status
;
834 ThreadPlanSP
new_plan_sp(thread
->QueueThreadPlanForRunToAddress(
835 abort_other_plans
, target_addr
, stop_other_threads
, new_plan_status
));
837 if (new_plan_status
.Success())
838 error
= ResumeNewPlan(exe_ctx
, new_plan_sp
.get());
840 error
.SetErrorString(new_plan_status
.AsCString());
843 SBError
SBThread::StepOverUntil(lldb::SBFrame
&sb_frame
,
844 lldb::SBFileSpec
&sb_file_spec
, uint32_t line
) {
845 LLDB_RECORD_METHOD(lldb::SBError
, SBThread
, StepOverUntil
,
846 (lldb::SBFrame
&, lldb::SBFileSpec
&, uint32_t), sb_frame
,
852 std::unique_lock
<std::recursive_mutex
> lock
;
853 ExecutionContext
exe_ctx(m_opaque_sp
.get(), lock
);
855 StackFrameSP
frame_sp(sb_frame
.GetFrameSP());
857 if (exe_ctx
.HasThreadScope()) {
858 Target
*target
= exe_ctx
.GetTargetPtr();
859 Thread
*thread
= exe_ctx
.GetThreadPtr();
862 sb_error
.SetErrorString("invalid line argument");
863 return LLDB_RECORD_RESULT(sb_error
);
867 frame_sp
= thread
->GetSelectedFrame();
869 frame_sp
= thread
->GetStackFrameAtIndex(0);
872 SymbolContext frame_sc
;
874 sb_error
.SetErrorString("no valid frames in thread to step");
875 return LLDB_RECORD_RESULT(sb_error
);
878 // If we have a frame, get its line
879 frame_sc
= frame_sp
->GetSymbolContext(
880 eSymbolContextCompUnit
| eSymbolContextFunction
|
881 eSymbolContextLineEntry
| eSymbolContextSymbol
);
883 if (frame_sc
.comp_unit
== nullptr) {
884 sb_error
.SetErrorStringWithFormat(
885 "frame %u doesn't have debug information", frame_sp
->GetFrameIndex());
886 return LLDB_RECORD_RESULT(sb_error
);
889 FileSpec step_file_spec
;
890 if (sb_file_spec
.IsValid()) {
891 // The file spec passed in was valid, so use it
892 step_file_spec
= sb_file_spec
.ref();
894 if (frame_sc
.line_entry
.IsValid())
895 step_file_spec
= frame_sc
.line_entry
.file
;
897 sb_error
.SetErrorString("invalid file argument or no file for frame");
898 return LLDB_RECORD_RESULT(sb_error
);
902 // Grab the current function, then we will make sure the "until" address is
903 // within the function. We discard addresses that are out of the current
904 // function, and then if there are no addresses remaining, give an
905 // appropriate error message.
907 bool all_in_function
= true;
908 AddressRange fun_range
= frame_sc
.function
->GetAddressRange();
910 std::vector
<addr_t
> step_over_until_addrs
;
911 const bool abort_other_plans
= false;
912 const bool stop_other_threads
= false;
913 const bool check_inlines
= true;
914 const bool exact
= false;
916 SymbolContextList sc_list
;
917 frame_sc
.comp_unit
->ResolveSymbolContext(step_file_spec
, line
,
918 check_inlines
, exact
,
919 eSymbolContextLineEntry
, sc_list
);
920 const uint32_t num_matches
= sc_list
.GetSize();
921 if (num_matches
> 0) {
923 for (uint32_t i
= 0; i
< num_matches
; ++i
) {
924 if (sc_list
.GetContextAtIndex(i
, sc
)) {
926 sc
.line_entry
.range
.GetBaseAddress().GetLoadAddress(target
);
927 if (step_addr
!= LLDB_INVALID_ADDRESS
) {
928 if (fun_range
.ContainsLoadAddress(step_addr
, target
))
929 step_over_until_addrs
.push_back(step_addr
);
931 all_in_function
= false;
937 if (step_over_until_addrs
.empty()) {
938 if (all_in_function
) {
939 step_file_spec
.GetPath(path
, sizeof(path
));
940 sb_error
.SetErrorStringWithFormat("No line entries for %s:%u", path
,
943 sb_error
.SetErrorString("step until target not in current function");
945 Status new_plan_status
;
946 ThreadPlanSP
new_plan_sp(thread
->QueueThreadPlanForStepUntil(
947 abort_other_plans
, &step_over_until_addrs
[0],
948 step_over_until_addrs
.size(), stop_other_threads
,
949 frame_sp
->GetFrameIndex(), new_plan_status
));
951 if (new_plan_status
.Success())
952 sb_error
= ResumeNewPlan(exe_ctx
, new_plan_sp
.get());
954 sb_error
.SetErrorString(new_plan_status
.AsCString());
957 sb_error
.SetErrorString("this SBThread object is invalid");
959 return LLDB_RECORD_RESULT(sb_error
);
962 SBError
SBThread::StepUsingScriptedThreadPlan(const char *script_class_name
) {
963 LLDB_RECORD_METHOD(lldb::SBError
, SBThread
, StepUsingScriptedThreadPlan
,
964 (const char *), script_class_name
);
966 return LLDB_RECORD_RESULT(
967 StepUsingScriptedThreadPlan(script_class_name
, true));
970 SBError
SBThread::StepUsingScriptedThreadPlan(const char *script_class_name
,
971 bool resume_immediately
) {
972 LLDB_RECORD_METHOD(lldb::SBError
, SBThread
, StepUsingScriptedThreadPlan
,
973 (const char *, bool), script_class_name
,
976 lldb::SBStructuredData no_data
;
977 return LLDB_RECORD_RESULT(
978 StepUsingScriptedThreadPlan(script_class_name
,
980 resume_immediately
));
983 SBError
SBThread::StepUsingScriptedThreadPlan(const char *script_class_name
,
984 SBStructuredData
&args_data
,
985 bool resume_immediately
) {
986 LLDB_RECORD_METHOD(lldb::SBError
, SBThread
, StepUsingScriptedThreadPlan
,
987 (const char *, lldb::SBStructuredData
&, bool),
988 script_class_name
, args_data
,
993 std::unique_lock
<std::recursive_mutex
> lock
;
994 ExecutionContext
exe_ctx(m_opaque_sp
.get(), lock
);
996 if (!exe_ctx
.HasThreadScope()) {
997 error
.SetErrorString("this SBThread object is invalid");
998 return LLDB_RECORD_RESULT(error
);
1001 Thread
*thread
= exe_ctx
.GetThreadPtr();
1002 Status new_plan_status
;
1003 StructuredData::ObjectSP obj_sp
= args_data
.m_impl_up
->GetObjectSP();
1005 ThreadPlanSP new_plan_sp
= thread
->QueueThreadPlanForStepScripted(
1006 false, script_class_name
, obj_sp
, false, new_plan_status
);
1008 if (new_plan_status
.Fail()) {
1009 error
.SetErrorString(new_plan_status
.AsCString());
1010 return LLDB_RECORD_RESULT(error
);
1013 if (!resume_immediately
)
1014 return LLDB_RECORD_RESULT(error
);
1016 if (new_plan_status
.Success())
1017 error
= ResumeNewPlan(exe_ctx
, new_plan_sp
.get());
1019 error
.SetErrorString(new_plan_status
.AsCString());
1021 return LLDB_RECORD_RESULT(error
);
1024 SBError
SBThread::JumpToLine(lldb::SBFileSpec
&file_spec
, uint32_t line
) {
1025 LLDB_RECORD_METHOD(lldb::SBError
, SBThread
, JumpToLine
,
1026 (lldb::SBFileSpec
&, uint32_t), file_spec
, line
);
1030 std::unique_lock
<std::recursive_mutex
> lock
;
1031 ExecutionContext
exe_ctx(m_opaque_sp
.get(), lock
);
1033 if (!exe_ctx
.HasThreadScope()) {
1034 sb_error
.SetErrorString("this SBThread object is invalid");
1035 return LLDB_RECORD_RESULT(sb_error
);
1038 Thread
*thread
= exe_ctx
.GetThreadPtr();
1040 Status err
= thread
->JumpToLine(file_spec
.ref(), line
, true);
1041 sb_error
.SetError(err
);
1042 return LLDB_RECORD_RESULT(sb_error
);
1045 SBError
SBThread::ReturnFromFrame(SBFrame
&frame
, SBValue
&return_value
) {
1046 LLDB_RECORD_METHOD(lldb::SBError
, SBThread
, ReturnFromFrame
,
1047 (lldb::SBFrame
&, lldb::SBValue
&), frame
, return_value
);
1051 std::unique_lock
<std::recursive_mutex
> lock
;
1052 ExecutionContext
exe_ctx(m_opaque_sp
.get(), lock
);
1054 if (exe_ctx
.HasThreadScope()) {
1055 Thread
*thread
= exe_ctx
.GetThreadPtr();
1057 thread
->ReturnFromFrame(frame
.GetFrameSP(), return_value
.GetSP()));
1060 return LLDB_RECORD_RESULT(sb_error
);
1063 SBError
SBThread::UnwindInnermostExpression() {
1064 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBError
, SBThread
,
1065 UnwindInnermostExpression
);
1069 std::unique_lock
<std::recursive_mutex
> lock
;
1070 ExecutionContext
exe_ctx(m_opaque_sp
.get(), lock
);
1072 if (exe_ctx
.HasThreadScope()) {
1073 Thread
*thread
= exe_ctx
.GetThreadPtr();
1074 sb_error
.SetError(thread
->UnwindInnermostExpression());
1075 if (sb_error
.Success())
1076 thread
->SetSelectedFrameByIndex(0, false);
1079 return LLDB_RECORD_RESULT(sb_error
);
1082 bool SBThread::Suspend() {
1083 LLDB_RECORD_METHOD_NO_ARGS(bool, SBThread
, Suspend
);
1085 SBError error
; // Ignored
1086 return Suspend(error
);
1089 bool SBThread::Suspend(SBError
&error
) {
1090 LLDB_RECORD_METHOD(bool, SBThread
, Suspend
, (lldb::SBError
&), error
);
1092 std::unique_lock
<std::recursive_mutex
> lock
;
1093 ExecutionContext
exe_ctx(m_opaque_sp
.get(), lock
);
1095 bool result
= false;
1096 if (exe_ctx
.HasThreadScope()) {
1097 Process::StopLocker stop_locker
;
1098 if (stop_locker
.TryLock(&exe_ctx
.GetProcessPtr()->GetRunLock())) {
1099 exe_ctx
.GetThreadPtr()->SetResumeState(eStateSuspended
);
1102 error
.SetErrorString("process is running");
1105 error
.SetErrorString("this SBThread object is invalid");
1109 bool SBThread::Resume() {
1110 LLDB_RECORD_METHOD_NO_ARGS(bool, SBThread
, Resume
);
1112 SBError error
; // Ignored
1113 return Resume(error
);
1116 bool SBThread::Resume(SBError
&error
) {
1117 LLDB_RECORD_METHOD(bool, SBThread
, Resume
, (lldb::SBError
&), error
);
1119 std::unique_lock
<std::recursive_mutex
> lock
;
1120 ExecutionContext
exe_ctx(m_opaque_sp
.get(), lock
);
1122 bool result
= false;
1123 if (exe_ctx
.HasThreadScope()) {
1124 Process::StopLocker stop_locker
;
1125 if (stop_locker
.TryLock(&exe_ctx
.GetProcessPtr()->GetRunLock())) {
1126 const bool override_suspend
= true;
1127 exe_ctx
.GetThreadPtr()->SetResumeState(eStateRunning
, override_suspend
);
1130 error
.SetErrorString("process is running");
1133 error
.SetErrorString("this SBThread object is invalid");
1137 bool SBThread::IsSuspended() {
1138 LLDB_RECORD_METHOD_NO_ARGS(bool, SBThread
, IsSuspended
);
1140 std::unique_lock
<std::recursive_mutex
> lock
;
1141 ExecutionContext
exe_ctx(m_opaque_sp
.get(), lock
);
1143 if (exe_ctx
.HasThreadScope())
1144 return exe_ctx
.GetThreadPtr()->GetResumeState() == eStateSuspended
;
1148 bool SBThread::IsStopped() {
1149 LLDB_RECORD_METHOD_NO_ARGS(bool, SBThread
, IsStopped
);
1151 std::unique_lock
<std::recursive_mutex
> lock
;
1152 ExecutionContext
exe_ctx(m_opaque_sp
.get(), lock
);
1154 if (exe_ctx
.HasThreadScope())
1155 return StateIsStoppedState(exe_ctx
.GetThreadPtr()->GetState(), true);
1159 SBProcess
SBThread::GetProcess() {
1160 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBProcess
, SBThread
, GetProcess
);
1162 SBProcess sb_process
;
1163 std::unique_lock
<std::recursive_mutex
> lock
;
1164 ExecutionContext
exe_ctx(m_opaque_sp
.get(), lock
);
1166 if (exe_ctx
.HasThreadScope()) {
1167 // Have to go up to the target so we can get a shared pointer to our
1169 sb_process
.SetSP(exe_ctx
.GetProcessSP());
1172 return LLDB_RECORD_RESULT(sb_process
);
1175 uint32_t SBThread::GetNumFrames() {
1176 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBThread
, GetNumFrames
);
1178 uint32_t num_frames
= 0;
1179 std::unique_lock
<std::recursive_mutex
> lock
;
1180 ExecutionContext
exe_ctx(m_opaque_sp
.get(), lock
);
1182 if (exe_ctx
.HasThreadScope()) {
1183 Process::StopLocker stop_locker
;
1184 if (stop_locker
.TryLock(&exe_ctx
.GetProcessPtr()->GetRunLock())) {
1185 num_frames
= exe_ctx
.GetThreadPtr()->GetStackFrameCount();
1192 SBFrame
SBThread::GetFrameAtIndex(uint32_t idx
) {
1193 LLDB_RECORD_METHOD(lldb::SBFrame
, SBThread
, GetFrameAtIndex
, (uint32_t), idx
);
1196 StackFrameSP frame_sp
;
1197 std::unique_lock
<std::recursive_mutex
> lock
;
1198 ExecutionContext
exe_ctx(m_opaque_sp
.get(), lock
);
1200 if (exe_ctx
.HasThreadScope()) {
1201 Process::StopLocker stop_locker
;
1202 if (stop_locker
.TryLock(&exe_ctx
.GetProcessPtr()->GetRunLock())) {
1203 frame_sp
= exe_ctx
.GetThreadPtr()->GetStackFrameAtIndex(idx
);
1204 sb_frame
.SetFrameSP(frame_sp
);
1208 return LLDB_RECORD_RESULT(sb_frame
);
1211 lldb::SBFrame
SBThread::GetSelectedFrame() {
1212 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBFrame
, SBThread
, GetSelectedFrame
);
1215 StackFrameSP frame_sp
;
1216 std::unique_lock
<std::recursive_mutex
> lock
;
1217 ExecutionContext
exe_ctx(m_opaque_sp
.get(), lock
);
1219 if (exe_ctx
.HasThreadScope()) {
1220 Process::StopLocker stop_locker
;
1221 if (stop_locker
.TryLock(&exe_ctx
.GetProcessPtr()->GetRunLock())) {
1222 frame_sp
= exe_ctx
.GetThreadPtr()->GetSelectedFrame();
1223 sb_frame
.SetFrameSP(frame_sp
);
1227 return LLDB_RECORD_RESULT(sb_frame
);
1230 lldb::SBFrame
SBThread::SetSelectedFrame(uint32_t idx
) {
1231 LLDB_RECORD_METHOD(lldb::SBFrame
, SBThread
, SetSelectedFrame
, (uint32_t),
1235 StackFrameSP frame_sp
;
1236 std::unique_lock
<std::recursive_mutex
> lock
;
1237 ExecutionContext
exe_ctx(m_opaque_sp
.get(), lock
);
1239 if (exe_ctx
.HasThreadScope()) {
1240 Process::StopLocker stop_locker
;
1241 if (stop_locker
.TryLock(&exe_ctx
.GetProcessPtr()->GetRunLock())) {
1242 Thread
*thread
= exe_ctx
.GetThreadPtr();
1243 frame_sp
= thread
->GetStackFrameAtIndex(idx
);
1245 thread
->SetSelectedFrame(frame_sp
.get());
1246 sb_frame
.SetFrameSP(frame_sp
);
1251 return LLDB_RECORD_RESULT(sb_frame
);
1254 bool SBThread::EventIsThreadEvent(const SBEvent
&event
) {
1255 LLDB_RECORD_STATIC_METHOD(bool, SBThread
, EventIsThreadEvent
,
1256 (const lldb::SBEvent
&), event
);
1258 return Thread::ThreadEventData::GetEventDataFromEvent(event
.get()) != nullptr;
1261 SBFrame
SBThread::GetStackFrameFromEvent(const SBEvent
&event
) {
1262 LLDB_RECORD_STATIC_METHOD(lldb::SBFrame
, SBThread
, GetStackFrameFromEvent
,
1263 (const lldb::SBEvent
&), event
);
1265 return LLDB_RECORD_RESULT(
1266 Thread::ThreadEventData::GetStackFrameFromEvent(event
.get()));
1269 SBThread
SBThread::GetThreadFromEvent(const SBEvent
&event
) {
1270 LLDB_RECORD_STATIC_METHOD(lldb::SBThread
, SBThread
, GetThreadFromEvent
,
1271 (const lldb::SBEvent
&), event
);
1273 return LLDB_RECORD_RESULT(
1274 Thread::ThreadEventData::GetThreadFromEvent(event
.get()));
1277 bool SBThread::operator==(const SBThread
&rhs
) const {
1278 LLDB_RECORD_METHOD_CONST(bool, SBThread
, operator==,(const lldb::SBThread
&),
1281 return m_opaque_sp
->GetThreadSP().get() ==
1282 rhs
.m_opaque_sp
->GetThreadSP().get();
1285 bool SBThread::operator!=(const SBThread
&rhs
) const {
1286 LLDB_RECORD_METHOD_CONST(bool, SBThread
, operator!=,(const lldb::SBThread
&),
1289 return m_opaque_sp
->GetThreadSP().get() !=
1290 rhs
.m_opaque_sp
->GetThreadSP().get();
1293 bool SBThread::GetStatus(SBStream
&status
) const {
1294 LLDB_RECORD_METHOD_CONST(bool, SBThread
, GetStatus
, (lldb::SBStream
&),
1297 Stream
&strm
= status
.ref();
1299 std::unique_lock
<std::recursive_mutex
> lock
;
1300 ExecutionContext
exe_ctx(m_opaque_sp
.get(), lock
);
1302 if (exe_ctx
.HasThreadScope()) {
1303 exe_ctx
.GetThreadPtr()->GetStatus(strm
, 0, 1, 1, true);
1305 strm
.PutCString("No status");
1310 bool SBThread::GetDescription(SBStream
&description
) const {
1311 LLDB_RECORD_METHOD_CONST(bool, SBThread
, GetDescription
, (lldb::SBStream
&),
1314 return GetDescription(description
, false);
1317 bool SBThread::GetDescription(SBStream
&description
, bool stop_format
) const {
1318 LLDB_RECORD_METHOD_CONST(bool, SBThread
, GetDescription
,
1319 (lldb::SBStream
&, bool), description
, stop_format
);
1321 Stream
&strm
= description
.ref();
1323 std::unique_lock
<std::recursive_mutex
> lock
;
1324 ExecutionContext
exe_ctx(m_opaque_sp
.get(), lock
);
1326 if (exe_ctx
.HasThreadScope()) {
1327 exe_ctx
.GetThreadPtr()->DumpUsingSettingsFormat(strm
,
1328 LLDB_INVALID_THREAD_ID
,
1330 // strm.Printf("SBThread: tid = 0x%4.4" PRIx64,
1331 // exe_ctx.GetThreadPtr()->GetID());
1333 strm
.PutCString("No value");
1338 SBThread
SBThread::GetExtendedBacktraceThread(const char *type
) {
1339 LLDB_RECORD_METHOD(lldb::SBThread
, SBThread
, GetExtendedBacktraceThread
,
1340 (const char *), type
);
1342 std::unique_lock
<std::recursive_mutex
> lock
;
1343 ExecutionContext
exe_ctx(m_opaque_sp
.get(), lock
);
1344 SBThread sb_origin_thread
;
1346 Process::StopLocker stop_locker
;
1347 if (stop_locker
.TryLock(&exe_ctx
.GetProcessPtr()->GetRunLock())) {
1348 if (exe_ctx
.HasThreadScope()) {
1349 ThreadSP
real_thread(exe_ctx
.GetThreadSP());
1351 ConstString
type_const(type
);
1352 Process
*process
= exe_ctx
.GetProcessPtr();
1354 SystemRuntime
*runtime
= process
->GetSystemRuntime();
1356 ThreadSP
new_thread_sp(
1357 runtime
->GetExtendedBacktraceThread(real_thread
, type_const
));
1358 if (new_thread_sp
) {
1359 // Save this in the Process' ExtendedThreadList so a strong
1360 // pointer retains the object.
1361 process
->GetExtendedThreadList().AddThread(new_thread_sp
);
1362 sb_origin_thread
.SetThread(new_thread_sp
);
1370 return LLDB_RECORD_RESULT(sb_origin_thread
);
1373 uint32_t SBThread::GetExtendedBacktraceOriginatingIndexID() {
1374 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBThread
,
1375 GetExtendedBacktraceOriginatingIndexID
);
1377 ThreadSP
thread_sp(m_opaque_sp
->GetThreadSP());
1379 return thread_sp
->GetExtendedBacktraceOriginatingIndexID();
1380 return LLDB_INVALID_INDEX32
;
1383 SBValue
SBThread::GetCurrentException() {
1384 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBValue
, SBThread
, GetCurrentException
);
1386 ThreadSP
thread_sp(m_opaque_sp
->GetThreadSP());
1388 return LLDB_RECORD_RESULT(SBValue());
1390 return LLDB_RECORD_RESULT(SBValue(thread_sp
->GetCurrentException()));
1393 SBThread
SBThread::GetCurrentExceptionBacktrace() {
1394 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBThread
, SBThread
,
1395 GetCurrentExceptionBacktrace
);
1397 ThreadSP
thread_sp(m_opaque_sp
->GetThreadSP());
1399 return LLDB_RECORD_RESULT(SBThread());
1401 return LLDB_RECORD_RESULT(
1402 SBThread(thread_sp
->GetCurrentExceptionBacktrace()));
1405 bool SBThread::SafeToCallFunctions() {
1406 LLDB_RECORD_METHOD_NO_ARGS(bool, SBThread
, SafeToCallFunctions
);
1408 ThreadSP
thread_sp(m_opaque_sp
->GetThreadSP());
1410 return thread_sp
->SafeToCallFunctions();
1414 lldb_private::Thread
*SBThread::operator->() {
1418 lldb_private::Thread
*SBThread::get() {
1419 return m_opaque_sp
->GetThreadSP().get();
1422 namespace lldb_private
{
1426 void RegisterMethods
<SBThread
>(Registry
&R
) {
1427 LLDB_REGISTER_STATIC_METHOD(const char *, SBThread
, GetBroadcasterClassName
,
1429 LLDB_REGISTER_CONSTRUCTOR(SBThread
, ());
1430 LLDB_REGISTER_CONSTRUCTOR(SBThread
, (const lldb::ThreadSP
&));
1431 LLDB_REGISTER_CONSTRUCTOR(SBThread
, (const lldb::SBThread
&));
1432 LLDB_REGISTER_METHOD(const lldb::SBThread
&,
1433 SBThread
, operator=,(const lldb::SBThread
&));
1434 LLDB_REGISTER_METHOD_CONST(lldb::SBQueue
, SBThread
, GetQueue
, ());
1435 LLDB_REGISTER_METHOD_CONST(bool, SBThread
, IsValid
, ());
1436 LLDB_REGISTER_METHOD_CONST(bool, SBThread
, operator bool, ());
1437 LLDB_REGISTER_METHOD(void, SBThread
, Clear
, ());
1438 LLDB_REGISTER_METHOD(lldb::StopReason
, SBThread
, GetStopReason
, ());
1439 LLDB_REGISTER_METHOD(size_t, SBThread
, GetStopReasonDataCount
, ());
1440 LLDB_REGISTER_METHOD(uint64_t, SBThread
, GetStopReasonDataAtIndex
,
1442 LLDB_REGISTER_METHOD(bool, SBThread
, GetStopReasonExtendedInfoAsJSON
,
1443 (lldb::SBStream
&));
1444 LLDB_REGISTER_METHOD(lldb::SBThreadCollection
, SBThread
,
1445 GetStopReasonExtendedBacktraces
,
1446 (lldb::InstrumentationRuntimeType
));
1447 LLDB_REGISTER_METHOD(size_t, SBThread
, GetStopDescription
,
1449 LLDB_REGISTER_METHOD(lldb::SBValue
, SBThread
, GetStopReturnValue
, ());
1450 LLDB_REGISTER_METHOD_CONST(lldb::tid_t
, SBThread
, GetThreadID
, ());
1451 LLDB_REGISTER_METHOD_CONST(uint32_t, SBThread
, GetIndexID
, ());
1452 LLDB_REGISTER_METHOD_CONST(const char *, SBThread
, GetName
, ());
1453 LLDB_REGISTER_METHOD_CONST(const char *, SBThread
, GetQueueName
, ());
1454 LLDB_REGISTER_METHOD_CONST(lldb::queue_id_t
, SBThread
, GetQueueID
, ());
1455 LLDB_REGISTER_METHOD(bool, SBThread
, GetInfoItemByPathAsString
,
1456 (const char *, lldb::SBStream
&));
1457 LLDB_REGISTER_METHOD(void, SBThread
, StepOver
, (lldb::RunMode
));
1458 LLDB_REGISTER_METHOD(void, SBThread
, StepOver
,
1459 (lldb::RunMode
, lldb::SBError
&));
1460 LLDB_REGISTER_METHOD(void, SBThread
, StepInto
, (lldb::RunMode
));
1461 LLDB_REGISTER_METHOD(void, SBThread
, StepInto
,
1462 (const char *, lldb::RunMode
));
1463 LLDB_REGISTER_METHOD(
1464 void, SBThread
, StepInto
,
1465 (const char *, uint32_t, lldb::SBError
&, lldb::RunMode
));
1466 LLDB_REGISTER_METHOD(void, SBThread
, StepOut
, ());
1467 LLDB_REGISTER_METHOD(void, SBThread
, StepOut
, (lldb::SBError
&));
1468 LLDB_REGISTER_METHOD(void, SBThread
, StepOutOfFrame
, (lldb::SBFrame
&));
1469 LLDB_REGISTER_METHOD(void, SBThread
, StepOutOfFrame
,
1470 (lldb::SBFrame
&, lldb::SBError
&));
1471 LLDB_REGISTER_METHOD(void, SBThread
, StepInstruction
, (bool));
1472 LLDB_REGISTER_METHOD(void, SBThread
, StepInstruction
,
1473 (bool, lldb::SBError
&));
1474 LLDB_REGISTER_METHOD(void, SBThread
, RunToAddress
, (lldb::addr_t
));
1475 LLDB_REGISTER_METHOD(void, SBThread
, RunToAddress
,
1476 (lldb::addr_t
, lldb::SBError
&));
1477 LLDB_REGISTER_METHOD(lldb::SBError
, SBThread
, StepOverUntil
,
1478 (lldb::SBFrame
&, lldb::SBFileSpec
&, uint32_t));
1479 LLDB_REGISTER_METHOD(lldb::SBError
, SBThread
, StepUsingScriptedThreadPlan
,
1481 LLDB_REGISTER_METHOD(lldb::SBError
, SBThread
, StepUsingScriptedThreadPlan
,
1482 (const char *, bool));
1483 LLDB_REGISTER_METHOD(lldb::SBError
, SBThread
, StepUsingScriptedThreadPlan
,
1484 (const char *, SBStructuredData
&, bool));
1485 LLDB_REGISTER_METHOD(lldb::SBError
, SBThread
, JumpToLine
,
1486 (lldb::SBFileSpec
&, uint32_t));
1487 LLDB_REGISTER_METHOD(lldb::SBError
, SBThread
, ReturnFromFrame
,
1488 (lldb::SBFrame
&, lldb::SBValue
&));
1489 LLDB_REGISTER_METHOD(lldb::SBError
, SBThread
, UnwindInnermostExpression
,
1491 LLDB_REGISTER_METHOD(bool, SBThread
, Suspend
, ());
1492 LLDB_REGISTER_METHOD(bool, SBThread
, Suspend
, (lldb::SBError
&));
1493 LLDB_REGISTER_METHOD(bool, SBThread
, Resume
, ());
1494 LLDB_REGISTER_METHOD(bool, SBThread
, Resume
, (lldb::SBError
&));
1495 LLDB_REGISTER_METHOD(bool, SBThread
, IsSuspended
, ());
1496 LLDB_REGISTER_METHOD(bool, SBThread
, IsStopped
, ());
1497 LLDB_REGISTER_METHOD(lldb::SBProcess
, SBThread
, GetProcess
, ());
1498 LLDB_REGISTER_METHOD(uint32_t, SBThread
, GetNumFrames
, ());
1499 LLDB_REGISTER_METHOD(lldb::SBFrame
, SBThread
, GetFrameAtIndex
, (uint32_t));
1500 LLDB_REGISTER_METHOD(lldb::SBFrame
, SBThread
, GetSelectedFrame
, ());
1501 LLDB_REGISTER_METHOD(lldb::SBFrame
, SBThread
, SetSelectedFrame
, (uint32_t));
1502 LLDB_REGISTER_STATIC_METHOD(bool, SBThread
, EventIsThreadEvent
,
1503 (const lldb::SBEvent
&));
1504 LLDB_REGISTER_STATIC_METHOD(lldb::SBFrame
, SBThread
, GetStackFrameFromEvent
,
1505 (const lldb::SBEvent
&));
1506 LLDB_REGISTER_STATIC_METHOD(lldb::SBThread
, SBThread
, GetThreadFromEvent
,
1507 (const lldb::SBEvent
&));
1508 LLDB_REGISTER_METHOD_CONST(bool,
1509 SBThread
, operator==,(const lldb::SBThread
&));
1510 LLDB_REGISTER_METHOD_CONST(bool,
1511 SBThread
, operator!=,(const lldb::SBThread
&));
1512 LLDB_REGISTER_METHOD_CONST(bool, SBThread
, GetStatus
, (lldb::SBStream
&));
1513 LLDB_REGISTER_METHOD_CONST(bool, SBThread
, GetDescription
,
1514 (lldb::SBStream
&));
1515 LLDB_REGISTER_METHOD_CONST(bool, SBThread
, GetDescription
,
1516 (lldb::SBStream
&, bool));
1517 LLDB_REGISTER_METHOD(lldb::SBThread
, SBThread
, GetExtendedBacktraceThread
,
1519 LLDB_REGISTER_METHOD(uint32_t, SBThread
,
1520 GetExtendedBacktraceOriginatingIndexID
, ());
1521 LLDB_REGISTER_METHOD(lldb::SBValue
, SBThread
, GetCurrentException
, ());
1522 LLDB_REGISTER_METHOD(lldb::SBThread
, SBThread
, GetCurrentExceptionBacktrace
,
1524 LLDB_REGISTER_METHOD(bool, SBThread
, SafeToCallFunctions
, ());