• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===-- ThreadPlan.h --------------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLDB_TARGET_THREADPLAN_H
10 #define LLDB_TARGET_THREADPLAN_H
11 
12 #include <mutex>
13 #include <string>
14 
15 #include "lldb/Target/Process.h"
16 #include "lldb/Target/StopInfo.h"
17 #include "lldb/Target/Target.h"
18 #include "lldb/Target/Thread.h"
19 #include "lldb/Target/ThreadPlanTracer.h"
20 #include "lldb/Utility/UserID.h"
21 #include "lldb/lldb-private.h"
22 
23 namespace lldb_private {
24 
25 //  ThreadPlan:
26 //
27 //  This is the pure virtual base class for thread plans.
28 //
29 //  The thread plans provide the "atoms" of behavior that all the logical
30 //  process control, either directly from commands or through more complex
31 //  composite plans will rely on.
32 //
33 //  Plan Stack:
34 //
35 //  The thread maintaining a thread plan stack, and you program the actions of
36 //  a particular thread by pushing plans onto the plan stack.  There is always
37 //  a "Current" plan, which is the top of the plan stack, though in some cases
38 //  a plan may defer to plans higher in the stack for some piece of information
39 //  (let us define that the plan stack grows downwards).
40 //
41 //  The plan stack is never empty, there is always a Base Plan which persists
42 //  through the life of the running process.
43 //
44 //
45 //  Creating Plans:
46 //
47 //  The thread plan is generally created and added to the plan stack through
48 //  the QueueThreadPlanFor... API in lldb::Thread.  Those API's will return the
49 //  plan that performs the named operation in a manner appropriate for the
50 //  current process.  The plans in lldb/source/Target are generic
51 //  implementations, but a Process plugin can override them.
52 //
53 //  ValidatePlan is then called.  If it returns false, the plan is unshipped.
54 //  This is a little convenience which keeps us from having to error out of the
55 //  constructor.
56 //
57 //  Then the plan is added to the plan stack.  When the plan is added to the
58 //  plan stack its DidPush will get called.  This is useful if a plan wants to
59 //  push any additional plans as it is constructed, since you need to make sure
60 //  you're already on the stack before you push additional plans.
61 //
62 //  Completed Plans:
63 //
64 //  When the target process stops the plans are queried, among other things,
65 //  for whether their job is done.  If it is they are moved from the plan stack
66 //  to the Completed Plan stack in reverse order from their position on the
67 //  plan stack (since multiple plans may be done at a given stop.)  This is
68 //  used primarily so that the lldb::Thread::StopInfo for the thread can be set
69 //  properly.  If one plan pushes another to achieve part of its job, but it
70 //  doesn't want that sub-plan to be the one that sets the StopInfo, then call
71 //  SetPrivate on the sub-plan when you create it, and the Thread will pass
72 //  over that plan in reporting the reason for the stop.
73 //
74 //  Discarded plans:
75 //
76 //  Your plan may also get discarded, i.e. moved from the plan stack to the
77 //  "discarded plan stack".  This can happen, for instance, if the plan is
78 //  calling a function and the function call crashes and you want to unwind the
79 //  attempt to call.  So don't assume that your plan will always successfully
80 //  stop.  Which leads to:
81 //
82 //  Cleaning up after your plans:
83 //
84 //  When the plan is moved from the plan stack its WillPop method is always
85 //  called, no matter why.  Once it is moved off the plan stack it is done, and
86 //  won't get a chance to run again.  So you should undo anything that affects
87 //  target state in this method.  But be sure to leave the plan able to
88 //  correctly fill the StopInfo, however.  N.B. Don't wait to do clean up
89 //  target state till the destructor, since that will usually get called when
90 //  the target resumes, and you want to leave the target state correct for new
91 //  plans in the time between when your plan gets unshipped and the next
92 //  resume.
93 //
94 //  Thread State Checkpoint:
95 //
96 //  Note that calling functions on target process (ThreadPlanCallFunction)
97 //  changes current thread state. The function can be called either by direct
98 //  user demand or internally, for example lldb allocates memory on device to
99 //  calculate breakpoint condition expression - on Linux it is performed by
100 //  calling mmap on device.  ThreadStateCheckpoint saves Thread state (stop
101 //  info and completed plan stack) to restore it after completing function
102 //  call.
103 //
104 //  Over the lifetime of the plan, various methods of the ThreadPlan are then
105 //  called in response to changes of state in the process we are debugging as
106 //  follows:
107 //
108 //  Resuming:
109 //
110 //  When the target process is about to be restarted, the plan's WillResume
111 //  method is called, giving the plan a chance to prepare for the run.  If
112 //  WillResume returns false, then the process is not restarted.  Be sure to
113 //  set an appropriate error value in the Process if you have to do this.
114 //  Note, ThreadPlans actually implement DoWillResume, WillResume wraps that
115 //  call.
116 //
117 //  Next the "StopOthers" method of all the threads are polled, and if one
118 //  thread's Current plan returns "true" then only that thread gets to run.  If
119 //  more than one returns "true" the threads that want to run solo get run one
120 //  by one round robin fashion.  Otherwise all are let to run.
121 //
122 //  Note, the way StopOthers is implemented, the base class implementation just
123 //  asks the previous plan.  So if your plan has no opinion about whether it
124 //  should run stopping others or not, just don't implement StopOthers, and the
125 //  parent will be asked.
126 //
127 //  Finally, for each thread that is running, it run state is set to the return
128 //  of RunState from the thread's Current plan.
129 //
130 //  Responding to a stop:
131 //
132 //  When the target process stops, the plan is called in the following stages:
133 //
134 //  First the thread asks the Current Plan if it can handle this stop by
135 //  calling PlanExplainsStop.  If the Current plan answers "true" then it is
136 //  asked if the stop should percolate all the way to the user by calling the
137 //  ShouldStop method.  If the current plan doesn't explain the stop, then we
138 //  query up the plan stack for a plan that does explain the stop.  The plan
139 //  that does explain the stop then needs to figure out what to do about the
140 //  plans below it in the stack.  If the stop is recoverable, then the plan
141 //  that understands it can just do what it needs to set up to restart, and
142 //  then continue.  Otherwise, the plan that understood the stop should call
143 //  DiscardPlanStack to clean up the stack below it.  Note, plans actually
144 //  implement DoPlanExplainsStop, the result is cached in PlanExplainsStop so
145 //  the DoPlanExplainsStop itself will only get called once per stop.
146 //
147 //  Master plans:
148 //
149 //  In the normal case, when we decide to stop, we will  collapse the plan
150 //  stack up to the point of the plan that understood the stop reason.
151 //  However, if a plan wishes to stay on the stack after an event it didn't
152 //  directly handle it can designate itself a "Master" plan by responding true
153 //  to IsMasterPlan, and then if it wants not to be discarded, it can return
154 //  false to OkayToDiscard, and it and all its dependent plans will be
155 //  preserved when we resume execution.
156 //
157 //  The other effect of being a master plan is that when the Master plan is
158 //  done , if it has set "OkayToDiscard" to false, then it will be popped &
159 //  execution will stop and return to the user.  Remember that if OkayToDiscard
160 //  is false, the plan will be popped and control will be given to the next
161 //  plan above it on the stack  So setting OkayToDiscard to false means the
162 //  user will regain control when the MasterPlan is completed.
163 //
164 //  Between these two controls this allows things like: a
165 //  MasterPlan/DontDiscard Step Over to hit a breakpoint, stop and return
166 //  control to the user, but then when the user continues, the step out
167 //  succeeds.  Even more tricky, when the breakpoint is hit, the user can
168 //  continue to step in/step over/etc, and finally when they continue, they
169 //  will finish up the Step Over.
170 //
171 //  FIXME: MasterPlan & OkayToDiscard aren't really orthogonal.  MasterPlan
172 //  designation means that this plan controls it's fate and the fate of plans
173 //  below it.  OkayToDiscard tells whether the MasterPlan wants to stay on the
174 //  stack.  I originally thought "MasterPlan-ness" would need to be a fixed
175 //  characteristic of a ThreadPlan, in which case you needed the extra control.
176 //  But that doesn't seem to be true.  So we should be able to convert to only
177 //  MasterPlan status to mean the current "MasterPlan/DontDiscard".  Then no
178 //  plans would be MasterPlans by default, and you would set the ones you
179 //  wanted to be "user level" in this way.
180 //
181 //
182 //  Actually Stopping:
183 //
184 //  If a plan says responds "true" to ShouldStop, then it is asked if it's job
185 //  is complete by calling MischiefManaged.  If that returns true, the plan is
186 //  popped from the plan stack and added to the Completed Plan Stack.  Then the
187 //  next plan in the stack is asked if it ShouldStop, and  it returns "true",
188 //  it is asked if it is done, and if yes popped, and so on till we reach a
189 //  plan that is not done.
190 //
191 //  Since you often know in the ShouldStop method whether your plan is
192 //  complete, as a convenience you can call SetPlanComplete and the ThreadPlan
193 //  implementation of MischiefManaged will return "true", without your having
194 //  to redo the calculation when your sub-classes MischiefManaged is called.
195 //  If you call SetPlanComplete, you can later use IsPlanComplete to determine
196 //  whether the plan is complete.  This is only a convenience for sub-classes,
197 //  the logic in lldb::Thread will only call MischiefManaged.
198 //
199 //  One slightly tricky point is you have to be careful using SetPlanComplete
200 //  in PlanExplainsStop because you are not guaranteed that PlanExplainsStop
201 //  for a plan will get called before ShouldStop gets called.  If your sub-plan
202 //  explained the stop and then popped itself, only your ShouldStop will get
203 //  called.
204 //
205 //  If ShouldStop for any thread returns "true", then the WillStop method of
206 //  the Current plan of all threads will be called, the stop event is placed on
207 //  the Process's public broadcaster, and control returns to the upper layers
208 //  of the debugger.
209 //
210 //  Reporting the stop:
211 //
212 //  When the process stops, the thread is given a StopReason, in the form of a
213 //  StopInfo object.  If there is a completed plan corresponding to the stop,
214 //  then the "actual" stop reason can be suppressed, and instead a
215 //  StopInfoThreadPlan object will be cons'ed up from the top completed plan in
216 //  the stack.  However, if the plan doesn't want to be the stop reason, then
217 //  it can call SetPlanComplete and pass in "false" for the "success"
218 //  parameter.  In that case, the real stop reason will be used instead.  One
219 //  example of this is the "StepRangeStepIn" thread plan.  If it stops because
220 //  of a crash or breakpoint hit, it wants to unship itself, because it isn't
221 //  so useful to have step in keep going after a breakpoint hit.  But it can't
222 //  be the reason for the stop or no-one would see that they had hit a
223 //  breakpoint.
224 //
225 //  Cleaning up the plan stack:
226 //
227 //  One of the complications of MasterPlans is that you may get past the limits
228 //  of a plan without triggering it to clean itself up.  For instance, if you
229 //  are doing a MasterPlan StepOver, and hit a breakpoint in a called function,
230 //  then step over enough times to step out of the initial StepOver range, each
231 //  of the step overs will explain the stop & take themselves off the stack,
232 //  but control would never be returned to the original StepOver.  Eventually,
233 //  the user will continue, and when that continue stops, the old stale
234 //  StepOver plan that was left on the stack will get woken up and notice it is
235 //  done. But that can leave junk on the stack for a while.  To avoid that, the
236 //  plans implement a "IsPlanStale" method, that can check whether it is
237 //  relevant anymore.  On stop, after the regular plan negotiation, the
238 //  remaining plan stack is consulted and if any plan says it is stale, it and
239 //  the plans below it are discarded from the stack.
240 //
241 //  Automatically Resuming:
242 //
243 //  If ShouldStop for all threads returns "false", then the target process will
244 //  resume.  This then cycles back to Resuming above.
245 //
246 //  Reporting eStateStopped events when the target is restarted:
247 //
248 //  If a plan decides to auto-continue the target by returning "false" from
249 //  ShouldStop, then it will be asked whether the Stopped event should still be
250 //  reported.  For instance, if you hit a breakpoint that is a User set
251 //  breakpoint, but the breakpoint callback said to continue the target
252 //  process, you might still want to inform the upper layers of lldb that the
253 //  stop had happened.  The way this works is every thread gets to vote on
254 //  whether to report the stop.  If all votes are eVoteNoOpinion, then the
255 //  thread list will decide what to do (at present it will pretty much always
256 //  suppress these stopped events.) If there is an eVoteYes, then the event
257 //  will be reported regardless of the other votes.  If there is an eVoteNo and
258 //  no eVoteYes's, then the event won't be reported.
259 //
260 //  One other little detail here, sometimes a plan will push another plan onto
261 //  the plan stack to do some part of the first plan's job, and it would be
262 //  convenient to tell that plan how it should respond to ShouldReportStop.
263 //  You can do that by setting the stop_vote in the child plan when you create
264 //  it.
265 //
266 //  Suppressing the initial eStateRunning event:
267 //
268 //  The private process running thread will take care of ensuring that only one
269 //  "eStateRunning" event will be delivered to the public Process broadcaster
270 //  per public eStateStopped event.  However there are some cases where the
271 //  public state of this process is eStateStopped, but a thread plan needs to
272 //  restart the target, but doesn't want the running event to be publicly
273 //  broadcast.  The obvious example of this is running functions by hand as
274 //  part of expression evaluation.  To suppress the running event return
275 //  eVoteNo from ShouldReportStop, to force a running event to be reported
276 //  return eVoteYes, in general though you should return eVoteNoOpinion which
277 //  will allow the ThreadList to figure out the right thing to do.  The
278 //  run_vote argument to the constructor works like stop_vote, and is a way for
279 //  a plan to instruct a sub-plan on how to respond to ShouldReportStop.
280 
281 class ThreadPlan : public std::enable_shared_from_this<ThreadPlan>,
282                    public UserID {
283 public:
284   enum ThreadScope { eAllThreads, eSomeThreads, eThisThread };
285 
286   // We use these enums so that we can cast a base thread plan to it's real
287   // type without having to resort to dynamic casting.
288   enum ThreadPlanKind {
289     eKindGeneric,
290     eKindNull,
291     eKindBase,
292     eKindCallFunction,
293     eKindPython,
294     eKindStepInstruction,
295     eKindStepOut,
296     eKindStepOverBreakpoint,
297     eKindStepOverRange,
298     eKindStepInRange,
299     eKindRunToAddress,
300     eKindStepThrough,
301     eKindStepUntil,
302     eKindTestCondition
303 
304   };
305 
306   // Constructors and Destructors
307   ThreadPlan(ThreadPlanKind kind, const char *name, Thread &thread,
308              Vote stop_vote, Vote run_vote);
309 
310   virtual ~ThreadPlan();
311 
312   /// Returns the name of this thread plan.
313   ///
314   /// \return
315   ///   A const char * pointer to the thread plan's name.
GetName()316   const char *GetName() const { return m_name.c_str(); }
317 
318   /// Returns the Thread that is using this thread plan.
319   ///
320   /// \return
321   ///   A  pointer to the thread plan's owning thread.
322   Thread &GetThread();
323 
324   Target &GetTarget();
325 
326   const Target &GetTarget() const;
327 
328   /// Print a description of this thread to the stream \a s.
329   /// \a thread.  Don't expect that the result of GetThread is valid in
330   /// the description method.  This might get called when the underlying
331   /// Thread has not been reported, so we only know the TID and not the thread.
332   ///
333   /// \param[in] s
334   ///    The stream to which to print the description.
335   ///
336   /// \param[in] level
337   ///    The level of description desired.  Note that eDescriptionLevelBrief
338   ///    will be used in the stop message printed when the plan is complete.
339   virtual void GetDescription(Stream *s, lldb::DescriptionLevel level) = 0;
340 
341   /// Returns whether this plan could be successfully created.
342   ///
343   /// \param[in] error
344   ///    A stream to which to print some reason why the plan could not be
345   ///    created.
346   ///    Can be NULL.
347   ///
348   /// \return
349   ///   \b true if the plan should be queued, \b false otherwise.
350   virtual bool ValidatePlan(Stream *error) = 0;
351 
TracerExplainsStop()352   bool TracerExplainsStop() {
353     if (!m_tracer_sp)
354       return false;
355     else
356       return m_tracer_sp->TracerExplainsStop();
357   }
358 
359   lldb::StateType RunState();
360 
361   bool PlanExplainsStop(Event *event_ptr);
362 
363   virtual bool ShouldStop(Event *event_ptr) = 0;
364 
ShouldAutoContinue(Event * event_ptr)365   virtual bool ShouldAutoContinue(Event *event_ptr) { return false; }
366 
367   // Whether a "stop class" event should be reported to the "outside world".
368   // In general if a thread plan is active, events should not be reported.
369 
370   virtual Vote ShouldReportStop(Event *event_ptr);
371 
372   virtual Vote ShouldReportRun(Event *event_ptr);
373 
374   virtual void SetStopOthers(bool new_value);
375 
376   virtual bool StopOthers();
377 
378   // This is the wrapper for DoWillResume that does generic ThreadPlan logic,
379   // then calls DoWillResume.
380   bool WillResume(lldb::StateType resume_state, bool current_plan);
381 
382   virtual bool WillStop() = 0;
383 
IsMasterPlan()384   bool IsMasterPlan() { return m_is_master_plan; }
385 
SetIsMasterPlan(bool value)386   bool SetIsMasterPlan(bool value) {
387     bool old_value = m_is_master_plan;
388     m_is_master_plan = value;
389     return old_value;
390   }
391 
392   virtual bool OkayToDiscard();
393 
SetOkayToDiscard(bool value)394   void SetOkayToDiscard(bool value) { m_okay_to_discard = value; }
395 
396   // The base class MischiefManaged does some cleanup - so you have to call it
397   // in your MischiefManaged derived class.
398   virtual bool MischiefManaged();
399 
ThreadDestroyed()400   virtual void ThreadDestroyed() {
401     // Any cleanup that a plan might want to do in case the thread goes away in
402     // the middle of the plan being queued on a thread can be done here.
403   }
404 
GetPrivate()405   bool GetPrivate() { return m_plan_private; }
406 
SetPrivate(bool input)407   void SetPrivate(bool input) { m_plan_private = input; }
408 
409   virtual void DidPush();
410 
411   virtual void WillPop();
412 
413   // This pushes a plan onto the plan stack of the current plan's thread.
414   // Also sets the plans to private and not master plans.  A plan pushed by
415   // another thread plan is never either of the above.
PushPlan(lldb::ThreadPlanSP & thread_plan_sp)416   void PushPlan(lldb::ThreadPlanSP &thread_plan_sp) {
417     GetThread().PushPlan(thread_plan_sp);
418     thread_plan_sp->SetPrivate(false);
419     thread_plan_sp->SetIsMasterPlan(false);
420   }
421 
GetKind()422   ThreadPlanKind GetKind() const { return m_kind; }
423 
424   bool IsPlanComplete();
425 
426   void SetPlanComplete(bool success = true);
427 
IsPlanStale()428   virtual bool IsPlanStale() { return false; }
429 
PlanSucceeded()430   bool PlanSucceeded() { return m_plan_succeeded; }
431 
IsBasePlan()432   virtual bool IsBasePlan() { return false; }
433 
GetThreadPlanTracer()434   lldb::ThreadPlanTracerSP &GetThreadPlanTracer() { return m_tracer_sp; }
435 
SetThreadPlanTracer(lldb::ThreadPlanTracerSP new_tracer_sp)436   void SetThreadPlanTracer(lldb::ThreadPlanTracerSP new_tracer_sp) {
437     m_tracer_sp = new_tracer_sp;
438   }
439 
DoTraceLog()440   void DoTraceLog() {
441     if (m_tracer_sp && m_tracer_sp->TracingEnabled())
442       m_tracer_sp->Log();
443   }
444 
445   // Some thread plans hide away the actual stop info which caused any
446   // particular stop.  For instance the ThreadPlanCallFunction restores the
447   // original stop reason so that stopping and calling a few functions won't
448   // lose the history of the run. This call can be implemented to get you back
449   // to the real stop info.
GetRealStopInfo()450   virtual lldb::StopInfoSP GetRealStopInfo() {
451     return GetThread().GetStopInfo();
452   }
453 
454   // If the completion of the thread plan stepped out of a function, the return
455   // value of the function might have been captured by the thread plan
456   // (currently only ThreadPlanStepOut does this.) If so, the ReturnValueObject
457   // can be retrieved from here.
458 
GetReturnValueObject()459   virtual lldb::ValueObjectSP GetReturnValueObject() {
460     return lldb::ValueObjectSP();
461   }
462 
463   // If the thread plan managing the evaluation of a user expression lives
464   // longer than the command that instigated the expression (generally because
465   // the expression evaluation hit a breakpoint, and the user regained control
466   // at that point) a subsequent process control command step/continue/etc.
467   // might complete the expression evaluations.  If so, the result of the
468   // expression evaluation will show up here.
469 
GetExpressionVariable()470   virtual lldb::ExpressionVariableSP GetExpressionVariable() {
471     return lldb::ExpressionVariableSP();
472   }
473 
474   // If a thread plan stores the state before it was run, then you might want
475   // to restore the state when it is done.  This will do that job. This is
476   // mostly useful for artificial plans like CallFunction plans.
477 
RestoreThreadState()478   virtual bool RestoreThreadState() {
479     // Nothing to do in general.
480     return true;
481   }
482 
IsVirtualStep()483   virtual bool IsVirtualStep() { return false; }
484 
SetIterationCount(size_t count)485   virtual bool SetIterationCount(size_t count) {
486     if (m_takes_iteration_count) {
487       // Don't tell me to do something 0 times...
488       if (count == 0)
489         return false;
490       m_iteration_count = count;
491     }
492     return m_takes_iteration_count;
493   }
494 
GetIterationCount()495   virtual size_t GetIterationCount() {
496     if (!m_takes_iteration_count)
497       return 0;
498     else
499       return m_iteration_count;
500   }
501 
502 protected:
503   // Classes that inherit from ThreadPlan can see and modify these
504 
DoWillResume(lldb::StateType resume_state,bool current_plan)505   virtual bool DoWillResume(lldb::StateType resume_state, bool current_plan) {
506     return true;
507   }
508 
509   virtual bool DoPlanExplainsStop(Event *event_ptr) = 0;
510 
511   // This gets the previous plan to the current plan (for forwarding requests).
512   // This is mostly a formal requirement, it allows us to make the Thread's
513   // GetPreviousPlan protected, but only friend ThreadPlan to thread.
514 
GetPreviousPlan()515   ThreadPlan *GetPreviousPlan() { return GetThread().GetPreviousPlan(this); }
516 
517   // This forwards the private Thread::GetPrivateStopInfo which is generally
518   // what ThreadPlan's need to know.
519 
GetPrivateStopInfo()520   lldb::StopInfoSP GetPrivateStopInfo() {
521     return GetThread().GetPrivateStopInfo();
522   }
523 
SetStopInfo(lldb::StopInfoSP stop_reason_sp)524   void SetStopInfo(lldb::StopInfoSP stop_reason_sp) {
525     GetThread().SetStopInfo(stop_reason_sp);
526   }
527 
CachePlanExplainsStop(bool does_explain)528   void CachePlanExplainsStop(bool does_explain) {
529     m_cached_plan_explains_stop = does_explain ? eLazyBoolYes : eLazyBoolNo;
530   }
531 
GetCachedPlanExplainsStop()532   LazyBool GetCachedPlanExplainsStop() const {
533     return m_cached_plan_explains_stop;
534   }
535 
536   virtual lldb::StateType GetPlanRunState() = 0;
537 
538   bool IsUsuallyUnexplainedStopReason(lldb::StopReason);
539 
540   Status m_status;
541   Process &m_process;
542   lldb::tid_t m_tid;
543   Vote m_stop_vote;
544   Vote m_run_vote;
545   bool m_takes_iteration_count;
546   bool m_could_not_resolve_hw_bp;
547   int32_t m_iteration_count = 1;
548 
549 private:
550   // For ThreadPlan only
551   static lldb::user_id_t GetNextID();
552 
553   Thread *m_thread; // Stores a cached value of the thread, which is set to
554                     // nullptr when the thread resumes.  Don't use this anywhere
555                     // but ThreadPlan::GetThread().
556   ThreadPlanKind m_kind;
557   std::string m_name;
558   std::recursive_mutex m_plan_complete_mutex;
559   LazyBool m_cached_plan_explains_stop;
560   bool m_plan_complete;
561   bool m_plan_private;
562   bool m_okay_to_discard;
563   bool m_is_master_plan;
564   bool m_plan_succeeded;
565 
566   lldb::ThreadPlanTracerSP m_tracer_sp;
567 
568   ThreadPlan(const ThreadPlan &) = delete;
569   const ThreadPlan &operator=(const ThreadPlan &) = delete;
570 };
571 
572 // ThreadPlanNull:
573 // Threads are assumed to always have at least one plan on the plan stack. This
574 // is put on the plan stack when a thread is destroyed so that if you
575 // accidentally access a thread after it is destroyed you won't crash. But
576 // asking questions of the ThreadPlanNull is definitely an error.
577 
578 class ThreadPlanNull : public ThreadPlan {
579 public:
580   ThreadPlanNull(Thread &thread);
581   ~ThreadPlanNull() override;
582 
583   void GetDescription(Stream *s, lldb::DescriptionLevel level) override;
584 
585   bool ValidatePlan(Stream *error) override;
586 
587   bool ShouldStop(Event *event_ptr) override;
588 
589   bool MischiefManaged() override;
590 
591   bool WillStop() override;
592 
IsBasePlan()593   bool IsBasePlan() override { return true; }
594 
OkayToDiscard()595   bool OkayToDiscard() override { return false; }
596 
GetStatus()597   const Status &GetStatus() { return m_status; }
598 
599 protected:
600   bool DoPlanExplainsStop(Event *event_ptr) override;
601 
602   lldb::StateType GetPlanRunState() override;
603 
604   ThreadPlanNull(const ThreadPlanNull &) = delete;
605   const ThreadPlanNull &operator=(const ThreadPlanNull &) = delete;
606 };
607 
608 } // namespace lldb_private
609 
610 #endif // LLDB_TARGET_THREADPLAN_H
611