blob: 7529991a7bdc72e6f36f45d0dd7b4fdbdb339873 [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);
Chris Lattner24943d22010-06-08 16:52:24 +000050}
51
52ThreadPlanBase::~ThreadPlanBase ()
53{
54
55}
56
57void
58ThreadPlanBase::GetDescription (Stream *s, lldb::DescriptionLevel level)
59{
60 s->Printf ("Base thread plan.");
61}
62
63bool
64ThreadPlanBase::ValidatePlan (Stream *error)
65{
66 return true;
67}
68
69bool
70ThreadPlanBase::PlanExplainsStop ()
71{
Jim Ingham745ac7a2010-11-11 19:26:09 +000072 // 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 Lattner24943d22010-06-08 16:52:24 +000078}
79
80bool
81ThreadPlanBase::ShouldStop (Event *event_ptr)
82{
83 m_stop_vote = eVoteYes;
84 m_run_vote = eVoteYes;
85
Jim Inghamf9f40c22011-02-08 05:20:59 +000086 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
87
Jim Ingham6297a3a2010-10-20 00:39:53 +000088 StopInfoSP stop_info_sp = GetPrivateStopReason();
89 if (stop_info_sp)
Chris Lattner24943d22010-06-08 16:52:24 +000090 {
Jim Ingham6297a3a2010-10-20 00:39:53 +000091 StopReason reason = stop_info_sp->GetStopReason();
Chris Lattner24943d22010-06-08 16:52:24 +000092 switch (reason)
93 {
Greg Clayton643ee732010-08-04 01:40:35 +000094 case eStopReasonInvalid:
95 case eStopReasonNone:
Jim Inghamac959662011-01-24 06:34:17 +000096 // This
97 m_run_vote = eVoteNoOpinion;
Greg Clayton643ee732010-08-04 01:40:35 +000098 m_stop_vote = eVoteNo;
99 return false;
100
101 case eStopReasonBreakpoint:
Jim Ingham6297a3a2010-10-20 00:39:53 +0000102 if (stop_info_sp->ShouldStop(event_ptr))
Chris Lattner24943d22010-06-08 16:52:24 +0000103 {
Greg Clayton643ee732010-08-04 01:40:35 +0000104 // 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 Inghamf9f40c22011-02-08 05:20:59 +0000107 if (log)
108 log->Printf("Base plan discarding thread plans for thread tid = 0x%4.4x (breakpoint hit.)", m_thread.GetID());
Chris Lattner24943d22010-06-08 16:52:24 +0000109 m_thread.DiscardThreadPlans(false);
110 return true;
Chris Lattner24943d22010-06-08 16:52:24 +0000111 }
Greg Clayton643ee732010-08-04 01:40:35 +0000112 // 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 Ingham6297a3a2010-10-20 00:39:53 +0000116 if (stop_info_sp->ShouldNotify (event_ptr))
Greg Clayton643ee732010-08-04 01:40:35 +0000117 {
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 Inghamf9f40c22011-02-08 05:20:59 +0000135 if (log)
136 log->Printf("Base plan discarding thread plans for thread tid = 0x%4.4x (exception.)", m_thread.GetID());
Greg Clayton643ee732010-08-04 01:40:35 +0000137 m_thread.DiscardThreadPlans(false);
138 return true;
139
140 case eStopReasonSignal:
Jim Ingham6297a3a2010-10-20 00:39:53 +0000141 if (stop_info_sp->ShouldStop(event_ptr))
Greg Clayton643ee732010-08-04 01:40:35 +0000142 {
Jim Inghamf9f40c22011-02-08 05:20:59 +0000143 if (log)
144 log->Printf("Base plan discarding thread plans for thread tid = 0x%4.4x (signal.)", m_thread.GetID());
Greg Clayton643ee732010-08-04 01:40:35 +0000145 m_thread.DiscardThreadPlans(false);
Chris Lattner24943d22010-06-08 16:52:24 +0000146 return true;
Greg Clayton643ee732010-08-04 01:40:35 +0000147 }
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 Ingham6297a3a2010-10-20 00:39:53 +0000152 if (stop_info_sp->ShouldNotify(event_ptr))
Greg Clayton643ee732010-08-04 01:40:35 +0000153 m_stop_vote = eVoteYes;
154 else
155 m_stop_vote = eVoteNo;
156 }
157 return false;
158
159 default:
160 return true;
Chris Lattner24943d22010-06-08 16:52:24 +0000161 }
162
163 }
Greg Clayton643ee732010-08-04 01:40:35 +0000164 else
165 {
Jim Inghamac959662011-01-24 06:34:17 +0000166 m_run_vote = eVoteNoOpinion;
Greg Clayton643ee732010-08-04 01:40:35 +0000167 m_stop_vote = eVoteNo;
168 }
Chris Lattner24943d22010-06-08 16:52:24 +0000169
170 // If there's no explicit reason to stop, then we will continue.
171 return false;
172}
173
174bool
175ThreadPlanBase::StopOthers ()
176{
177 return false;
178}
179
180StateType
Jim Ingham745ac7a2010-11-11 19:26:09 +0000181ThreadPlanBase::GetPlanRunState ()
Chris Lattner24943d22010-06-08 16:52:24 +0000182{
183 return eStateRunning;
184}
185
186bool
187ThreadPlanBase::WillStop ()
188{
189 return true;
190}
191
Jim Inghamac959662011-01-24 06:34:17 +0000192bool
193ThreadPlanBase::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 Lattner24943d22010-06-08 16:52:24 +0000203// The base plan is never done.
204bool
205ThreadPlanBase::MischiefManaged ()
206{
207 // The base plan is never done.
208 return false;
209}
210