blob: b83306cb62a8c7cc5ece0441b9effeb10d7e9ab0 [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:
Jim Inghamac959662011-01-24 06:34:17 +000093 // This
94 m_run_vote = eVoteNoOpinion;
Greg Clayton643ee732010-08-04 01:40:35 +000095 m_stop_vote = eVoteNo;
96 return false;
97
98 case eStopReasonBreakpoint:
Jim Ingham6297a3a2010-10-20 00:39:53 +000099 if (stop_info_sp->ShouldStop(event_ptr))
Chris Lattner24943d22010-06-08 16:52:24 +0000100 {
Greg Clayton643ee732010-08-04 01:40:35 +0000101 // If we are going to stop for a breakpoint, then unship the other plans
102 // at this point. Don't force the discard, however, so Master plans can stay
103 // in place if they want to.
Chris Lattner24943d22010-06-08 16:52:24 +0000104 m_thread.DiscardThreadPlans(false);
105 return true;
Chris Lattner24943d22010-06-08 16:52:24 +0000106 }
Greg Clayton643ee732010-08-04 01:40:35 +0000107 // If we aren't going to stop at this breakpoint, and it is internal,
108 // don't report this stop or the subsequent running event.
109 // Otherwise we will post the stopped & running, but the stopped event will get marked
110 // with "restarted" so the UI will know to wait and expect the consequent "running".
Jim Ingham6297a3a2010-10-20 00:39:53 +0000111 if (stop_info_sp->ShouldNotify (event_ptr))
Greg Clayton643ee732010-08-04 01:40:35 +0000112 {
113 m_stop_vote = eVoteYes;
114 m_run_vote = eVoteYes;
115 }
116 else
117 {
118 m_stop_vote = eVoteNo;
119 m_run_vote = eVoteNo;
120 }
121 return false;
122
123 // TODO: the break below was missing, was this intentional??? If so
124 // please mention it
125 break;
126
127 case eStopReasonException:
128 // If we crashed, discard thread plans and stop. Don't force the discard, however,
129 // since on rerun the target may clean up this exception and continue normally from there.
130 m_thread.DiscardThreadPlans(false);
131 return true;
132
133 case eStopReasonSignal:
Jim Ingham6297a3a2010-10-20 00:39:53 +0000134 if (stop_info_sp->ShouldStop(event_ptr))
Greg Clayton643ee732010-08-04 01:40:35 +0000135 {
136 m_thread.DiscardThreadPlans(false);
Chris Lattner24943d22010-06-08 16:52:24 +0000137 return true;
Greg Clayton643ee732010-08-04 01:40:35 +0000138 }
139 else
140 {
141 // We're not going to stop, but while we are here, let's figure out
142 // whether to report this.
Jim Ingham6297a3a2010-10-20 00:39:53 +0000143 if (stop_info_sp->ShouldNotify(event_ptr))
Greg Clayton643ee732010-08-04 01:40:35 +0000144 m_stop_vote = eVoteYes;
145 else
146 m_stop_vote = eVoteNo;
147 }
148 return false;
149
150 default:
151 return true;
Chris Lattner24943d22010-06-08 16:52:24 +0000152 }
153
154 }
Greg Clayton643ee732010-08-04 01:40:35 +0000155 else
156 {
Jim Inghamac959662011-01-24 06:34:17 +0000157 m_run_vote = eVoteNoOpinion;
Greg Clayton643ee732010-08-04 01:40:35 +0000158 m_stop_vote = eVoteNo;
159 }
Chris Lattner24943d22010-06-08 16:52:24 +0000160
161 // If there's no explicit reason to stop, then we will continue.
162 return false;
163}
164
165bool
166ThreadPlanBase::StopOthers ()
167{
168 return false;
169}
170
171StateType
Jim Ingham745ac7a2010-11-11 19:26:09 +0000172ThreadPlanBase::GetPlanRunState ()
Chris Lattner24943d22010-06-08 16:52:24 +0000173{
174 return eStateRunning;
175}
176
177bool
178ThreadPlanBase::WillStop ()
179{
180 return true;
181}
182
Jim Inghamac959662011-01-24 06:34:17 +0000183bool
184ThreadPlanBase::WillResume (lldb::StateType resume_state, bool current_plan)
185{
186 // Reset these to the default values so we don't set them wrong, then not get asked
187 // for a while, then return the wrong answer.
188 m_run_vote = eVoteNoOpinion;
189 m_stop_vote = eVoteNo;
190 return true;
191}
192
193
Chris Lattner24943d22010-06-08 16:52:24 +0000194// The base plan is never done.
195bool
196ThreadPlanBase::MischiefManaged ()
197{
198 // The base plan is never done.
199 return false;
200}
201