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 SetIsMasterPlan (true); 51 } 52 53 ThreadPlanBase::~ThreadPlanBase () 54 { 55 56 } 57 58 void 59 ThreadPlanBase::GetDescription (Stream *s, lldb::DescriptionLevel level) 60 { 61 s->Printf ("Base thread plan."); 62 } 63 64 bool 65 ThreadPlanBase::ValidatePlan (Stream *error) 66 { 67 return true; 68 } 69 70 bool 71 ThreadPlanBase::PlanExplainsStop () 72 { 73 // The base plan should defer to its tracer, since by default it 74 // always handles the stop. 75 if (TracerExplainsStop()) 76 return false; 77 else 78 return true; 79 } 80 81 bool 82 ThreadPlanBase::ShouldStop (Event *event_ptr) 83 { 84 m_stop_vote = eVoteYes; 85 m_run_vote = eVoteYes; 86 87 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); 88 89 StopInfoSP stop_info_sp = GetPrivateStopReason(); 90 if (stop_info_sp) 91 { 92 StopReason reason = stop_info_sp->GetStopReason(); 93 switch (reason) 94 { 95 case eStopReasonInvalid: 96 case eStopReasonNone: 97 // This 98 m_run_vote = eVoteNoOpinion; 99 m_stop_vote = eVoteNo; 100 return false; 101 102 case eStopReasonBreakpoint: 103 case eStopReasonWatchpoint: 104 if (stop_info_sp->ShouldStop(event_ptr)) 105 { 106 // If we are going to stop for a breakpoint, then unship the other plans 107 // at this point. Don't force the discard, however, so Master plans can stay 108 // in place if they want to. 109 if (log) 110 log->Printf("Base plan discarding thread plans for thread tid = 0x%4.4llx (breakpoint hit.)", m_thread.GetID()); 111 m_thread.DiscardThreadPlans(false); 112 return true; 113 } 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 will get marked 117 // with "restarted" so the UI will know to wait and expect the consequent "running". 118 if (stop_info_sp->ShouldNotify (event_ptr)) 119 { 120 m_stop_vote = eVoteYes; 121 m_run_vote = eVoteYes; 122 } 123 else 124 { 125 m_stop_vote = eVoteNo; 126 m_run_vote = eVoteNo; 127 } 128 return false; 129 130 // TODO: the break below was missing, was this intentional??? If so 131 // please mention it 132 break; 133 134 case eStopReasonException: 135 // If we crashed, discard thread plans and stop. Don't force the discard, however, 136 // since on rerun the target may clean up this exception and continue normally from there. 137 if (log) 138 log->Printf("Base plan discarding thread plans for thread tid = 0x%4.4llx (exception.)", m_thread.GetID()); 139 m_thread.DiscardThreadPlans(false); 140 return true; 141 142 case eStopReasonSignal: 143 if (stop_info_sp->ShouldStop(event_ptr)) 144 { 145 if (log) 146 log->Printf("Base plan discarding thread plans for thread tid = 0x%4.4llx (signal.)", m_thread.GetID()); 147 m_thread.DiscardThreadPlans(false); 148 return true; 149 } 150 else 151 { 152 // We're not going to stop, but while we are here, let's figure out 153 // whether to report this. 154 if (stop_info_sp->ShouldNotify(event_ptr)) 155 m_stop_vote = eVoteYes; 156 else 157 m_stop_vote = eVoteNo; 158 } 159 return false; 160 161 default: 162 return true; 163 } 164 165 } 166 else 167 { 168 m_run_vote = eVoteNoOpinion; 169 m_stop_vote = eVoteNo; 170 } 171 172 // If there's no explicit reason to stop, then we will continue. 173 return false; 174 } 175 176 bool 177 ThreadPlanBase::StopOthers () 178 { 179 return false; 180 } 181 182 StateType 183 ThreadPlanBase::GetPlanRunState () 184 { 185 return eStateRunning; 186 } 187 188 bool 189 ThreadPlanBase::WillStop () 190 { 191 return true; 192 } 193 194 bool 195 ThreadPlanBase::WillResume (lldb::StateType resume_state, bool current_plan) 196 { 197 // Reset these to the default values so we don't set them wrong, then not get asked 198 // for a while, then return the wrong answer. 199 m_run_vote = eVoteNoOpinion; 200 m_stop_vote = eVoteNo; 201 return true; 202 } 203 204 205 // The base plan is never done. 206 bool 207 ThreadPlanBase::MischiefManaged () 208 { 209 // The base plan is never done. 210 return false; 211 } 212 213