blob: 55ef2f71551ee9f74a2b19a74b0ac1411c052f4c [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.
39 ThreadPlanTracerSP new_tracer_sp (new ThreadPlanTracer (m_thread));
40 new_tracer_sp->EnableTracing (m_thread.GetTraceEnabledState());
41 SetThreadPlanTracer(new_tracer_sp);
Chris Lattner24943d22010-06-08 16:52:24 +000042}
43
44ThreadPlanBase::~ThreadPlanBase ()
45{
46
47}
48
49void
50ThreadPlanBase::GetDescription (Stream *s, lldb::DescriptionLevel level)
51{
52 s->Printf ("Base thread plan.");
53}
54
55bool
56ThreadPlanBase::ValidatePlan (Stream *error)
57{
58 return true;
59}
60
61bool
62ThreadPlanBase::PlanExplainsStop ()
63{
Jim Ingham745ac7a2010-11-11 19:26:09 +000064 // The base plan should defer to its tracer, since by default it
65 // always handles the stop.
66 if (TracerExplainsStop())
67 return false;
68 else
69 return true;
Chris Lattner24943d22010-06-08 16:52:24 +000070}
71
72bool
73ThreadPlanBase::ShouldStop (Event *event_ptr)
74{
75 m_stop_vote = eVoteYes;
76 m_run_vote = eVoteYes;
77
Jim Ingham6297a3a2010-10-20 00:39:53 +000078 StopInfoSP stop_info_sp = GetPrivateStopReason();
79 if (stop_info_sp)
Chris Lattner24943d22010-06-08 16:52:24 +000080 {
Jim Ingham6297a3a2010-10-20 00:39:53 +000081 StopReason reason = stop_info_sp->GetStopReason();
Chris Lattner24943d22010-06-08 16:52:24 +000082 switch (reason)
83 {
Greg Clayton643ee732010-08-04 01:40:35 +000084 case eStopReasonInvalid:
85 case eStopReasonNone:
86 m_run_vote = eVoteNo;
87 m_stop_vote = eVoteNo;
88 return false;
89
90 case eStopReasonBreakpoint:
Jim Ingham6297a3a2010-10-20 00:39:53 +000091 if (stop_info_sp->ShouldStop(event_ptr))
Chris Lattner24943d22010-06-08 16:52:24 +000092 {
Greg Clayton643ee732010-08-04 01:40:35 +000093 // If we are going to stop for a breakpoint, then unship the other plans
94 // at this point. Don't force the discard, however, so Master plans can stay
95 // in place if they want to.
Chris Lattner24943d22010-06-08 16:52:24 +000096 m_thread.DiscardThreadPlans(false);
97 return true;
Chris Lattner24943d22010-06-08 16:52:24 +000098 }
Greg Clayton643ee732010-08-04 01:40:35 +000099 // If we aren't going to stop at this breakpoint, and it is internal,
100 // don't report this stop or the subsequent running event.
101 // Otherwise we will post the stopped & running, but the stopped event will get marked
102 // with "restarted" so the UI will know to wait and expect the consequent "running".
Jim Ingham6297a3a2010-10-20 00:39:53 +0000103 if (stop_info_sp->ShouldNotify (event_ptr))
Greg Clayton643ee732010-08-04 01:40:35 +0000104 {
105 m_stop_vote = eVoteYes;
106 m_run_vote = eVoteYes;
107 }
108 else
109 {
110 m_stop_vote = eVoteNo;
111 m_run_vote = eVoteNo;
112 }
113 return false;
114
115 // TODO: the break below was missing, was this intentional??? If so
116 // please mention it
117 break;
118
119 case eStopReasonException:
120 // If we crashed, discard thread plans and stop. Don't force the discard, however,
121 // since on rerun the target may clean up this exception and continue normally from there.
122 m_thread.DiscardThreadPlans(false);
123 return true;
124
125 case eStopReasonSignal:
Jim Ingham6297a3a2010-10-20 00:39:53 +0000126 if (stop_info_sp->ShouldStop(event_ptr))
Greg Clayton643ee732010-08-04 01:40:35 +0000127 {
128 m_thread.DiscardThreadPlans(false);
Chris Lattner24943d22010-06-08 16:52:24 +0000129 return true;
Greg Clayton643ee732010-08-04 01:40:35 +0000130 }
131 else
132 {
133 // We're not going to stop, but while we are here, let's figure out
134 // whether to report this.
Jim Ingham6297a3a2010-10-20 00:39:53 +0000135 if (stop_info_sp->ShouldNotify(event_ptr))
Greg Clayton643ee732010-08-04 01:40:35 +0000136 m_stop_vote = eVoteYes;
137 else
138 m_stop_vote = eVoteNo;
139 }
140 return false;
141
142 default:
143 return true;
Chris Lattner24943d22010-06-08 16:52:24 +0000144 }
145
146 }
Greg Clayton643ee732010-08-04 01:40:35 +0000147 else
148 {
149 m_run_vote = eVoteNo;
150 m_stop_vote = eVoteNo;
151 }
Chris Lattner24943d22010-06-08 16:52:24 +0000152
153 // If there's no explicit reason to stop, then we will continue.
154 return false;
155}
156
157bool
158ThreadPlanBase::StopOthers ()
159{
160 return false;
161}
162
163StateType
Jim Ingham745ac7a2010-11-11 19:26:09 +0000164ThreadPlanBase::GetPlanRunState ()
Chris Lattner24943d22010-06-08 16:52:24 +0000165{
166 return eStateRunning;
167}
168
169bool
170ThreadPlanBase::WillStop ()
171{
172 return true;
173}
174
175// The base plan is never done.
176bool
177ThreadPlanBase::MischiefManaged ()
178{
179 // The base plan is never done.
180 return false;
181}
182