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" |
| 21 | #include "lldb/Core/Stream.h" |
| 22 | #include "lldb/Target/Process.h" |
| 23 | #include "lldb/Target/RegisterContext.h" |
Greg Clayton | 643ee73 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 24 | #include "lldb/Target/StopInfo.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 25 | |
| 26 | using namespace lldb; |
| 27 | using namespace lldb_private; |
| 28 | |
| 29 | //---------------------------------------------------------------------- |
| 30 | // ThreadPlanBase: This one always stops, and never has anything particular |
| 31 | // to do. |
| 32 | // FIXME: The "signal handling" policies should probably go here. |
| 33 | //---------------------------------------------------------------------- |
| 34 | |
| 35 | ThreadPlanBase::ThreadPlanBase (Thread &thread) : |
Jim Ingham | 5a47e8b | 2010-06-19 04:45:32 +0000 | [diff] [blame] | 36 | ThreadPlan(ThreadPlan::eKindBase, "base plan", thread, eVoteYes, eVoteNoOpinion) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 37 | { |
Jim Ingham | 745ac7a | 2010-11-11 19:26:09 +0000 | [diff] [blame^] | 38 | // Set the tracer to a default tracer. |
| 39 | ThreadPlanTracerSP new_tracer_sp (new ThreadPlanTracer (m_thread)); |
| 40 | new_tracer_sp->EnableTracing (m_thread.GetTraceEnabledState()); |
| 41 | SetThreadPlanTracer(new_tracer_sp); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | ThreadPlanBase::~ThreadPlanBase () |
| 45 | { |
| 46 | |
| 47 | } |
| 48 | |
| 49 | void |
| 50 | ThreadPlanBase::GetDescription (Stream *s, lldb::DescriptionLevel level) |
| 51 | { |
| 52 | s->Printf ("Base thread plan."); |
| 53 | } |
| 54 | |
| 55 | bool |
| 56 | ThreadPlanBase::ValidatePlan (Stream *error) |
| 57 | { |
| 58 | return true; |
| 59 | } |
| 60 | |
| 61 | bool |
| 62 | ThreadPlanBase::PlanExplainsStop () |
| 63 | { |
Jim Ingham | 745ac7a | 2010-11-11 19:26:09 +0000 | [diff] [blame^] | 64 | // The base plan should defer to its tracer, since by default it |
| 65 | // always handles the stop. |
| 66 | if (TracerExplainsStop()) |
| 67 | return false; |
| 68 | else |
| 69 | return true; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | bool |
| 73 | ThreadPlanBase::ShouldStop (Event *event_ptr) |
| 74 | { |
| 75 | m_stop_vote = eVoteYes; |
| 76 | m_run_vote = eVoteYes; |
| 77 | |
Jim Ingham | 6297a3a | 2010-10-20 00:39:53 +0000 | [diff] [blame] | 78 | StopInfoSP stop_info_sp = GetPrivateStopReason(); |
| 79 | if (stop_info_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 80 | { |
Jim Ingham | 6297a3a | 2010-10-20 00:39:53 +0000 | [diff] [blame] | 81 | StopReason reason = stop_info_sp->GetStopReason(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 82 | switch (reason) |
| 83 | { |
Greg Clayton | 643ee73 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 84 | case eStopReasonInvalid: |
| 85 | case eStopReasonNone: |
| 86 | m_run_vote = eVoteNo; |
| 87 | m_stop_vote = eVoteNo; |
| 88 | return false; |
| 89 | |
| 90 | case eStopReasonBreakpoint: |
Jim Ingham | 6297a3a | 2010-10-20 00:39:53 +0000 | [diff] [blame] | 91 | if (stop_info_sp->ShouldStop(event_ptr)) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 92 | { |
Greg Clayton | 643ee73 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 93 | // If we are going to stop for a breakpoint, then unship the other plans |
| 94 | // at this point. Don't force the discard, however, so Master plans can stay |
| 95 | // in place if they want to. |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 96 | m_thread.DiscardThreadPlans(false); |
| 97 | return true; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 98 | } |
Greg Clayton | 643ee73 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 99 | // If we aren't going to stop at this breakpoint, and it is internal, |
| 100 | // don't report this stop or the subsequent running event. |
| 101 | // Otherwise we will post the stopped & running, but the stopped event will get marked |
| 102 | // 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] | 103 | if (stop_info_sp->ShouldNotify (event_ptr)) |
Greg Clayton | 643ee73 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 104 | { |
| 105 | m_stop_vote = eVoteYes; |
| 106 | m_run_vote = eVoteYes; |
| 107 | } |
| 108 | else |
| 109 | { |
| 110 | m_stop_vote = eVoteNo; |
| 111 | m_run_vote = eVoteNo; |
| 112 | } |
| 113 | return false; |
| 114 | |
| 115 | // TODO: the break below was missing, was this intentional??? If so |
| 116 | // please mention it |
| 117 | break; |
| 118 | |
| 119 | case eStopReasonException: |
| 120 | // If we crashed, discard thread plans and stop. Don't force the discard, however, |
| 121 | // since on rerun the target may clean up this exception and continue normally from there. |
| 122 | m_thread.DiscardThreadPlans(false); |
| 123 | return true; |
| 124 | |
| 125 | case eStopReasonSignal: |
Jim Ingham | 6297a3a | 2010-10-20 00:39:53 +0000 | [diff] [blame] | 126 | if (stop_info_sp->ShouldStop(event_ptr)) |
Greg Clayton | 643ee73 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 127 | { |
| 128 | m_thread.DiscardThreadPlans(false); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 129 | return true; |
Greg Clayton | 643ee73 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 130 | } |
| 131 | else |
| 132 | { |
| 133 | // We're not going to stop, but while we are here, let's figure out |
| 134 | // whether to report this. |
Jim Ingham | 6297a3a | 2010-10-20 00:39:53 +0000 | [diff] [blame] | 135 | if (stop_info_sp->ShouldNotify(event_ptr)) |
Greg Clayton | 643ee73 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 136 | m_stop_vote = eVoteYes; |
| 137 | else |
| 138 | m_stop_vote = eVoteNo; |
| 139 | } |
| 140 | return false; |
| 141 | |
| 142 | default: |
| 143 | return true; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | } |
Greg Clayton | 643ee73 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 147 | else |
| 148 | { |
| 149 | m_run_vote = eVoteNo; |
| 150 | m_stop_vote = eVoteNo; |
| 151 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 152 | |
| 153 | // If there's no explicit reason to stop, then we will continue. |
| 154 | return false; |
| 155 | } |
| 156 | |
| 157 | bool |
| 158 | ThreadPlanBase::StopOthers () |
| 159 | { |
| 160 | return false; |
| 161 | } |
| 162 | |
| 163 | StateType |
Jim Ingham | 745ac7a | 2010-11-11 19:26:09 +0000 | [diff] [blame^] | 164 | ThreadPlanBase::GetPlanRunState () |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 165 | { |
| 166 | return eStateRunning; |
| 167 | } |
| 168 | |
| 169 | bool |
| 170 | ThreadPlanBase::WillStop () |
| 171 | { |
| 172 | return true; |
| 173 | } |
| 174 | |
| 175 | // The base plan is never done. |
| 176 | bool |
| 177 | ThreadPlanBase::MischiefManaged () |
| 178 | { |
| 179 | // The base plan is never done. |
| 180 | return false; |
| 181 | } |
| 182 | |