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_
13 #include "lldb/Target/ThreadPlan.h"
15 namespace lldb_private {
17 // This is an interface that ThreadPlans can adopt to allow flexible
18 // modifications of the behavior when a thread plan comes to a place where it
19 // would ordinarily stop. If such modification makes sense for your plan,
20 // inherit from this class, and when you would be about to stop (in your
21 // ShouldStop method), call InvokeShouldStopHereCallback, passing in the frame
22 // comparison between where the step operation started and where you arrived.
23 // If it returns true, then QueueStepOutFromHere will queue the plan to execute
24 // instead of stopping.
26 // The classic example of the use of this is ThreadPlanStepInRange not stopping
27 // in frames that have no debug information.
29 // This class also defines a set of flags to control general aspects of this
30 // "ShouldStop" behavior.
31 // A class implementing this protocol needs to define a default set of flags,
32 // and can provide access to
33 // changing that default flag set if it wishes.
35 class ThreadPlanShouldStopHere {
37 struct ThreadPlanShouldStopHereCallbacks {
38 ThreadPlanShouldStopHereCallbacks() {
39 should_stop_here_callback = nullptr;
40 step_from_here_callback = nullptr;
43 ThreadPlanShouldStopHereCallbacks(
44 ThreadPlanShouldStopHereCallback should_stop,
45 ThreadPlanStepFromHereCallback step_from_here) {
46 should_stop_here_callback = should_stop;
47 step_from_here_callback = step_from_here;
51 should_stop_here_callback = nullptr;
52 step_from_here_callback = nullptr;
55 ThreadPlanShouldStopHereCallback should_stop_here_callback;
56 ThreadPlanStepFromHereCallback step_from_here_callback;
61 eAvoidInlines = (1 << 0),
62 eStepInAvoidNoDebug = (1 << 1),
63 eStepOutAvoidNoDebug = (1 << 2)
66 //------------------------------------------------------------------
67 // Constructors and Destructors
68 //------------------------------------------------------------------
69 ThreadPlanShouldStopHere(ThreadPlan *owner);
71 ThreadPlanShouldStopHere(ThreadPlan *owner,
72 const ThreadPlanShouldStopHereCallbacks *callbacks,
73 void *baton = nullptr);
74 virtual ~ThreadPlanShouldStopHere();
76 // Set the ShouldStopHere callbacks. Pass in null to clear them and have no
77 // special behavior (though you can also call ClearShouldStopHereCallbacks
78 // for that purpose. If you pass in a valid pointer, it will adopt the non-
79 // null fields, and any null fields will be set to the default values.
82 SetShouldStopHereCallbacks(const ThreadPlanShouldStopHereCallbacks *callbacks,
85 m_callbacks = *callbacks;
86 if (!m_callbacks.should_stop_here_callback)
87 m_callbacks.should_stop_here_callback =
88 ThreadPlanShouldStopHere::DefaultShouldStopHereCallback;
89 if (!m_callbacks.step_from_here_callback)
90 m_callbacks.step_from_here_callback =
91 ThreadPlanShouldStopHere::DefaultStepFromHereCallback;
93 ClearShouldStopHereCallbacks();
98 void ClearShouldStopHereCallbacks() { m_callbacks.Clear(); }
100 bool InvokeShouldStopHereCallback(lldb::FrameComparison operation,
104 CheckShouldStopHereAndQueueStepOut(lldb::FrameComparison operation,
107 lldb_private::Flags &GetFlags() { return m_flags; }
109 const lldb_private::Flags &GetFlags() const { return m_flags; }
112 static bool DefaultShouldStopHereCallback(ThreadPlan *current_plan,
114 lldb::FrameComparison operation,
115 Status &status, void *baton);
117 static lldb::ThreadPlanSP
118 DefaultStepFromHereCallback(ThreadPlan *current_plan, Flags &flags,
119 lldb::FrameComparison operation, Status &status,
122 virtual lldb::ThreadPlanSP
123 QueueStepOutFromHerePlan(Flags &flags, lldb::FrameComparison operation,
126 // Implement this, and call it in the plan's constructor to set the default
128 virtual void SetFlagsToDefault() = 0;
130 ThreadPlanShouldStopHereCallbacks m_callbacks;
133 lldb_private::Flags m_flags;
136 DISALLOW_COPY_AND_ASSIGN(ThreadPlanShouldStopHere);
139 } // namespace lldb_private
141 #endif // liblldb_ThreadPlanShouldStopHere_h_