1 //===-- SBThread.cpp --------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/API/SBThread.h"
12 #include "lldb/API/SBFileSpec.h"
13 #include "lldb/API/SBStream.h"
14 #include "lldb/API/SBSymbolContext.h"
15 #include "lldb/Breakpoint/BreakpointLocation.h"
16 #include "lldb/Core/Debugger.h"
17 #include "lldb/Core/StreamFile.h"
18 #include "lldb/Core/ValueObject.h"
19 #include "lldb/Interpreter/CommandInterpreter.h"
20 #include "lldb/Symbol/CompileUnit.h"
21 #include "lldb/Symbol/SymbolContext.h"
22 #include "lldb/Target/Process.h"
23 #include "lldb/Target/Queue.h"
24 #include "lldb/Target/StopInfo.h"
25 #include "lldb/Target/SystemRuntime.h"
26 #include "lldb/Target/Target.h"
27 #include "lldb/Target/Thread.h"
28 #include "lldb/Target/ThreadPlan.h"
29 #include "lldb/Target/ThreadPlanStepInRange.h"
30 #include "lldb/Target/ThreadPlanStepInstruction.h"
31 #include "lldb/Target/ThreadPlanStepOut.h"
32 #include "lldb/Target/ThreadPlanStepRange.h"
33 #include "lldb/Target/UnixSignals.h"
34 #include "lldb/Utility/State.h"
35 #include "lldb/Utility/Stream.h"
36 #include "lldb/Utility/StructuredData.h"
38 #include "lldb/API/SBAddress.h"
39 #include "lldb/API/SBDebugger.h"
40 #include "lldb/API/SBEvent.h"
41 #include "lldb/API/SBFrame.h"
42 #include "lldb/API/SBProcess.h"
43 #include "lldb/API/SBThreadCollection.h"
44 #include "lldb/API/SBThreadPlan.h"
45 #include "lldb/API/SBValue.h"
46 #include "lldb/lldb-enumerations.h"
49 using namespace lldb_private;
51 const char *SBThread::GetBroadcasterClassName() {
52 return Thread::GetStaticBroadcasterClass().AsCString();
55 //----------------------------------------------------------------------
57 //----------------------------------------------------------------------
58 SBThread::SBThread() : m_opaque_sp(new ExecutionContextRef()) {}
60 SBThread::SBThread(const ThreadSP &lldb_object_sp)
61 : m_opaque_sp(new ExecutionContextRef(lldb_object_sp)) {}
63 SBThread::SBThread(const SBThread &rhs)
64 : m_opaque_sp(new ExecutionContextRef(*rhs.m_opaque_sp)) {}
66 //----------------------------------------------------------------------
67 // Assignment operator
68 //----------------------------------------------------------------------
70 const lldb::SBThread &SBThread::operator=(const SBThread &rhs) {
72 *m_opaque_sp = *rhs.m_opaque_sp;
76 //----------------------------------------------------------------------
78 //----------------------------------------------------------------------
79 SBThread::~SBThread() {}
81 lldb::SBQueue SBThread::GetQueue() const {
84 std::unique_lock<std::recursive_mutex> lock;
85 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
87 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
88 if (exe_ctx.HasThreadScope()) {
89 Process::StopLocker stop_locker;
90 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) {
91 queue_sp = exe_ctx.GetThreadPtr()->GetQueue();
93 sb_queue.SetQueue(queue_sp);
97 log->Printf("SBThread(%p)::GetQueue() => error: process is running",
98 static_cast<void *>(exe_ctx.GetThreadPtr()));
103 log->Printf("SBThread(%p)::GetQueue () => SBQueue(%p)",
104 static_cast<void *>(exe_ctx.GetThreadPtr()),
105 static_cast<void *>(queue_sp.get()));
110 bool SBThread::IsValid() const {
111 std::unique_lock<std::recursive_mutex> lock;
112 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
114 Target *target = exe_ctx.GetTargetPtr();
115 Process *process = exe_ctx.GetProcessPtr();
116 if (target && process) {
117 Process::StopLocker stop_locker;
118 if (stop_locker.TryLock(&process->GetRunLock()))
119 return m_opaque_sp->GetThreadSP().get() != NULL;
121 // Without a valid target & process, this thread can't be valid.
125 void SBThread::Clear() { m_opaque_sp->Clear(); }
127 StopReason SBThread::GetStopReason() {
128 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
130 StopReason reason = eStopReasonInvalid;
131 std::unique_lock<std::recursive_mutex> lock;
132 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
134 if (exe_ctx.HasThreadScope()) {
135 Process::StopLocker stop_locker;
136 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) {
137 return exe_ctx.GetThreadPtr()->GetStopReason();
141 "SBThread(%p)::GetStopReason() => error: process is running",
142 static_cast<void *>(exe_ctx.GetThreadPtr()));
147 log->Printf("SBThread(%p)::GetStopReason () => %s",
148 static_cast<void *>(exe_ctx.GetThreadPtr()),
149 Thread::StopReasonAsCString(reason));
154 size_t SBThread::GetStopReasonDataCount() {
155 std::unique_lock<std::recursive_mutex> lock;
156 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
158 if (exe_ctx.HasThreadScope()) {
159 Process::StopLocker stop_locker;
160 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) {
161 StopInfoSP stop_info_sp = exe_ctx.GetThreadPtr()->GetStopInfo();
163 StopReason reason = stop_info_sp->GetStopReason();
165 case eStopReasonInvalid:
166 case eStopReasonNone:
167 case eStopReasonTrace:
168 case eStopReasonExec:
169 case eStopReasonPlanComplete:
170 case eStopReasonThreadExiting:
171 case eStopReasonInstrumentation:
172 // There is no data for these stop reasons.
175 case eStopReasonBreakpoint: {
176 break_id_t site_id = stop_info_sp->GetValue();
177 lldb::BreakpointSiteSP bp_site_sp(
178 exe_ctx.GetProcessPtr()->GetBreakpointSiteList().FindByID(
181 return bp_site_sp->GetNumberOfOwners() * 2;
183 return 0; // Breakpoint must have cleared itself...
186 case eStopReasonWatchpoint:
189 case eStopReasonSignal:
192 case eStopReasonException:
197 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
199 log->Printf("SBThread(%p)::GetStopReasonDataCount() => error: process "
201 static_cast<void *>(exe_ctx.GetThreadPtr()));
207 uint64_t SBThread::GetStopReasonDataAtIndex(uint32_t idx) {
208 std::unique_lock<std::recursive_mutex> lock;
209 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
211 if (exe_ctx.HasThreadScope()) {
212 Process::StopLocker stop_locker;
213 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) {
214 Thread *thread = exe_ctx.GetThreadPtr();
215 StopInfoSP stop_info_sp = thread->GetStopInfo();
217 StopReason reason = stop_info_sp->GetStopReason();
219 case eStopReasonInvalid:
220 case eStopReasonNone:
221 case eStopReasonTrace:
222 case eStopReasonExec:
223 case eStopReasonPlanComplete:
224 case eStopReasonThreadExiting:
225 case eStopReasonInstrumentation:
226 // There is no data for these stop reasons.
229 case eStopReasonBreakpoint: {
230 break_id_t site_id = stop_info_sp->GetValue();
231 lldb::BreakpointSiteSP bp_site_sp(
232 exe_ctx.GetProcessPtr()->GetBreakpointSiteList().FindByID(
235 uint32_t bp_index = idx / 2;
236 BreakpointLocationSP bp_loc_sp(
237 bp_site_sp->GetOwnerAtIndex(bp_index));
240 // Odd idx, return the breakpoint location ID
241 return bp_loc_sp->GetID();
243 // Even idx, return the breakpoint ID
244 return bp_loc_sp->GetBreakpoint().GetID();
248 return LLDB_INVALID_BREAK_ID;
251 case eStopReasonWatchpoint:
252 return stop_info_sp->GetValue();
254 case eStopReasonSignal:
255 return stop_info_sp->GetValue();
257 case eStopReasonException:
258 return stop_info_sp->GetValue();
262 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
264 log->Printf("SBThread(%p)::GetStopReasonDataAtIndex() => error: "
265 "process is running",
266 static_cast<void *>(exe_ctx.GetThreadPtr()));
272 bool SBThread::GetStopReasonExtendedInfoAsJSON(lldb::SBStream &stream) {
273 Stream &strm = stream.ref();
275 std::unique_lock<std::recursive_mutex> lock;
276 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
278 if (!exe_ctx.HasThreadScope())
281 StopInfoSP stop_info = exe_ctx.GetThreadPtr()->GetStopInfo();
282 StructuredData::ObjectSP info = stop_info->GetExtendedInfo();
292 SBThread::GetStopReasonExtendedBacktraces(InstrumentationRuntimeType type) {
293 ThreadCollectionSP threads;
294 threads.reset(new ThreadCollection());
296 std::unique_lock<std::recursive_mutex> lock;
297 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
299 if (!exe_ctx.HasThreadScope())
302 ProcessSP process_sp = exe_ctx.GetProcessSP();
304 StopInfoSP stop_info = exe_ctx.GetThreadPtr()->GetStopInfo();
305 StructuredData::ObjectSP info = stop_info->GetExtendedInfo();
309 return process_sp->GetInstrumentationRuntime(type)
310 ->GetBacktracesFromExtendedStopInfo(info);
313 size_t SBThread::GetStopDescription(char *dst, size_t dst_len) {
314 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
316 std::unique_lock<std::recursive_mutex> lock;
317 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
319 if (exe_ctx.HasThreadScope()) {
320 Process::StopLocker stop_locker;
321 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) {
323 StopInfoSP stop_info_sp = exe_ctx.GetThreadPtr()->GetStopInfo();
325 const char *stop_desc = stop_info_sp->GetDescription();
329 "SBThread(%p)::GetStopDescription (dst, dst_len) => \"%s\"",
330 static_cast<void *>(exe_ctx.GetThreadPtr()), stop_desc);
332 return ::snprintf(dst, dst_len, "%s", stop_desc);
334 // NULL dst passed in, return the length needed to contain the
336 return ::strlen(stop_desc) + 1; // Include the NULL byte for size
339 size_t stop_desc_len = 0;
340 switch (stop_info_sp->GetStopReason()) {
341 case eStopReasonTrace:
342 case eStopReasonPlanComplete: {
343 static char trace_desc[] = "step";
344 stop_desc = trace_desc;
346 sizeof(trace_desc); // Include the NULL byte for size
349 case eStopReasonBreakpoint: {
350 static char bp_desc[] = "breakpoint hit";
352 stop_desc_len = sizeof(bp_desc); // Include the NULL byte for size
355 case eStopReasonWatchpoint: {
356 static char wp_desc[] = "watchpoint hit";
358 stop_desc_len = sizeof(wp_desc); // Include the NULL byte for size
361 case eStopReasonSignal: {
363 exe_ctx.GetProcessPtr()->GetUnixSignals()->GetSignalAsCString(
364 stop_info_sp->GetValue());
365 if (stop_desc == NULL || stop_desc[0] == '\0') {
366 static char signal_desc[] = "signal";
367 stop_desc = signal_desc;
369 sizeof(signal_desc); // Include the NULL byte for size
373 case eStopReasonException: {
374 char exc_desc[] = "exception";
375 stop_desc = exc_desc;
376 stop_desc_len = sizeof(exc_desc); // Include the NULL byte for size
379 case eStopReasonExec: {
380 char exc_desc[] = "exec";
381 stop_desc = exc_desc;
382 stop_desc_len = sizeof(exc_desc); // Include the NULL byte for size
385 case eStopReasonThreadExiting: {
386 char limbo_desc[] = "thread exiting";
387 stop_desc = limbo_desc;
388 stop_desc_len = sizeof(limbo_desc);
394 if (stop_desc && stop_desc[0]) {
397 "SBThread(%p)::GetStopDescription (dst, dst_len) => '%s'",
398 static_cast<void *>(exe_ctx.GetThreadPtr()), stop_desc);
401 return ::snprintf(dst, dst_len, "%s", stop_desc) +
402 1; // Include the NULL byte
404 if (stop_desc_len == 0)
405 stop_desc_len = ::strlen(stop_desc) + 1; // Include the NULL byte
407 return stop_desc_len;
412 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
415 "SBThread(%p)::GetStopDescription() => error: process is running",
416 static_cast<void *>(exe_ctx.GetThreadPtr()));
424 SBValue SBThread::GetStopReturnValue() {
425 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
426 ValueObjectSP return_valobj_sp;
427 std::unique_lock<std::recursive_mutex> lock;
428 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
430 if (exe_ctx.HasThreadScope()) {
431 Process::StopLocker stop_locker;
432 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) {
433 StopInfoSP stop_info_sp = exe_ctx.GetThreadPtr()->GetStopInfo();
435 return_valobj_sp = StopInfo::GetReturnValueObject(stop_info_sp);
440 "SBThread(%p)::GetStopReturnValue() => error: process is running",
441 static_cast<void *>(exe_ctx.GetThreadPtr()));
446 log->Printf("SBThread(%p)::GetStopReturnValue () => %s",
447 static_cast<void *>(exe_ctx.GetThreadPtr()),
448 return_valobj_sp.get() ? return_valobj_sp->GetValueAsCString()
449 : "<no return value>");
451 return SBValue(return_valobj_sp);
454 void SBThread::SetThread(const ThreadSP &lldb_object_sp) {
455 m_opaque_sp->SetThreadSP(lldb_object_sp);
458 lldb::tid_t SBThread::GetThreadID() const {
459 ThreadSP thread_sp(m_opaque_sp->GetThreadSP());
461 return thread_sp->GetID();
462 return LLDB_INVALID_THREAD_ID;
465 uint32_t SBThread::GetIndexID() const {
466 ThreadSP thread_sp(m_opaque_sp->GetThreadSP());
468 return thread_sp->GetIndexID();
469 return LLDB_INVALID_INDEX32;
472 const char *SBThread::GetName() const {
473 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
474 const char *name = NULL;
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()->GetName();
484 log->Printf("SBThread(%p)::GetName() => error: process is running",
485 static_cast<void *>(exe_ctx.GetThreadPtr()));
490 log->Printf("SBThread(%p)::GetName () => %s",
491 static_cast<void *>(exe_ctx.GetThreadPtr()),
492 name ? name : "NULL");
497 const char *SBThread::GetQueueName() const {
498 const char *name = NULL;
499 std::unique_lock<std::recursive_mutex> lock;
500 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
502 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
503 if (exe_ctx.HasThreadScope()) {
504 Process::StopLocker stop_locker;
505 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) {
506 name = exe_ctx.GetThreadPtr()->GetQueueName();
509 log->Printf("SBThread(%p)::GetQueueName() => error: process is running",
510 static_cast<void *>(exe_ctx.GetThreadPtr()));
515 log->Printf("SBThread(%p)::GetQueueName () => %s",
516 static_cast<void *>(exe_ctx.GetThreadPtr()),
517 name ? name : "NULL");
522 lldb::queue_id_t SBThread::GetQueueID() const {
523 queue_id_t id = LLDB_INVALID_QUEUE_ID;
524 std::unique_lock<std::recursive_mutex> lock;
525 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
527 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
528 if (exe_ctx.HasThreadScope()) {
529 Process::StopLocker stop_locker;
530 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) {
531 id = exe_ctx.GetThreadPtr()->GetQueueID();
534 log->Printf("SBThread(%p)::GetQueueID() => error: process is running",
535 static_cast<void *>(exe_ctx.GetThreadPtr()));
540 log->Printf("SBThread(%p)::GetQueueID () => 0x%" PRIx64,
541 static_cast<void *>(exe_ctx.GetThreadPtr()), id);
546 bool SBThread::GetInfoItemByPathAsString(const char *path, SBStream &strm) {
547 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
548 bool success = false;
549 std::unique_lock<std::recursive_mutex> lock;
550 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
552 if (exe_ctx.HasThreadScope()) {
553 Process::StopLocker stop_locker;
554 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) {
555 Thread *thread = exe_ctx.GetThreadPtr();
556 StructuredData::ObjectSP info_root_sp = thread->GetExtendedInfo();
558 StructuredData::ObjectSP node =
559 info_root_sp->GetObjectForDotSeparatedPath(path);
561 if (node->GetType() == eStructuredDataTypeString) {
562 strm.Printf("%s", node->GetAsString()->GetValue().str().c_str());
565 if (node->GetType() == eStructuredDataTypeInteger) {
566 strm.Printf("0x%" PRIx64, node->GetAsInteger()->GetValue());
569 if (node->GetType() == eStructuredDataTypeFloat) {
570 strm.Printf("0x%f", node->GetAsFloat()->GetValue());
573 if (node->GetType() == eStructuredDataTypeBoolean) {
574 if (node->GetAsBoolean()->GetValue())
577 strm.Printf("false");
580 if (node->GetType() == eStructuredDataTypeNull) {
588 log->Printf("SBThread(%p)::GetInfoItemByPathAsString() => error: "
589 "process is running",
590 static_cast<void *>(exe_ctx.GetThreadPtr()));
595 log->Printf("SBThread(%p)::GetInfoItemByPathAsString (\"%s\") => \"%s\"",
596 static_cast<void *>(exe_ctx.GetThreadPtr()), path, strm.GetData());
601 SBError SBThread::ResumeNewPlan(ExecutionContext &exe_ctx,
602 ThreadPlan *new_plan) {
605 Process *process = exe_ctx.GetProcessPtr();
607 sb_error.SetErrorString("No process in SBThread::ResumeNewPlan");
611 Thread *thread = exe_ctx.GetThreadPtr();
613 sb_error.SetErrorString("No thread in SBThread::ResumeNewPlan");
617 // User level plans should be Master Plans so they can be interrupted, other
618 // plans executed, and then a "continue" will resume the plan.
619 if (new_plan != NULL) {
620 new_plan->SetIsMasterPlan(true);
621 new_plan->SetOkayToDiscard(false);
624 // Why do we need to set the current thread by ID here???
625 process->GetThreadList().SetSelectedThreadByID(thread->GetID());
627 if (process->GetTarget().GetDebugger().GetAsyncExecution())
628 sb_error.ref() = process->Resume();
630 sb_error.ref() = process->ResumeSynchronous(NULL);
635 void SBThread::StepOver(lldb::RunMode stop_other_threads) {
636 SBError error; // Ignored
637 StepOver(stop_other_threads, error);
640 void SBThread::StepOver(lldb::RunMode stop_other_threads, SBError &error) {
641 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
643 std::unique_lock<std::recursive_mutex> lock;
644 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
647 log->Printf("SBThread(%p)::StepOver (stop_other_threads='%s')",
648 static_cast<void *>(exe_ctx.GetThreadPtr()),
649 Thread::RunModeAsCString(stop_other_threads));
651 if (!exe_ctx.HasThreadScope()) {
652 error.SetErrorString("this SBThread object is invalid");
656 Thread *thread = exe_ctx.GetThreadPtr();
657 bool abort_other_plans = false;
658 StackFrameSP frame_sp(thread->GetStackFrameAtIndex(0));
660 Status new_plan_status;
661 ThreadPlanSP new_plan_sp;
663 if (frame_sp->HasDebugInformation()) {
664 const LazyBool avoid_no_debug = eLazyBoolCalculate;
665 SymbolContext sc(frame_sp->GetSymbolContext(eSymbolContextEverything));
666 new_plan_sp = thread->QueueThreadPlanForStepOverRange(
667 abort_other_plans, sc.line_entry, sc, stop_other_threads,
668 new_plan_status, avoid_no_debug);
670 new_plan_sp = thread->QueueThreadPlanForStepSingleInstruction(
671 true, abort_other_plans, stop_other_threads, new_plan_status);
674 error = ResumeNewPlan(exe_ctx, new_plan_sp.get());
677 void SBThread::StepInto(lldb::RunMode stop_other_threads) {
678 StepInto(NULL, stop_other_threads);
681 void SBThread::StepInto(const char *target_name,
682 lldb::RunMode stop_other_threads) {
683 SBError error; // Ignored
684 StepInto(target_name, LLDB_INVALID_LINE_NUMBER, error, stop_other_threads);
687 void SBThread::StepInto(const char *target_name, uint32_t end_line,
688 SBError &error, lldb::RunMode stop_other_threads) {
689 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
691 std::unique_lock<std::recursive_mutex> lock;
692 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
696 "SBThread(%p)::StepInto (target_name='%s', stop_other_threads='%s')",
697 static_cast<void *>(exe_ctx.GetThreadPtr()),
698 target_name ? target_name : "<NULL>",
699 Thread::RunModeAsCString(stop_other_threads));
701 if (!exe_ctx.HasThreadScope()) {
702 error.SetErrorString("this SBThread object is invalid");
706 bool abort_other_plans = false;
708 Thread *thread = exe_ctx.GetThreadPtr();
709 StackFrameSP frame_sp(thread->GetStackFrameAtIndex(0));
710 ThreadPlanSP new_plan_sp;
711 Status new_plan_status;
713 if (frame_sp && frame_sp->HasDebugInformation()) {
714 SymbolContext sc(frame_sp->GetSymbolContext(eSymbolContextEverything));
716 if (end_line == LLDB_INVALID_LINE_NUMBER)
717 range = sc.line_entry.range;
719 if (!sc.GetAddressRangeFromHereToEndLine(end_line, range, error.ref()))
723 const LazyBool step_out_avoids_code_without_debug_info =
725 const LazyBool step_in_avoids_code_without_debug_info =
727 new_plan_sp = thread->QueueThreadPlanForStepInRange(
728 abort_other_plans, range, sc, target_name, stop_other_threads,
729 new_plan_status, step_in_avoids_code_without_debug_info,
730 step_out_avoids_code_without_debug_info);
732 new_plan_sp = thread->QueueThreadPlanForStepSingleInstruction(
733 false, abort_other_plans, stop_other_threads, new_plan_status);
736 if (new_plan_status.Success())
737 error = ResumeNewPlan(exe_ctx, new_plan_sp.get());
739 error.SetErrorString(new_plan_status.AsCString());
742 void SBThread::StepOut() {
743 SBError error; // Ignored
747 void SBThread::StepOut(SBError &error) {
748 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
750 std::unique_lock<std::recursive_mutex> lock;
751 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
754 log->Printf("SBThread(%p)::StepOut ()",
755 static_cast<void *>(exe_ctx.GetThreadPtr()));
757 if (!exe_ctx.HasThreadScope()) {
758 error.SetErrorString("this SBThread object is invalid");
762 bool abort_other_plans = false;
763 bool stop_other_threads = false;
765 Thread *thread = exe_ctx.GetThreadPtr();
767 const LazyBool avoid_no_debug = eLazyBoolCalculate;
768 Status new_plan_status;
769 ThreadPlanSP new_plan_sp(thread->QueueThreadPlanForStepOut(
770 abort_other_plans, NULL, false, stop_other_threads, eVoteYes,
771 eVoteNoOpinion, 0, new_plan_status, avoid_no_debug));
773 if (new_plan_status.Success())
774 error = ResumeNewPlan(exe_ctx, new_plan_sp.get());
776 error.SetErrorString(new_plan_status.AsCString());
779 void SBThread::StepOutOfFrame(SBFrame &sb_frame) {
780 SBError error; // Ignored
781 StepOutOfFrame(sb_frame, error);
784 void SBThread::StepOutOfFrame(SBFrame &sb_frame, SBError &error) {
785 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
787 std::unique_lock<std::recursive_mutex> lock;
788 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
790 if (!sb_frame.IsValid()) {
793 "SBThread(%p)::StepOutOfFrame passed an invalid frame, returning.",
794 static_cast<void *>(exe_ctx.GetThreadPtr()));
795 error.SetErrorString("passed invalid SBFrame object");
799 StackFrameSP frame_sp(sb_frame.GetFrameSP());
801 SBStream frame_desc_strm;
802 sb_frame.GetDescription(frame_desc_strm);
803 log->Printf("SBThread(%p)::StepOutOfFrame (frame = SBFrame(%p): %s)",
804 static_cast<void *>(exe_ctx.GetThreadPtr()),
805 static_cast<void *>(frame_sp.get()), frame_desc_strm.GetData());
808 if (!exe_ctx.HasThreadScope()) {
809 error.SetErrorString("this SBThread object is invalid");
813 bool abort_other_plans = false;
814 bool stop_other_threads = false;
815 Thread *thread = exe_ctx.GetThreadPtr();
816 if (sb_frame.GetThread().GetThreadID() != thread->GetID()) {
817 log->Printf("SBThread(%p)::StepOutOfFrame passed a frame from another "
818 "thread (0x%" PRIx64 " vrs. 0x%" PRIx64 ", returning.",
819 static_cast<void *>(exe_ctx.GetThreadPtr()),
820 sb_frame.GetThread().GetThreadID(), thread->GetID());
821 error.SetErrorString("passed a frame from another thread");
825 Status new_plan_status;
826 ThreadPlanSP new_plan_sp(thread->QueueThreadPlanForStepOut(
827 abort_other_plans, NULL, false, stop_other_threads, eVoteYes,
828 eVoteNoOpinion, frame_sp->GetFrameIndex(), new_plan_status));
830 if (new_plan_status.Success())
831 error = ResumeNewPlan(exe_ctx, new_plan_sp.get());
833 error.SetErrorString(new_plan_status.AsCString());
836 void SBThread::StepInstruction(bool step_over) {
837 SBError error; // Ignored
838 StepInstruction(step_over, error);
841 void SBThread::StepInstruction(bool step_over, SBError &error) {
842 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
844 std::unique_lock<std::recursive_mutex> lock;
845 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
848 log->Printf("SBThread(%p)::StepInstruction (step_over=%i)",
849 static_cast<void *>(exe_ctx.GetThreadPtr()), step_over);
851 if (!exe_ctx.HasThreadScope()) {
852 error.SetErrorString("this SBThread object is invalid");
856 Thread *thread = exe_ctx.GetThreadPtr();
857 Status new_plan_status;
858 ThreadPlanSP new_plan_sp(thread->QueueThreadPlanForStepSingleInstruction(
859 step_over, true, true, new_plan_status));
861 if (new_plan_status.Success())
862 error = ResumeNewPlan(exe_ctx, new_plan_sp.get());
864 error.SetErrorString(new_plan_status.AsCString());
867 void SBThread::RunToAddress(lldb::addr_t addr) {
868 SBError error; // Ignored
869 RunToAddress(addr, error);
872 void SBThread::RunToAddress(lldb::addr_t addr, SBError &error) {
873 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
875 std::unique_lock<std::recursive_mutex> lock;
876 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
879 log->Printf("SBThread(%p)::RunToAddress (addr=0x%" PRIx64 ")",
880 static_cast<void *>(exe_ctx.GetThreadPtr()), addr);
882 if (!exe_ctx.HasThreadScope()) {
883 error.SetErrorString("this SBThread object is invalid");
887 bool abort_other_plans = false;
888 bool stop_other_threads = true;
890 Address target_addr(addr);
892 Thread *thread = exe_ctx.GetThreadPtr();
894 Status new_plan_status;
895 ThreadPlanSP new_plan_sp(thread->QueueThreadPlanForRunToAddress(
896 abort_other_plans, target_addr, stop_other_threads, new_plan_status));
898 if (new_plan_status.Success())
899 error = ResumeNewPlan(exe_ctx, new_plan_sp.get());
901 error.SetErrorString(new_plan_status.AsCString());
904 SBError SBThread::StepOverUntil(lldb::SBFrame &sb_frame,
905 lldb::SBFileSpec &sb_file_spec, uint32_t line) {
907 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
910 std::unique_lock<std::recursive_mutex> lock;
911 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
913 StackFrameSP frame_sp(sb_frame.GetFrameSP());
916 SBStream frame_desc_strm;
917 sb_frame.GetDescription(frame_desc_strm);
918 sb_file_spec->GetPath(path, sizeof(path));
919 log->Printf("SBThread(%p)::StepOverUntil (frame = SBFrame(%p): %s, "
920 "file+line = %s:%u)",
921 static_cast<void *>(exe_ctx.GetThreadPtr()),
922 static_cast<void *>(frame_sp.get()), frame_desc_strm.GetData(),
926 if (exe_ctx.HasThreadScope()) {
927 Target *target = exe_ctx.GetTargetPtr();
928 Thread *thread = exe_ctx.GetThreadPtr();
931 sb_error.SetErrorString("invalid line argument");
936 frame_sp = thread->GetSelectedFrame();
938 frame_sp = thread->GetStackFrameAtIndex(0);
941 SymbolContext frame_sc;
943 sb_error.SetErrorString("no valid frames in thread to step");
947 // If we have a frame, get its line
948 frame_sc = frame_sp->GetSymbolContext(
949 eSymbolContextCompUnit | eSymbolContextFunction |
950 eSymbolContextLineEntry | eSymbolContextSymbol);
952 if (frame_sc.comp_unit == NULL) {
953 sb_error.SetErrorStringWithFormat(
954 "frame %u doesn't have debug information", frame_sp->GetFrameIndex());
958 FileSpec step_file_spec;
959 if (sb_file_spec.IsValid()) {
960 // The file spec passed in was valid, so use it
961 step_file_spec = sb_file_spec.ref();
963 if (frame_sc.line_entry.IsValid())
964 step_file_spec = frame_sc.line_entry.file;
966 sb_error.SetErrorString("invalid file argument or no file for frame");
971 // Grab the current function, then we will make sure the "until" address is
972 // within the function. We discard addresses that are out of the current
973 // function, and then if there are no addresses remaining, give an
974 // appropriate error message.
976 bool all_in_function = true;
977 AddressRange fun_range = frame_sc.function->GetAddressRange();
979 std::vector<addr_t> step_over_until_addrs;
980 const bool abort_other_plans = false;
981 const bool stop_other_threads = false;
982 const bool check_inlines = true;
983 const bool exact = false;
985 SymbolContextList sc_list;
986 const uint32_t num_matches = frame_sc.comp_unit->ResolveSymbolContext(
987 step_file_spec, line, check_inlines, exact, eSymbolContextLineEntry,
989 if (num_matches > 0) {
991 for (uint32_t i = 0; i < num_matches; ++i) {
992 if (sc_list.GetContextAtIndex(i, sc)) {
994 sc.line_entry.range.GetBaseAddress().GetLoadAddress(target);
995 if (step_addr != LLDB_INVALID_ADDRESS) {
996 if (fun_range.ContainsLoadAddress(step_addr, target))
997 step_over_until_addrs.push_back(step_addr);
999 all_in_function = false;
1005 if (step_over_until_addrs.empty()) {
1006 if (all_in_function) {
1007 step_file_spec.GetPath(path, sizeof(path));
1008 sb_error.SetErrorStringWithFormat("No line entries for %s:%u", path,
1011 sb_error.SetErrorString("step until target not in current function");
1013 Status new_plan_status;
1014 ThreadPlanSP new_plan_sp(thread->QueueThreadPlanForStepUntil(
1015 abort_other_plans, &step_over_until_addrs[0],
1016 step_over_until_addrs.size(), stop_other_threads,
1017 frame_sp->GetFrameIndex(), new_plan_status));
1019 if (new_plan_status.Success())
1020 sb_error = ResumeNewPlan(exe_ctx, new_plan_sp.get());
1022 sb_error.SetErrorString(new_plan_status.AsCString());
1025 sb_error.SetErrorString("this SBThread object is invalid");
1030 SBError SBThread::StepUsingScriptedThreadPlan(const char *script_class_name) {
1031 return StepUsingScriptedThreadPlan(script_class_name, true);
1034 SBError SBThread::StepUsingScriptedThreadPlan(const char *script_class_name,
1035 bool resume_immediately) {
1036 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1039 std::unique_lock<std::recursive_mutex> lock;
1040 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
1043 log->Printf("SBThread(%p)::StepUsingScriptedThreadPlan: class name: %s",
1044 static_cast<void *>(exe_ctx.GetThreadPtr()), script_class_name);
1047 if (!exe_ctx.HasThreadScope()) {
1048 error.SetErrorString("this SBThread object is invalid");
1052 Thread *thread = exe_ctx.GetThreadPtr();
1053 Status new_plan_status;
1054 ThreadPlanSP new_plan_sp = thread->QueueThreadPlanForStepScripted(
1055 false, script_class_name, false, new_plan_status);
1057 if (new_plan_status.Fail()) {
1058 error.SetErrorString(new_plan_status.AsCString());
1062 if (!resume_immediately)
1065 if (new_plan_status.Success())
1066 error = ResumeNewPlan(exe_ctx, new_plan_sp.get());
1068 error.SetErrorString(new_plan_status.AsCString());
1073 SBError SBThread::JumpToLine(lldb::SBFileSpec &file_spec, uint32_t line) {
1074 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1077 std::unique_lock<std::recursive_mutex> lock;
1078 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
1081 log->Printf("SBThread(%p)::JumpToLine (file+line = %s:%u)",
1082 static_cast<void *>(exe_ctx.GetThreadPtr()),
1083 file_spec->GetPath().c_str(), line);
1085 if (!exe_ctx.HasThreadScope()) {
1086 sb_error.SetErrorString("this SBThread object is invalid");
1090 Thread *thread = exe_ctx.GetThreadPtr();
1092 Status err = thread->JumpToLine(file_spec.get(), line, true);
1093 sb_error.SetError(err);
1097 SBError SBThread::ReturnFromFrame(SBFrame &frame, SBValue &return_value) {
1100 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1102 std::unique_lock<std::recursive_mutex> lock;
1103 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
1106 log->Printf("SBThread(%p)::ReturnFromFrame (frame=%d)",
1107 static_cast<void *>(exe_ctx.GetThreadPtr()),
1108 frame.GetFrameID());
1110 if (exe_ctx.HasThreadScope()) {
1111 Thread *thread = exe_ctx.GetThreadPtr();
1113 thread->ReturnFromFrame(frame.GetFrameSP(), return_value.GetSP()));
1119 SBError SBThread::UnwindInnermostExpression() {
1122 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1124 std::unique_lock<std::recursive_mutex> lock;
1125 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
1128 log->Printf("SBThread(%p)::UnwindExpressionEvaluation",
1129 static_cast<void *>(exe_ctx.GetThreadPtr()));
1131 if (exe_ctx.HasThreadScope()) {
1132 Thread *thread = exe_ctx.GetThreadPtr();
1133 sb_error.SetError(thread->UnwindInnermostExpression());
1134 if (sb_error.Success())
1135 thread->SetSelectedFrameByIndex(0, false);
1141 bool SBThread::Suspend() {
1142 SBError error; // Ignored
1143 return Suspend(error);
1146 bool SBThread::Suspend(SBError &error) {
1147 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1148 std::unique_lock<std::recursive_mutex> lock;
1149 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
1151 bool result = false;
1152 if (exe_ctx.HasThreadScope()) {
1153 Process::StopLocker stop_locker;
1154 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) {
1155 exe_ctx.GetThreadPtr()->SetResumeState(eStateSuspended);
1158 error.SetErrorString("process is running");
1160 log->Printf("SBThread(%p)::Suspend() => error: process is running",
1161 static_cast<void *>(exe_ctx.GetThreadPtr()));
1164 error.SetErrorString("this SBThread object is invalid");
1166 log->Printf("SBThread(%p)::Suspend() => %i",
1167 static_cast<void *>(exe_ctx.GetThreadPtr()), result);
1171 bool SBThread::Resume() {
1172 SBError error; // Ignored
1173 return Resume(error);
1176 bool SBThread::Resume(SBError &error) {
1177 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1178 std::unique_lock<std::recursive_mutex> lock;
1179 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
1181 bool result = false;
1182 if (exe_ctx.HasThreadScope()) {
1183 Process::StopLocker stop_locker;
1184 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) {
1185 const bool override_suspend = true;
1186 exe_ctx.GetThreadPtr()->SetResumeState(eStateRunning, override_suspend);
1189 error.SetErrorString("process is running");
1191 log->Printf("SBThread(%p)::Resume() => error: process is running",
1192 static_cast<void *>(exe_ctx.GetThreadPtr()));
1195 error.SetErrorString("this SBThread object is invalid");
1197 log->Printf("SBThread(%p)::Resume() => %i",
1198 static_cast<void *>(exe_ctx.GetThreadPtr()), result);
1202 bool SBThread::IsSuspended() {
1203 std::unique_lock<std::recursive_mutex> lock;
1204 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
1206 if (exe_ctx.HasThreadScope())
1207 return exe_ctx.GetThreadPtr()->GetResumeState() == eStateSuspended;
1211 bool SBThread::IsStopped() {
1212 std::unique_lock<std::recursive_mutex> lock;
1213 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
1215 if (exe_ctx.HasThreadScope())
1216 return StateIsStoppedState(exe_ctx.GetThreadPtr()->GetState(), true);
1220 SBProcess SBThread::GetProcess() {
1221 SBProcess sb_process;
1222 std::unique_lock<std::recursive_mutex> lock;
1223 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
1225 if (exe_ctx.HasThreadScope()) {
1226 // Have to go up to the target so we can get a shared pointer to our
1228 sb_process.SetSP(exe_ctx.GetProcessSP());
1231 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1233 SBStream frame_desc_strm;
1234 sb_process.GetDescription(frame_desc_strm);
1235 log->Printf("SBThread(%p)::GetProcess () => SBProcess(%p): %s",
1236 static_cast<void *>(exe_ctx.GetThreadPtr()),
1237 static_cast<void *>(sb_process.GetSP().get()),
1238 frame_desc_strm.GetData());
1244 uint32_t SBThread::GetNumFrames() {
1245 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1247 uint32_t num_frames = 0;
1248 std::unique_lock<std::recursive_mutex> lock;
1249 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
1251 if (exe_ctx.HasThreadScope()) {
1252 Process::StopLocker stop_locker;
1253 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) {
1254 num_frames = exe_ctx.GetThreadPtr()->GetStackFrameCount();
1257 log->Printf("SBThread(%p)::GetNumFrames() => error: process is running",
1258 static_cast<void *>(exe_ctx.GetThreadPtr()));
1263 log->Printf("SBThread(%p)::GetNumFrames () => %u",
1264 static_cast<void *>(exe_ctx.GetThreadPtr()), num_frames);
1269 SBFrame SBThread::GetFrameAtIndex(uint32_t idx) {
1270 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1273 StackFrameSP frame_sp;
1274 std::unique_lock<std::recursive_mutex> lock;
1275 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
1277 if (exe_ctx.HasThreadScope()) {
1278 Process::StopLocker stop_locker;
1279 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) {
1280 frame_sp = exe_ctx.GetThreadPtr()->GetStackFrameAtIndex(idx);
1281 sb_frame.SetFrameSP(frame_sp);
1285 "SBThread(%p)::GetFrameAtIndex() => error: process is running",
1286 static_cast<void *>(exe_ctx.GetThreadPtr()));
1291 SBStream frame_desc_strm;
1292 sb_frame.GetDescription(frame_desc_strm);
1293 log->Printf("SBThread(%p)::GetFrameAtIndex (idx=%d) => SBFrame(%p): %s",
1294 static_cast<void *>(exe_ctx.GetThreadPtr()), idx,
1295 static_cast<void *>(frame_sp.get()), frame_desc_strm.GetData());
1301 lldb::SBFrame SBThread::GetSelectedFrame() {
1302 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1305 StackFrameSP frame_sp;
1306 std::unique_lock<std::recursive_mutex> lock;
1307 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
1309 if (exe_ctx.HasThreadScope()) {
1310 Process::StopLocker stop_locker;
1311 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) {
1312 frame_sp = exe_ctx.GetThreadPtr()->GetSelectedFrame();
1313 sb_frame.SetFrameSP(frame_sp);
1317 "SBThread(%p)::GetSelectedFrame() => error: process is running",
1318 static_cast<void *>(exe_ctx.GetThreadPtr()));
1323 SBStream frame_desc_strm;
1324 sb_frame.GetDescription(frame_desc_strm);
1325 log->Printf("SBThread(%p)::GetSelectedFrame () => SBFrame(%p): %s",
1326 static_cast<void *>(exe_ctx.GetThreadPtr()),
1327 static_cast<void *>(frame_sp.get()), frame_desc_strm.GetData());
1333 lldb::SBFrame SBThread::SetSelectedFrame(uint32_t idx) {
1334 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1337 StackFrameSP frame_sp;
1338 std::unique_lock<std::recursive_mutex> lock;
1339 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
1341 if (exe_ctx.HasThreadScope()) {
1342 Process::StopLocker stop_locker;
1343 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) {
1344 Thread *thread = exe_ctx.GetThreadPtr();
1345 frame_sp = thread->GetStackFrameAtIndex(idx);
1347 thread->SetSelectedFrame(frame_sp.get());
1348 sb_frame.SetFrameSP(frame_sp);
1353 "SBThread(%p)::SetSelectedFrame() => error: process is running",
1354 static_cast<void *>(exe_ctx.GetThreadPtr()));
1359 SBStream frame_desc_strm;
1360 sb_frame.GetDescription(frame_desc_strm);
1361 log->Printf("SBThread(%p)::SetSelectedFrame (idx=%u) => SBFrame(%p): %s",
1362 static_cast<void *>(exe_ctx.GetThreadPtr()), idx,
1363 static_cast<void *>(frame_sp.get()), frame_desc_strm.GetData());
1368 bool SBThread::EventIsThreadEvent(const SBEvent &event) {
1369 return Thread::ThreadEventData::GetEventDataFromEvent(event.get()) != NULL;
1372 SBFrame SBThread::GetStackFrameFromEvent(const SBEvent &event) {
1373 return Thread::ThreadEventData::GetStackFrameFromEvent(event.get());
1376 SBThread SBThread::GetThreadFromEvent(const SBEvent &event) {
1377 return Thread::ThreadEventData::GetThreadFromEvent(event.get());
1380 bool SBThread::operator==(const SBThread &rhs) const {
1381 return m_opaque_sp->GetThreadSP().get() ==
1382 rhs.m_opaque_sp->GetThreadSP().get();
1385 bool SBThread::operator!=(const SBThread &rhs) const {
1386 return m_opaque_sp->GetThreadSP().get() !=
1387 rhs.m_opaque_sp->GetThreadSP().get();
1390 bool SBThread::GetStatus(SBStream &status) const {
1391 Stream &strm = status.ref();
1393 std::unique_lock<std::recursive_mutex> lock;
1394 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
1396 if (exe_ctx.HasThreadScope()) {
1397 exe_ctx.GetThreadPtr()->GetStatus(strm, 0, 1, 1, true);
1399 strm.PutCString("No status");
1404 bool SBThread::GetDescription(SBStream &description) const {
1405 return GetDescription(description, false);
1408 bool SBThread::GetDescription(SBStream &description, bool stop_format) const {
1409 Stream &strm = description.ref();
1411 std::unique_lock<std::recursive_mutex> lock;
1412 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
1414 if (exe_ctx.HasThreadScope()) {
1415 exe_ctx.GetThreadPtr()->DumpUsingSettingsFormat(strm,
1416 LLDB_INVALID_THREAD_ID,
1418 // strm.Printf("SBThread: tid = 0x%4.4" PRIx64,
1419 // exe_ctx.GetThreadPtr()->GetID());
1421 strm.PutCString("No value");
1426 SBThread SBThread::GetExtendedBacktraceThread(const char *type) {
1427 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1428 std::unique_lock<std::recursive_mutex> lock;
1429 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
1430 SBThread sb_origin_thread;
1432 if (exe_ctx.HasThreadScope()) {
1433 Process::StopLocker stop_locker;
1434 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) {
1435 ThreadSP real_thread(exe_ctx.GetThreadSP());
1437 ConstString type_const(type);
1438 Process *process = exe_ctx.GetProcessPtr();
1440 SystemRuntime *runtime = process->GetSystemRuntime();
1442 ThreadSP new_thread_sp(
1443 runtime->GetExtendedBacktraceThread(real_thread, type_const));
1444 if (new_thread_sp) {
1445 // Save this in the Process' ExtendedThreadList so a strong
1446 // pointer retains the object.
1447 process->GetExtendedThreadList().AddThread(new_thread_sp);
1448 sb_origin_thread.SetThread(new_thread_sp);
1450 const char *queue_name = new_thread_sp->GetQueueName();
1451 if (queue_name == NULL)
1453 log->Printf("SBThread(%p)::GetExtendedBacktraceThread() => new "
1455 "created (%p) with queue_id 0x%" PRIx64
1457 static_cast<void *>(exe_ctx.GetThreadPtr()),
1458 static_cast<void *>(new_thread_sp.get()),
1459 new_thread_sp->GetQueueID(), queue_name);
1467 log->Printf("SBThread(%p)::GetExtendedBacktraceThread() => error: "
1468 "process is running",
1469 static_cast<void *>(exe_ctx.GetThreadPtr()));
1473 if (log && !sb_origin_thread.IsValid())
1474 log->Printf("SBThread(%p)::GetExtendedBacktraceThread() is not returning a "
1476 static_cast<void *>(exe_ctx.GetThreadPtr()));
1477 return sb_origin_thread;
1480 uint32_t SBThread::GetExtendedBacktraceOriginatingIndexID() {
1481 ThreadSP thread_sp(m_opaque_sp->GetThreadSP());
1483 return thread_sp->GetExtendedBacktraceOriginatingIndexID();
1484 return LLDB_INVALID_INDEX32;
1487 SBValue SBThread::GetCurrentException() {
1488 ThreadSP thread_sp(m_opaque_sp->GetThreadSP());
1489 if (!thread_sp) return SBValue();
1491 return SBValue(thread_sp->GetCurrentException());
1494 SBThread SBThread::GetCurrentExceptionBacktrace() {
1495 ThreadSP thread_sp(m_opaque_sp->GetThreadSP());
1496 if (!thread_sp) return SBThread();
1498 return SBThread(thread_sp->GetCurrentExceptionBacktrace());
1501 bool SBThread::SafeToCallFunctions() {
1502 ThreadSP thread_sp(m_opaque_sp->GetThreadSP());
1504 return thread_sp->SafeToCallFunctions();
1508 lldb_private::Thread *SBThread::operator->() {
1509 ThreadSP thread_sp(m_opaque_sp->GetThreadSP());
1511 return thread_sp.get();
1516 lldb_private::Thread *SBThread::get() {
1517 ThreadSP thread_sp(m_opaque_sp->GetThreadSP());
1519 return thread_sp.get();