1 //===-- Thread.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/lldb-private-log.h"
13 #include "lldb/Breakpoint/BreakpointLocation.h"
14 #include "lldb/Core/Debugger.h"
15 #include "lldb/Core/Log.h"
16 #include "lldb/Core/State.h"
17 #include "lldb/Core/Stream.h"
18 #include "lldb/Core/StreamString.h"
19 #include "lldb/Core/RegularExpression.h"
20 #include "lldb/Host/Host.h"
21 #include "lldb/Symbol/Function.h"
22 #include "lldb/Target/DynamicLoader.h"
23 #include "lldb/Target/ExecutionContext.h"
24 #include "lldb/Target/ObjCLanguageRuntime.h"
25 #include "lldb/Target/Process.h"
26 #include "lldb/Target/RegisterContext.h"
27 #include "lldb/Target/StopInfo.h"
28 #include "lldb/Target/Target.h"
29 #include "lldb/Target/Thread.h"
30 #include "lldb/Target/ThreadPlan.h"
31 #include "lldb/Target/ThreadPlanCallFunction.h"
32 #include "lldb/Target/ThreadPlanBase.h"
33 #include "lldb/Target/ThreadPlanStepInstruction.h"
34 #include "lldb/Target/ThreadPlanStepOut.h"
35 #include "lldb/Target/ThreadPlanStepOverBreakpoint.h"
36 #include "lldb/Target/ThreadPlanStepThrough.h"
37 #include "lldb/Target/ThreadPlanStepInRange.h"
38 #include "lldb/Target/ThreadPlanStepOverRange.h"
39 #include "lldb/Target/ThreadPlanRunToAddress.h"
40 #include "lldb/Target/ThreadPlanStepUntil.h"
41 #include "lldb/Target/ThreadSpec.h"
42 #include "lldb/Target/Unwind.h"
43 #include "Plugins/Process/Utility/UnwindLLDB.h"
44 #include "UnwindMacOSXFrameBackchain.h"
48 using namespace lldb_private;
51 const ThreadPropertiesSP &
52 Thread::GetGlobalProperties()
54 static ThreadPropertiesSP g_settings_sp;
56 g_settings_sp.reset (new ThreadProperties (true));
60 static PropertyDefinition
63 { "step-avoid-regexp", OptionValue::eTypeRegex , true , REG_EXTENDED, "^std::", NULL, "A regular expression defining functions step-in won't stop in." },
64 { "trace-thread", OptionValue::eTypeBoolean, false, false, NULL, NULL, "If true, this thread will single-step and log execution." },
65 { NULL , OptionValue::eTypeInvalid, false, 0 , NULL, NULL, NULL }
69 ePropertyStepAvoidRegex,
70 ePropertyEnableThreadTrace
74 class ThreadOptionValueProperties : public OptionValueProperties
77 ThreadOptionValueProperties (const ConstString &name) :
78 OptionValueProperties (name)
82 // This constructor is used when creating ThreadOptionValueProperties when it
83 // is part of a new lldb_private::Thread instance. It will copy all current
84 // global property values as needed
85 ThreadOptionValueProperties (ThreadProperties *global_properties) :
86 OptionValueProperties(*global_properties->GetValueProperties())
90 virtual const Property *
91 GetPropertyAtIndex (const ExecutionContext *exe_ctx, bool will_modify, uint32_t idx) const
93 // When gettings the value for a key from the thread options, we will always
94 // try and grab the setting from the current thread if there is one. Else we just
95 // use the one from this instance.
98 Thread *thread = exe_ctx->GetThreadPtr();
101 ThreadOptionValueProperties *instance_properties = static_cast<ThreadOptionValueProperties *>(thread->GetValueProperties().get());
102 if (this != instance_properties)
103 return instance_properties->ProtectedGetPropertyAtIndex (idx);
106 return ProtectedGetPropertyAtIndex (idx);
112 ThreadProperties::ThreadProperties (bool is_global) :
117 m_collection_sp.reset (new ThreadOptionValueProperties(ConstString("thread")));
118 m_collection_sp->Initialize(g_properties);
121 m_collection_sp.reset (new ThreadOptionValueProperties(Thread::GetGlobalProperties().get()));
124 ThreadProperties::~ThreadProperties()
128 const RegularExpression *
129 ThreadProperties::GetSymbolsToAvoidRegexp()
131 const uint32_t idx = ePropertyStepAvoidRegex;
132 return m_collection_sp->GetPropertyAtIndexAsOptionValueRegex (NULL, idx);
136 ThreadProperties::GetTraceEnabledState() const
138 const uint32_t idx = ePropertyEnableThreadTrace;
139 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
142 //------------------------------------------------------------------
144 //------------------------------------------------------------------
148 Thread::ThreadEventData::GetFlavorString ()
150 static ConstString g_flavor ("Thread::ThreadEventData");
154 Thread::ThreadEventData::ThreadEventData (const lldb::ThreadSP thread_sp) :
155 m_thread_sp (thread_sp),
160 Thread::ThreadEventData::ThreadEventData (const lldb::ThreadSP thread_sp, const StackID &stack_id) :
161 m_thread_sp (thread_sp),
162 m_stack_id (stack_id)
166 Thread::ThreadEventData::ThreadEventData () :
172 Thread::ThreadEventData::~ThreadEventData ()
177 Thread::ThreadEventData::Dump (Stream *s) const
182 const Thread::ThreadEventData *
183 Thread::ThreadEventData::GetEventDataFromEvent (const Event *event_ptr)
187 const EventData *event_data = event_ptr->GetData();
188 if (event_data && event_data->GetFlavor() == ThreadEventData::GetFlavorString())
189 return static_cast <const ThreadEventData *> (event_ptr->GetData());
195 Thread::ThreadEventData::GetThreadFromEvent (const Event *event_ptr)
198 const ThreadEventData *event_data = GetEventDataFromEvent (event_ptr);
200 thread_sp = event_data->GetThread();
205 Thread::ThreadEventData::GetStackIDFromEvent (const Event *event_ptr)
208 const ThreadEventData *event_data = GetEventDataFromEvent (event_ptr);
210 stack_id = event_data->GetStackID();
215 Thread::ThreadEventData::GetStackFrameFromEvent (const Event *event_ptr)
217 const ThreadEventData *event_data = GetEventDataFromEvent (event_ptr);
218 StackFrameSP frame_sp;
221 ThreadSP thread_sp = event_data->GetThread();
224 frame_sp = thread_sp->GetStackFrameList()->GetFrameWithStackID (event_data->GetStackID());
230 //------------------------------------------------------------------
232 //------------------------------------------------------------------
235 Thread::GetStaticBroadcasterClass ()
237 static ConstString class_name ("lldb.thread");
241 Thread::Thread (Process &process, lldb::tid_t tid) :
242 ThreadProperties (false),
244 Broadcaster(&process.GetTarget().GetDebugger(), Thread::GetStaticBroadcasterClass().AsCString()),
245 m_process_wp (process.shared_from_this()),
247 m_stop_info_stop_id (0),
248 m_index_id (process.GetNextThreadIndexID(tid)),
250 m_state (eStateUnloaded),
251 m_state_mutex (Mutex::eMutexTypeRecursive),
253 m_completed_plan_stack(),
254 m_frame_mutex (Mutex::eMutexTypeRecursive),
257 m_resume_signal (LLDB_INVALID_SIGNAL_NUMBER),
258 m_resume_state (eStateRunning),
259 m_temporary_resume_state (eStateRunning),
261 m_destroy_called (false),
262 m_override_should_notify (eLazyBoolCalculate)
264 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
266 log->Printf ("%p Thread::Thread(tid = 0x%4.4" PRIx64 ")", this, GetID());
268 CheckInWithManager();
269 QueueFundamentalPlan(true);
275 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
277 log->Printf ("%p Thread::~Thread(tid = 0x%4.4" PRIx64 ")", this, GetID());
278 /// If you hit this assert, it means your derived class forgot to call DoDestroy in its destructor.
279 assert (m_destroy_called);
283 Thread::DestroyThread ()
285 // Tell any plans on the plan stack that the thread is being destroyed since
286 // any active plans that have a thread go away in the middle of might need
288 for (auto plan : m_plan_stack)
289 plan->ThreadDestroyed();
291 m_destroy_called = true;
292 m_plan_stack.clear();
293 m_discarded_plan_stack.clear();
294 m_completed_plan_stack.clear();
296 // Push a ThreadPlanNull on the plan stack. That way we can continue assuming that the
297 // plan stack is never empty, but if somebody errantly asks questions of a destroyed thread
298 // without checking first whether it is destroyed, they won't crash.
299 ThreadPlanSP null_plan_sp(new ThreadPlanNull (*this));
300 m_plan_stack.push_back (null_plan_sp);
302 m_stop_info_sp.reset();
303 m_reg_context_sp.reset();
304 m_unwinder_ap.reset();
305 Mutex::Locker locker(m_frame_mutex);
306 m_curr_frames_sp.reset();
307 m_prev_frames_sp.reset();
311 Thread::BroadcastSelectedFrameChange(StackID &new_frame_id)
313 if (EventTypeHasListeners(eBroadcastBitSelectedFrameChanged))
314 BroadcastEvent(eBroadcastBitSelectedFrameChanged, new ThreadEventData (this->shared_from_this(), new_frame_id));
318 Thread::SetSelectedFrame (lldb_private::StackFrame *frame, bool broadcast)
320 uint32_t ret_value = GetStackFrameList()->SetSelectedFrame(frame);
322 BroadcastSelectedFrameChange(frame->GetStackID());
327 Thread::SetSelectedFrameByIndex (uint32_t frame_idx, bool broadcast)
329 StackFrameSP frame_sp(GetStackFrameList()->GetFrameAtIndex (frame_idx));
332 GetStackFrameList()->SetSelectedFrame(frame_sp.get());
334 BroadcastSelectedFrameChange(frame_sp->GetStackID());
342 Thread::SetSelectedFrameByIndexNoisily (uint32_t frame_idx, Stream &output_stream)
344 const bool broadcast = true;
345 bool success = SetSelectedFrameByIndex (frame_idx, broadcast);
348 StackFrameSP frame_sp = GetSelectedFrame();
351 bool already_shown = false;
352 SymbolContext frame_sc(frame_sp->GetSymbolContext(eSymbolContextLineEntry));
353 if (GetProcess()->GetTarget().GetDebugger().GetUseExternalEditor() && frame_sc.line_entry.file && frame_sc.line_entry.line != 0)
355 already_shown = Host::OpenFileInExternalEditor (frame_sc.line_entry.file, frame_sc.line_entry.line);
358 bool show_frame_info = true;
359 bool show_source = !already_shown;
360 return frame_sp->GetStatus (output_stream, show_frame_info, show_source);
370 Thread::GetStopInfo ()
372 if (m_destroy_called)
373 return m_stop_info_sp;
375 ThreadPlanSP plan_sp (GetCompletedPlan());
376 ProcessSP process_sp (GetProcess());
377 const uint32_t stop_id = process_sp ? process_sp->GetStopID() : UINT32_MAX;
378 if (plan_sp && plan_sp->PlanSucceeded())
380 return StopInfo::CreateStopReasonWithPlan (plan_sp, GetReturnValueObject());
384 if ((m_stop_info_stop_id == stop_id) || // Stop info is valid, just return what we have (even if empty)
385 (m_stop_info_sp && m_stop_info_sp->IsValid())) // Stop info is valid, just return what we have
387 return m_stop_info_sp;
391 GetPrivateStopInfo ();
392 return m_stop_info_sp;
398 Thread::GetPrivateStopInfo ()
400 if (m_destroy_called)
401 return m_stop_info_sp;
403 ProcessSP process_sp (GetProcess());
406 const uint32_t process_stop_id = process_sp->GetStopID();
407 if (m_stop_info_stop_id != process_stop_id)
411 if (m_stop_info_sp->IsValid()
412 || IsStillAtLastBreakpointHit()
413 || GetCurrentPlan()->IsVirtualStep())
414 SetStopInfo (m_stop_info_sp);
416 m_stop_info_sp.reset();
421 if (CalculateStopInfo() == false)
422 SetStopInfo (StopInfoSP());
426 return m_stop_info_sp;
431 Thread::GetStopReason()
433 lldb::StopInfoSP stop_info_sp (GetStopInfo ());
435 return stop_info_sp->GetStopReason();
436 return eStopReasonNone;
442 Thread::SetStopInfo (const lldb::StopInfoSP &stop_info_sp)
444 m_stop_info_sp = stop_info_sp;
447 m_stop_info_sp->MakeStopInfoValid();
448 // If we are overriding the ShouldReportStop, do that here:
449 if (m_override_should_notify != eLazyBoolCalculate)
450 m_stop_info_sp->OverrideShouldNotify (m_override_should_notify == eLazyBoolYes);
453 ProcessSP process_sp (GetProcess());
455 m_stop_info_stop_id = process_sp->GetStopID();
457 m_stop_info_stop_id = UINT32_MAX;
458 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_THREAD));
460 log->Printf("%p: tid = 0x%" PRIx64 ": stop info = %s (stop_id = %u)\n", this, GetID(), stop_info_sp ? stop_info_sp->GetDescription() : "<NULL>", m_stop_info_stop_id);
464 Thread::SetShouldReportStop (Vote vote)
466 if (vote == eVoteNoOpinion)
470 m_override_should_notify = (vote == eVoteYes ? eLazyBoolYes : eLazyBoolNo);
472 m_stop_info_sp->OverrideShouldNotify (m_override_should_notify == eLazyBoolYes);
477 Thread::SetStopInfoToNothing()
479 // Note, we can't just NULL out the private reason, or the native thread implementation will try to
480 // go calculate it again. For now, just set it to a Unix Signal with an invalid signal number.
481 SetStopInfo (StopInfo::CreateStopReasonWithSignal (*this, LLDB_INVALID_SIGNAL_NUMBER));
485 Thread::ThreadStoppedForAReason (void)
487 return (bool) GetPrivateStopInfo ();
491 Thread::CheckpointThreadState (ThreadStateCheckpoint &saved_state)
493 if (!SaveFrameZeroState(saved_state.register_backup))
496 saved_state.stop_info_sp = GetStopInfo();
497 ProcessSP process_sp (GetProcess());
499 saved_state.orig_stop_id = process_sp->GetStopID();
500 saved_state.current_inlined_depth = GetCurrentInlinedDepth();
506 Thread::RestoreRegisterStateFromCheckpoint (ThreadStateCheckpoint &saved_state)
508 RestoreSaveFrameZero(saved_state.register_backup);
513 Thread::RestoreThreadStateFromCheckpoint (ThreadStateCheckpoint &saved_state)
515 if (saved_state.stop_info_sp)
516 saved_state.stop_info_sp->MakeStopInfoValid();
517 SetStopInfo(saved_state.stop_info_sp);
518 GetStackFrameList()->SetCurrentInlinedDepth (saved_state.current_inlined_depth);
523 Thread::GetState() const
525 // If any other threads access this we will need a mutex for it
526 Mutex::Locker locker(m_state_mutex);
531 Thread::SetState(StateType state)
533 Mutex::Locker locker(m_state_mutex);
540 ThreadPlan *current_plan = GetCurrentPlan();
542 // FIXME: I may decide to disallow threads with no plans. In which
543 // case this should go to an assert.
548 current_plan->WillStop();
552 Thread::SetupForResume ()
554 if (GetResumeState() != eStateSuspended)
557 // If we're at a breakpoint push the step-over breakpoint plan. Do this before
558 // telling the current plan it will resume, since we might change what the current
561 // StopReason stop_reason = lldb::eStopReasonInvalid;
562 // StopInfoSP stop_info_sp = GetStopInfo();
563 // if (stop_info_sp.get())
564 // stop_reason = stop_info_sp->GetStopReason();
565 // if (stop_reason == lldb::eStopReasonBreakpoint)
566 lldb::RegisterContextSP reg_ctx_sp (GetRegisterContext());
569 BreakpointSiteSP bp_site_sp = GetProcess()->GetBreakpointSiteList().FindByAddress(reg_ctx_sp->GetPC());
572 // Note, don't assume there's a ThreadPlanStepOverBreakpoint, the target may not require anything
573 // special to step over a breakpoint.
575 ThreadPlan *cur_plan = GetCurrentPlan();
577 if (cur_plan->GetKind() != ThreadPlan::eKindStepOverBreakpoint)
579 ThreadPlanStepOverBreakpoint *step_bp_plan = new ThreadPlanStepOverBreakpoint (*this);
582 ThreadPlanSP step_bp_plan_sp;
583 step_bp_plan->SetPrivate (true);
585 if (GetCurrentPlan()->RunState() != eStateStepping)
587 step_bp_plan->SetAutoContinue(true);
589 step_bp_plan_sp.reset (step_bp_plan);
590 QueueThreadPlan (step_bp_plan_sp, false);
599 Thread::ShouldResume (StateType resume_state)
601 // At this point clear the completed plan stack.
602 m_completed_plan_stack.clear();
603 m_discarded_plan_stack.clear();
604 m_override_should_notify = eLazyBoolCalculate;
606 m_temporary_resume_state = resume_state;
608 lldb::ThreadSP backing_thread_sp (GetBackingThread ());
609 if (backing_thread_sp)
610 backing_thread_sp->m_temporary_resume_state = resume_state;
612 // Make sure m_stop_info_sp is valid
613 GetPrivateStopInfo();
615 // This is a little dubious, but we are trying to limit how often we actually fetch stop info from
616 // the target, 'cause that slows down single stepping. So assume that if we got to the point where
617 // we're about to resume, and we haven't yet had to fetch the stop reason, then it doesn't need to know
618 // about the fact that we are resuming...
619 const uint32_t process_stop_id = GetProcess()->GetStopID();
620 if (m_stop_info_stop_id == process_stop_id &&
621 (m_stop_info_sp && m_stop_info_sp->IsValid()))
623 StopInfo *stop_info = GetPrivateStopInfo().get();
625 stop_info->WillResume (resume_state);
628 // Tell all the plans that we are about to resume in case they need to clear any state.
629 // We distinguish between the plan on the top of the stack and the lower
630 // plans in case a plan needs to do any special business before it runs.
632 bool need_to_resume = false;
633 ThreadPlan *plan_ptr = GetCurrentPlan();
636 need_to_resume = plan_ptr->WillResume(resume_state, true);
638 while ((plan_ptr = GetPreviousPlan(plan_ptr)) != NULL)
640 plan_ptr->WillResume (resume_state, false);
643 // If the WillResume for the plan says we are faking a resume, then it will have set an appropriate stop info.
644 // In that case, don't reset it here.
646 if (need_to_resume && resume_state != eStateSuspended)
648 m_stop_info_sp.reset();
655 // Let Thread subclasses do any special work they need to prior to resuming
656 WillResume (resume_state);
659 return need_to_resume;
665 SetResumeSignal (LLDB_INVALID_SIGNAL_NUMBER);
671 SetState (eStateStopped);
675 Thread::ShouldStop (Event* event_ptr)
677 ThreadPlan *current_plan = GetCurrentPlan();
679 bool should_stop = true;
681 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
683 if (GetResumeState () == eStateSuspended)
686 log->Printf ("Thread::%s for tid = 0x%4.4" PRIx64 " 0x%4.4" PRIx64 ", should_stop = 0 (ignore since thread was suspended)",
693 if (GetTemporaryResumeState () == eStateSuspended)
696 log->Printf ("Thread::%s for tid = 0x%4.4" PRIx64 " 0x%4.4" PRIx64 ", should_stop = 0 (ignore since thread was suspended)",
703 // Based on the current thread plan and process stop info, check if this
704 // thread caused the process to stop. NOTE: this must take place before
705 // the plan is moved from the current plan stack to the completed plan
707 if (ThreadStoppedForAReason() == false)
710 log->Printf ("Thread::%s for tid = 0x%4.4" PRIx64 " 0x%4.4" PRIx64 ", pc = 0x%16.16" PRIx64 ", should_stop = 0 (ignore since no stop reason)",
714 GetRegisterContext() ? GetRegisterContext()->GetPC() : LLDB_INVALID_ADDRESS);
720 log->Printf ("Thread::%s(%p) for tid = 0x%4.4" PRIx64 " 0x%4.4" PRIx64 ", pc = 0x%16.16" PRIx64,
725 GetRegisterContext() ? GetRegisterContext()->GetPC() : LLDB_INVALID_ADDRESS);
726 log->Printf ("^^^^^^^^ Thread::ShouldStop Begin ^^^^^^^^");
730 log->Printf ("Plan stack initial state:\n%s", s.GetData());
733 // The top most plan always gets to do the trace log...
734 current_plan->DoTraceLog ();
736 // First query the stop info's ShouldStopSynchronous. This handles "synchronous" stop reasons, for example the breakpoint
737 // command on internal breakpoints. If a synchronous stop reason says we should not stop, then we don't have to
738 // do any more work on this stop.
739 StopInfoSP private_stop_info (GetPrivateStopInfo());
740 if (private_stop_info && private_stop_info->ShouldStopSynchronous(event_ptr) == false)
743 log->Printf ("StopInfo::ShouldStop async callback says we should not stop, returning ShouldStop of false.");
747 // If we've already been restarted, don't query the plans since the state they would examine is not current.
748 if (Process::ProcessEventData::GetRestartedFromEvent(event_ptr))
751 // Before the plans see the state of the world, calculate the current inlined depth.
752 GetStackFrameList()->CalculateCurrentInlinedDepth();
754 // If the base plan doesn't understand why we stopped, then we have to find a plan that does.
755 // If that plan is still working, then we don't need to do any more work. If the plan that explains
756 // the stop is done, then we should pop all the plans below it, and pop it, and then let the plans above it decide
757 // whether they still need to do more work.
759 bool done_processing_current_plan = false;
761 if (!current_plan->PlanExplainsStop(event_ptr))
763 if (current_plan->TracerExplainsStop())
765 done_processing_current_plan = true;
770 // If the current plan doesn't explain the stop, then find one that
771 // does and let it handle the situation.
772 ThreadPlan *plan_ptr = current_plan;
773 while ((plan_ptr = GetPreviousPlan(plan_ptr)) != NULL)
775 if (plan_ptr->PlanExplainsStop(event_ptr))
777 should_stop = plan_ptr->ShouldStop (event_ptr);
779 // plan_ptr explains the stop, next check whether plan_ptr is done, if so, then we should take it
780 // and all the plans below it off the stack.
782 if (plan_ptr->MischiefManaged())
784 // We're going to pop the plans up to and including the plan that explains the stop.
785 ThreadPlan *prev_plan_ptr = GetPreviousPlan (plan_ptr);
790 current_plan->WillStop();
793 while ((current_plan = GetCurrentPlan()) != prev_plan_ptr);
794 // Now, if the responsible plan was not "Okay to discard" then we're done,
795 // otherwise we forward this to the next plan in the stack below.
796 if (plan_ptr->IsMasterPlan() && !plan_ptr->OkayToDiscard())
797 done_processing_current_plan = true;
799 done_processing_current_plan = false;
802 done_processing_current_plan = true;
811 if (!done_processing_current_plan)
813 bool over_ride_stop = current_plan->ShouldAutoContinue(event_ptr);
816 log->Printf("Plan %s explains stop, auto-continue %i.", current_plan->GetName(), over_ride_stop);
818 // We're starting from the base plan, so just let it decide;
819 if (PlanIsBasePlan(current_plan))
821 should_stop = current_plan->ShouldStop (event_ptr);
823 log->Printf("Base plan says should stop: %i.", should_stop);
827 // Otherwise, don't let the base plan override what the other plans say to do, since
828 // presumably if there were other plans they would know what to do...
831 if (PlanIsBasePlan(current_plan))
834 should_stop = current_plan->ShouldStop(event_ptr);
836 log->Printf("Plan %s should stop: %d.", current_plan->GetName(), should_stop);
837 if (current_plan->MischiefManaged())
840 current_plan->WillStop();
842 // If a Master Plan wants to stop, and wants to stick on the stack, we let it.
843 // Otherwise, see if the plan's parent wants to stop.
845 if (should_stop && current_plan->IsMasterPlan() && !current_plan->OkayToDiscard())
855 current_plan = GetCurrentPlan();
856 if (current_plan == NULL)
872 // One other potential problem is that we set up a master plan, then stop in before it is complete - for instance
873 // by hitting a breakpoint during a step-over - then do some step/finish/etc operations that wind up
874 // past the end point condition of the initial plan. We don't want to strand the original plan on the stack,
875 // This code clears stale plans off the stack.
879 ThreadPlan *plan_ptr = GetCurrentPlan();
880 while (!PlanIsBasePlan(plan_ptr))
882 bool stale = plan_ptr->IsPlanStale ();
883 ThreadPlan *examined_plan = plan_ptr;
884 plan_ptr = GetPreviousPlan (examined_plan);
889 log->Printf("Plan %s being discarded in cleanup, it says it is already done.", examined_plan->GetName());
890 DiscardThreadPlansUpToPlan(examined_plan);
902 log->Printf ("Plan stack final state:\n%s", s.GetData());
903 log->Printf ("vvvvvvvv Thread::ShouldStop End (returning %i) vvvvvvvv", should_stop);
909 Thread::ShouldReportStop (Event* event_ptr)
911 StateType thread_state = GetResumeState ();
912 StateType temp_thread_state = GetTemporaryResumeState();
914 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
916 if (thread_state == eStateSuspended || thread_state == eStateInvalid)
919 log->Printf ("Thread::ShouldReportStop() tid = 0x%4.4" PRIx64 ": returning vote %i (state was suspended or invalid)", GetID(), eVoteNoOpinion);
920 return eVoteNoOpinion;
923 if (temp_thread_state == eStateSuspended || temp_thread_state == eStateInvalid)
926 log->Printf ("Thread::ShouldReportStop() tid = 0x%4.4" PRIx64 ": returning vote %i (temporary state was suspended or invalid)", GetID(), eVoteNoOpinion);
927 return eVoteNoOpinion;
930 if (!ThreadStoppedForAReason())
933 log->Printf ("Thread::ShouldReportStop() tid = 0x%4.4" PRIx64 ": returning vote %i (thread didn't stop for a reason.)", GetID(), eVoteNoOpinion);
934 return eVoteNoOpinion;
937 if (m_completed_plan_stack.size() > 0)
939 // Don't use GetCompletedPlan here, since that suppresses private plans.
941 log->Printf ("Thread::ShouldReportStop() tid = 0x%4.4" PRIx64 ": returning vote for complete stack's back plan", GetID());
942 return m_completed_plan_stack.back()->ShouldReportStop (event_ptr);
946 Vote thread_vote = eVoteNoOpinion;
947 ThreadPlan *plan_ptr = GetCurrentPlan();
950 if (plan_ptr->PlanExplainsStop(event_ptr))
952 thread_vote = plan_ptr->ShouldReportStop(event_ptr);
955 if (PlanIsBasePlan(plan_ptr))
958 plan_ptr = GetPreviousPlan(plan_ptr);
961 log->Printf ("Thread::ShouldReportStop() tid = 0x%4.4" PRIx64 ": returning vote %i for current plan", GetID(), thread_vote);
968 Thread::ShouldReportRun (Event* event_ptr)
970 StateType thread_state = GetResumeState ();
972 if (thread_state == eStateSuspended
973 || thread_state == eStateInvalid)
975 return eVoteNoOpinion;
978 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
979 if (m_completed_plan_stack.size() > 0)
981 // Don't use GetCompletedPlan here, since that suppresses private plans.
983 log->Printf ("Current Plan for thread %d(%p) (0x%4.4" PRIx64 ", %s): %s being asked whether we should report run.",
987 StateAsCString(GetTemporaryResumeState()),
988 m_completed_plan_stack.back()->GetName());
990 return m_completed_plan_stack.back()->ShouldReportRun (event_ptr);
995 log->Printf ("Current Plan for thread %d(%p) (0x%4.4" PRIx64 ", %s): %s being asked whether we should report run.",
999 StateAsCString(GetTemporaryResumeState()),
1000 GetCurrentPlan()->GetName());
1002 return GetCurrentPlan()->ShouldReportRun (event_ptr);
1007 Thread::MatchesSpec (const ThreadSpec *spec)
1012 return spec->ThreadPassesBasicTests(*this);
1016 Thread::PushPlan (ThreadPlanSP &thread_plan_sp)
1020 // If the thread plan doesn't already have a tracer, give it its parent's tracer:
1021 if (!thread_plan_sp->GetThreadPlanTracer())
1022 thread_plan_sp->SetThreadPlanTracer(m_plan_stack.back()->GetThreadPlanTracer());
1023 m_plan_stack.push_back (thread_plan_sp);
1025 thread_plan_sp->DidPush();
1027 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
1031 thread_plan_sp->GetDescription (&s, lldb::eDescriptionLevelFull);
1032 log->Printf("Thread::PushPlan(0x%p): \"%s\", tid = 0x%4.4" PRIx64 ".",
1035 thread_plan_sp->GetThread().GetID());
1043 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
1045 if (m_plan_stack.size() <= 1)
1049 ThreadPlanSP &plan = m_plan_stack.back();
1052 log->Printf("Popping plan: \"%s\", tid = 0x%4.4" PRIx64 ".", plan->GetName(), plan->GetThread().GetID());
1054 m_completed_plan_stack.push_back (plan);
1056 m_plan_stack.pop_back();
1061 Thread::DiscardPlan ()
1063 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
1064 if (m_plan_stack.size() > 1)
1066 ThreadPlanSP &plan = m_plan_stack.back();
1068 log->Printf("Discarding plan: \"%s\", tid = 0x%4.4" PRIx64 ".", plan->GetName(), plan->GetThread().GetID());
1070 m_discarded_plan_stack.push_back (plan);
1072 m_plan_stack.pop_back();
1077 Thread::GetCurrentPlan ()
1079 // There will always be at least the base plan. If somebody is mucking with a
1080 // thread with an empty plan stack, we should assert right away.
1081 if (m_plan_stack.empty())
1083 return m_plan_stack.back().get();
1087 Thread::GetCompletedPlan ()
1089 ThreadPlanSP empty_plan_sp;
1090 if (!m_completed_plan_stack.empty())
1092 for (int i = m_completed_plan_stack.size() - 1; i >= 0; i--)
1094 ThreadPlanSP completed_plan_sp;
1095 completed_plan_sp = m_completed_plan_stack[i];
1096 if (!completed_plan_sp->GetPrivate ())
1097 return completed_plan_sp;
1100 return empty_plan_sp;
1104 Thread::GetReturnValueObject ()
1106 if (!m_completed_plan_stack.empty())
1108 for (int i = m_completed_plan_stack.size() - 1; i >= 0; i--)
1110 ValueObjectSP return_valobj_sp;
1111 return_valobj_sp = m_completed_plan_stack[i]->GetReturnValueObject();
1112 if (return_valobj_sp)
1113 return return_valobj_sp;
1116 return ValueObjectSP();
1120 Thread::IsThreadPlanDone (ThreadPlan *plan)
1122 if (!m_completed_plan_stack.empty())
1124 for (int i = m_completed_plan_stack.size() - 1; i >= 0; i--)
1126 if (m_completed_plan_stack[i].get() == plan)
1134 Thread::WasThreadPlanDiscarded (ThreadPlan *plan)
1136 if (!m_discarded_plan_stack.empty())
1138 for (int i = m_discarded_plan_stack.size() - 1; i >= 0; i--)
1140 if (m_discarded_plan_stack[i].get() == plan)
1148 Thread::GetPreviousPlan (ThreadPlan *current_plan)
1150 if (current_plan == NULL)
1153 int stack_size = m_completed_plan_stack.size();
1154 for (int i = stack_size - 1; i > 0; i--)
1156 if (current_plan == m_completed_plan_stack[i].get())
1157 return m_completed_plan_stack[i-1].get();
1160 if (stack_size > 0 && m_completed_plan_stack[0].get() == current_plan)
1162 if (m_plan_stack.size() > 0)
1163 return m_plan_stack.back().get();
1168 stack_size = m_plan_stack.size();
1169 for (int i = stack_size - 1; i > 0; i--)
1171 if (current_plan == m_plan_stack[i].get())
1172 return m_plan_stack[i-1].get();
1178 Thread::QueueThreadPlan (ThreadPlanSP &thread_plan_sp, bool abort_other_plans)
1180 if (abort_other_plans)
1181 DiscardThreadPlans(true);
1183 PushPlan (thread_plan_sp);
1188 Thread::EnableTracer (bool value, bool single_stepping)
1190 int stack_size = m_plan_stack.size();
1191 for (int i = 0; i < stack_size; i++)
1193 if (m_plan_stack[i]->GetThreadPlanTracer())
1195 m_plan_stack[i]->GetThreadPlanTracer()->EnableTracing(value);
1196 m_plan_stack[i]->GetThreadPlanTracer()->EnableSingleStep(single_stepping);
1202 Thread::SetTracer (lldb::ThreadPlanTracerSP &tracer_sp)
1204 int stack_size = m_plan_stack.size();
1205 for (int i = 0; i < stack_size; i++)
1206 m_plan_stack[i]->SetThreadPlanTracer(tracer_sp);
1210 Thread::DiscardThreadPlansUpToPlan (lldb::ThreadPlanSP &up_to_plan_sp)
1212 DiscardThreadPlansUpToPlan (up_to_plan_sp.get());
1216 Thread::DiscardThreadPlansUpToPlan (ThreadPlan *up_to_plan_ptr)
1218 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
1221 log->Printf("Discarding thread plans for thread tid = 0x%4.4" PRIx64 ", up to %p", GetID(), up_to_plan_ptr);
1224 int stack_size = m_plan_stack.size();
1226 // If the input plan is NULL, discard all plans. Otherwise make sure this plan is in the
1227 // stack, and if so discard up to and including it.
1229 if (up_to_plan_ptr == NULL)
1231 for (int i = stack_size - 1; i > 0; i--)
1236 bool found_it = false;
1237 for (int i = stack_size - 1; i > 0; i--)
1239 if (m_plan_stack[i].get() == up_to_plan_ptr)
1244 bool last_one = false;
1245 for (int i = stack_size - 1; i > 0 && !last_one ; i--)
1247 if (GetCurrentPlan() == up_to_plan_ptr)
1257 Thread::DiscardThreadPlans(bool force)
1259 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
1262 log->Printf("Discarding thread plans for thread (tid = 0x%4.4" PRIx64 ", force %d)", GetID(), force);
1267 int stack_size = m_plan_stack.size();
1268 for (int i = stack_size - 1; i > 0; i--)
1278 int master_plan_idx;
1279 bool discard = true;
1281 // Find the first master plan, see if it wants discarding, and if yes discard up to it.
1282 for (master_plan_idx = m_plan_stack.size() - 1; master_plan_idx >= 0; master_plan_idx--)
1284 if (m_plan_stack[master_plan_idx]->IsMasterPlan())
1286 discard = m_plan_stack[master_plan_idx]->OkayToDiscard();
1293 // First pop all the dependent plans:
1294 for (int i = m_plan_stack.size() - 1; i > master_plan_idx; i--)
1297 // FIXME: Do we need a finalize here, or is the rule that "PrepareForStop"
1298 // for the plan leaves it in a state that it is safe to pop the plan
1299 // with no more notice?
1303 // Now discard the master plan itself.
1304 // The bottom-most plan never gets discarded. "OkayToDiscard" for it means
1305 // discard it's dependent plans, but not it...
1306 if (master_plan_idx > 0)
1313 // If the master plan doesn't want to get discarded, then we're done.
1321 Thread::PlanIsBasePlan (ThreadPlan *plan_ptr)
1323 if (plan_ptr->IsBasePlan())
1325 else if (m_plan_stack.size() == 0)
1328 return m_plan_stack[0].get() == plan_ptr;
1332 Thread::UnwindInnermostExpression()
1335 int stack_size = m_plan_stack.size();
1337 // If the input plan is NULL, discard all plans. Otherwise make sure this plan is in the
1338 // stack, and if so discard up to and including it.
1340 for (int i = stack_size - 1; i > 0; i--)
1342 if (m_plan_stack[i]->GetKind() == ThreadPlan::eKindCallFunction)
1344 DiscardThreadPlansUpToPlan(m_plan_stack[i].get());
1348 error.SetErrorString("No expressions currently active on this thread");
1354 Thread::QueueFundamentalPlan (bool abort_other_plans)
1356 ThreadPlanSP thread_plan_sp (new ThreadPlanBase(*this));
1357 QueueThreadPlan (thread_plan_sp, abort_other_plans);
1358 return thread_plan_sp;
1362 Thread::QueueThreadPlanForStepSingleInstruction
1365 bool abort_other_plans,
1366 bool stop_other_threads
1369 ThreadPlanSP thread_plan_sp (new ThreadPlanStepInstruction (*this, step_over, stop_other_threads, eVoteNoOpinion, eVoteNoOpinion));
1370 QueueThreadPlan (thread_plan_sp, abort_other_plans);
1371 return thread_plan_sp;
1375 Thread::QueueThreadPlanForStepOverRange
1377 bool abort_other_plans,
1378 const AddressRange &range,
1379 const SymbolContext &addr_context,
1380 lldb::RunMode stop_other_threads
1383 ThreadPlanSP thread_plan_sp;
1384 thread_plan_sp.reset (new ThreadPlanStepOverRange (*this, range, addr_context, stop_other_threads));
1386 QueueThreadPlan (thread_plan_sp, abort_other_plans);
1387 return thread_plan_sp;
1391 Thread::QueueThreadPlanForStepInRange
1393 bool abort_other_plans,
1394 const AddressRange &range,
1395 const SymbolContext &addr_context,
1396 const char *step_in_target,
1397 lldb::RunMode stop_other_threads,
1398 bool avoid_code_without_debug_info
1401 ThreadPlanSP thread_plan_sp;
1402 ThreadPlanStepInRange *plan = new ThreadPlanStepInRange (*this, range, addr_context, stop_other_threads);
1403 if (avoid_code_without_debug_info)
1404 plan->GetFlags().Set (ThreadPlanShouldStopHere::eAvoidNoDebug);
1406 plan->GetFlags().Clear (ThreadPlanShouldStopHere::eAvoidNoDebug);
1408 plan->SetStepInTarget(step_in_target);
1409 thread_plan_sp.reset (plan);
1411 QueueThreadPlan (thread_plan_sp, abort_other_plans);
1412 return thread_plan_sp;
1417 Thread::QueueThreadPlanForStepOverBreakpointPlan (bool abort_other_plans)
1419 ThreadPlanSP thread_plan_sp (new ThreadPlanStepOverBreakpoint (*this));
1420 QueueThreadPlan (thread_plan_sp, abort_other_plans);
1421 return thread_plan_sp;
1425 Thread::QueueThreadPlanForStepOut
1427 bool abort_other_plans,
1428 SymbolContext *addr_context,
1430 bool stop_other_threads,
1436 ThreadPlanSP thread_plan_sp (new ThreadPlanStepOut (*this,
1444 if (thread_plan_sp->ValidatePlan(NULL))
1446 QueueThreadPlan (thread_plan_sp, abort_other_plans);
1447 return thread_plan_sp;
1451 return ThreadPlanSP();
1456 Thread::QueueThreadPlanForStepThrough (StackID &return_stack_id, bool abort_other_plans, bool stop_other_threads)
1458 ThreadPlanSP thread_plan_sp(new ThreadPlanStepThrough (*this, return_stack_id, stop_other_threads));
1459 if (!thread_plan_sp || !thread_plan_sp->ValidatePlan (NULL))
1460 return ThreadPlanSP();
1462 QueueThreadPlan (thread_plan_sp, abort_other_plans);
1463 return thread_plan_sp;
1467 Thread::QueueThreadPlanForCallFunction (bool abort_other_plans,
1470 bool stop_other_threads,
1471 bool unwind_on_error,
1472 bool ignore_breakpoints)
1474 ThreadPlanSP thread_plan_sp (new ThreadPlanCallFunction (*this,
1480 ignore_breakpoints));
1481 QueueThreadPlan (thread_plan_sp, abort_other_plans);
1482 return thread_plan_sp;
1486 Thread::QueueThreadPlanForRunToAddress (bool abort_other_plans,
1487 Address &target_addr,
1488 bool stop_other_threads)
1490 ThreadPlanSP thread_plan_sp (new ThreadPlanRunToAddress (*this, target_addr, stop_other_threads));
1491 QueueThreadPlan (thread_plan_sp, abort_other_plans);
1492 return thread_plan_sp;
1496 Thread::QueueThreadPlanForStepUntil (bool abort_other_plans,
1497 lldb::addr_t *address_list,
1498 size_t num_addresses,
1499 bool stop_other_threads,
1502 ThreadPlanSP thread_plan_sp (new ThreadPlanStepUntil (*this, address_list, num_addresses, stop_other_threads, frame_idx));
1503 QueueThreadPlan (thread_plan_sp, abort_other_plans);
1504 return thread_plan_sp;
1509 Thread::GetIndexID () const
1515 Thread::DumpThreadPlans (lldb_private::Stream *s) const
1517 uint32_t stack_size = m_plan_stack.size();
1520 s->Printf ("Plan Stack for thread #%u: tid = 0x%4.4" PRIx64 ", stack_size = %d\n", GetIndexID(), GetID(), stack_size);
1521 for (i = stack_size - 1; i >= 0; i--)
1525 s->Printf ("Element %d: ", i);
1526 m_plan_stack[i]->GetDescription (s, eDescriptionLevelFull);
1531 stack_size = m_completed_plan_stack.size();
1535 s->Printf ("Completed Plan Stack: %d elements.\n", stack_size);
1536 for (i = stack_size - 1; i >= 0; i--)
1540 s->Printf ("Element %d: ", i);
1541 m_completed_plan_stack[i]->GetDescription (s, eDescriptionLevelFull);
1547 stack_size = m_discarded_plan_stack.size();
1551 s->Printf ("Discarded Plan Stack: %d elements.\n", stack_size);
1552 for (i = stack_size - 1; i >= 0; i--)
1556 s->Printf ("Element %d: ", i);
1557 m_discarded_plan_stack[i]->GetDescription (s, eDescriptionLevelFull);
1566 Thread::CalculateTarget ()
1569 ProcessSP process_sp(GetProcess());
1571 target_sp = process_sp->CalculateTarget();
1577 Thread::CalculateProcess ()
1579 return GetProcess();
1583 Thread::CalculateThread ()
1585 return shared_from_this();
1589 Thread::CalculateStackFrame ()
1591 return StackFrameSP();
1595 Thread::CalculateExecutionContext (ExecutionContext &exe_ctx)
1597 exe_ctx.SetContext (shared_from_this());
1602 Thread::GetStackFrameList ()
1604 StackFrameListSP frame_list_sp;
1605 Mutex::Locker locker(m_frame_mutex);
1606 if (m_curr_frames_sp)
1608 frame_list_sp = m_curr_frames_sp;
1612 frame_list_sp.reset(new StackFrameList (*this, m_prev_frames_sp, true));
1613 m_curr_frames_sp = frame_list_sp;
1615 return frame_list_sp;
1619 Thread::ClearStackFrames ()
1621 Mutex::Locker locker(m_frame_mutex);
1623 Unwind *unwinder = GetUnwinder ();
1627 // Only store away the old "reference" StackFrameList if we got all its frames:
1628 // FIXME: At some point we can try to splice in the frames we have fetched into
1629 // the new frame as we make it, but let's not try that now.
1630 if (m_curr_frames_sp && m_curr_frames_sp->GetAllFramesFetched())
1631 m_prev_frames_sp.swap (m_curr_frames_sp);
1632 m_curr_frames_sp.reset();
1636 Thread::GetFrameWithConcreteFrameIndex (uint32_t unwind_idx)
1638 return GetStackFrameList()->GetFrameWithConcreteFrameIndex (unwind_idx);
1643 Thread::ReturnFromFrameWithIndex (uint32_t frame_idx, lldb::ValueObjectSP return_value_sp, bool broadcast)
1645 StackFrameSP frame_sp = GetStackFrameAtIndex (frame_idx);
1650 return_error.SetErrorStringWithFormat("Could not find frame with index %d in thread 0x%" PRIx64 ".", frame_idx, GetID());
1653 return ReturnFromFrame(frame_sp, return_value_sp, broadcast);
1657 Thread::ReturnFromFrame (lldb::StackFrameSP frame_sp, lldb::ValueObjectSP return_value_sp, bool broadcast)
1663 return_error.SetErrorString("Can't return to a null frame.");
1664 return return_error;
1667 Thread *thread = frame_sp->GetThread().get();
1668 uint32_t older_frame_idx = frame_sp->GetFrameIndex() + 1;
1669 StackFrameSP older_frame_sp = thread->GetStackFrameAtIndex(older_frame_idx);
1670 if (!older_frame_sp)
1672 return_error.SetErrorString("No older frame to return to.");
1673 return return_error;
1676 if (return_value_sp)
1678 lldb::ABISP abi = thread->GetProcess()->GetABI();
1681 return_error.SetErrorString("Could not find ABI to set return value.");
1682 return return_error;
1684 SymbolContext sc = frame_sp->GetSymbolContext(eSymbolContextFunction);
1686 // FIXME: ValueObject::Cast doesn't currently work correctly, at least not for scalars.
1687 // Turn that back on when that works.
1688 if (0 && sc.function != NULL)
1690 Type *function_type = sc.function->GetType();
1693 ClangASTType return_type = sc.function->GetClangType().GetFunctionReturnType();
1697 return_type.DumpTypeDescription(&s);
1698 ValueObjectSP cast_value_sp = return_value_sp->Cast(return_type);
1701 cast_value_sp->SetFormat(eFormatHex);
1702 return_value_sp = cast_value_sp;
1708 return_error = abi->SetReturnValueObject(older_frame_sp, return_value_sp);
1709 if (!return_error.Success())
1710 return return_error;
1713 // Now write the return registers for the chosen frame:
1714 // Note, we can't use ReadAllRegisterValues->WriteAllRegisterValues, since the read & write
1717 StackFrameSP youngest_frame_sp = thread->GetStackFrameAtIndex(0);
1718 if (youngest_frame_sp)
1720 lldb::RegisterContextSP reg_ctx_sp (youngest_frame_sp->GetRegisterContext());
1723 bool copy_success = reg_ctx_sp->CopyFromRegisterContext(older_frame_sp->GetRegisterContext());
1726 thread->DiscardThreadPlans(true);
1727 thread->ClearStackFrames();
1728 if (broadcast && EventTypeHasListeners(eBroadcastBitStackChanged))
1729 BroadcastEvent(eBroadcastBitStackChanged, new ThreadEventData (this->shared_from_this()));
1733 return_error.SetErrorString("Could not reset register values.");
1738 return_error.SetErrorString("Frame has no register context.");
1743 return_error.SetErrorString("Returned past top frame.");
1745 return return_error;
1749 Thread::DumpUsingSettingsFormat (Stream &strm, uint32_t frame_idx)
1751 ExecutionContext exe_ctx (shared_from_this());
1752 Process *process = exe_ctx.GetProcessPtr();
1753 if (process == NULL)
1756 StackFrameSP frame_sp;
1757 SymbolContext frame_sc;
1758 if (frame_idx != LLDB_INVALID_INDEX32)
1760 frame_sp = GetStackFrameAtIndex (frame_idx);
1763 exe_ctx.SetFrameSP(frame_sp);
1764 frame_sc = frame_sp->GetSymbolContext(eSymbolContextEverything);
1768 const char *thread_format = exe_ctx.GetTargetRef().GetDebugger().GetThreadFormat();
1769 assert (thread_format);
1770 Debugger::FormatPrompt (thread_format,
1771 frame_sp ? &frame_sc : NULL,
1778 Thread::SettingsInitialize ()
1783 Thread::SettingsTerminate ()
1788 Thread::GetStackFrameSPForStackFramePtr (StackFrame *stack_frame_ptr)
1790 return GetStackFrameList()->GetStackFrameSPForStackFramePtr (stack_frame_ptr);
1794 Thread::StopReasonAsCString (lldb::StopReason reason)
1798 case eStopReasonInvalid: return "invalid";
1799 case eStopReasonNone: return "none";
1800 case eStopReasonTrace: return "trace";
1801 case eStopReasonBreakpoint: return "breakpoint";
1802 case eStopReasonWatchpoint: return "watchpoint";
1803 case eStopReasonSignal: return "signal";
1804 case eStopReasonException: return "exception";
1805 case eStopReasonExec: return "exec";
1806 case eStopReasonPlanComplete: return "plan complete";
1807 case eStopReasonThreadExiting: return "thread exiting";
1811 static char unknown_state_string[64];
1812 snprintf(unknown_state_string, sizeof (unknown_state_string), "StopReason = %i", reason);
1813 return unknown_state_string;
1817 Thread::RunModeAsCString (lldb::RunMode mode)
1821 case eOnlyThisThread: return "only this thread";
1822 case eAllThreads: return "all threads";
1823 case eOnlyDuringStepping: return "only during stepping";
1826 static char unknown_state_string[64];
1827 snprintf(unknown_state_string, sizeof (unknown_state_string), "RunMode = %i", mode);
1828 return unknown_state_string;
1832 Thread::GetStatus (Stream &strm, uint32_t start_frame, uint32_t num_frames, uint32_t num_frames_with_source)
1834 ExecutionContext exe_ctx (shared_from_this());
1835 Target *target = exe_ctx.GetTargetPtr();
1836 Process *process = exe_ctx.GetProcessPtr();
1837 size_t num_frames_shown = 0;
1839 bool is_selected = false;
1842 if (process->GetThreadList().GetSelectedThread().get() == this)
1845 strm.Printf("%c ", is_selected ? '*' : ' ');
1846 if (target && target->GetDebugger().GetUseExternalEditor())
1848 StackFrameSP frame_sp = GetStackFrameAtIndex(start_frame);
1851 SymbolContext frame_sc(frame_sp->GetSymbolContext (eSymbolContextLineEntry));
1852 if (frame_sc.line_entry.line != 0 && frame_sc.line_entry.file)
1854 Host::OpenFileInExternalEditor (frame_sc.line_entry.file, frame_sc.line_entry.line);
1859 DumpUsingSettingsFormat (strm, start_frame);
1865 const bool show_frame_info = true;
1867 num_frames_shown = GetStackFrameList ()->GetStatus (strm,
1871 num_frames_with_source);
1875 return num_frames_shown;
1879 Thread::GetStackFrameStatus (Stream& strm,
1880 uint32_t first_frame,
1881 uint32_t num_frames,
1882 bool show_frame_info,
1883 uint32_t num_frames_with_source)
1885 return GetStackFrameList()->GetStatus (strm,
1889 num_frames_with_source);
1893 Thread::SaveFrameZeroState (RegisterCheckpoint &checkpoint)
1895 lldb::StackFrameSP frame_sp(GetStackFrameAtIndex (0));
1898 checkpoint.SetStackID(frame_sp->GetStackID());
1899 lldb::RegisterContextSP reg_ctx_sp (frame_sp->GetRegisterContext());
1901 return reg_ctx_sp->ReadAllRegisterValues (checkpoint.GetData());
1907 Thread::RestoreSaveFrameZero (const RegisterCheckpoint &checkpoint)
1909 return ResetFrameZeroRegisters (checkpoint.GetData());
1913 Thread::ResetFrameZeroRegisters (lldb::DataBufferSP register_data_sp)
1915 lldb::StackFrameSP frame_sp(GetStackFrameAtIndex (0));
1918 lldb::RegisterContextSP reg_ctx_sp (frame_sp->GetRegisterContext());
1921 bool ret = reg_ctx_sp->WriteAllRegisterValues (register_data_sp);
1923 // Clear out all stack frames as our world just changed.
1925 reg_ctx_sp->InvalidateIfNeeded(true);
1926 if (m_unwinder_ap.get())
1927 m_unwinder_ap->Clear();
1935 Thread::GetUnwinder ()
1937 if (m_unwinder_ap.get() == NULL)
1939 const ArchSpec target_arch (CalculateTarget()->GetArchitecture ());
1940 const llvm::Triple::ArchType machine = target_arch.GetMachine();
1943 case llvm::Triple::x86_64:
1944 case llvm::Triple::x86:
1945 case llvm::Triple::arm:
1946 case llvm::Triple::thumb:
1947 m_unwinder_ap.reset (new UnwindLLDB (*this));
1951 if (target_arch.GetTriple().getVendor() == llvm::Triple::Apple)
1952 m_unwinder_ap.reset (new UnwindMacOSXFrameBackchain (*this));
1956 return m_unwinder_ap.get();
1963 ClearStackFrames ();
1964 m_reg_context_sp.reset();
1968 Thread::IsStillAtLastBreakpointHit ()
1970 // If we are currently stopped at a breakpoint, always return that stopinfo and don't reset it.
1971 // This allows threads to maintain their breakpoint stopinfo, such as when thread-stepping in
1972 // multithreaded programs.
1973 if (m_stop_info_sp) {
1974 StopReason stop_reason = m_stop_info_sp->GetStopReason();
1975 if (stop_reason == lldb::eStopReasonBreakpoint) {
1976 uint64_t value = m_stop_info_sp->GetValue();
1977 lldb::RegisterContextSP reg_ctx_sp (GetRegisterContext());
1980 lldb::addr_t pc = reg_ctx_sp->GetPC();
1981 BreakpointSiteSP bp_site_sp = GetProcess()->GetBreakpointSiteList().FindByAddress(pc);
1982 if (bp_site_sp && value == bp_site_sp->GetID())