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);
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::GetQueueID () const
513 queue_id_t id = LLDB_INVALID_QUEUE_ID;
514 Mutex::Locker api_locker;
515 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
517 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
518 if (exe_ctx.HasThreadScope())
520 Process::StopLocker stop_locker;
521 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
523 id = exe_ctx.GetThreadPtr()->GetQueueID();
528 log->Printf ("SBThread(%p)::GetQueueID() => error: process is running", exe_ctx.GetThreadPtr());
533 log->Printf ("SBThread(%p)::GetQueueID () => 0x%" PRIx64, exe_ctx.GetThreadPtr(), id);
539 SBThread::ResumeNewPlan (ExecutionContext &exe_ctx, ThreadPlan *new_plan)
543 Process *process = exe_ctx.GetProcessPtr();
546 sb_error.SetErrorString("No process in SBThread::ResumeNewPlan");
550 Thread *thread = exe_ctx.GetThreadPtr();
553 sb_error.SetErrorString("No thread in SBThread::ResumeNewPlan");
557 // User level plans should be Master Plans so they can be interrupted, other plans executed, and
558 // then a "continue" will resume the plan.
559 if (new_plan != NULL)
561 new_plan->SetIsMasterPlan(true);
562 new_plan->SetOkayToDiscard(false);
565 // Why do we need to set the current thread by ID here???
566 process->GetThreadList().SetSelectedThreadByID (thread->GetID());
567 sb_error.ref() = process->Resume();
569 if (sb_error.Success())
571 // If we are doing synchronous mode, then wait for the
572 // process to stop yet again!
573 if (process->GetTarget().GetDebugger().GetAsyncExecution () == false)
574 process->WaitForProcessToStop (NULL);
581 SBThread::StepOver (lldb::RunMode stop_other_threads)
583 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
585 Mutex::Locker api_locker;
586 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
590 log->Printf ("SBThread(%p)::StepOver (stop_other_threads='%s')", exe_ctx.GetThreadPtr(),
591 Thread::RunModeAsCString (stop_other_threads));
593 if (exe_ctx.HasThreadScope())
595 Thread *thread = exe_ctx.GetThreadPtr();
596 bool abort_other_plans = false;
597 StackFrameSP frame_sp(thread->GetStackFrameAtIndex (0));
599 ThreadPlanSP new_plan_sp;
602 if (frame_sp->HasDebugInformation ())
604 SymbolContext sc(frame_sp->GetSymbolContext(eSymbolContextEverything));
605 new_plan_sp = thread->QueueThreadPlanForStepOverRange (abort_other_plans,
612 new_plan_sp = thread->QueueThreadPlanForStepSingleInstruction (true,
618 // This returns an error, we should use it!
619 ResumeNewPlan (exe_ctx, new_plan_sp.get());
624 SBThread::StepInto (lldb::RunMode stop_other_threads)
626 StepInto (NULL, stop_other_threads);
630 SBThread::StepInto (const char *target_name, lldb::RunMode stop_other_threads)
632 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
634 Mutex::Locker api_locker;
635 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
638 log->Printf ("SBThread(%p)::StepInto (target_name='%s', stop_other_threads='%s')",
639 exe_ctx.GetThreadPtr(),
640 target_name? target_name: "<NULL>",
641 Thread::RunModeAsCString (stop_other_threads));
643 if (exe_ctx.HasThreadScope())
645 bool abort_other_plans = false;
647 Thread *thread = exe_ctx.GetThreadPtr();
648 StackFrameSP frame_sp(thread->GetStackFrameAtIndex (0));
649 ThreadPlanSP new_plan_sp;
651 if (frame_sp && frame_sp->HasDebugInformation ())
653 bool avoid_code_without_debug_info = true;
654 SymbolContext sc(frame_sp->GetSymbolContext(eSymbolContextEverything));
655 new_plan_sp = thread->QueueThreadPlanForStepInRange (abort_other_plans,
660 avoid_code_without_debug_info);
664 new_plan_sp = thread->QueueThreadPlanForStepSingleInstruction (false,
669 // This returns an error, we should use it!
670 ResumeNewPlan (exe_ctx, new_plan_sp.get());
677 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
679 Mutex::Locker api_locker;
680 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
684 log->Printf ("SBThread(%p)::StepOut ()", exe_ctx.GetThreadPtr());
686 if (exe_ctx.HasThreadScope())
688 bool abort_other_plans = false;
689 bool stop_other_threads = false;
691 Thread *thread = exe_ctx.GetThreadPtr();
693 ThreadPlanSP new_plan_sp(thread->QueueThreadPlanForStepOut (abort_other_plans,
701 // This returns an error, we should use it!
702 ResumeNewPlan (exe_ctx, new_plan_sp.get());
707 SBThread::StepOutOfFrame (lldb::SBFrame &sb_frame)
709 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
711 Mutex::Locker api_locker;
712 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
714 StackFrameSP frame_sp (sb_frame.GetFrameSP());
717 SBStream frame_desc_strm;
718 sb_frame.GetDescription (frame_desc_strm);
719 log->Printf ("SBThread(%p)::StepOutOfFrame (frame = SBFrame(%p): %s)", exe_ctx.GetThreadPtr(), frame_sp.get(), frame_desc_strm.GetData());
722 if (exe_ctx.HasThreadScope())
724 bool abort_other_plans = false;
725 bool stop_other_threads = false;
726 Thread *thread = exe_ctx.GetThreadPtr();
728 ThreadPlanSP new_plan_sp(thread->QueueThreadPlanForStepOut (abort_other_plans,
734 frame_sp->GetFrameIndex()));
736 // This returns an error, we should use it!
737 ResumeNewPlan (exe_ctx, new_plan_sp.get());
742 SBThread::StepInstruction (bool step_over)
744 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
746 Mutex::Locker api_locker;
747 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
752 log->Printf ("SBThread(%p)::StepInstruction (step_over=%i)", exe_ctx.GetThreadPtr(), step_over);
754 if (exe_ctx.HasThreadScope())
756 Thread *thread = exe_ctx.GetThreadPtr();
757 ThreadPlanSP new_plan_sp(thread->QueueThreadPlanForStepSingleInstruction (step_over, true, true));
759 // This returns an error, we should use it!
760 ResumeNewPlan (exe_ctx, new_plan_sp.get());
765 SBThread::RunToAddress (lldb::addr_t addr)
767 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
769 Mutex::Locker api_locker;
770 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
774 log->Printf ("SBThread(%p)::RunToAddress (addr=0x%" PRIx64 ")", exe_ctx.GetThreadPtr(), addr);
776 if (exe_ctx.HasThreadScope())
778 bool abort_other_plans = false;
779 bool stop_other_threads = true;
781 Address target_addr (addr);
783 Thread *thread = exe_ctx.GetThreadPtr();
785 ThreadPlanSP new_plan_sp(thread->QueueThreadPlanForRunToAddress (abort_other_plans, target_addr, stop_other_threads));
787 // This returns an error, we should use it!
788 ResumeNewPlan (exe_ctx, new_plan_sp.get());
793 SBThread::StepOverUntil (lldb::SBFrame &sb_frame,
794 lldb::SBFileSpec &sb_file_spec,
798 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
801 Mutex::Locker api_locker;
802 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
804 StackFrameSP frame_sp (sb_frame.GetFrameSP());
808 SBStream frame_desc_strm;
809 sb_frame.GetDescription (frame_desc_strm);
810 sb_file_spec->GetPath (path, sizeof(path));
811 log->Printf ("SBThread(%p)::StepOverUntil (frame = SBFrame(%p): %s, file+line = %s:%u)",
812 exe_ctx.GetThreadPtr(),
814 frame_desc_strm.GetData(),
818 if (exe_ctx.HasThreadScope())
820 Target *target = exe_ctx.GetTargetPtr();
821 Thread *thread = exe_ctx.GetThreadPtr();
825 sb_error.SetErrorString("invalid line argument");
831 frame_sp = thread->GetSelectedFrame ();
833 frame_sp = thread->GetStackFrameAtIndex (0);
836 SymbolContext frame_sc;
839 sb_error.SetErrorString("no valid frames in thread to step");
843 // If we have a frame, get its line
844 frame_sc = frame_sp->GetSymbolContext (eSymbolContextCompUnit |
845 eSymbolContextFunction |
846 eSymbolContextLineEntry |
847 eSymbolContextSymbol );
849 if (frame_sc.comp_unit == NULL)
851 sb_error.SetErrorStringWithFormat("frame %u doesn't have debug information", frame_sp->GetFrameIndex());
855 FileSpec step_file_spec;
856 if (sb_file_spec.IsValid())
858 // The file spec passed in was valid, so use it
859 step_file_spec = sb_file_spec.ref();
863 if (frame_sc.line_entry.IsValid())
864 step_file_spec = frame_sc.line_entry.file;
867 sb_error.SetErrorString("invalid file argument or no file for frame");
872 // Grab the current function, then we will make sure the "until" address is
873 // within the function. We discard addresses that are out of the current
874 // function, and then if there are no addresses remaining, give an appropriate
877 bool all_in_function = true;
878 AddressRange fun_range = frame_sc.function->GetAddressRange();
880 std::vector<addr_t> step_over_until_addrs;
881 const bool abort_other_plans = false;
882 const bool stop_other_threads = false;
883 const bool check_inlines = true;
884 const bool exact = false;
886 SymbolContextList sc_list;
887 const uint32_t num_matches = frame_sc.comp_unit->ResolveSymbolContext (step_file_spec,
891 eSymbolContextLineEntry,
896 for (uint32_t i=0; i<num_matches; ++i)
898 if (sc_list.GetContextAtIndex(i, sc))
900 addr_t step_addr = sc.line_entry.range.GetBaseAddress().GetLoadAddress(target);
901 if (step_addr != LLDB_INVALID_ADDRESS)
903 if (fun_range.ContainsLoadAddress(step_addr, target))
904 step_over_until_addrs.push_back(step_addr);
906 all_in_function = false;
912 if (step_over_until_addrs.empty())
916 step_file_spec.GetPath (path, sizeof(path));
917 sb_error.SetErrorStringWithFormat("No line entries for %s:%u", path, line);
920 sb_error.SetErrorString ("step until target not in current function");
924 ThreadPlanSP new_plan_sp(thread->QueueThreadPlanForStepUntil (abort_other_plans,
925 &step_over_until_addrs[0],
926 step_over_until_addrs.size(),
928 frame_sp->GetFrameIndex()));
930 sb_error = ResumeNewPlan (exe_ctx, new_plan_sp.get());
935 sb_error.SetErrorString("this SBThread object is invalid");
941 SBThread::JumpToLine (lldb::SBFileSpec &file_spec, uint32_t line)
943 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
946 Mutex::Locker api_locker;
947 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
950 log->Printf ("SBThread(%p)::JumpToLine (file+line = %s:%u)", exe_ctx.GetThreadPtr(), file_spec->GetPath().c_str(), line);
952 if (!exe_ctx.HasThreadScope())
954 sb_error.SetErrorString("this SBThread object is invalid");
958 Thread *thread = exe_ctx.GetThreadPtr();
960 Error err = thread->JumpToLine (file_spec.get(), line, true);
961 sb_error.SetError (err);
966 SBThread::ReturnFromFrame (SBFrame &frame, SBValue &return_value)
970 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
972 Mutex::Locker api_locker;
973 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
977 log->Printf ("SBThread(%p)::ReturnFromFrame (frame=%d)", exe_ctx.GetThreadPtr(), frame.GetFrameID());
979 if (exe_ctx.HasThreadScope())
981 Thread *thread = exe_ctx.GetThreadPtr();
982 sb_error.SetError (thread->ReturnFromFrame(frame.GetFrameSP(), return_value.GetSP()));
992 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
993 ExecutionContext exe_ctx (m_opaque_sp.get());
995 if (exe_ctx.HasThreadScope())
997 Process::StopLocker stop_locker;
998 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
1000 exe_ctx.GetThreadPtr()->SetResumeState (eStateSuspended);
1006 log->Printf ("SBThread(%p)::Suspend() => error: process is running", exe_ctx.GetThreadPtr());
1010 log->Printf ("SBThread(%p)::Suspend() => %i", exe_ctx.GetThreadPtr(), result);
1017 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1018 ExecutionContext exe_ctx (m_opaque_sp.get());
1019 bool result = false;
1020 if (exe_ctx.HasThreadScope())
1022 Process::StopLocker stop_locker;
1023 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
1025 exe_ctx.GetThreadPtr()->SetResumeState (eStateRunning);
1031 log->Printf ("SBThread(%p)::Resume() => error: process is running", exe_ctx.GetThreadPtr());
1035 log->Printf ("SBThread(%p)::Resume() => %i", exe_ctx.GetThreadPtr(), result);
1040 SBThread::IsSuspended()
1042 ExecutionContext exe_ctx (m_opaque_sp.get());
1043 if (exe_ctx.HasThreadScope())
1044 return exe_ctx.GetThreadPtr()->GetResumeState () == eStateSuspended;
1049 SBThread::IsStopped()
1051 ExecutionContext exe_ctx (m_opaque_sp.get());
1052 if (exe_ctx.HasThreadScope())
1053 return StateIsStoppedState(exe_ctx.GetThreadPtr()->GetState(), true);
1058 SBThread::GetProcess ()
1060 SBProcess sb_process;
1061 ExecutionContext exe_ctx (m_opaque_sp.get());
1062 if (exe_ctx.HasThreadScope())
1064 // Have to go up to the target so we can get a shared pointer to our process...
1065 sb_process.SetSP (exe_ctx.GetProcessSP());
1068 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1071 SBStream frame_desc_strm;
1072 sb_process.GetDescription (frame_desc_strm);
1073 log->Printf ("SBThread(%p)::GetProcess () => SBProcess(%p): %s", exe_ctx.GetThreadPtr(),
1074 sb_process.GetSP().get(), frame_desc_strm.GetData());
1081 SBThread::GetNumFrames ()
1083 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1085 uint32_t num_frames = 0;
1086 Mutex::Locker api_locker;
1087 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1089 if (exe_ctx.HasThreadScope())
1091 Process::StopLocker stop_locker;
1092 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
1094 num_frames = exe_ctx.GetThreadPtr()->GetStackFrameCount();
1099 log->Printf ("SBThread(%p)::GetNumFrames() => error: process is running", exe_ctx.GetThreadPtr());
1104 log->Printf ("SBThread(%p)::GetNumFrames () => %u", exe_ctx.GetThreadPtr(), num_frames);
1110 SBThread::GetFrameAtIndex (uint32_t idx)
1112 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1115 StackFrameSP frame_sp;
1116 Mutex::Locker api_locker;
1117 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1119 if (exe_ctx.HasThreadScope())
1121 Process::StopLocker stop_locker;
1122 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
1124 frame_sp = exe_ctx.GetThreadPtr()->GetStackFrameAtIndex (idx);
1125 sb_frame.SetFrameSP (frame_sp);
1130 log->Printf ("SBThread(%p)::GetFrameAtIndex() => error: process is running", exe_ctx.GetThreadPtr());
1136 SBStream frame_desc_strm;
1137 sb_frame.GetDescription (frame_desc_strm);
1138 log->Printf ("SBThread(%p)::GetFrameAtIndex (idx=%d) => SBFrame(%p): %s",
1139 exe_ctx.GetThreadPtr(), idx, frame_sp.get(), frame_desc_strm.GetData());
1146 SBThread::GetSelectedFrame ()
1148 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1151 StackFrameSP frame_sp;
1152 Mutex::Locker api_locker;
1153 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1155 if (exe_ctx.HasThreadScope())
1157 Process::StopLocker stop_locker;
1158 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
1160 frame_sp = exe_ctx.GetThreadPtr()->GetSelectedFrame ();
1161 sb_frame.SetFrameSP (frame_sp);
1166 log->Printf ("SBThread(%p)::GetSelectedFrame() => error: process is running", exe_ctx.GetThreadPtr());
1172 SBStream frame_desc_strm;
1173 sb_frame.GetDescription (frame_desc_strm);
1174 log->Printf ("SBThread(%p)::GetSelectedFrame () => SBFrame(%p): %s",
1175 exe_ctx.GetThreadPtr(), frame_sp.get(), frame_desc_strm.GetData());
1182 SBThread::SetSelectedFrame (uint32_t idx)
1184 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1187 StackFrameSP frame_sp;
1188 Mutex::Locker api_locker;
1189 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1191 if (exe_ctx.HasThreadScope())
1193 Process::StopLocker stop_locker;
1194 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
1196 Thread *thread = exe_ctx.GetThreadPtr();
1197 frame_sp = thread->GetStackFrameAtIndex (idx);
1200 thread->SetSelectedFrame (frame_sp.get());
1201 sb_frame.SetFrameSP (frame_sp);
1207 log->Printf ("SBThread(%p)::SetSelectedFrame() => error: process is running", exe_ctx.GetThreadPtr());
1213 SBStream frame_desc_strm;
1214 sb_frame.GetDescription (frame_desc_strm);
1215 log->Printf ("SBThread(%p)::SetSelectedFrame (idx=%u) => SBFrame(%p): %s",
1216 exe_ctx.GetThreadPtr(), idx, frame_sp.get(), frame_desc_strm.GetData());
1222 SBThread::EventIsThreadEvent (const SBEvent &event)
1224 return Thread::ThreadEventData::GetEventDataFromEvent(event.get()) != NULL;
1228 SBThread::GetStackFrameFromEvent (const SBEvent &event)
1230 return Thread::ThreadEventData::GetStackFrameFromEvent (event.get());
1235 SBThread::GetThreadFromEvent (const SBEvent &event)
1237 return Thread::ThreadEventData::GetThreadFromEvent (event.get());
1241 SBThread::operator == (const SBThread &rhs) const
1243 return m_opaque_sp->GetThreadSP().get() == rhs.m_opaque_sp->GetThreadSP().get();
1247 SBThread::operator != (const SBThread &rhs) const
1249 return m_opaque_sp->GetThreadSP().get() != rhs.m_opaque_sp->GetThreadSP().get();
1253 SBThread::GetStatus (SBStream &status) const
1255 Stream &strm = status.ref();
1257 ExecutionContext exe_ctx (m_opaque_sp.get());
1258 if (exe_ctx.HasThreadScope())
1260 exe_ctx.GetThreadPtr()->GetStatus(strm, 0, 1, 1);
1263 strm.PutCString ("No status");
1269 SBThread::GetDescription (SBStream &description) const
1271 Stream &strm = description.ref();
1273 ExecutionContext exe_ctx (m_opaque_sp.get());
1274 if (exe_ctx.HasThreadScope())
1276 strm.Printf("SBThread: tid = 0x%4.4" PRIx64, exe_ctx.GetThreadPtr()->GetID());
1279 strm.PutCString ("No value");
1285 SBThread::GetExtendedBacktraceThread (const char *type)
1287 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1288 Mutex::Locker api_locker;
1289 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1290 SBThread sb_origin_thread;
1292 if (exe_ctx.HasThreadScope())
1294 Process::StopLocker stop_locker;
1295 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
1297 ThreadSP real_thread(exe_ctx.GetThreadSP());
1300 ConstString type_const (type);
1301 Process *process = exe_ctx.GetProcessPtr();
1304 SystemRuntime *runtime = process->GetSystemRuntime();
1307 ThreadSP new_thread_sp (runtime->GetExtendedBacktraceThread (real_thread, type_const));
1310 // Save this in the Process' ExtendedThreadList so a strong pointer retains the
1312 process->GetExtendedThreadList().AddThread (new_thread_sp);
1313 sb_origin_thread.SetThread (new_thread_sp);
1316 const char *queue_name = new_thread_sp->GetQueueName();
1317 if (queue_name == NULL)
1319 log->Printf ("SBThread(%p)::GetExtendedBacktraceThread() => new extended Thread created (%p) with queue_id 0x%" PRIx64 " queue name '%s'", exe_ctx.GetThreadPtr(), new_thread_sp.get(), new_thread_sp->GetQueueID(), queue_name);
1329 log->Printf ("SBThread(%p)::GetExtendedBacktraceThread() => error: process is running", exe_ctx.GetThreadPtr());
1333 return sb_origin_thread;
1337 SBThread::GetExtendedBacktraceOriginatingIndexID ()
1339 ThreadSP thread_sp(m_opaque_sp->GetThreadSP());
1341 return thread_sp->GetExtendedBacktraceOriginatingIndexID();
1342 return LLDB_INVALID_INDEX32;