1 //===-- ThreadPlanBase.cpp --------------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #include "lldb/Target/ThreadPlanBase.h" 11 12 // C Includes 13 // C++ Includes 14 // Other libraries and framework includes 15 // Project includes 16 // 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" 26 27 using namespace lldb; 28 using namespace lldb_private; 29 30 //---------------------------------------------------------------------- 31 // ThreadPlanBase: This one always stops, and never has anything particular 32 // to do. 33 // FIXME: The "signal handling" policies should probably go here. 34 //---------------------------------------------------------------------- 35 36 ThreadPlanBase::ThreadPlanBase (Thread &thread) : 37 ThreadPlan(ThreadPlan::eKindBase, "base plan", thread, eVoteYes, eVoteNoOpinion) 38 { 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 42 43 #ifdef THREAD_PLAN_USE_ASSEMBLY_TRACER 44 ThreadPlanTracerSP new_tracer_sp (new ThreadPlanAssemblyTracer (m_thread)); 45 #else 46 ThreadPlanTracerSP new_tracer_sp (new ThreadPlanTracer (m_thread)); 47 #endif 48 new_tracer_sp->EnableTracing (m_thread.GetTraceEnabledState()); 49 SetThreadPlanTracer(new_tracer_sp); 50 } 51 52 ThreadPlanBase::~ThreadPlanBase () 53 { 54 55 } 56 57 void 58 ThreadPlanBase::GetDescription (Stream *s, lldb::DescriptionLevel level) 59 { 60 s->Printf ("Base thread plan."); 61 } 62 63 bool 64 ThreadPlanBase::ValidatePlan (Stream *error) 65 { 66 return true; 67 } 68 69 bool 70 ThreadPlanBase::PlanExplainsStop () 71 { 72 // The base plan should defer to its tracer, since by default it 73 // always handles the stop. 74 if (TracerExplainsStop()) 75 return false; 76 else 77 return true; 78 } 79 80 bool 81 ThreadPlanBase::ShouldStop (Event *event_ptr) 82 { 83 m_stop_vote = eVoteYes; 84 m_run_vote = eVoteYes; 85 86 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); 87 88 StopInfoSP stop_info_sp = GetPrivateStopReason(); 89 if (stop_info_sp) 90 { 91 StopReason reason = stop_info_sp->GetStopReason(); 92 switch (reason) 93 { 94 case eStopReasonInvalid: 95 case eStopReasonNone: 96 // This 97 m_run_vote = eVoteNoOpinion; 98 m_stop_vote = eVoteNo; 99 return false; 100 101 case eStopReasonBreakpoint: 102 if (stop_info_sp->ShouldStop(event_ptr)) 103 { 104 // If we are going to stop for a breakpoint, then unship the other plans 105 // at this point. Don't force the discard, however, so Master plans can stay 106 // in place if they want to. 107 if (log) 108 log->Printf("Base plan discarding thread plans for thread tid = 0x%4.4x (breakpoint hit.)", m_thread.GetID()); 109 m_thread.DiscardThreadPlans(false); 110 return true; 111 } 112 // If we aren't going to stop at this breakpoint, and it is internal, 113 // don't report this stop or the subsequent running event. 114 // Otherwise we will post the stopped & running, but the stopped event will get marked 115 // with "restarted" so the UI will know to wait and expect the consequent "running". 116 if (stop_info_sp->ShouldNotify (event_ptr)) 117 { 118 m_stop_vote = eVoteYes; 119 m_run_vote = eVoteYes; 120 } 121 else 122 { 123 m_stop_vote = eVoteNo; 124 m_run_vote = eVoteNo; 125 } 126 return false; 127 128 // TODO: the break below was missing, was this intentional??? If so 129 // please mention it 130 break; 131 132 case eStopReasonException: 133 // If we crashed, discard thread plans and stop. Don't force the discard, however, 134 // since on rerun the target may clean up this exception and continue normally from there. 135 if (log) 136 log->Printf("Base plan discarding thread plans for thread tid = 0x%4.4x (exception.)", m_thread.GetID()); 137 m_thread.DiscardThreadPlans(false); 138 return true; 139 140 case eStopReasonSignal: 141 if (stop_info_sp->ShouldStop(event_ptr)) 142 { 143 if (log) 144 log->Printf("Base plan discarding thread plans for thread tid = 0x%4.4x (signal.)", m_thread.GetID()); 145 m_thread.DiscardThreadPlans(false); 146 return true; 147 } 148 else 149 { 150 // We're not going to stop, but while we are here, let's figure out 151 // whether to report this. 152 if (stop_info_sp->ShouldNotify(event_ptr)) 153 m_stop_vote = eVoteYes; 154 else 155 m_stop_vote = eVoteNo; 156 } 157 return false; 158 159 default: 160 return true; 161 } 162 163 } 164 else 165 { 166 m_run_vote = eVoteNoOpinion; 167 m_stop_vote = eVoteNo; 168 } 169 170 // If there's no explicit reason to stop, then we will continue. 171 return false; 172 } 173 174 bool 175 ThreadPlanBase::StopOthers () 176 { 177 return false; 178 } 179 180 StateType 181 ThreadPlanBase::GetPlanRunState () 182 { 183 return eStateRunning; 184 } 185 186 bool 187 ThreadPlanBase::WillStop () 188 { 189 return true; 190 } 191 192 bool 193 ThreadPlanBase::WillResume (lldb::StateType resume_state, bool current_plan) 194 { 195 // Reset these to the default values so we don't set them wrong, then not get asked 196 // for a while, then return the wrong answer. 197 m_run_vote = eVoteNoOpinion; 198 m_stop_vote = eVoteNo; 199 return true; 200 } 201 202 203 // The base plan is never done. 204 bool 205 ThreadPlanBase::MischiefManaged () 206 { 207 // The base plan is never done. 208 return false; 209 } 210 211