1 //===-- ThreadPlanShouldStopHere.h ------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_ThreadPlanShouldStopHere_h_
11 #define liblldb_ThreadPlanShouldStopHere_h_
15 // Other libraries and framework includes
17 #include "lldb/Target/ThreadPlan.h"
19 namespace lldb_private {
21 // This is an interface that ThreadPlans can adopt to allow flexible
22 // modifications of the behavior
23 // when a thread plan comes to a place where it would ordinarily stop. If such
25 // sense for your plan, inherit from this class, and when you would be about to
26 // stop (in your ShouldStop
27 // method), call InvokeShouldStopHereCallback, passing in the frame comparison
28 // between where the step operation
29 // started and where you arrived. If it returns true, then QueueStepOutFromHere
30 // will queue the plan
31 // to execute instead of stopping.
33 // The classic example of the use of this is ThreadPlanStepInRange not stopping
34 // in frames that have
35 // no debug information.
37 // This class also defines a set of flags to control general aspects of this
38 // "ShouldStop" behavior.
39 // A class implementing this protocol needs to define a default set of flags,
40 // and can provide access to
41 // changing that default flag set if it wishes.
43 class ThreadPlanShouldStopHere {
45 struct ThreadPlanShouldStopHereCallbacks {
46 ThreadPlanShouldStopHereCallbacks() {
47 should_stop_here_callback = nullptr;
48 step_from_here_callback = nullptr;
51 ThreadPlanShouldStopHereCallbacks(
52 ThreadPlanShouldStopHereCallback should_stop,
53 ThreadPlanStepFromHereCallback step_from_here) {
54 should_stop_here_callback = should_stop;
55 step_from_here_callback = step_from_here;
59 should_stop_here_callback = nullptr;
60 step_from_here_callback = nullptr;
63 ThreadPlanShouldStopHereCallback should_stop_here_callback;
64 ThreadPlanStepFromHereCallback step_from_here_callback;
69 eAvoidInlines = (1 << 0),
70 eStepInAvoidNoDebug = (1 << 1),
71 eStepOutAvoidNoDebug = (1 << 2)
74 //------------------------------------------------------------------
75 // Constructors and Destructors
76 //------------------------------------------------------------------
77 ThreadPlanShouldStopHere(ThreadPlan *owner);
79 ThreadPlanShouldStopHere(ThreadPlan *owner,
80 const ThreadPlanShouldStopHereCallbacks *callbacks,
81 void *baton = nullptr);
82 virtual ~ThreadPlanShouldStopHere();
84 // Set the ShouldStopHere callbacks. Pass in null to clear them and have no
85 // special behavior (though you
86 // can also call ClearShouldStopHereCallbacks for that purpose. If you pass
87 // in a valid pointer, it will
88 // adopt the non-null fields, and any null fields will be set to the default
92 SetShouldStopHereCallbacks(const ThreadPlanShouldStopHereCallbacks *callbacks,
95 m_callbacks = *callbacks;
96 if (!m_callbacks.should_stop_here_callback)
97 m_callbacks.should_stop_here_callback =
98 ThreadPlanShouldStopHere::DefaultShouldStopHereCallback;
99 if (!m_callbacks.step_from_here_callback)
100 m_callbacks.step_from_here_callback =
101 ThreadPlanShouldStopHere::DefaultStepFromHereCallback;
103 ClearShouldStopHereCallbacks();
108 void ClearShouldStopHereCallbacks() { m_callbacks.Clear(); }
110 bool InvokeShouldStopHereCallback(lldb::FrameComparison operation);
113 CheckShouldStopHereAndQueueStepOut(lldb::FrameComparison operation);
115 lldb_private::Flags &GetFlags() { return m_flags; }
117 const lldb_private::Flags &GetFlags() const { return m_flags; }
120 static bool DefaultShouldStopHereCallback(ThreadPlan *current_plan,
122 lldb::FrameComparison operation,
125 static lldb::ThreadPlanSP
126 DefaultStepFromHereCallback(ThreadPlan *current_plan, Flags &flags,
127 lldb::FrameComparison operation, void *baton);
129 virtual lldb::ThreadPlanSP
130 QueueStepOutFromHerePlan(Flags &flags, lldb::FrameComparison operation);
132 // Implement this, and call it in the plan's constructor to set the default
134 virtual void SetFlagsToDefault() = 0;
136 ThreadPlanShouldStopHereCallbacks m_callbacks;
139 lldb_private::Flags m_flags;
142 DISALLOW_COPY_AND_ASSIGN(ThreadPlanShouldStopHere);
145 } // namespace lldb_private
147 #endif // liblldb_ThreadPlanShouldStopHere_h_