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 // 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" 22 23 using namespace lldb; 24 using namespace lldb_private; 25 26 //---------------------------------------------------------------------- 27 // ThreadPlanBase: This one always stops, and never has anything particular to 28 // do. 29 // FIXME: The "signal handling" policies should probably go here. 30 //---------------------------------------------------------------------- 31 32 ThreadPlanBase::ThreadPlanBase(Thread &thread) 33 : ThreadPlan(ThreadPlan::eKindBase, "base plan", thread, eVoteYes, 34 eVoteNoOpinion) { 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 38 39 #ifdef THREAD_PLAN_USE_ASSEMBLY_TRACER 40 ThreadPlanTracerSP new_tracer_sp(new ThreadPlanAssemblyTracer(m_thread)); 41 #else 42 ThreadPlanTracerSP new_tracer_sp(new ThreadPlanTracer(m_thread)); 43 #endif 44 new_tracer_sp->EnableTracing(m_thread.GetTraceEnabledState()); 45 SetThreadPlanTracer(new_tracer_sp); 46 SetIsMasterPlan(true); 47 } 48 49 ThreadPlanBase::~ThreadPlanBase() {} 50 51 void ThreadPlanBase::GetDescription(Stream *s, lldb::DescriptionLevel level) { 52 s->Printf("Base thread plan."); 53 } 54 55 bool ThreadPlanBase::ValidatePlan(Stream *error) { return true; } 56 57 bool ThreadPlanBase::DoPlanExplainsStop(Event *event_ptr) { 58 // The base plan should defer to its tracer, since by default it always 59 // handles the stop. 60 return !TracerExplainsStop(); 61 } 62 63 Vote ThreadPlanBase::ShouldReportStop(Event *event_ptr) { 64 StopInfoSP stop_info_sp = m_thread.GetStopInfo(); 65 if (stop_info_sp) { 66 bool should_notify = stop_info_sp->ShouldNotify(event_ptr); 67 if (should_notify) 68 return eVoteYes; 69 else 70 return eVoteNoOpinion; 71 } else 72 return eVoteNoOpinion; 73 } 74 75 bool ThreadPlanBase::ShouldStop(Event *event_ptr) { 76 m_stop_vote = eVoteYes; 77 m_run_vote = eVoteYes; 78 79 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP)); 80 81 StopInfoSP stop_info_sp = GetPrivateStopInfo(); 82 if (stop_info_sp) { 83 StopReason reason = stop_info_sp->GetStopReason(); 84 switch (reason) { 85 case eStopReasonInvalid: 86 case eStopReasonNone: 87 // This 88 m_run_vote = eVoteNoOpinion; 89 m_stop_vote = eVoteNo; 90 return false; 91 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. 98 if (log) 99 log->Printf( 100 "Base plan discarding thread plans for thread tid = 0x%4.4" PRIx64 101 " (breakpoint hit.)", 102 m_thread.GetID()); 103 m_thread.DiscardThreadPlans(false); 104 return true; 105 } 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 110 // "running". 111 if (stop_info_sp->ShouldNotify(event_ptr)) { 112 m_stop_vote = eVoteYes; 113 m_run_vote = eVoteYes; 114 } else { 115 m_stop_vote = eVoteNo; 116 m_run_vote = eVoteNo; 117 } 118 return false; 119 120 // TODO: the break below was missing, was this intentional??? If so 121 // please mention it 122 break; 123 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. 128 if (log) 129 log->Printf( 130 "Base plan discarding thread plans for thread tid = 0x%4.4" PRIx64 131 " (exception: %s)", 132 m_thread.GetID(), stop_info_sp->GetDescription()); 133 m_thread.DiscardThreadPlans(false); 134 return true; 135 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. 140 if (log) 141 log->Printf( 142 "Base plan discarding thread plans for thread tid = 0x%4.4" PRIx64 143 " (exec.)", 144 m_thread.GetID()); 145 m_thread.DiscardThreadPlans(false); 146 return true; 147 148 case eStopReasonThreadExiting: 149 case eStopReasonSignal: 150 if (stop_info_sp->ShouldStop(event_ptr)) { 151 if (log) 152 log->Printf( 153 "Base plan discarding thread plans for thread tid = 0x%4.4" PRIx64 154 " (signal: %s)", 155 m_thread.GetID(), stop_info_sp->GetDescription()); 156 m_thread.DiscardThreadPlans(false); 157 return true; 158 } else { 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; 163 else 164 m_stop_vote = eVoteNo; 165 } 166 return false; 167 168 default: 169 return true; 170 } 171 172 } else { 173 m_run_vote = eVoteNoOpinion; 174 m_stop_vote = eVoteNo; 175 } 176 177 // If there's no explicit reason to stop, then we will continue. 178 return false; 179 } 180 181 bool ThreadPlanBase::StopOthers() { return false; } 182 183 StateType ThreadPlanBase::GetPlanRunState() { return eStateRunning; } 184 185 bool ThreadPlanBase::WillStop() { return true; } 186 187 bool ThreadPlanBase::DoWillResume(lldb::StateType resume_state, 188 bool current_plan) { 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; 193 return true; 194 } 195 196 // The base plan is never done. 197 bool ThreadPlanBase::MischiefManaged() { 198 // The base plan is never done. 199 return false; 200 } 201