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/lldb-python.h"
12 #include "lldb/API/SBThread.h"
14 #include "lldb/API/SBSymbolContext.h"
15 #include "lldb/API/SBFileSpec.h"
16 #include "lldb/API/SBStream.h"
17 #include "lldb/Breakpoint/BreakpointLocation.h"
18 #include "lldb/Core/Debugger.h"
19 #include "lldb/Core/State.h"
20 #include "lldb/Core/Stream.h"
21 #include "lldb/Core/StreamFile.h"
22 #include "lldb/Interpreter/CommandInterpreter.h"
23 #include "lldb/Target/Thread.h"
24 #include "lldb/Target/Process.h"
25 #include "lldb/Symbol/SymbolContext.h"
26 #include "lldb/Symbol/CompileUnit.h"
27 #include "lldb/Target/StopInfo.h"
28 #include "lldb/Target/Target.h"
29 #include "lldb/Target/ThreadPlan.h"
30 #include "lldb/Target/ThreadPlanStepInstruction.h"
31 #include "lldb/Target/ThreadPlanStepOut.h"
32 #include "lldb/Target/ThreadPlanStepRange.h"
33 #include "lldb/Target/ThreadPlanStepInRange.h"
36 #include "lldb/API/SBAddress.h"
37 #include "lldb/API/SBDebugger.h"
38 #include "lldb/API/SBEvent.h"
39 #include "lldb/API/SBFrame.h"
40 #include "lldb/API/SBProcess.h"
41 #include "lldb/API/SBValue.h"
44 using namespace lldb_private;
47 SBThread::GetBroadcasterClassName ()
49 return Thread::GetStaticBroadcasterClass().AsCString();
52 //----------------------------------------------------------------------
54 //----------------------------------------------------------------------
55 SBThread::SBThread () :
56 m_opaque_sp (new ExecutionContextRef())
60 SBThread::SBThread (const ThreadSP& lldb_object_sp) :
61 m_opaque_sp (new ExecutionContextRef(lldb_object_sp))
65 SBThread::SBThread (const SBThread &rhs) :
66 m_opaque_sp (new ExecutionContextRef(*rhs.m_opaque_sp))
71 //----------------------------------------------------------------------
72 // Assignment operator
73 //----------------------------------------------------------------------
75 const lldb::SBThread &
76 SBThread::operator = (const SBThread &rhs)
79 *m_opaque_sp = *rhs.m_opaque_sp;
83 //----------------------------------------------------------------------
85 //----------------------------------------------------------------------
91 SBThread::IsValid() const
93 return m_opaque_sp->GetThreadSP().get() != NULL;
104 SBThread::GetStopReason()
106 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
108 StopReason reason = eStopReasonInvalid;
109 Mutex::Locker api_locker;
110 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
112 if (exe_ctx.HasThreadScope())
114 Process::StopLocker stop_locker;
115 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
117 return exe_ctx.GetThreadPtr()->GetStopReason();
122 log->Printf ("SBThread(%p)::GetStopReason() => error: process is running", exe_ctx.GetThreadPtr());
127 log->Printf ("SBThread(%p)::GetStopReason () => %s", exe_ctx.GetThreadPtr(),
128 Thread::StopReasonAsCString (reason));
134 SBThread::GetStopReasonDataCount ()
136 Mutex::Locker api_locker;
137 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
139 if (exe_ctx.HasThreadScope())
141 Process::StopLocker stop_locker;
142 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
144 StopInfoSP stop_info_sp = exe_ctx.GetThreadPtr()->GetStopInfo ();
147 StopReason reason = stop_info_sp->GetStopReason();
150 case eStopReasonInvalid:
151 case eStopReasonNone:
152 case eStopReasonTrace:
153 case eStopReasonExec:
154 case eStopReasonPlanComplete:
155 case eStopReasonThreadExiting:
156 // There is no data for these stop reasons.
159 case eStopReasonBreakpoint:
161 break_id_t site_id = stop_info_sp->GetValue();
162 lldb::BreakpointSiteSP bp_site_sp (exe_ctx.GetProcessPtr()->GetBreakpointSiteList().FindByID (site_id));
164 return bp_site_sp->GetNumberOfOwners () * 2;
166 return 0; // Breakpoint must have cleared itself...
170 case eStopReasonWatchpoint:
173 case eStopReasonSignal:
176 case eStopReasonException:
183 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
185 log->Printf ("SBThread(%p)::GetStopReasonDataCount() => error: process is running", exe_ctx.GetThreadPtr());
192 SBThread::GetStopReasonDataAtIndex (uint32_t idx)
194 Mutex::Locker api_locker;
195 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
197 if (exe_ctx.HasThreadScope())
199 Process::StopLocker stop_locker;
200 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
202 Thread *thread = exe_ctx.GetThreadPtr();
203 StopInfoSP stop_info_sp = thread->GetStopInfo ();
206 StopReason reason = stop_info_sp->GetStopReason();
209 case eStopReasonInvalid:
210 case eStopReasonNone:
211 case eStopReasonTrace:
212 case eStopReasonExec:
213 case eStopReasonPlanComplete:
214 case eStopReasonThreadExiting:
215 // There is no data for these stop reasons.
218 case eStopReasonBreakpoint:
220 break_id_t site_id = stop_info_sp->GetValue();
221 lldb::BreakpointSiteSP bp_site_sp (exe_ctx.GetProcessPtr()->GetBreakpointSiteList().FindByID (site_id));
224 uint32_t bp_index = idx / 2;
225 BreakpointLocationSP bp_loc_sp (bp_site_sp->GetOwnerAtIndex (bp_index));
230 // Odd idx, return the breakpoint location ID
231 return bp_loc_sp->GetID();
235 // Even idx, return the breakpoint ID
236 return bp_loc_sp->GetBreakpoint().GetID();
240 return LLDB_INVALID_BREAK_ID;
244 case eStopReasonWatchpoint:
245 return stop_info_sp->GetValue();
247 case eStopReasonSignal:
248 return stop_info_sp->GetValue();
250 case eStopReasonException:
251 return stop_info_sp->GetValue();
257 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
259 log->Printf ("SBThread(%p)::GetStopReasonDataAtIndex() => error: process is running", exe_ctx.GetThreadPtr());
266 SBThread::GetStopDescription (char *dst, size_t dst_len)
268 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
270 Mutex::Locker api_locker;
271 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
273 if (exe_ctx.HasThreadScope())
275 Process::StopLocker stop_locker;
276 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
279 StopInfoSP stop_info_sp = exe_ctx.GetThreadPtr()->GetStopInfo ();
282 const char *stop_desc = stop_info_sp->GetDescription();
286 log->Printf ("SBThread(%p)::GetStopDescription (dst, dst_len) => \"%s\"",
287 exe_ctx.GetThreadPtr(), stop_desc);
289 return ::snprintf (dst, dst_len, "%s", stop_desc);
292 // NULL dst passed in, return the length needed to contain the description
293 return ::strlen (stop_desc) + 1; // Include the NULL byte for size
298 size_t stop_desc_len = 0;
299 switch (stop_info_sp->GetStopReason())
301 case eStopReasonTrace:
302 case eStopReasonPlanComplete:
304 static char trace_desc[] = "step";
305 stop_desc = trace_desc;
306 stop_desc_len = sizeof(trace_desc); // Include the NULL byte for size
310 case eStopReasonBreakpoint:
312 static char bp_desc[] = "breakpoint hit";
314 stop_desc_len = sizeof(bp_desc); // Include the NULL byte for size
318 case eStopReasonWatchpoint:
320 static char wp_desc[] = "watchpoint hit";
322 stop_desc_len = sizeof(wp_desc); // Include the NULL byte for size
326 case eStopReasonSignal:
328 stop_desc = exe_ctx.GetProcessPtr()->GetUnixSignals ().GetSignalAsCString (stop_info_sp->GetValue());
329 if (stop_desc == NULL || stop_desc[0] == '\0')
331 static char signal_desc[] = "signal";
332 stop_desc = signal_desc;
333 stop_desc_len = sizeof(signal_desc); // Include the NULL byte for size
338 case eStopReasonException:
340 char exc_desc[] = "exception";
341 stop_desc = exc_desc;
342 stop_desc_len = sizeof(exc_desc); // Include the NULL byte for size
346 case eStopReasonExec:
348 char exc_desc[] = "exec";
349 stop_desc = exc_desc;
350 stop_desc_len = sizeof(exc_desc); // Include the NULL byte for size
354 case eStopReasonThreadExiting:
356 char limbo_desc[] = "thread exiting";
357 stop_desc = limbo_desc;
358 stop_desc_len = sizeof(limbo_desc);
365 if (stop_desc && stop_desc[0])
368 log->Printf ("SBThread(%p)::GetStopDescription (dst, dst_len) => '%s'",
369 exe_ctx.GetThreadPtr(), stop_desc);
372 return ::snprintf (dst, dst_len, "%s", stop_desc) + 1; // Include the NULL byte
374 if (stop_desc_len == 0)
375 stop_desc_len = ::strlen (stop_desc) + 1; // Include the NULL byte
377 return stop_desc_len;
384 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
386 log->Printf ("SBThread(%p)::GetStopDescription() => error: process is running", exe_ctx.GetThreadPtr());
395 SBThread::GetStopReturnValue ()
397 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
398 ValueObjectSP return_valobj_sp;
399 Mutex::Locker api_locker;
400 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
402 if (exe_ctx.HasThreadScope())
404 Process::StopLocker stop_locker;
405 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
407 StopInfoSP stop_info_sp = exe_ctx.GetThreadPtr()->GetStopInfo ();
410 return_valobj_sp = StopInfo::GetReturnValueObject (stop_info_sp);
416 log->Printf ("SBThread(%p)::GetStopReturnValue() => error: process is running", exe_ctx.GetThreadPtr());
421 log->Printf ("SBThread(%p)::GetStopReturnValue () => %s", exe_ctx.GetThreadPtr(),
422 return_valobj_sp.get()
423 ? return_valobj_sp->GetValueAsCString()
424 : "<no return value>");
426 return SBValue (return_valobj_sp);
430 SBThread::SetThread (const ThreadSP& lldb_object_sp)
432 m_opaque_sp->SetThreadSP (lldb_object_sp);
437 SBThread::GetThreadID () const
439 ThreadSP thread_sp(m_opaque_sp->GetThreadSP());
441 return thread_sp->GetID();
442 return LLDB_INVALID_THREAD_ID;
446 SBThread::GetIndexID () const
448 ThreadSP thread_sp(m_opaque_sp->GetThreadSP());
450 return thread_sp->GetIndexID();
451 return LLDB_INVALID_INDEX32;
455 SBThread::GetName () const
457 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
458 const char *name = NULL;
459 Mutex::Locker api_locker;
460 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
462 if (exe_ctx.HasThreadScope())
464 Process::StopLocker stop_locker;
465 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
467 name = exe_ctx.GetThreadPtr()->GetName();
472 log->Printf ("SBThread(%p)::GetName() => error: process is running", exe_ctx.GetThreadPtr());
477 log->Printf ("SBThread(%p)::GetName () => %s", exe_ctx.GetThreadPtr(), name ? name : "NULL");
483 SBThread::GetQueueName () const
485 const char *name = NULL;
486 Mutex::Locker api_locker;
487 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
489 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
490 if (exe_ctx.HasThreadScope())
492 Process::StopLocker stop_locker;
493 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
495 name = exe_ctx.GetThreadPtr()->GetQueueName();
500 log->Printf ("SBThread(%p)::GetQueueName() => error: process is running", exe_ctx.GetThreadPtr());
505 log->Printf ("SBThread(%p)::GetQueueName () => %s", exe_ctx.GetThreadPtr(), name ? name : "NULL");
511 SBThread::ResumeNewPlan (ExecutionContext &exe_ctx, ThreadPlan *new_plan)
515 Process *process = exe_ctx.GetProcessPtr();
518 sb_error.SetErrorString("No process in SBThread::ResumeNewPlan");
522 Thread *thread = exe_ctx.GetThreadPtr();
525 sb_error.SetErrorString("No thread in SBThread::ResumeNewPlan");
529 // User level plans should be Master Plans so they can be interrupted, other plans executed, and
530 // then a "continue" will resume the plan.
531 if (new_plan != NULL)
533 new_plan->SetIsMasterPlan(true);
534 new_plan->SetOkayToDiscard(false);
537 // Why do we need to set the current thread by ID here???
538 process->GetThreadList().SetSelectedThreadByID (thread->GetID());
539 sb_error.ref() = process->Resume();
541 if (sb_error.Success())
543 // If we are doing synchronous mode, then wait for the
544 // process to stop yet again!
545 if (process->GetTarget().GetDebugger().GetAsyncExecution () == false)
546 process->WaitForProcessToStop (NULL);
553 SBThread::StepOver (lldb::RunMode stop_other_threads)
555 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
557 Mutex::Locker api_locker;
558 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
562 log->Printf ("SBThread(%p)::StepOver (stop_other_threads='%s')", exe_ctx.GetThreadPtr(),
563 Thread::RunModeAsCString (stop_other_threads));
565 if (exe_ctx.HasThreadScope())
567 Thread *thread = exe_ctx.GetThreadPtr();
568 bool abort_other_plans = false;
569 StackFrameSP frame_sp(thread->GetStackFrameAtIndex (0));
571 ThreadPlanSP new_plan_sp;
574 if (frame_sp->HasDebugInformation ())
576 SymbolContext sc(frame_sp->GetSymbolContext(eSymbolContextEverything));
577 new_plan_sp = thread->QueueThreadPlanForStepOverRange (abort_other_plans,
584 new_plan_sp = thread->QueueThreadPlanForStepSingleInstruction (true,
590 // This returns an error, we should use it!
591 ResumeNewPlan (exe_ctx, new_plan_sp.get());
596 SBThread::StepInto (lldb::RunMode stop_other_threads)
598 StepInto (NULL, stop_other_threads);
602 SBThread::StepInto (const char *target_name, lldb::RunMode stop_other_threads)
604 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
606 Mutex::Locker api_locker;
607 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
610 log->Printf ("SBThread(%p)::StepInto (target_name='%s', stop_other_threads='%s')",
611 exe_ctx.GetThreadPtr(),
612 target_name? target_name: "<NULL>",
613 Thread::RunModeAsCString (stop_other_threads));
615 if (exe_ctx.HasThreadScope())
617 bool abort_other_plans = false;
619 Thread *thread = exe_ctx.GetThreadPtr();
620 StackFrameSP frame_sp(thread->GetStackFrameAtIndex (0));
621 ThreadPlanSP new_plan_sp;
623 if (frame_sp && frame_sp->HasDebugInformation ())
625 bool avoid_code_without_debug_info = true;
626 SymbolContext sc(frame_sp->GetSymbolContext(eSymbolContextEverything));
627 new_plan_sp = thread->QueueThreadPlanForStepInRange (abort_other_plans,
632 avoid_code_without_debug_info);
636 new_plan_sp = thread->QueueThreadPlanForStepSingleInstruction (false,
641 // This returns an error, we should use it!
642 ResumeNewPlan (exe_ctx, new_plan_sp.get());
649 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
651 Mutex::Locker api_locker;
652 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
656 log->Printf ("SBThread(%p)::StepOut ()", exe_ctx.GetThreadPtr());
658 if (exe_ctx.HasThreadScope())
660 bool abort_other_plans = false;
661 bool stop_other_threads = false;
663 Thread *thread = exe_ctx.GetThreadPtr();
665 ThreadPlanSP new_plan_sp(thread->QueueThreadPlanForStepOut (abort_other_plans,
673 // This returns an error, we should use it!
674 ResumeNewPlan (exe_ctx, new_plan_sp.get());
679 SBThread::StepOutOfFrame (lldb::SBFrame &sb_frame)
681 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
683 Mutex::Locker api_locker;
684 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
686 StackFrameSP frame_sp (sb_frame.GetFrameSP());
689 SBStream frame_desc_strm;
690 sb_frame.GetDescription (frame_desc_strm);
691 log->Printf ("SBThread(%p)::StepOutOfFrame (frame = SBFrame(%p): %s)", exe_ctx.GetThreadPtr(), frame_sp.get(), frame_desc_strm.GetData());
694 if (exe_ctx.HasThreadScope())
696 bool abort_other_plans = false;
697 bool stop_other_threads = false;
698 Thread *thread = exe_ctx.GetThreadPtr();
700 ThreadPlanSP new_plan_sp(thread->QueueThreadPlanForStepOut (abort_other_plans,
706 frame_sp->GetFrameIndex()));
708 // This returns an error, we should use it!
709 ResumeNewPlan (exe_ctx, new_plan_sp.get());
714 SBThread::StepInstruction (bool step_over)
716 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
718 Mutex::Locker api_locker;
719 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
724 log->Printf ("SBThread(%p)::StepInstruction (step_over=%i)", exe_ctx.GetThreadPtr(), step_over);
726 if (exe_ctx.HasThreadScope())
728 Thread *thread = exe_ctx.GetThreadPtr();
729 ThreadPlanSP new_plan_sp(thread->QueueThreadPlanForStepSingleInstruction (step_over, true, true));
731 // This returns an error, we should use it!
732 ResumeNewPlan (exe_ctx, new_plan_sp.get());
737 SBThread::RunToAddress (lldb::addr_t addr)
739 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
741 Mutex::Locker api_locker;
742 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
746 log->Printf ("SBThread(%p)::RunToAddress (addr=0x%" PRIx64 ")", exe_ctx.GetThreadPtr(), addr);
748 if (exe_ctx.HasThreadScope())
750 bool abort_other_plans = false;
751 bool stop_other_threads = true;
753 Address target_addr (addr);
755 Thread *thread = exe_ctx.GetThreadPtr();
757 ThreadPlanSP new_plan_sp(thread->QueueThreadPlanForRunToAddress (abort_other_plans, target_addr, stop_other_threads));
759 // This returns an error, we should use it!
760 ResumeNewPlan (exe_ctx, new_plan_sp.get());
765 SBThread::StepOverUntil (lldb::SBFrame &sb_frame,
766 lldb::SBFileSpec &sb_file_spec,
770 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
773 Mutex::Locker api_locker;
774 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
776 StackFrameSP frame_sp (sb_frame.GetFrameSP());
780 SBStream frame_desc_strm;
781 sb_frame.GetDescription (frame_desc_strm);
782 sb_file_spec->GetPath (path, sizeof(path));
783 log->Printf ("SBThread(%p)::StepOverUntil (frame = SBFrame(%p): %s, file+line = %s:%u)",
784 exe_ctx.GetThreadPtr(),
786 frame_desc_strm.GetData(),
790 if (exe_ctx.HasThreadScope())
792 Target *target = exe_ctx.GetTargetPtr();
793 Thread *thread = exe_ctx.GetThreadPtr();
797 sb_error.SetErrorString("invalid line argument");
803 frame_sp = thread->GetSelectedFrame ();
805 frame_sp = thread->GetStackFrameAtIndex (0);
808 SymbolContext frame_sc;
811 sb_error.SetErrorString("no valid frames in thread to step");
815 // If we have a frame, get its line
816 frame_sc = frame_sp->GetSymbolContext (eSymbolContextCompUnit |
817 eSymbolContextFunction |
818 eSymbolContextLineEntry |
819 eSymbolContextSymbol );
821 if (frame_sc.comp_unit == NULL)
823 sb_error.SetErrorStringWithFormat("frame %u doesn't have debug information", frame_sp->GetFrameIndex());
827 FileSpec step_file_spec;
828 if (sb_file_spec.IsValid())
830 // The file spec passed in was valid, so use it
831 step_file_spec = sb_file_spec.ref();
835 if (frame_sc.line_entry.IsValid())
836 step_file_spec = frame_sc.line_entry.file;
839 sb_error.SetErrorString("invalid file argument or no file for frame");
844 // Grab the current function, then we will make sure the "until" address is
845 // within the function. We discard addresses that are out of the current
846 // function, and then if there are no addresses remaining, give an appropriate
849 bool all_in_function = true;
850 AddressRange fun_range = frame_sc.function->GetAddressRange();
852 std::vector<addr_t> step_over_until_addrs;
853 const bool abort_other_plans = false;
854 const bool stop_other_threads = false;
855 const bool check_inlines = true;
856 const bool exact = false;
858 SymbolContextList sc_list;
859 const uint32_t num_matches = frame_sc.comp_unit->ResolveSymbolContext (step_file_spec,
863 eSymbolContextLineEntry,
868 for (uint32_t i=0; i<num_matches; ++i)
870 if (sc_list.GetContextAtIndex(i, sc))
872 addr_t step_addr = sc.line_entry.range.GetBaseAddress().GetLoadAddress(target);
873 if (step_addr != LLDB_INVALID_ADDRESS)
875 if (fun_range.ContainsLoadAddress(step_addr, target))
876 step_over_until_addrs.push_back(step_addr);
878 all_in_function = false;
884 if (step_over_until_addrs.empty())
888 step_file_spec.GetPath (path, sizeof(path));
889 sb_error.SetErrorStringWithFormat("No line entries for %s:%u", path, line);
892 sb_error.SetErrorString ("step until target not in current function");
896 ThreadPlanSP new_plan_sp(thread->QueueThreadPlanForStepUntil (abort_other_plans,
897 &step_over_until_addrs[0],
898 step_over_until_addrs.size(),
900 frame_sp->GetFrameIndex()));
902 sb_error = ResumeNewPlan (exe_ctx, new_plan_sp.get());
907 sb_error.SetErrorString("this SBThread object is invalid");
913 SBThread::ReturnFromFrame (SBFrame &frame, SBValue &return_value)
917 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
919 Mutex::Locker api_locker;
920 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
924 log->Printf ("SBThread(%p)::ReturnFromFrame (frame=%d)", exe_ctx.GetThreadPtr(), frame.GetFrameID());
926 if (exe_ctx.HasThreadScope())
928 Thread *thread = exe_ctx.GetThreadPtr();
929 sb_error.SetError (thread->ReturnFromFrame(frame.GetFrameSP(), return_value.GetSP()));
939 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
940 ExecutionContext exe_ctx (m_opaque_sp.get());
942 if (exe_ctx.HasThreadScope())
944 Process::StopLocker stop_locker;
945 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
947 exe_ctx.GetThreadPtr()->SetResumeState (eStateSuspended);
953 log->Printf ("SBThread(%p)::Suspend() => error: process is running", exe_ctx.GetThreadPtr());
957 log->Printf ("SBThread(%p)::Suspend() => %i", exe_ctx.GetThreadPtr(), result);
964 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
965 ExecutionContext exe_ctx (m_opaque_sp.get());
967 if (exe_ctx.HasThreadScope())
969 Process::StopLocker stop_locker;
970 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
972 exe_ctx.GetThreadPtr()->SetResumeState (eStateRunning);
978 log->Printf ("SBThread(%p)::Resume() => error: process is running", exe_ctx.GetThreadPtr());
982 log->Printf ("SBThread(%p)::Resume() => %i", exe_ctx.GetThreadPtr(), result);
987 SBThread::IsSuspended()
989 ExecutionContext exe_ctx (m_opaque_sp.get());
990 if (exe_ctx.HasThreadScope())
991 return exe_ctx.GetThreadPtr()->GetResumeState () == eStateSuspended;
996 SBThread::IsStopped()
998 ExecutionContext exe_ctx (m_opaque_sp.get());
999 if (exe_ctx.HasThreadScope())
1000 return StateIsStoppedState(exe_ctx.GetThreadPtr()->GetState(), true);
1005 SBThread::GetProcess ()
1007 SBProcess sb_process;
1008 ExecutionContext exe_ctx (m_opaque_sp.get());
1009 if (exe_ctx.HasThreadScope())
1011 // Have to go up to the target so we can get a shared pointer to our process...
1012 sb_process.SetSP (exe_ctx.GetProcessSP());
1015 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1018 SBStream frame_desc_strm;
1019 sb_process.GetDescription (frame_desc_strm);
1020 log->Printf ("SBThread(%p)::GetProcess () => SBProcess(%p): %s", exe_ctx.GetThreadPtr(),
1021 sb_process.GetSP().get(), frame_desc_strm.GetData());
1028 SBThread::GetNumFrames ()
1030 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1032 uint32_t num_frames = 0;
1033 Mutex::Locker api_locker;
1034 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1036 if (exe_ctx.HasThreadScope())
1038 Process::StopLocker stop_locker;
1039 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
1041 num_frames = exe_ctx.GetThreadPtr()->GetStackFrameCount();
1046 log->Printf ("SBThread(%p)::GetNumFrames() => error: process is running", exe_ctx.GetThreadPtr());
1051 log->Printf ("SBThread(%p)::GetNumFrames () => %u", exe_ctx.GetThreadPtr(), num_frames);
1057 SBThread::GetFrameAtIndex (uint32_t idx)
1059 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1062 StackFrameSP frame_sp;
1063 Mutex::Locker api_locker;
1064 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1066 if (exe_ctx.HasThreadScope())
1068 Process::StopLocker stop_locker;
1069 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
1071 frame_sp = exe_ctx.GetThreadPtr()->GetStackFrameAtIndex (idx);
1072 sb_frame.SetFrameSP (frame_sp);
1077 log->Printf ("SBThread(%p)::GetFrameAtIndex() => error: process is running", exe_ctx.GetThreadPtr());
1083 SBStream frame_desc_strm;
1084 sb_frame.GetDescription (frame_desc_strm);
1085 log->Printf ("SBThread(%p)::GetFrameAtIndex (idx=%d) => SBFrame(%p): %s",
1086 exe_ctx.GetThreadPtr(), idx, frame_sp.get(), frame_desc_strm.GetData());
1093 SBThread::GetSelectedFrame ()
1095 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1098 StackFrameSP frame_sp;
1099 Mutex::Locker api_locker;
1100 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1102 if (exe_ctx.HasThreadScope())
1104 Process::StopLocker stop_locker;
1105 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
1107 frame_sp = exe_ctx.GetThreadPtr()->GetSelectedFrame ();
1108 sb_frame.SetFrameSP (frame_sp);
1113 log->Printf ("SBThread(%p)::GetSelectedFrame() => error: process is running", exe_ctx.GetThreadPtr());
1119 SBStream frame_desc_strm;
1120 sb_frame.GetDescription (frame_desc_strm);
1121 log->Printf ("SBThread(%p)::GetSelectedFrame () => SBFrame(%p): %s",
1122 exe_ctx.GetThreadPtr(), frame_sp.get(), frame_desc_strm.GetData());
1129 SBThread::SetSelectedFrame (uint32_t idx)
1131 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1134 StackFrameSP frame_sp;
1135 Mutex::Locker api_locker;
1136 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1138 if (exe_ctx.HasThreadScope())
1140 Process::StopLocker stop_locker;
1141 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
1143 Thread *thread = exe_ctx.GetThreadPtr();
1144 frame_sp = thread->GetStackFrameAtIndex (idx);
1147 thread->SetSelectedFrame (frame_sp.get());
1148 sb_frame.SetFrameSP (frame_sp);
1154 log->Printf ("SBThread(%p)::SetSelectedFrame() => error: process is running", exe_ctx.GetThreadPtr());
1160 SBStream frame_desc_strm;
1161 sb_frame.GetDescription (frame_desc_strm);
1162 log->Printf ("SBThread(%p)::SetSelectedFrame (idx=%u) => SBFrame(%p): %s",
1163 exe_ctx.GetThreadPtr(), idx, frame_sp.get(), frame_desc_strm.GetData());
1169 SBThread::EventIsThreadEvent (const SBEvent &event)
1171 return Thread::ThreadEventData::GetEventDataFromEvent(event.get()) != NULL;
1175 SBThread::GetStackFrameFromEvent (const SBEvent &event)
1177 return Thread::ThreadEventData::GetStackFrameFromEvent (event.get());
1182 SBThread::GetThreadFromEvent (const SBEvent &event)
1184 return Thread::ThreadEventData::GetThreadFromEvent (event.get());
1188 SBThread::operator == (const SBThread &rhs) const
1190 return m_opaque_sp->GetThreadSP().get() == rhs.m_opaque_sp->GetThreadSP().get();
1194 SBThread::operator != (const SBThread &rhs) const
1196 return m_opaque_sp->GetThreadSP().get() != rhs.m_opaque_sp->GetThreadSP().get();
1200 SBThread::GetStatus (SBStream &status) const
1202 Stream &strm = status.ref();
1204 ExecutionContext exe_ctx (m_opaque_sp.get());
1205 if (exe_ctx.HasThreadScope())
1207 exe_ctx.GetThreadPtr()->GetStatus(strm, 0, 1, 1);
1210 strm.PutCString ("No status");
1216 SBThread::GetDescription (SBStream &description) const
1218 Stream &strm = description.ref();
1220 ExecutionContext exe_ctx (m_opaque_sp.get());
1221 if (exe_ctx.HasThreadScope())
1223 strm.Printf("SBThread: tid = 0x%4.4" PRIx64, exe_ctx.GetThreadPtr()->GetID());
1226 strm.PutCString ("No value");