blob: ebf468603cf71df0039ad31fb28e2a78de70d64f [file] [log] [blame]
Chris Lattner24943d22010-06-08 16:52:24 +00001//===-- 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 Inghamf9f40c22011-02-08 05:20:59 +000021#include "lldb/Core/Log.h"
Chris Lattner24943d22010-06-08 16:52:24 +000022#include "lldb/Core/Stream.h"
23#include "lldb/Target/Process.h"
24#include "lldb/Target/RegisterContext.h"
Greg Clayton643ee732010-08-04 01:40:35 +000025#include "lldb/Target/StopInfo.h"
Chris Lattner24943d22010-06-08 16:52:24 +000026
27using namespace lldb;
28using 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
36ThreadPlanBase::ThreadPlanBase (Thread &thread) :
Jim Ingham5a47e8b2010-06-19 04:45:32 +000037 ThreadPlan(ThreadPlan::eKindBase, "base plan", thread, eVoteYes, eVoteNoOpinion)
Chris Lattner24943d22010-06-08 16:52:24 +000038{
Jim Ingham745ac7a2010-11-11 19:26:09 +000039 // Set the tracer to a default tracer.
Jim Inghamcdea2362010-11-18 02:47:07 +000040 // 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 Ingham745ac7a2010-11-11 19:26:09 +000046 ThreadPlanTracerSP new_tracer_sp (new ThreadPlanTracer (m_thread));
Jim Inghamcdea2362010-11-18 02:47:07 +000047#endif
Jim Ingham745ac7a2010-11-11 19:26:09 +000048 new_tracer_sp->EnableTracing (m_thread.GetTraceEnabledState());
49 SetThreadPlanTracer(new_tracer_sp);
Jim Ingham2bcbaf62012-04-09 22:37:39 +000050 SetIsMasterPlan (true);
Chris Lattner24943d22010-06-08 16:52:24 +000051}
52
53ThreadPlanBase::~ThreadPlanBase ()
54{
55
56}
57
58void
59ThreadPlanBase::GetDescription (Stream *s, lldb::DescriptionLevel level)
60{
61 s->Printf ("Base thread plan.");
62}
63
64bool
65ThreadPlanBase::ValidatePlan (Stream *error)
66{
67 return true;
68}
69
70bool
71ThreadPlanBase::PlanExplainsStop ()
72{
Jim Ingham745ac7a2010-11-11 19:26:09 +000073 // 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 Lattner24943d22010-06-08 16:52:24 +000079}
80
81bool
82ThreadPlanBase::ShouldStop (Event *event_ptr)
83{
84 m_stop_vote = eVoteYes;
85 m_run_vote = eVoteYes;
86
Jim Inghamf9f40c22011-02-08 05:20:59 +000087 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
88
Jim Ingham6297a3a2010-10-20 00:39:53 +000089 StopInfoSP stop_info_sp = GetPrivateStopReason();
90 if (stop_info_sp)
Chris Lattner24943d22010-06-08 16:52:24 +000091 {
Jim Ingham6297a3a2010-10-20 00:39:53 +000092 StopReason reason = stop_info_sp->GetStopReason();
Chris Lattner24943d22010-06-08 16:52:24 +000093 switch (reason)
94 {
Greg Clayton643ee732010-08-04 01:40:35 +000095 case eStopReasonInvalid:
96 case eStopReasonNone:
Jim Inghamac959662011-01-24 06:34:17 +000097 // This
98 m_run_vote = eVoteNoOpinion;
Greg Clayton643ee732010-08-04 01:40:35 +000099 m_stop_vote = eVoteNo;
100 return false;
101
102 case eStopReasonBreakpoint:
Johnny Chen043f8c22011-09-21 22:47:15 +0000103 case eStopReasonWatchpoint:
Jim Ingham6297a3a2010-10-20 00:39:53 +0000104 if (stop_info_sp->ShouldStop(event_ptr))
Chris Lattner24943d22010-06-08 16:52:24 +0000105 {
Greg Clayton643ee732010-08-04 01:40:35 +0000106 // If we are going to stop for a breakpoint, then unship the other plans
107 // at this point. Don't force the discard, however, so Master plans can stay
108 // in place if they want to.
Jim Inghamf9f40c22011-02-08 05:20:59 +0000109 if (log)
Daniel Malea5f35a4b2012-11-29 21:49:15 +0000110 log->Printf("Base plan discarding thread plans for thread tid = 0x%4.4" PRIx64 " (breakpoint hit.)", m_thread.GetID());
Chris Lattner24943d22010-06-08 16:52:24 +0000111 m_thread.DiscardThreadPlans(false);
112 return true;
Chris Lattner24943d22010-06-08 16:52:24 +0000113 }
Greg Clayton643ee732010-08-04 01:40:35 +0000114 // If we aren't going to stop at this breakpoint, and it is internal,
115 // don't report this stop or the subsequent running event.
116 // Otherwise we will post the stopped & running, but the stopped event will get marked
117 // with "restarted" so the UI will know to wait and expect the consequent "running".
Jim Ingham6297a3a2010-10-20 00:39:53 +0000118 if (stop_info_sp->ShouldNotify (event_ptr))
Greg Clayton643ee732010-08-04 01:40:35 +0000119 {
120 m_stop_vote = eVoteYes;
121 m_run_vote = eVoteYes;
122 }
123 else
124 {
125 m_stop_vote = eVoteNo;
126 m_run_vote = eVoteNo;
127 }
128 return false;
129
130 // TODO: the break below was missing, was this intentional??? If so
131 // please mention it
132 break;
133
134 case eStopReasonException:
135 // If we crashed, discard thread plans and stop. Don't force the discard, however,
136 // since on rerun the target may clean up this exception and continue normally from there.
Jim Inghamf9f40c22011-02-08 05:20:59 +0000137 if (log)
Daniel Malea5f35a4b2012-11-29 21:49:15 +0000138 log->Printf("Base plan discarding thread plans for thread tid = 0x%4.4" PRIx64 " (exception.)", m_thread.GetID());
Greg Clayton643ee732010-08-04 01:40:35 +0000139 m_thread.DiscardThreadPlans(false);
140 return true;
141
Greg Clayton0bce9a22012-12-05 00:16:59 +0000142 case eStopReasonExec:
143 // If we crashed, discard thread plans and stop. Don't force the discard, however,
144 // since on rerun the target may clean up this exception and continue normally from there.
145 if (log)
146 log->Printf("Base plan discarding thread plans for thread tid = 0x%4.4" PRIx64 " (exec.)", m_thread.GetID());
147 m_thread.DiscardThreadPlans(false);
148 return true;
149
Greg Clayton643ee732010-08-04 01:40:35 +0000150 case eStopReasonSignal:
Jim Ingham6297a3a2010-10-20 00:39:53 +0000151 if (stop_info_sp->ShouldStop(event_ptr))
Greg Clayton643ee732010-08-04 01:40:35 +0000152 {
Jim Inghamf9f40c22011-02-08 05:20:59 +0000153 if (log)
Daniel Malea5f35a4b2012-11-29 21:49:15 +0000154 log->Printf("Base plan discarding thread plans for thread tid = 0x%4.4" PRIx64 " (signal.)", m_thread.GetID());
Greg Clayton643ee732010-08-04 01:40:35 +0000155 m_thread.DiscardThreadPlans(false);
Chris Lattner24943d22010-06-08 16:52:24 +0000156 return true;
Greg Clayton643ee732010-08-04 01:40:35 +0000157 }
158 else
159 {
160 // We're not going to stop, but while we are here, let's figure out
161 // whether to report this.
Jim Ingham6297a3a2010-10-20 00:39:53 +0000162 if (stop_info_sp->ShouldNotify(event_ptr))
Greg Clayton643ee732010-08-04 01:40:35 +0000163 m_stop_vote = eVoteYes;
164 else
165 m_stop_vote = eVoteNo;
166 }
167 return false;
168
169 default:
170 return true;
Chris Lattner24943d22010-06-08 16:52:24 +0000171 }
172
173 }
Greg Clayton643ee732010-08-04 01:40:35 +0000174 else
175 {
Jim Inghamac959662011-01-24 06:34:17 +0000176 m_run_vote = eVoteNoOpinion;
Greg Clayton643ee732010-08-04 01:40:35 +0000177 m_stop_vote = eVoteNo;
178 }
Chris Lattner24943d22010-06-08 16:52:24 +0000179
180 // If there's no explicit reason to stop, then we will continue.
181 return false;
182}
183
184bool
185ThreadPlanBase::StopOthers ()
186{
187 return false;
188}
189
190StateType
Jim Ingham745ac7a2010-11-11 19:26:09 +0000191ThreadPlanBase::GetPlanRunState ()
Chris Lattner24943d22010-06-08 16:52:24 +0000192{
193 return eStateRunning;
194}
195
196bool
197ThreadPlanBase::WillStop ()
198{
199 return true;
200}
201
Jim Inghamac959662011-01-24 06:34:17 +0000202bool
203ThreadPlanBase::WillResume (lldb::StateType resume_state, bool current_plan)
204{
205 // Reset these to the default values so we don't set them wrong, then not get asked
206 // for a while, then return the wrong answer.
207 m_run_vote = eVoteNoOpinion;
208 m_stop_vote = eVoteNo;
209 return true;
210}
211
212
Chris Lattner24943d22010-06-08 16:52:24 +0000213// The base plan is never done.
214bool
215ThreadPlanBase::MischiefManaged ()
216{
217 // The base plan is never done.
218 return false;
219}
220