Chris Lattner | 30fdc8d | 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 | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 21 | #include "lldb/Core/Log.h" |
Chris Lattner | 30fdc8d | 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 | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 25 | #include "lldb/Target/StopInfo.h" |
Chris Lattner | 30fdc8d | 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 | b01e742 | 2010-06-19 04:45:32 +0000 | [diff] [blame] | 37 | ThreadPlan(ThreadPlan::eKindBase, "base plan", thread, eVoteYes, eVoteNoOpinion) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 38 | { |
Jim Ingham | 06e827c | 2010-11-11 19:26:09 +0000 | [diff] [blame] | 39 | // Set the tracer to a default tracer. |
Jim Ingham | 773d981 | 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 | 06e827c | 2010-11-11 19:26:09 +0000 | [diff] [blame] | 46 | ThreadPlanTracerSP new_tracer_sp (new ThreadPlanTracer (m_thread)); |
Jim Ingham | 773d981 | 2010-11-18 02:47:07 +0000 | [diff] [blame] | 47 | #endif |
Jim Ingham | 06e827c | 2010-11-11 19:26:09 +0000 | [diff] [blame] | 48 | new_tracer_sp->EnableTracing (m_thread.GetTraceEnabledState()); |
| 49 | SetThreadPlanTracer(new_tracer_sp); |
Jim Ingham | cf274f9 | 2012-04-09 22:37:39 +0000 | [diff] [blame] | 50 | SetIsMasterPlan (true); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 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 |
Jim Ingham | 221d51c | 2013-05-08 00:35:16 +0000 | [diff] [blame] | 71 | ThreadPlanBase::DoPlanExplainsStop (Event *event_ptr) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 72 | { |
Jim Ingham | 06e827c | 2010-11-11 19:26:09 +0000 | [diff] [blame] | 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; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 79 | } |
| 80 | |
Jim Ingham | 221d51c | 2013-05-08 00:35:16 +0000 | [diff] [blame] | 81 | Vote |
| 82 | ThreadPlanBase::ShouldReportStop(Event *event_ptr) |
| 83 | { |
| 84 | StopInfoSP stop_info_sp = m_thread.GetStopInfo (); |
| 85 | if (stop_info_sp) |
| 86 | { |
| 87 | bool should_notify = stop_info_sp->ShouldNotify(event_ptr); |
| 88 | if (should_notify) |
| 89 | return eVoteYes; |
| 90 | else |
| 91 | return eVoteNoOpinion; |
| 92 | } |
| 93 | else |
| 94 | return eVoteNoOpinion; |
| 95 | } |
| 96 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 97 | bool |
| 98 | ThreadPlanBase::ShouldStop (Event *event_ptr) |
| 99 | { |
| 100 | m_stop_vote = eVoteYes; |
| 101 | m_run_vote = eVoteYes; |
| 102 | |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 103 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 104 | |
Jim Ingham | 60c4118 | 2013-06-04 01:40:51 +0000 | [diff] [blame] | 105 | StopInfoSP stop_info_sp = GetPrivateStopInfo (); |
Jim Ingham | b15bfc7 | 2010-10-20 00:39:53 +0000 | [diff] [blame] | 106 | if (stop_info_sp) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 107 | { |
Jim Ingham | 60c4118 | 2013-06-04 01:40:51 +0000 | [diff] [blame] | 108 | StopReason reason = stop_info_sp->GetStopReason (); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 109 | switch (reason) |
| 110 | { |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 111 | case eStopReasonInvalid: |
| 112 | case eStopReasonNone: |
Jim Ingham | 444586b | 2011-01-24 06:34:17 +0000 | [diff] [blame] | 113 | // This |
| 114 | m_run_vote = eVoteNoOpinion; |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 115 | m_stop_vote = eVoteNo; |
| 116 | return false; |
| 117 | |
| 118 | case eStopReasonBreakpoint: |
Johnny Chen | fd158f4 | 2011-09-21 22:47:15 +0000 | [diff] [blame] | 119 | case eStopReasonWatchpoint: |
Jim Ingham | 9b620f3 | 2013-02-22 21:23:43 +0000 | [diff] [blame] | 120 | if (stop_info_sp->ShouldStopSynchronous(event_ptr)) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 121 | { |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 122 | // If we are going to stop for a breakpoint, then unship the other plans |
| 123 | // at this point. Don't force the discard, however, so Master plans can stay |
| 124 | // in place if they want to. |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 125 | if (log) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 126 | log->Printf("Base plan discarding thread plans for thread tid = 0x%4.4" PRIx64 " (breakpoint hit.)", m_thread.GetID()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 127 | m_thread.DiscardThreadPlans(false); |
| 128 | return true; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 129 | } |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 130 | // If we aren't going to stop at this breakpoint, and it is internal, |
| 131 | // don't report this stop or the subsequent running event. |
| 132 | // Otherwise we will post the stopped & running, but the stopped event will get marked |
| 133 | // with "restarted" so the UI will know to wait and expect the consequent "running". |
Jim Ingham | b15bfc7 | 2010-10-20 00:39:53 +0000 | [diff] [blame] | 134 | if (stop_info_sp->ShouldNotify (event_ptr)) |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 135 | { |
| 136 | m_stop_vote = eVoteYes; |
| 137 | m_run_vote = eVoteYes; |
| 138 | } |
| 139 | else |
| 140 | { |
| 141 | m_stop_vote = eVoteNo; |
| 142 | m_run_vote = eVoteNo; |
| 143 | } |
| 144 | return false; |
| 145 | |
| 146 | // TODO: the break below was missing, was this intentional??? If so |
| 147 | // please mention it |
| 148 | break; |
| 149 | |
| 150 | case eStopReasonException: |
| 151 | // If we crashed, discard thread plans and stop. Don't force the discard, however, |
| 152 | // since on rerun the target may clean up this exception and continue normally from there. |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 153 | if (log) |
Greg Clayton | fdbad6d5 | 2014-02-27 19:35:12 +0000 | [diff] [blame] | 154 | log->Printf("Base plan discarding thread plans for thread tid = 0x%4.4" PRIx64 " (exception: %s)", m_thread.GetID(), stop_info_sp->GetDescription()); |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 155 | m_thread.DiscardThreadPlans(false); |
| 156 | return true; |
| 157 | |
Greg Clayton | 90ba811 | 2012-12-05 00:16:59 +0000 | [diff] [blame] | 158 | case eStopReasonExec: |
| 159 | // If we crashed, discard thread plans and stop. Don't force the discard, however, |
| 160 | // since on rerun the target may clean up this exception and continue normally from there. |
| 161 | if (log) |
| 162 | log->Printf("Base plan discarding thread plans for thread tid = 0x%4.4" PRIx64 " (exec.)", m_thread.GetID()); |
| 163 | m_thread.DiscardThreadPlans(false); |
| 164 | return true; |
Andrew Kaylor | f85defa | 2012-12-20 23:08:03 +0000 | [diff] [blame] | 165 | |
| 166 | case eStopReasonThreadExiting: |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 167 | case eStopReasonSignal: |
Jim Ingham | b15bfc7 | 2010-10-20 00:39:53 +0000 | [diff] [blame] | 168 | if (stop_info_sp->ShouldStop(event_ptr)) |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 169 | { |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 170 | if (log) |
Greg Clayton | fdbad6d5 | 2014-02-27 19:35:12 +0000 | [diff] [blame] | 171 | log->Printf("Base plan discarding thread plans for thread tid = 0x%4.4" PRIx64 " (signal: %s)", m_thread.GetID(), stop_info_sp->GetDescription()); |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 172 | m_thread.DiscardThreadPlans(false); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 173 | return true; |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 174 | } |
| 175 | else |
| 176 | { |
| 177 | // We're not going to stop, but while we are here, let's figure out |
| 178 | // whether to report this. |
Jim Ingham | b15bfc7 | 2010-10-20 00:39:53 +0000 | [diff] [blame] | 179 | if (stop_info_sp->ShouldNotify(event_ptr)) |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 180 | m_stop_vote = eVoteYes; |
| 181 | else |
| 182 | m_stop_vote = eVoteNo; |
| 183 | } |
| 184 | return false; |
| 185 | |
| 186 | default: |
| 187 | return true; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | } |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 191 | else |
| 192 | { |
Jim Ingham | 444586b | 2011-01-24 06:34:17 +0000 | [diff] [blame] | 193 | m_run_vote = eVoteNoOpinion; |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 194 | m_stop_vote = eVoteNo; |
| 195 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 196 | |
| 197 | // If there's no explicit reason to stop, then we will continue. |
| 198 | return false; |
| 199 | } |
| 200 | |
| 201 | bool |
| 202 | ThreadPlanBase::StopOthers () |
| 203 | { |
| 204 | return false; |
| 205 | } |
| 206 | |
| 207 | StateType |
Jim Ingham | 06e827c | 2010-11-11 19:26:09 +0000 | [diff] [blame] | 208 | ThreadPlanBase::GetPlanRunState () |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 209 | { |
| 210 | return eStateRunning; |
| 211 | } |
| 212 | |
| 213 | bool |
| 214 | ThreadPlanBase::WillStop () |
| 215 | { |
| 216 | return true; |
| 217 | } |
| 218 | |
Jim Ingham | 444586b | 2011-01-24 06:34:17 +0000 | [diff] [blame] | 219 | bool |
Jim Ingham | 221d51c | 2013-05-08 00:35:16 +0000 | [diff] [blame] | 220 | ThreadPlanBase::DoWillResume (lldb::StateType resume_state, bool current_plan) |
Jim Ingham | 444586b | 2011-01-24 06:34:17 +0000 | [diff] [blame] | 221 | { |
| 222 | // Reset these to the default values so we don't set them wrong, then not get asked |
| 223 | // for a while, then return the wrong answer. |
| 224 | m_run_vote = eVoteNoOpinion; |
| 225 | m_stop_vote = eVoteNo; |
| 226 | return true; |
| 227 | } |
| 228 | |
| 229 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 230 | // The base plan is never done. |
| 231 | bool |
| 232 | ThreadPlanBase::MischiefManaged () |
| 233 | { |
| 234 | // The base plan is never done. |
| 235 | return false; |
| 236 | } |
| 237 | |