1 //===-- ThreadPlanBase.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/Target/ThreadPlanBase.h"
14 // Other libraries and framework includes
17 #include "lldb/Breakpoint/Breakpoint.h"
18 #include "lldb/Breakpoint/BreakpointLocation.h"
19 #include "lldb/Breakpoint/BreakpointSite.h"
20 #include "lldb/Breakpoint/StoppointCallbackContext.h"
21 #include "lldb/Target/Process.h"
22 #include "lldb/Target/RegisterContext.h"
23 #include "lldb/Target/StopInfo.h"
24 #include "lldb/Utility/Log.h"
25 #include "lldb/Utility/Stream.h"
28 using namespace lldb_private;
30 //----------------------------------------------------------------------
31 // ThreadPlanBase: This one always stops, and never has anything particular
33 // FIXME: The "signal handling" policies should probably go here.
34 //----------------------------------------------------------------------
36 ThreadPlanBase::ThreadPlanBase(Thread &thread)
37 : ThreadPlan(ThreadPlan::eKindBase, "base plan", thread, eVoteYes,
39 // Set the tracer to a default tracer.
40 // FIXME: need to add a thread settings variable to pix various tracers...
41 #define THREAD_PLAN_USE_ASSEMBLY_TRACER 1
43 #ifdef THREAD_PLAN_USE_ASSEMBLY_TRACER
44 ThreadPlanTracerSP new_tracer_sp(new ThreadPlanAssemblyTracer(m_thread));
46 ThreadPlanTracerSP new_tracer_sp(new ThreadPlanTracer(m_thread));
48 new_tracer_sp->EnableTracing(m_thread.GetTraceEnabledState());
49 SetThreadPlanTracer(new_tracer_sp);
50 SetIsMasterPlan(true);
53 ThreadPlanBase::~ThreadPlanBase() {}
55 void ThreadPlanBase::GetDescription(Stream *s, lldb::DescriptionLevel level) {
56 s->Printf("Base thread plan.");
59 bool ThreadPlanBase::ValidatePlan(Stream *error) { return true; }
61 bool ThreadPlanBase::DoPlanExplainsStop(Event *event_ptr) {
62 // The base plan should defer to its tracer, since by default it
63 // always handles the stop.
64 if (TracerExplainsStop())
70 Vote ThreadPlanBase::ShouldReportStop(Event *event_ptr) {
71 StopInfoSP stop_info_sp = m_thread.GetStopInfo();
73 bool should_notify = stop_info_sp->ShouldNotify(event_ptr);
77 return eVoteNoOpinion;
79 return eVoteNoOpinion;
82 bool ThreadPlanBase::ShouldStop(Event *event_ptr) {
83 m_stop_vote = eVoteYes;
84 m_run_vote = eVoteYes;
86 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP));
88 StopInfoSP stop_info_sp = GetPrivateStopInfo();
90 StopReason reason = stop_info_sp->GetStopReason();
92 case eStopReasonInvalid:
95 m_run_vote = eVoteNoOpinion;
96 m_stop_vote = eVoteNo;
99 case eStopReasonBreakpoint:
100 case eStopReasonWatchpoint:
101 if (stop_info_sp->ShouldStopSynchronous(event_ptr)) {
102 // If we are going to stop for a breakpoint, then unship the other plans
103 // at this point. Don't force the discard, however, so Master plans can
105 // in place if they want to.
108 "Base plan discarding thread plans for thread tid = 0x%4.4" PRIx64
109 " (breakpoint hit.)",
111 m_thread.DiscardThreadPlans(false);
114 // If we aren't going to stop at this breakpoint, and it is internal,
115 // don't report this stop or the subsequent running event.
116 // Otherwise we will post the stopped & running, but the stopped event
118 // with "restarted" so the UI will know to wait and expect the consequent
120 if (stop_info_sp->ShouldNotify(event_ptr)) {
121 m_stop_vote = eVoteYes;
122 m_run_vote = eVoteYes;
124 m_stop_vote = eVoteNo;
125 m_run_vote = eVoteNo;
129 // TODO: the break below was missing, was this intentional??? If so
133 case eStopReasonException:
134 // If we crashed, discard thread plans and stop. Don't force the discard,
136 // since on rerun the target may clean up this exception and continue
137 // normally from there.
140 "Base plan discarding thread plans for thread tid = 0x%4.4" PRIx64
142 m_thread.GetID(), stop_info_sp->GetDescription());
143 m_thread.DiscardThreadPlans(false);
146 case eStopReasonExec:
147 // If we crashed, discard thread plans and stop. Don't force the discard,
149 // since on rerun the target may clean up this exception and continue
150 // normally from there.
153 "Base plan discarding thread plans for thread tid = 0x%4.4" PRIx64
156 m_thread.DiscardThreadPlans(false);
159 case eStopReasonThreadExiting:
160 case eStopReasonSignal:
161 if (stop_info_sp->ShouldStop(event_ptr)) {
164 "Base plan discarding thread plans for thread tid = 0x%4.4" PRIx64
166 m_thread.GetID(), stop_info_sp->GetDescription());
167 m_thread.DiscardThreadPlans(false);
170 // We're not going to stop, but while we are here, let's figure out
171 // whether to report this.
172 if (stop_info_sp->ShouldNotify(event_ptr))
173 m_stop_vote = eVoteYes;
175 m_stop_vote = eVoteNo;
184 m_run_vote = eVoteNoOpinion;
185 m_stop_vote = eVoteNo;
188 // If there's no explicit reason to stop, then we will continue.
192 bool ThreadPlanBase::StopOthers() { return false; }
194 StateType ThreadPlanBase::GetPlanRunState() { return eStateRunning; }
196 bool ThreadPlanBase::WillStop() { return true; }
198 bool ThreadPlanBase::DoWillResume(lldb::StateType resume_state,
200 // Reset these to the default values so we don't set them wrong, then not get
202 // for a while, then return the wrong answer.
203 m_run_vote = eVoteNoOpinion;
204 m_stop_vote = eVoteNo;
208 // The base plan is never done.
209 bool ThreadPlanBase::MischiefManaged() {
210 // The base plan is never done.