blob: eceb383b38066b511bed08db3e26af942b9e2400 [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"
21#include "lldb/Core/Stream.h"
22#include "lldb/Target/Process.h"
23#include "lldb/Target/RegisterContext.h"
Greg Clayton643ee732010-08-04 01:40:35 +000024#include "lldb/Target/StopInfo.h"
Chris Lattner24943d22010-06-08 16:52:24 +000025
26using namespace lldb;
27using 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
35ThreadPlanBase::ThreadPlanBase (Thread &thread) :
Jim Ingham5a47e8b2010-06-19 04:45:32 +000036 ThreadPlan(ThreadPlan::eKindBase, "base plan", thread, eVoteYes, eVoteNoOpinion)
Chris Lattner24943d22010-06-08 16:52:24 +000037{
Jim Ingham745ac7a2010-11-11 19:26:09 +000038 // Set the tracer to a default tracer.
Jim Inghamcdea2362010-11-18 02:47:07 +000039 // FIXME: need to add a thread settings variable to pix various tracers...
40#define THREAD_PLAN_USE_ASSEMBLY_TRACER 1
41
42#ifdef THREAD_PLAN_USE_ASSEMBLY_TRACER
43 ThreadPlanTracerSP new_tracer_sp (new ThreadPlanAssemblyTracer (m_thread));
44#else
Jim Ingham745ac7a2010-11-11 19:26:09 +000045 ThreadPlanTracerSP new_tracer_sp (new ThreadPlanTracer (m_thread));
Jim Inghamcdea2362010-11-18 02:47:07 +000046#endif
Jim Ingham745ac7a2010-11-11 19:26:09 +000047 new_tracer_sp->EnableTracing (m_thread.GetTraceEnabledState());
48 SetThreadPlanTracer(new_tracer_sp);
Chris Lattner24943d22010-06-08 16:52:24 +000049}
50
51ThreadPlanBase::~ThreadPlanBase ()
52{
53
54}
55
56void
57ThreadPlanBase::GetDescription (Stream *s, lldb::DescriptionLevel level)
58{
59 s->Printf ("Base thread plan.");
60}
61
62bool
63ThreadPlanBase::ValidatePlan (Stream *error)
64{
65 return true;
66}
67
68bool
69ThreadPlanBase::PlanExplainsStop ()
70{
Jim Ingham745ac7a2010-11-11 19:26:09 +000071 // The base plan should defer to its tracer, since by default it
72 // always handles the stop.
73 if (TracerExplainsStop())
74 return false;
75 else
76 return true;
Chris Lattner24943d22010-06-08 16:52:24 +000077}
78
79bool
80ThreadPlanBase::ShouldStop (Event *event_ptr)
81{
82 m_stop_vote = eVoteYes;
83 m_run_vote = eVoteYes;
84
Jim Ingham6297a3a2010-10-20 00:39:53 +000085 StopInfoSP stop_info_sp = GetPrivateStopReason();
86 if (stop_info_sp)
Chris Lattner24943d22010-06-08 16:52:24 +000087 {
Jim Ingham6297a3a2010-10-20 00:39:53 +000088 StopReason reason = stop_info_sp->GetStopReason();
Chris Lattner24943d22010-06-08 16:52:24 +000089 switch (reason)
90 {
Greg Clayton643ee732010-08-04 01:40:35 +000091 case eStopReasonInvalid:
92 case eStopReasonNone:
93 m_run_vote = eVoteNo;
94 m_stop_vote = eVoteNo;
95 return false;
96
97 case eStopReasonBreakpoint:
Jim Ingham6297a3a2010-10-20 00:39:53 +000098 if (stop_info_sp->ShouldStop(event_ptr))
Chris Lattner24943d22010-06-08 16:52:24 +000099 {
Greg Clayton643ee732010-08-04 01:40:35 +0000100 // If we are going to stop for a breakpoint, then unship the other plans
101 // at this point. Don't force the discard, however, so Master plans can stay
102 // in place if they want to.
Chris Lattner24943d22010-06-08 16:52:24 +0000103 m_thread.DiscardThreadPlans(false);
104 return true;
Chris Lattner24943d22010-06-08 16:52:24 +0000105 }
Greg Clayton643ee732010-08-04 01:40:35 +0000106 // If we aren't going to stop at this breakpoint, and it is internal,
107 // don't report this stop or the subsequent running event.
108 // Otherwise we will post the stopped & running, but the stopped event will get marked
109 // with "restarted" so the UI will know to wait and expect the consequent "running".
Jim Ingham6297a3a2010-10-20 00:39:53 +0000110 if (stop_info_sp->ShouldNotify (event_ptr))
Greg Clayton643ee732010-08-04 01:40:35 +0000111 {
112 m_stop_vote = eVoteYes;
113 m_run_vote = eVoteYes;
114 }
115 else
116 {
117 m_stop_vote = eVoteNo;
118 m_run_vote = eVoteNo;
119 }
120 return false;
121
122 // TODO: the break below was missing, was this intentional??? If so
123 // please mention it
124 break;
125
126 case eStopReasonException:
127 // If we crashed, discard thread plans and stop. Don't force the discard, however,
128 // since on rerun the target may clean up this exception and continue normally from there.
129 m_thread.DiscardThreadPlans(false);
130 return true;
131
132 case eStopReasonSignal:
Jim Ingham6297a3a2010-10-20 00:39:53 +0000133 if (stop_info_sp->ShouldStop(event_ptr))
Greg Clayton643ee732010-08-04 01:40:35 +0000134 {
135 m_thread.DiscardThreadPlans(false);
Chris Lattner24943d22010-06-08 16:52:24 +0000136 return true;
Greg Clayton643ee732010-08-04 01:40:35 +0000137 }
138 else
139 {
140 // We're not going to stop, but while we are here, let's figure out
141 // whether to report this.
Jim Ingham6297a3a2010-10-20 00:39:53 +0000142 if (stop_info_sp->ShouldNotify(event_ptr))
Greg Clayton643ee732010-08-04 01:40:35 +0000143 m_stop_vote = eVoteYes;
144 else
145 m_stop_vote = eVoteNo;
146 }
147 return false;
148
149 default:
150 return true;
Chris Lattner24943d22010-06-08 16:52:24 +0000151 }
152
153 }
Greg Clayton643ee732010-08-04 01:40:35 +0000154 else
155 {
156 m_run_vote = eVoteNo;
157 m_stop_vote = eVoteNo;
158 }
Chris Lattner24943d22010-06-08 16:52:24 +0000159
160 // If there's no explicit reason to stop, then we will continue.
161 return false;
162}
163
164bool
165ThreadPlanBase::StopOthers ()
166{
167 return false;
168}
169
170StateType
Jim Ingham745ac7a2010-11-11 19:26:09 +0000171ThreadPlanBase::GetPlanRunState ()
Chris Lattner24943d22010-06-08 16:52:24 +0000172{
173 return eStateRunning;
174}
175
176bool
177ThreadPlanBase::WillStop ()
178{
179 return true;
180}
181
182// The base plan is never done.
183bool
184ThreadPlanBase::MischiefManaged ()
185{
186 // The base plan is never done.
187 return false;
188}
189