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/SystemRuntime.h"
24 #include "lldb/Target/Thread.h"
25 #include "lldb/Target/Process.h"
26 #include "lldb/Symbol/SymbolContext.h"
27 #include "lldb/Symbol/CompileUnit.h"
28 #include "lldb/Target/StopInfo.h"
29 #include "lldb/Target/Target.h"
30 #include "lldb/Target/ThreadPlan.h"
31 #include "lldb/Target/ThreadPlanStepInstruction.h"
32 #include "lldb/Target/ThreadPlanStepOut.h"
33 #include "lldb/Target/ThreadPlanStepRange.h"
34 #include "lldb/Target/ThreadPlanStepInRange.h"
37 #include "lldb/API/SBAddress.h"
38 #include "lldb/API/SBDebugger.h"
39 #include "lldb/API/SBEvent.h"
40 #include "lldb/API/SBFrame.h"
41 #include "lldb/API/SBProcess.h"
42 #include "lldb/API/SBValue.h"
45 using namespace lldb_private;
48 SBThread::GetBroadcasterClassName ()
50 return Thread::GetStaticBroadcasterClass().AsCString();
53 //----------------------------------------------------------------------
55 //----------------------------------------------------------------------
56 SBThread::SBThread () :
57 m_opaque_sp (new ExecutionContextRef())
61 SBThread::SBThread (const ThreadSP& lldb_object_sp) :
62 m_opaque_sp (new ExecutionContextRef(lldb_object_sp))
66 SBThread::SBThread (const SBThread &rhs) :
67 m_opaque_sp (new ExecutionContextRef(*rhs.m_opaque_sp))
72 //----------------------------------------------------------------------
73 // Assignment operator
74 //----------------------------------------------------------------------
76 const lldb::SBThread &
77 SBThread::operator = (const SBThread &rhs)
80 *m_opaque_sp = *rhs.m_opaque_sp;
84 //----------------------------------------------------------------------
86 //----------------------------------------------------------------------
92 SBThread::IsValid() const
94 return m_opaque_sp->GetThreadSP().get() != NULL;
100 m_opaque_sp->Clear();
105 SBThread::GetStopReason()
107 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
109 StopReason reason = eStopReasonInvalid;
110 Mutex::Locker api_locker;
111 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
113 if (exe_ctx.HasThreadScope())
115 Process::StopLocker stop_locker;
116 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
118 return exe_ctx.GetThreadPtr()->GetStopReason();
123 log->Printf ("SBThread(%p)::GetStopReason() => error: process is running", exe_ctx.GetThreadPtr());
128 log->Printf ("SBThread(%p)::GetStopReason () => %s", exe_ctx.GetThreadPtr(),
129 Thread::StopReasonAsCString (reason));
135 SBThread::GetStopReasonDataCount ()
137 Mutex::Locker api_locker;
138 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
140 if (exe_ctx.HasThreadScope())
142 Process::StopLocker stop_locker;
143 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
145 StopInfoSP stop_info_sp = exe_ctx.GetThreadPtr()->GetStopInfo ();
148 StopReason reason = stop_info_sp->GetStopReason();
151 case eStopReasonInvalid:
152 case eStopReasonNone:
153 case eStopReasonTrace:
154 case eStopReasonExec:
155 case eStopReasonPlanComplete:
156 case eStopReasonThreadExiting:
157 // There is no data for these stop reasons.
160 case eStopReasonBreakpoint:
162 break_id_t site_id = stop_info_sp->GetValue();
163 lldb::BreakpointSiteSP bp_site_sp (exe_ctx.GetProcessPtr()->GetBreakpointSiteList().FindByID (site_id));
165 return bp_site_sp->GetNumberOfOwners () * 2;
167 return 0; // Breakpoint must have cleared itself...
171 case eStopReasonWatchpoint:
174 case eStopReasonSignal:
177 case eStopReasonException:
184 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
186 log->Printf ("SBThread(%p)::GetStopReasonDataCount() => error: process is running", exe_ctx.GetThreadPtr());
193 SBThread::GetStopReasonDataAtIndex (uint32_t idx)
195 Mutex::Locker api_locker;
196 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
198 if (exe_ctx.HasThreadScope())
200 Process::StopLocker stop_locker;
201 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
203 Thread *thread = exe_ctx.GetThreadPtr();
204 StopInfoSP stop_info_sp = thread->GetStopInfo ();
207 StopReason reason = stop_info_sp->GetStopReason();
210 case eStopReasonInvalid:
211 case eStopReasonNone:
212 case eStopReasonTrace:
213 case eStopReasonExec:
214 case eStopReasonPlanComplete:
215 case eStopReasonThreadExiting:
216 // There is no data for these stop reasons.
219 case eStopReasonBreakpoint:
221 break_id_t site_id = stop_info_sp->GetValue();
222 lldb::BreakpointSiteSP bp_site_sp (exe_ctx.GetProcessPtr()->GetBreakpointSiteList().FindByID (site_id));
225 uint32_t bp_index = idx / 2;
226 BreakpointLocationSP bp_loc_sp (bp_site_sp->GetOwnerAtIndex (bp_index));
231 // Odd idx, return the breakpoint location ID
232 return bp_loc_sp->GetID();
236 // Even idx, return the breakpoint ID
237 return bp_loc_sp->GetBreakpoint().GetID();
241 return LLDB_INVALID_BREAK_ID;
245 case eStopReasonWatchpoint:
246 return stop_info_sp->GetValue();
248 case eStopReasonSignal:
249 return stop_info_sp->GetValue();
251 case eStopReasonException:
252 return stop_info_sp->GetValue();
258 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
260 log->Printf ("SBThread(%p)::GetStopReasonDataAtIndex() => error: process is running", exe_ctx.GetThreadPtr());
267 SBThread::GetStopDescription (char *dst, size_t dst_len)
269 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
271 Mutex::Locker api_locker;
272 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
274 if (exe_ctx.HasThreadScope())
276 Process::StopLocker stop_locker;
277 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
280 StopInfoSP stop_info_sp = exe_ctx.GetThreadPtr()->GetStopInfo ();
283 const char *stop_desc = stop_info_sp->GetDescription();
287 log->Printf ("SBThread(%p)::GetStopDescription (dst, dst_len) => \"%s\"",
288 exe_ctx.GetThreadPtr(), stop_desc);
290 return ::snprintf (dst, dst_len, "%s", stop_desc);
293 // NULL dst passed in, return the length needed to contain the description
294 return ::strlen (stop_desc) + 1; // Include the NULL byte for size
299 size_t stop_desc_len = 0;
300 switch (stop_info_sp->GetStopReason())
302 case eStopReasonTrace:
303 case eStopReasonPlanComplete:
305 static char trace_desc[] = "step";
306 stop_desc = trace_desc;
307 stop_desc_len = sizeof(trace_desc); // Include the NULL byte for size
311 case eStopReasonBreakpoint:
313 static char bp_desc[] = "breakpoint hit";
315 stop_desc_len = sizeof(bp_desc); // Include the NULL byte for size
319 case eStopReasonWatchpoint:
321 static char wp_desc[] = "watchpoint hit";
323 stop_desc_len = sizeof(wp_desc); // Include the NULL byte for size
327 case eStopReasonSignal:
329 stop_desc = exe_ctx.GetProcessPtr()->GetUnixSignals ().GetSignalAsCString (stop_info_sp->GetValue());
330 if (stop_desc == NULL || stop_desc[0] == '\0')
332 static char signal_desc[] = "signal";
333 stop_desc = signal_desc;
334 stop_desc_len = sizeof(signal_desc); // Include the NULL byte for size
339 case eStopReasonException:
341 char exc_desc[] = "exception";
342 stop_desc = exc_desc;
343 stop_desc_len = sizeof(exc_desc); // Include the NULL byte for size
347 case eStopReasonExec:
349 char exc_desc[] = "exec";
350 stop_desc = exc_desc;
351 stop_desc_len = sizeof(exc_desc); // Include the NULL byte for size
355 case eStopReasonThreadExiting:
357 char limbo_desc[] = "thread exiting";
358 stop_desc = limbo_desc;
359 stop_desc_len = sizeof(limbo_desc);
366 if (stop_desc && stop_desc[0])
369 log->Printf ("SBThread(%p)::GetStopDescription (dst, dst_len) => '%s'",
370 exe_ctx.GetThreadPtr(), stop_desc);
373 return ::snprintf (dst, dst_len, "%s", stop_desc) + 1; // Include the NULL byte
375 if (stop_desc_len == 0)
376 stop_desc_len = ::strlen (stop_desc) + 1; // Include the NULL byte
378 return stop_desc_len;
385 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
387 log->Printf ("SBThread(%p)::GetStopDescription() => error: process is running", exe_ctx.GetThreadPtr());
396 SBThread::GetStopReturnValue ()
398 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
399 ValueObjectSP return_valobj_sp;
400 Mutex::Locker api_locker;
401 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
403 if (exe_ctx.HasThreadScope())
405 Process::StopLocker stop_locker;
406 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
408 StopInfoSP stop_info_sp = exe_ctx.GetThreadPtr()->GetStopInfo ();
411 return_valobj_sp = StopInfo::GetReturnValueObject (stop_info_sp);
417 log->Printf ("SBThread(%p)::GetStopReturnValue() => error: process is running", exe_ctx.GetThreadPtr());
422 log->Printf ("SBThread(%p)::GetStopReturnValue () => %s", exe_ctx.GetThreadPtr(),
423 return_valobj_sp.get()
424 ? return_valobj_sp->GetValueAsCString()
425 : "<no return value>");
427 return SBValue (return_valobj_sp);
431 SBThread::SetThread (const ThreadSP& lldb_object_sp)
433 m_opaque_sp->SetThreadSP (lldb_object_sp);
438 SBThread::GetThreadID () const
440 ThreadSP thread_sp(m_opaque_sp->GetThreadSP());
442 return thread_sp->GetID();
443 return LLDB_INVALID_THREAD_ID;
447 SBThread::GetIndexID () const
449 ThreadSP thread_sp(m_opaque_sp->GetThreadSP());
451 return thread_sp->GetIndexID();
452 return LLDB_INVALID_INDEX32;
456 SBThread::GetName () const
458 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
459 const char *name = NULL;
460 Mutex::Locker api_locker;
461 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
463 if (exe_ctx.HasThreadScope())
465 Process::StopLocker stop_locker;
466 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
468 name = exe_ctx.GetThreadPtr()->GetName();
473 log->Printf ("SBThread(%p)::GetName() => error: process is running", exe_ctx.GetThreadPtr());
478 log->Printf ("SBThread(%p)::GetName () => %s", exe_ctx.GetThreadPtr(), name ? name : "NULL");
484 SBThread::GetQueueName () const
486 const char *name = NULL;
487 Mutex::Locker api_locker;
488 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
490 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
491 if (exe_ctx.HasThreadScope())
493 Process::StopLocker stop_locker;
494 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
496 name = exe_ctx.GetThreadPtr()->GetQueueName();
501 log->Printf ("SBThread(%p)::GetQueueName() => error: process is running", exe_ctx.GetThreadPtr());
506 log->Printf ("SBThread(%p)::GetQueueName () => %s", exe_ctx.GetThreadPtr(), name ? name : "NULL");
512 SBThread::GetQueueID () const
514 queue_id_t id = LLDB_INVALID_QUEUE_ID;
515 Mutex::Locker api_locker;
516 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
518 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
519 if (exe_ctx.HasThreadScope())
521 Process::StopLocker stop_locker;
522 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
524 id = exe_ctx.GetThreadPtr()->GetQueueID();
529 log->Printf ("SBThread(%p)::GetQueueID() => error: process is running", exe_ctx.GetThreadPtr());
534 log->Printf ("SBThread(%p)::GetQueueID () => 0x%" PRIx64, exe_ctx.GetThreadPtr(), id);
540 SBThread::ResumeNewPlan (ExecutionContext &exe_ctx, ThreadPlan *new_plan)
544 Process *process = exe_ctx.GetProcessPtr();
547 sb_error.SetErrorString("No process in SBThread::ResumeNewPlan");
551 Thread *thread = exe_ctx.GetThreadPtr();
554 sb_error.SetErrorString("No thread in SBThread::ResumeNewPlan");
558 // User level plans should be Master Plans so they can be interrupted, other plans executed, and
559 // then a "continue" will resume the plan.
560 if (new_plan != NULL)
562 new_plan->SetIsMasterPlan(true);
563 new_plan->SetOkayToDiscard(false);
566 // Why do we need to set the current thread by ID here???
567 process->GetThreadList().SetSelectedThreadByID (thread->GetID());
568 sb_error.ref() = process->Resume();
570 if (sb_error.Success())
572 // If we are doing synchronous mode, then wait for the
573 // process to stop yet again!
574 if (process->GetTarget().GetDebugger().GetAsyncExecution () == false)
575 process->WaitForProcessToStop (NULL);
582 SBThread::StepOver (lldb::RunMode stop_other_threads)
584 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
586 Mutex::Locker api_locker;
587 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
591 log->Printf ("SBThread(%p)::StepOver (stop_other_threads='%s')", exe_ctx.GetThreadPtr(),
592 Thread::RunModeAsCString (stop_other_threads));
594 if (exe_ctx.HasThreadScope())
596 Thread *thread = exe_ctx.GetThreadPtr();
597 bool abort_other_plans = false;
598 StackFrameSP frame_sp(thread->GetStackFrameAtIndex (0));
600 ThreadPlanSP new_plan_sp;
603 if (frame_sp->HasDebugInformation ())
605 SymbolContext sc(frame_sp->GetSymbolContext(eSymbolContextEverything));
606 new_plan_sp = thread->QueueThreadPlanForStepOverRange (abort_other_plans,
613 new_plan_sp = thread->QueueThreadPlanForStepSingleInstruction (true,
619 // This returns an error, we should use it!
620 ResumeNewPlan (exe_ctx, new_plan_sp.get());
625 SBThread::StepInto (lldb::RunMode stop_other_threads)
627 StepInto (NULL, stop_other_threads);
631 SBThread::StepInto (const char *target_name, lldb::RunMode stop_other_threads)
633 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
635 Mutex::Locker api_locker;
636 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
639 log->Printf ("SBThread(%p)::StepInto (target_name='%s', stop_other_threads='%s')",
640 exe_ctx.GetThreadPtr(),
641 target_name? target_name: "<NULL>",
642 Thread::RunModeAsCString (stop_other_threads));
644 if (exe_ctx.HasThreadScope())
646 bool abort_other_plans = false;
648 Thread *thread = exe_ctx.GetThreadPtr();
649 StackFrameSP frame_sp(thread->GetStackFrameAtIndex (0));
650 ThreadPlanSP new_plan_sp;
652 if (frame_sp && frame_sp->HasDebugInformation ())
654 bool avoid_code_without_debug_info = true;
655 SymbolContext sc(frame_sp->GetSymbolContext(eSymbolContextEverything));
656 new_plan_sp = thread->QueueThreadPlanForStepInRange (abort_other_plans,
661 avoid_code_without_debug_info);
665 new_plan_sp = thread->QueueThreadPlanForStepSingleInstruction (false,
670 // This returns an error, we should use it!
671 ResumeNewPlan (exe_ctx, new_plan_sp.get());
678 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
680 Mutex::Locker api_locker;
681 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
685 log->Printf ("SBThread(%p)::StepOut ()", exe_ctx.GetThreadPtr());
687 if (exe_ctx.HasThreadScope())
689 bool abort_other_plans = false;
690 bool stop_other_threads = false;
692 Thread *thread = exe_ctx.GetThreadPtr();
694 ThreadPlanSP new_plan_sp(thread->QueueThreadPlanForStepOut (abort_other_plans,
702 // This returns an error, we should use it!
703 ResumeNewPlan (exe_ctx, new_plan_sp.get());
708 SBThread::StepOutOfFrame (lldb::SBFrame &sb_frame)
710 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
712 Mutex::Locker api_locker;
713 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
715 StackFrameSP frame_sp (sb_frame.GetFrameSP());
718 SBStream frame_desc_strm;
719 sb_frame.GetDescription (frame_desc_strm);
720 log->Printf ("SBThread(%p)::StepOutOfFrame (frame = SBFrame(%p): %s)", exe_ctx.GetThreadPtr(), frame_sp.get(), frame_desc_strm.GetData());
723 if (exe_ctx.HasThreadScope())
725 bool abort_other_plans = false;
726 bool stop_other_threads = false;
727 Thread *thread = exe_ctx.GetThreadPtr();
729 ThreadPlanSP new_plan_sp(thread->QueueThreadPlanForStepOut (abort_other_plans,
735 frame_sp->GetFrameIndex()));
737 // This returns an error, we should use it!
738 ResumeNewPlan (exe_ctx, new_plan_sp.get());
743 SBThread::StepInstruction (bool step_over)
745 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
747 Mutex::Locker api_locker;
748 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
753 log->Printf ("SBThread(%p)::StepInstruction (step_over=%i)", exe_ctx.GetThreadPtr(), step_over);
755 if (exe_ctx.HasThreadScope())
757 Thread *thread = exe_ctx.GetThreadPtr();
758 ThreadPlanSP new_plan_sp(thread->QueueThreadPlanForStepSingleInstruction (step_over, true, true));
760 // This returns an error, we should use it!
761 ResumeNewPlan (exe_ctx, new_plan_sp.get());
766 SBThread::RunToAddress (lldb::addr_t addr)
768 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
770 Mutex::Locker api_locker;
771 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
775 log->Printf ("SBThread(%p)::RunToAddress (addr=0x%" PRIx64 ")", exe_ctx.GetThreadPtr(), addr);
777 if (exe_ctx.HasThreadScope())
779 bool abort_other_plans = false;
780 bool stop_other_threads = true;
782 Address target_addr (addr);
784 Thread *thread = exe_ctx.GetThreadPtr();
786 ThreadPlanSP new_plan_sp(thread->QueueThreadPlanForRunToAddress (abort_other_plans, target_addr, stop_other_threads));
788 // This returns an error, we should use it!
789 ResumeNewPlan (exe_ctx, new_plan_sp.get());
794 SBThread::StepOverUntil (lldb::SBFrame &sb_frame,
795 lldb::SBFileSpec &sb_file_spec,
799 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
802 Mutex::Locker api_locker;
803 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
805 StackFrameSP frame_sp (sb_frame.GetFrameSP());
809 SBStream frame_desc_strm;
810 sb_frame.GetDescription (frame_desc_strm);
811 sb_file_spec->GetPath (path, sizeof(path));
812 log->Printf ("SBThread(%p)::StepOverUntil (frame = SBFrame(%p): %s, file+line = %s:%u)",
813 exe_ctx.GetThreadPtr(),
815 frame_desc_strm.GetData(),
819 if (exe_ctx.HasThreadScope())
821 Target *target = exe_ctx.GetTargetPtr();
822 Thread *thread = exe_ctx.GetThreadPtr();
826 sb_error.SetErrorString("invalid line argument");
832 frame_sp = thread->GetSelectedFrame ();
834 frame_sp = thread->GetStackFrameAtIndex (0);
837 SymbolContext frame_sc;
840 sb_error.SetErrorString("no valid frames in thread to step");
844 // If we have a frame, get its line
845 frame_sc = frame_sp->GetSymbolContext (eSymbolContextCompUnit |
846 eSymbolContextFunction |
847 eSymbolContextLineEntry |
848 eSymbolContextSymbol );
850 if (frame_sc.comp_unit == NULL)
852 sb_error.SetErrorStringWithFormat("frame %u doesn't have debug information", frame_sp->GetFrameIndex());
856 FileSpec step_file_spec;
857 if (sb_file_spec.IsValid())
859 // The file spec passed in was valid, so use it
860 step_file_spec = sb_file_spec.ref();
864 if (frame_sc.line_entry.IsValid())
865 step_file_spec = frame_sc.line_entry.file;
868 sb_error.SetErrorString("invalid file argument or no file for frame");
873 // Grab the current function, then we will make sure the "until" address is
874 // within the function. We discard addresses that are out of the current
875 // function, and then if there are no addresses remaining, give an appropriate
878 bool all_in_function = true;
879 AddressRange fun_range = frame_sc.function->GetAddressRange();
881 std::vector<addr_t> step_over_until_addrs;
882 const bool abort_other_plans = false;
883 const bool stop_other_threads = false;
884 const bool check_inlines = true;
885 const bool exact = false;
887 SymbolContextList sc_list;
888 const uint32_t num_matches = frame_sc.comp_unit->ResolveSymbolContext (step_file_spec,
892 eSymbolContextLineEntry,
897 for (uint32_t i=0; i<num_matches; ++i)
899 if (sc_list.GetContextAtIndex(i, sc))
901 addr_t step_addr = sc.line_entry.range.GetBaseAddress().GetLoadAddress(target);
902 if (step_addr != LLDB_INVALID_ADDRESS)
904 if (fun_range.ContainsLoadAddress(step_addr, target))
905 step_over_until_addrs.push_back(step_addr);
907 all_in_function = false;
913 if (step_over_until_addrs.empty())
917 step_file_spec.GetPath (path, sizeof(path));
918 sb_error.SetErrorStringWithFormat("No line entries for %s:%u", path, line);
921 sb_error.SetErrorString ("step until target not in current function");
925 ThreadPlanSP new_plan_sp(thread->QueueThreadPlanForStepUntil (abort_other_plans,
926 &step_over_until_addrs[0],
927 step_over_until_addrs.size(),
929 frame_sp->GetFrameIndex()));
931 sb_error = ResumeNewPlan (exe_ctx, new_plan_sp.get());
936 sb_error.SetErrorString("this SBThread object is invalid");
942 SBThread::JumpToLine (lldb::SBFileSpec &file_spec, uint32_t line)
944 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
947 Mutex::Locker api_locker;
948 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
951 log->Printf ("SBThread(%p)::JumpToLine (file+line = %s:%u)", exe_ctx.GetThreadPtr(), file_spec->GetPath().c_str(), line);
953 if (!exe_ctx.HasThreadScope())
955 sb_error.SetErrorString("this SBThread object is invalid");
959 Thread *thread = exe_ctx.GetThreadPtr();
961 Error err = thread->JumpToLine (file_spec.get(), line, true);
962 sb_error.SetError (err);
967 SBThread::ReturnFromFrame (SBFrame &frame, SBValue &return_value)
971 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
973 Mutex::Locker api_locker;
974 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
978 log->Printf ("SBThread(%p)::ReturnFromFrame (frame=%d)", exe_ctx.GetThreadPtr(), frame.GetFrameID());
980 if (exe_ctx.HasThreadScope())
982 Thread *thread = exe_ctx.GetThreadPtr();
983 sb_error.SetError (thread->ReturnFromFrame(frame.GetFrameSP(), return_value.GetSP()));
993 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
994 ExecutionContext exe_ctx (m_opaque_sp.get());
996 if (exe_ctx.HasThreadScope())
998 Process::StopLocker stop_locker;
999 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
1001 exe_ctx.GetThreadPtr()->SetResumeState (eStateSuspended);
1007 log->Printf ("SBThread(%p)::Suspend() => error: process is running", exe_ctx.GetThreadPtr());
1011 log->Printf ("SBThread(%p)::Suspend() => %i", exe_ctx.GetThreadPtr(), result);
1018 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1019 ExecutionContext exe_ctx (m_opaque_sp.get());
1020 bool result = false;
1021 if (exe_ctx.HasThreadScope())
1023 Process::StopLocker stop_locker;
1024 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
1026 exe_ctx.GetThreadPtr()->SetResumeState (eStateRunning);
1032 log->Printf ("SBThread(%p)::Resume() => error: process is running", exe_ctx.GetThreadPtr());
1036 log->Printf ("SBThread(%p)::Resume() => %i", exe_ctx.GetThreadPtr(), result);
1041 SBThread::IsSuspended()
1043 ExecutionContext exe_ctx (m_opaque_sp.get());
1044 if (exe_ctx.HasThreadScope())
1045 return exe_ctx.GetThreadPtr()->GetResumeState () == eStateSuspended;
1050 SBThread::IsStopped()
1052 ExecutionContext exe_ctx (m_opaque_sp.get());
1053 if (exe_ctx.HasThreadScope())
1054 return StateIsStoppedState(exe_ctx.GetThreadPtr()->GetState(), true);
1059 SBThread::GetProcess ()
1061 SBProcess sb_process;
1062 ExecutionContext exe_ctx (m_opaque_sp.get());
1063 if (exe_ctx.HasThreadScope())
1065 // Have to go up to the target so we can get a shared pointer to our process...
1066 sb_process.SetSP (exe_ctx.GetProcessSP());
1069 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1072 SBStream frame_desc_strm;
1073 sb_process.GetDescription (frame_desc_strm);
1074 log->Printf ("SBThread(%p)::GetProcess () => SBProcess(%p): %s", exe_ctx.GetThreadPtr(),
1075 sb_process.GetSP().get(), frame_desc_strm.GetData());
1082 SBThread::GetNumFrames ()
1084 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1086 uint32_t num_frames = 0;
1087 Mutex::Locker api_locker;
1088 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1090 if (exe_ctx.HasThreadScope())
1092 Process::StopLocker stop_locker;
1093 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
1095 num_frames = exe_ctx.GetThreadPtr()->GetStackFrameCount();
1100 log->Printf ("SBThread(%p)::GetNumFrames() => error: process is running", exe_ctx.GetThreadPtr());
1105 log->Printf ("SBThread(%p)::GetNumFrames () => %u", exe_ctx.GetThreadPtr(), num_frames);
1111 SBThread::GetFrameAtIndex (uint32_t idx)
1113 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1116 StackFrameSP frame_sp;
1117 Mutex::Locker api_locker;
1118 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1120 if (exe_ctx.HasThreadScope())
1122 Process::StopLocker stop_locker;
1123 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
1125 frame_sp = exe_ctx.GetThreadPtr()->GetStackFrameAtIndex (idx);
1126 sb_frame.SetFrameSP (frame_sp);
1131 log->Printf ("SBThread(%p)::GetFrameAtIndex() => error: process is running", exe_ctx.GetThreadPtr());
1137 SBStream frame_desc_strm;
1138 sb_frame.GetDescription (frame_desc_strm);
1139 log->Printf ("SBThread(%p)::GetFrameAtIndex (idx=%d) => SBFrame(%p): %s",
1140 exe_ctx.GetThreadPtr(), idx, frame_sp.get(), frame_desc_strm.GetData());
1147 SBThread::GetSelectedFrame ()
1149 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1152 StackFrameSP frame_sp;
1153 Mutex::Locker api_locker;
1154 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1156 if (exe_ctx.HasThreadScope())
1158 Process::StopLocker stop_locker;
1159 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
1161 frame_sp = exe_ctx.GetThreadPtr()->GetSelectedFrame ();
1162 sb_frame.SetFrameSP (frame_sp);
1167 log->Printf ("SBThread(%p)::GetSelectedFrame() => error: process is running", exe_ctx.GetThreadPtr());
1173 SBStream frame_desc_strm;
1174 sb_frame.GetDescription (frame_desc_strm);
1175 log->Printf ("SBThread(%p)::GetSelectedFrame () => SBFrame(%p): %s",
1176 exe_ctx.GetThreadPtr(), frame_sp.get(), frame_desc_strm.GetData());
1183 SBThread::SetSelectedFrame (uint32_t idx)
1185 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1188 StackFrameSP frame_sp;
1189 Mutex::Locker api_locker;
1190 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1192 if (exe_ctx.HasThreadScope())
1194 Process::StopLocker stop_locker;
1195 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
1197 Thread *thread = exe_ctx.GetThreadPtr();
1198 frame_sp = thread->GetStackFrameAtIndex (idx);
1201 thread->SetSelectedFrame (frame_sp.get());
1202 sb_frame.SetFrameSP (frame_sp);
1208 log->Printf ("SBThread(%p)::SetSelectedFrame() => error: process is running", exe_ctx.GetThreadPtr());
1214 SBStream frame_desc_strm;
1215 sb_frame.GetDescription (frame_desc_strm);
1216 log->Printf ("SBThread(%p)::SetSelectedFrame (idx=%u) => SBFrame(%p): %s",
1217 exe_ctx.GetThreadPtr(), idx, frame_sp.get(), frame_desc_strm.GetData());
1223 SBThread::EventIsThreadEvent (const SBEvent &event)
1225 return Thread::ThreadEventData::GetEventDataFromEvent(event.get()) != NULL;
1229 SBThread::GetStackFrameFromEvent (const SBEvent &event)
1231 return Thread::ThreadEventData::GetStackFrameFromEvent (event.get());
1236 SBThread::GetThreadFromEvent (const SBEvent &event)
1238 return Thread::ThreadEventData::GetThreadFromEvent (event.get());
1242 SBThread::operator == (const SBThread &rhs) const
1244 return m_opaque_sp->GetThreadSP().get() == rhs.m_opaque_sp->GetThreadSP().get();
1248 SBThread::operator != (const SBThread &rhs) const
1250 return m_opaque_sp->GetThreadSP().get() != rhs.m_opaque_sp->GetThreadSP().get();
1254 SBThread::GetStatus (SBStream &status) const
1256 Stream &strm = status.ref();
1258 ExecutionContext exe_ctx (m_opaque_sp.get());
1259 if (exe_ctx.HasThreadScope())
1261 exe_ctx.GetThreadPtr()->GetStatus(strm, 0, 1, 1);
1264 strm.PutCString ("No status");
1270 SBThread::GetDescription (SBStream &description) const
1272 Stream &strm = description.ref();
1274 ExecutionContext exe_ctx (m_opaque_sp.get());
1275 if (exe_ctx.HasThreadScope())
1277 strm.Printf("SBThread: tid = 0x%4.4" PRIx64, exe_ctx.GetThreadPtr()->GetID());
1280 strm.PutCString ("No value");
1286 SBThread::GetExtendedBacktrace (const char *type)
1288 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1289 Mutex::Locker api_locker;
1290 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1291 SBThread sb_origin_thread;
1293 if (exe_ctx.HasThreadScope())
1295 Process::StopLocker stop_locker;
1296 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
1298 ThreadSP real_thread(exe_ctx.GetThreadPtr());
1301 ConstString type_const (type);
1302 SystemRuntime *runtime = exe_ctx.GetProcessPtr()->GetSystemRuntime();
1305 ThreadSP origin_thread = runtime->GetExtendedBacktrace (real_thread, type_const);
1306 sb_origin_thread.SetThread (origin_thread);
1313 log->Printf ("SBThread(%p)::GetExtendedBacktrace() => error: process is running", exe_ctx.GetThreadPtr());
1317 return sb_origin_thread;