]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - include/lldb/Target/ThreadPlanShouldStopHere.h
Vendor import of lldb trunk r290819:
[FreeBSD/FreeBSD.git] / include / lldb / Target / ThreadPlanShouldStopHere.h
1 //===-- ThreadPlanShouldStopHere.h ------------------------------*- 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 #ifndef liblldb_ThreadPlanShouldStopHere_h_
11 #define liblldb_ThreadPlanShouldStopHere_h_
12
13 // C Includes
14 // C++ Includes
15 // Other libraries and framework includes
16 // Project includes
17 #include "lldb/Target/ThreadPlan.h"
18
19 namespace lldb_private {
20
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
24 // modification makes
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.
32 //
33 // The classic example of the use of this is ThreadPlanStepInRange not stopping
34 // in frames that have
35 // no debug information.
36 //
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.
42
43 class ThreadPlanShouldStopHere {
44 public:
45   struct ThreadPlanShouldStopHereCallbacks {
46     ThreadPlanShouldStopHereCallbacks() {
47       should_stop_here_callback = nullptr;
48       step_from_here_callback = nullptr;
49     }
50
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;
56     }
57
58     void Clear() {
59       should_stop_here_callback = nullptr;
60       step_from_here_callback = nullptr;
61     }
62
63     ThreadPlanShouldStopHereCallback should_stop_here_callback;
64     ThreadPlanStepFromHereCallback step_from_here_callback;
65   };
66
67   enum {
68     eNone = 0,
69     eAvoidInlines = (1 << 0),
70     eStepInAvoidNoDebug = (1 << 1),
71     eStepOutAvoidNoDebug = (1 << 2)
72   };
73
74   //------------------------------------------------------------------
75   // Constructors and Destructors
76   //------------------------------------------------------------------
77   ThreadPlanShouldStopHere(ThreadPlan *owner);
78
79   ThreadPlanShouldStopHere(ThreadPlan *owner,
80                            const ThreadPlanShouldStopHereCallbacks *callbacks,
81                            void *baton = nullptr);
82   virtual ~ThreadPlanShouldStopHere();
83
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
89   // values.
90
91   void
92   SetShouldStopHereCallbacks(const ThreadPlanShouldStopHereCallbacks *callbacks,
93                              void *baton) {
94     if (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;
102     } else {
103       ClearShouldStopHereCallbacks();
104     }
105     m_baton = baton;
106   }
107
108   void ClearShouldStopHereCallbacks() { m_callbacks.Clear(); }
109
110   bool InvokeShouldStopHereCallback(lldb::FrameComparison operation);
111
112   lldb::ThreadPlanSP
113   CheckShouldStopHereAndQueueStepOut(lldb::FrameComparison operation);
114
115   lldb_private::Flags &GetFlags() { return m_flags; }
116
117   const lldb_private::Flags &GetFlags() const { return m_flags; }
118
119 protected:
120   static bool DefaultShouldStopHereCallback(ThreadPlan *current_plan,
121                                             Flags &flags,
122                                             lldb::FrameComparison operation,
123                                             void *baton);
124
125   static lldb::ThreadPlanSP
126   DefaultStepFromHereCallback(ThreadPlan *current_plan, Flags &flags,
127                               lldb::FrameComparison operation, void *baton);
128
129   virtual lldb::ThreadPlanSP
130   QueueStepOutFromHerePlan(Flags &flags, lldb::FrameComparison operation);
131
132   // Implement this, and call it in the plan's constructor to set the default
133   // flags.
134   virtual void SetFlagsToDefault() = 0;
135
136   ThreadPlanShouldStopHereCallbacks m_callbacks;
137   void *m_baton;
138   ThreadPlan *m_owner;
139   lldb_private::Flags m_flags;
140
141 private:
142   DISALLOW_COPY_AND_ASSIGN(ThreadPlanShouldStopHere);
143 };
144
145 } // namespace lldb_private
146
147 #endif // liblldb_ThreadPlanShouldStopHere_h_