1 //===-- 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"
24 #include "lldb/Target/StopInfo.h"
25 
26 using namespace lldb;
27 using 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 
35 ThreadPlanBase::ThreadPlanBase (Thread &thread) :
36     ThreadPlan(ThreadPlan::eKindBase, "base plan", thread, eVoteYes, eVoteNoOpinion)
37 {
38 
39 }
40 
41 ThreadPlanBase::~ThreadPlanBase ()
42 {
43 
44 }
45 
46 void
47 ThreadPlanBase::GetDescription (Stream *s, lldb::DescriptionLevel level)
48 {
49     s->Printf ("Base thread plan.");
50 }
51 
52 bool
53 ThreadPlanBase::ValidatePlan (Stream *error)
54 {
55     return true;
56 }
57 
58 bool
59 ThreadPlanBase::PlanExplainsStop ()
60 {
61     return true;
62 }
63 
64 bool
65 ThreadPlanBase::ShouldStop (Event *event_ptr)
66 {
67     m_stop_vote = eVoteYes;
68     m_run_vote = eVoteYes;
69 
70     StopInfoSP stop_info_sp = GetPrivateStopReason();
71     if (stop_info_sp)
72     {
73         StopReason reason = stop_info_sp->GetStopReason();
74         switch (reason)
75         {
76         case eStopReasonInvalid:
77         case eStopReasonNone:
78             m_run_vote = eVoteNo;
79             m_stop_vote = eVoteNo;
80             return false;
81 
82         case eStopReasonBreakpoint:
83             if (stop_info_sp->ShouldStop(event_ptr))
84             {
85                 // If we are going to stop for a breakpoint, then unship the other plans
86                 // at this point.  Don't force the discard, however, so Master plans can stay
87                 // in place if they want to.
88                 m_thread.DiscardThreadPlans(false);
89                 return true;
90             }
91             // If we aren't going to stop at this breakpoint, and it is internal,
92             // don't report this stop or the subsequent running event.
93             // Otherwise we will post the stopped & running, but the stopped event will get marked
94             // with "restarted" so the UI will know to wait and expect the consequent "running".
95             if (stop_info_sp->ShouldNotify (event_ptr))
96             {
97                 m_stop_vote = eVoteYes;
98                 m_run_vote = eVoteYes;
99             }
100             else
101             {
102                 m_stop_vote = eVoteNo;
103                 m_run_vote = eVoteNo;
104             }
105             return false;
106 
107             // TODO: the break below was missing, was this intentional??? If so
108             // please mention it
109             break;
110 
111         case eStopReasonException:
112             // If we crashed, discard thread plans and stop.  Don't force the discard, however,
113             // since on rerun the target may clean up this exception and continue normally from there.
114             m_thread.DiscardThreadPlans(false);
115             return true;
116 
117         case eStopReasonSignal:
118             if (stop_info_sp->ShouldStop(event_ptr))
119             {
120                 m_thread.DiscardThreadPlans(false);
121                 return true;
122             }
123             else
124             {
125                 // We're not going to stop, but while we are here, let's figure out
126                 // whether to report this.
127                  if (stop_info_sp->ShouldNotify(event_ptr))
128                     m_stop_vote = eVoteYes;
129                 else
130                     m_stop_vote = eVoteNo;
131             }
132             return false;
133 
134         default:
135             return true;
136         }
137 
138     }
139     else
140     {
141         m_run_vote = eVoteNo;
142         m_stop_vote = eVoteNo;
143     }
144 
145     // If there's no explicit reason to stop, then we will continue.
146     return false;
147 }
148 
149 bool
150 ThreadPlanBase::StopOthers ()
151 {
152     return false;
153 }
154 
155 StateType
156 ThreadPlanBase::RunState ()
157 {
158     return eStateRunning;
159 }
160 
161 bool
162 ThreadPlanBase::WillStop ()
163 {
164     return true;
165 }
166 
167 // The base plan is never done.
168 bool
169 ThreadPlanBase::MischiefManaged ()
170 {
171     // The base plan is never done.
172     return false;
173 }
174 
175