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"
13 #include "lldb/Breakpoint/Breakpoint.h"
14 #include "lldb/Breakpoint/BreakpointLocation.h"
15 #include "lldb/Breakpoint/BreakpointSite.h"
16 #include "lldb/Breakpoint/StoppointCallbackContext.h"
17 #include "lldb/Target/Process.h"
18 #include "lldb/Target/RegisterContext.h"
19 #include "lldb/Target/StopInfo.h"
20 #include "lldb/Utility/Log.h"
21 #include "lldb/Utility/Stream.h"
24 using namespace lldb_private;
26 //----------------------------------------------------------------------
27 // ThreadPlanBase: This one always stops, and never has anything particular to
29 // FIXME: The "signal handling" policies should probably go here.
30 //----------------------------------------------------------------------
32 ThreadPlanBase::ThreadPlanBase(Thread &thread)
33 : ThreadPlan(ThreadPlan::eKindBase, "base plan", thread, eVoteYes,
35 // Set the tracer to a default tracer.
36 // FIXME: need to add a thread settings variable to pix various tracers...
37 #define THREAD_PLAN_USE_ASSEMBLY_TRACER 1
39 #ifdef THREAD_PLAN_USE_ASSEMBLY_TRACER
40 ThreadPlanTracerSP new_tracer_sp(new ThreadPlanAssemblyTracer(m_thread));
42 ThreadPlanTracerSP new_tracer_sp(new ThreadPlanTracer(m_thread));
44 new_tracer_sp->EnableTracing(m_thread.GetTraceEnabledState());
45 SetThreadPlanTracer(new_tracer_sp);
46 SetIsMasterPlan(true);
49 ThreadPlanBase::~ThreadPlanBase() {}
51 void ThreadPlanBase::GetDescription(Stream *s, lldb::DescriptionLevel level) {
52 s->Printf("Base thread plan.");
55 bool ThreadPlanBase::ValidatePlan(Stream *error) { return true; }
57 bool ThreadPlanBase::DoPlanExplainsStop(Event *event_ptr) {
58 // The base plan should defer to its tracer, since by default it always
60 return !TracerExplainsStop();
63 Vote ThreadPlanBase::ShouldReportStop(Event *event_ptr) {
64 StopInfoSP stop_info_sp = m_thread.GetStopInfo();
66 bool should_notify = stop_info_sp->ShouldNotify(event_ptr);
70 return eVoteNoOpinion;
72 return eVoteNoOpinion;
75 bool ThreadPlanBase::ShouldStop(Event *event_ptr) {
76 m_stop_vote = eVoteYes;
77 m_run_vote = eVoteYes;
79 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP));
81 StopInfoSP stop_info_sp = GetPrivateStopInfo();
83 StopReason reason = stop_info_sp->GetStopReason();
85 case eStopReasonInvalid:
88 m_run_vote = eVoteNoOpinion;
89 m_stop_vote = eVoteNo;
92 case eStopReasonBreakpoint:
93 case eStopReasonWatchpoint:
94 if (stop_info_sp->ShouldStopSynchronous(event_ptr)) {
95 // If we are going to stop for a breakpoint, then unship the other
96 // plans at this point. Don't force the discard, however, so Master
97 // plans can stay in place if they want to.
100 "Base plan discarding thread plans for thread tid = 0x%4.4" PRIx64
101 " (breakpoint hit.)",
103 m_thread.DiscardThreadPlans(false);
106 // If we aren't going to stop at this breakpoint, and it is internal,
107 // don't report this stop or the subsequent running event. Otherwise we
108 // will post the stopped & running, but the stopped event will get marked
109 // with "restarted" so the UI will know to wait and expect the consequent
111 if (stop_info_sp->ShouldNotify(event_ptr)) {
112 m_stop_vote = eVoteYes;
113 m_run_vote = eVoteYes;
115 m_stop_vote = eVoteNo;
116 m_run_vote = eVoteNo;
120 // TODO: the break below was missing, was this intentional??? If so
124 case eStopReasonException:
125 // If we crashed, discard thread plans and stop. Don't force the
126 // discard, however, since on rerun the target may clean up this
127 // exception and continue normally from there.
130 "Base plan discarding thread plans for thread tid = 0x%4.4" PRIx64
132 m_thread.GetID(), stop_info_sp->GetDescription());
133 m_thread.DiscardThreadPlans(false);
136 case eStopReasonExec:
137 // If we crashed, discard thread plans and stop. Don't force the
138 // discard, however, since on rerun the target may clean up this
139 // exception and continue normally from there.
142 "Base plan discarding thread plans for thread tid = 0x%4.4" PRIx64
145 m_thread.DiscardThreadPlans(false);
148 case eStopReasonThreadExiting:
149 case eStopReasonSignal:
150 if (stop_info_sp->ShouldStop(event_ptr)) {
153 "Base plan discarding thread plans for thread tid = 0x%4.4" PRIx64
155 m_thread.GetID(), stop_info_sp->GetDescription());
156 m_thread.DiscardThreadPlans(false);
159 // We're not going to stop, but while we are here, let's figure out
160 // whether to report this.
161 if (stop_info_sp->ShouldNotify(event_ptr))
162 m_stop_vote = eVoteYes;
164 m_stop_vote = eVoteNo;
173 m_run_vote = eVoteNoOpinion;
174 m_stop_vote = eVoteNo;
177 // If there's no explicit reason to stop, then we will continue.
181 bool ThreadPlanBase::StopOthers() { return false; }
183 StateType ThreadPlanBase::GetPlanRunState() { return eStateRunning; }
185 bool ThreadPlanBase::WillStop() { return true; }
187 bool ThreadPlanBase::DoWillResume(lldb::StateType resume_state,
189 // Reset these to the default values so we don't set them wrong, then not get
190 // asked for a while, then return the wrong answer.
191 m_run_vote = eVoteNoOpinion;
192 m_stop_vote = eVoteNo;
196 // The base plan is never done.
197 bool ThreadPlanBase::MischiefManaged() {
198 // The base plan is never done.