Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 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" |
Jim Ingham | f9f40c2 | 2011-02-08 05:20:59 +0000 | [diff] [blame^] | 21 | #include "lldb/Core/Log.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 22 | #include "lldb/Core/Stream.h" |
| 23 | #include "lldb/Target/Process.h" |
| 24 | #include "lldb/Target/RegisterContext.h" |
Greg Clayton | 643ee73 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 25 | #include "lldb/Target/StopInfo.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 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) : |
Jim Ingham | 5a47e8b | 2010-06-19 04:45:32 +0000 | [diff] [blame] | 37 | ThreadPlan(ThreadPlan::eKindBase, "base plan", thread, eVoteYes, eVoteNoOpinion) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 38 | { |
Jim Ingham | 745ac7a | 2010-11-11 19:26:09 +0000 | [diff] [blame] | 39 | // Set the tracer to a default tracer. |
Jim Ingham | cdea236 | 2010-11-18 02:47:07 +0000 | [diff] [blame] | 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 |
Jim Ingham | 745ac7a | 2010-11-11 19:26:09 +0000 | [diff] [blame] | 46 | ThreadPlanTracerSP new_tracer_sp (new ThreadPlanTracer (m_thread)); |
Jim Ingham | cdea236 | 2010-11-18 02:47:07 +0000 | [diff] [blame] | 47 | #endif |
Jim Ingham | 745ac7a | 2010-11-11 19:26:09 +0000 | [diff] [blame] | 48 | new_tracer_sp->EnableTracing (m_thread.GetTraceEnabledState()); |
| 49 | SetThreadPlanTracer(new_tracer_sp); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 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 | { |
Jim Ingham | 745ac7a | 2010-11-11 19:26:09 +0000 | [diff] [blame] | 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; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | bool |
| 81 | ThreadPlanBase::ShouldStop (Event *event_ptr) |
| 82 | { |
| 83 | m_stop_vote = eVoteYes; |
| 84 | m_run_vote = eVoteYes; |
| 85 | |
Jim Ingham | f9f40c2 | 2011-02-08 05:20:59 +0000 | [diff] [blame^] | 86 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
| 87 | |
Jim Ingham | 6297a3a | 2010-10-20 00:39:53 +0000 | [diff] [blame] | 88 | StopInfoSP stop_info_sp = GetPrivateStopReason(); |
| 89 | if (stop_info_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 90 | { |
Jim Ingham | 6297a3a | 2010-10-20 00:39:53 +0000 | [diff] [blame] | 91 | StopReason reason = stop_info_sp->GetStopReason(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 92 | switch (reason) |
| 93 | { |
Greg Clayton | 643ee73 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 94 | case eStopReasonInvalid: |
| 95 | case eStopReasonNone: |
Jim Ingham | ac95966 | 2011-01-24 06:34:17 +0000 | [diff] [blame] | 96 | // This |
| 97 | m_run_vote = eVoteNoOpinion; |
Greg Clayton | 643ee73 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 98 | m_stop_vote = eVoteNo; |
| 99 | return false; |
| 100 | |
| 101 | case eStopReasonBreakpoint: |
Jim Ingham | 6297a3a | 2010-10-20 00:39:53 +0000 | [diff] [blame] | 102 | if (stop_info_sp->ShouldStop(event_ptr)) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 103 | { |
Greg Clayton | 643ee73 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 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. |
Jim Ingham | f9f40c2 | 2011-02-08 05:20:59 +0000 | [diff] [blame^] | 107 | if (log) |
| 108 | log->Printf("Base plan discarding thread plans for thread tid = 0x%4.4x (breakpoint hit.)", m_thread.GetID()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 109 | m_thread.DiscardThreadPlans(false); |
| 110 | return true; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 111 | } |
Greg Clayton | 643ee73 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 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". |
Jim Ingham | 6297a3a | 2010-10-20 00:39:53 +0000 | [diff] [blame] | 116 | if (stop_info_sp->ShouldNotify (event_ptr)) |
Greg Clayton | 643ee73 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 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. |
Jim Ingham | f9f40c2 | 2011-02-08 05:20:59 +0000 | [diff] [blame^] | 135 | if (log) |
| 136 | log->Printf("Base plan discarding thread plans for thread tid = 0x%4.4x (exception.)", m_thread.GetID()); |
Greg Clayton | 643ee73 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 137 | m_thread.DiscardThreadPlans(false); |
| 138 | return true; |
| 139 | |
| 140 | case eStopReasonSignal: |
Jim Ingham | 6297a3a | 2010-10-20 00:39:53 +0000 | [diff] [blame] | 141 | if (stop_info_sp->ShouldStop(event_ptr)) |
Greg Clayton | 643ee73 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 142 | { |
Jim Ingham | f9f40c2 | 2011-02-08 05:20:59 +0000 | [diff] [blame^] | 143 | if (log) |
| 144 | log->Printf("Base plan discarding thread plans for thread tid = 0x%4.4x (signal.)", m_thread.GetID()); |
Greg Clayton | 643ee73 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 145 | m_thread.DiscardThreadPlans(false); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 146 | return true; |
Greg Clayton | 643ee73 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 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. |
Jim Ingham | 6297a3a | 2010-10-20 00:39:53 +0000 | [diff] [blame] | 152 | if (stop_info_sp->ShouldNotify(event_ptr)) |
Greg Clayton | 643ee73 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 153 | m_stop_vote = eVoteYes; |
| 154 | else |
| 155 | m_stop_vote = eVoteNo; |
| 156 | } |
| 157 | return false; |
| 158 | |
| 159 | default: |
| 160 | return true; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | } |
Greg Clayton | 643ee73 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 164 | else |
| 165 | { |
Jim Ingham | ac95966 | 2011-01-24 06:34:17 +0000 | [diff] [blame] | 166 | m_run_vote = eVoteNoOpinion; |
Greg Clayton | 643ee73 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 167 | m_stop_vote = eVoteNo; |
| 168 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 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 |
Jim Ingham | 745ac7a | 2010-11-11 19:26:09 +0000 | [diff] [blame] | 181 | ThreadPlanBase::GetPlanRunState () |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 182 | { |
| 183 | return eStateRunning; |
| 184 | } |
| 185 | |
| 186 | bool |
| 187 | ThreadPlanBase::WillStop () |
| 188 | { |
| 189 | return true; |
| 190 | } |
| 191 | |
Jim Ingham | ac95966 | 2011-01-24 06:34:17 +0000 | [diff] [blame] | 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 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 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 | |