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 case eStopReasonWatchpoint: 103 if (stop_info_sp->ShouldStop(event_ptr)) 104 { 105 // If we are going to stop for a breakpoint, then unship the other plans 106 // at this point. Don't force the discard, however, so Master plans can stay 107 // in place if they want to. 108 if (log) 109 log->Printf("Base plan discarding thread plans for thread tid = 0x%4.4llx (breakpoint hit.)", m_thread.GetID()); 110 m_thread.DiscardThreadPlans(false); 111 return true; 112 } 113 // If we aren't going to stop at this breakpoint, and it is internal, 114 // don't report this stop or the subsequent running event. 115 // Otherwise we will post the stopped & running, but the stopped event will get marked 116 // with "restarted" so the UI will know to wait and expect the consequent "running". 117 if (stop_info_sp->ShouldNotify (event_ptr)) 118 { 119 m_stop_vote = eVoteYes; 120 m_run_vote = eVoteYes; 121 } 122 else 123 { 124 m_stop_vote = eVoteNo; 125 m_run_vote = eVoteNo; 126 } 127 return false; 128 129 // TODO: the break below was missing, was this intentional??? If so 130 // please mention it 131 break; 132 133 case eStopReasonException: 134 // If we crashed, discard thread plans and stop. Don't force the discard, however, 135 // since on rerun the target may clean up this exception and continue normally from there. 136 if (log) 137 log->Printf("Base plan discarding thread plans for thread tid = 0x%4.4llx (exception.)", m_thread.GetID()); 138 m_thread.DiscardThreadPlans(false); 139 return true; 140 141 case eStopReasonSignal: 142 if (stop_info_sp->ShouldStop(event_ptr)) 143 { 144 if (log) 145 log->Printf("Base plan discarding thread plans for thread tid = 0x%4.4llx (signal.)", m_thread.GetID()); 146 m_thread.DiscardThreadPlans(false); 147 return true; 148 } 149 else 150 { 151 // We're not going to stop, but while we are here, let's figure out 152 // whether to report this. 153 if (stop_info_sp->ShouldNotify(event_ptr)) 154 m_stop_vote = eVoteYes; 155 else 156 m_stop_vote = eVoteNo; 157 } 158 return false; 159 160 default: 161 return true; 162 } 163 164 } 165 else 166 { 167 m_run_vote = eVoteNoOpinion; 168 m_stop_vote = eVoteNo; 169 } 170 171 // If there's no explicit reason to stop, then we will continue. 172 return false; 173 } 174 175 bool 176 ThreadPlanBase::StopOthers () 177 { 178 return false; 179 } 180 181 StateType 182 ThreadPlanBase::GetPlanRunState () 183 { 184 return eStateRunning; 185 } 186 187 bool 188 ThreadPlanBase::WillStop () 189 { 190 return true; 191 } 192 193 bool 194 ThreadPlanBase::WillResume (lldb::StateType resume_state, bool current_plan) 195 { 196 // Reset these to the default values so we don't set them wrong, then not get asked 197 // for a while, then return the wrong answer. 198 m_run_vote = eVoteNoOpinion; 199 m_stop_vote = eVoteNo; 200 return true; 201 } 202 203 204 // The base plan is never done. 205 bool 206 ThreadPlanBase::MischiefManaged () 207 { 208 // The base plan is never done. 209 return false; 210 } 211 212