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/StoppointCallbackContext.h"
18 #include "lldb/Breakpoint/BreakpointSite.h"
19 #include "lldb/Breakpoint/BreakpointLocation.h"
20 #include "lldb/Breakpoint/Breakpoint.h"
21 #include "lldb/Core/Log.h"
22 #include "lldb/Core/Stream.h"
23 #include "lldb/Target/Process.h"
24 #include "lldb/Target/RegisterContext.h"
25 #include "lldb/Target/StopInfo.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, eVoteNoOpinion)
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 ()
59 ThreadPlanBase::GetDescription (Stream *s, lldb::DescriptionLevel level)
61 s->Printf ("Base thread plan.");
65 ThreadPlanBase::ValidatePlan (Stream *error)
71 ThreadPlanBase::DoPlanExplainsStop (Event *event_ptr)
73 // The base plan should defer to its tracer, since by default it
74 // always handles the stop.
75 if (TracerExplainsStop())
82 ThreadPlanBase::ShouldReportStop(Event *event_ptr)
84 StopInfoSP stop_info_sp = m_thread.GetStopInfo ();
87 bool should_notify = stop_info_sp->ShouldNotify(event_ptr);
91 return eVoteNoOpinion;
94 return eVoteNoOpinion;
98 ThreadPlanBase::ShouldStop (Event *event_ptr)
100 m_stop_vote = eVoteYes;
101 m_run_vote = eVoteYes;
103 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
105 StopInfoSP stop_info_sp = GetPrivateStopInfo ();
108 StopReason reason = stop_info_sp->GetStopReason ();
111 case eStopReasonInvalid:
112 case eStopReasonNone:
114 m_run_vote = eVoteNoOpinion;
115 m_stop_vote = eVoteNo;
118 case eStopReasonBreakpoint:
119 case eStopReasonWatchpoint:
120 if (stop_info_sp->ShouldStopSynchronous(event_ptr))
122 // If we are going to stop for a breakpoint, then unship the other plans
123 // at this point. Don't force the discard, however, so Master plans can stay
124 // in place if they want to.
126 log->Printf("Base plan discarding thread plans for thread tid = 0x%4.4" PRIx64 " (breakpoint hit.)", m_thread.GetID());
127 m_thread.DiscardThreadPlans(false);
130 // If we aren't going to stop at this breakpoint, and it is internal,
131 // don't report this stop or the subsequent running event.
132 // Otherwise we will post the stopped & running, but the stopped event will get marked
133 // with "restarted" so the UI will know to wait and expect the consequent "running".
134 if (stop_info_sp->ShouldNotify (event_ptr))
136 m_stop_vote = eVoteYes;
137 m_run_vote = eVoteYes;
141 m_stop_vote = eVoteNo;
142 m_run_vote = eVoteNo;
146 // TODO: the break below was missing, was this intentional??? If so
150 case eStopReasonException:
151 // If we crashed, discard thread plans and stop. Don't force the discard, however,
152 // since on rerun the target may clean up this exception and continue normally from there.
154 log->Printf("Base plan discarding thread plans for thread tid = 0x%4.4" PRIx64 " (exception.)", m_thread.GetID());
155 m_thread.DiscardThreadPlans(false);
158 case eStopReasonExec:
159 // If we crashed, discard thread plans and stop. Don't force the discard, however,
160 // since on rerun the target may clean up this exception and continue normally from there.
162 log->Printf("Base plan discarding thread plans for thread tid = 0x%4.4" PRIx64 " (exec.)", m_thread.GetID());
163 m_thread.DiscardThreadPlans(false);
166 case eStopReasonThreadExiting:
167 case eStopReasonSignal:
168 if (stop_info_sp->ShouldStop(event_ptr))
171 log->Printf("Base plan discarding thread plans for thread tid = 0x%4.4" PRIx64 " (signal.)", m_thread.GetID());
172 m_thread.DiscardThreadPlans(false);
177 // We're not going to stop, but while we are here, let's figure out
178 // whether to report this.
179 if (stop_info_sp->ShouldNotify(event_ptr))
180 m_stop_vote = eVoteYes;
182 m_stop_vote = eVoteNo;
193 m_run_vote = eVoteNoOpinion;
194 m_stop_vote = eVoteNo;
197 // If there's no explicit reason to stop, then we will continue.
202 ThreadPlanBase::StopOthers ()
208 ThreadPlanBase::GetPlanRunState ()
210 return eStateRunning;
214 ThreadPlanBase::WillStop ()
220 ThreadPlanBase::DoWillResume (lldb::StateType resume_state, bool current_plan)
222 // Reset these to the default values so we don't set them wrong, then not get asked
223 // for a while, then return the wrong answer.
224 m_run_vote = eVoteNoOpinion;
225 m_stop_vote = eVoteNo;
230 // The base plan is never done.
232 ThreadPlanBase::MischiefManaged ()
234 // The base plan is never done.