BreakpointOptions.h revision d168690e51f9020b926d3d0d57dc9a2cfb2095a8
1//===-- BreakpointOptions.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_BreakpointOptions_h_
11#define liblldb_BreakpointOptions_h_
12
13// C Includes
14// C++ Includes
15#include <memory>
16// Other libraries and framework includes
17// Project includes
18#include "lldb/lldb-private.h"
19#include "lldb/Core/Baton.h"
20#include "lldb/Core/StringList.h"
21#include "lldb/Expression/ClangUserExpression.h"
22
23namespace lldb_private {
24
25//----------------------------------------------------------------------
26/// @class BreakpointOptions BreakpointOptions.h "lldb/Breakpoint/BreakpointOptions.h"
27/// @brief Class that manages the options on a breakpoint or breakpoint location.
28//----------------------------------------------------------------------
29
30class BreakpointOptions
31{
32public:
33    //------------------------------------------------------------------
34    // Constructors and Destructors
35    //------------------------------------------------------------------
36    //------------------------------------------------------------------
37    /// Default constructor.  The breakpoint is enabled, and has no condition,
38    /// callback, ignore count, etc...
39    //------------------------------------------------------------------
40    BreakpointOptions();
41    BreakpointOptions(const BreakpointOptions& rhs);
42
43    static BreakpointOptions *
44    CopyOptionsNoCallback (BreakpointOptions &rhs);
45    //------------------------------------------------------------------
46    /// This constructor allows you to specify all the breakpoint options.
47    ///
48    /// @param[in] condition
49    ///    The expression which if it evaluates to \b true if we are to stop
50    ///
51    /// @param[in] callback
52    ///    This is the plugin for some code that gets run, returns \b true if we are to stop.
53    ///
54    /// @param[in] baton
55    ///    Client data that will get passed to the callback.
56    ///
57    /// @param[in] enabled
58    ///    Is this breakpoint enabled.
59    ///
60    /// @param[in] ignore
61    ///    How many breakpoint hits we should ignore before stopping.
62    ///
63    /// @param[in] thread_id
64    ///    Only stop if \a thread_id hits the breakpoint.
65    //------------------------------------------------------------------
66    BreakpointOptions(void *condition,
67                      BreakpointHitCallback callback,
68                      void *baton,
69                      bool enabled = true,
70                      int32_t ignore = 0,
71                      lldb::tid_t thread_id = LLDB_INVALID_THREAD_ID);
72
73    virtual ~BreakpointOptions();
74
75    //------------------------------------------------------------------
76    // Operators
77    //------------------------------------------------------------------
78    const BreakpointOptions&
79    operator=(const BreakpointOptions& rhs);
80
81    //------------------------------------------------------------------
82    // Callbacks
83    //------------------------------------------------------------------
84    void SetCallback (BreakpointHitCallback callback, const lldb::BatonSP &baton_sp, bool synchronous = false);
85    bool InvokeCallback (StoppointCallbackContext *context, lldb::user_id_t break_id, lldb::user_id_t break_loc_id);
86    bool IsCallbackSynchronous () {
87        return m_callback_is_synchronous;
88    }
89    Baton *GetBaton ();
90    const Baton *GetBaton () const;
91    void ClearCallback ();
92
93    //------------------------------------------------------------------
94    // Condition
95    //------------------------------------------------------------------
96    //------------------------------------------------------------------
97    /// Set the breakpoint option's condition.
98    ///
99    /// @param[in] condition
100    ///    The condition expression to evaluate when the breakpoint is hit.
101    //------------------------------------------------------------------
102    void SetCondition (const char *condition);
103
104    //------------------------------------------------------------------
105    /// Test the breakpoint condition in the Execution context passed in.
106    ///
107    /// @param[in] exe_ctx
108    ///    The execution context in which to evaluate this expression.
109    ///
110    /// @param[in] break_loc_sp
111    ///    A shared pointer to the location that we are testing thsi condition for.
112    ///
113    /// @param[in] error
114    ///    Error messages will be written to this stream.
115    ///
116    /// @return
117    ///     A thread plan to run to test the condition, or NULL if there is no thread plan.
118    //------------------------------------------------------------------
119    ThreadPlan *GetThreadPlanToTestCondition (ExecutionContext &exe_ctx,
120                                              lldb::BreakpointLocationSP break_loc_sp,
121                                              Stream &error);
122
123    //------------------------------------------------------------------
124    /// Return a pointer to the text of the condition expression.
125    ///
126    /// @return
127    ///    A pointer to the condition expression text, or NULL if no
128    //     condition has been set.
129    //------------------------------------------------------------------
130    const char *GetConditionText ();
131
132    //------------------------------------------------------------------
133    // Enabled/Ignore Count
134    //------------------------------------------------------------------
135
136    //------------------------------------------------------------------
137    /// Check the Enable/Disable state.
138    /// @return
139    ///     \b true if the breakpoint is enabled, \b false if disabled.
140    //------------------------------------------------------------------
141    bool
142    IsEnabled () const;
143
144    //------------------------------------------------------------------
145    /// If \a enable is \b true, enable the breakpoint, if \b false disable it.
146    //------------------------------------------------------------------
147    void
148    SetEnabled (bool enabled);
149
150    //------------------------------------------------------------------
151    /// Set the breakpoint to ignore the next \a count breakpoint hits.
152    /// @param[in] count
153    ///    The number of breakpoint hits to ignore.
154    //------------------------------------------------------------------
155
156    void
157    SetIgnoreCount (uint32_t n);
158
159    //------------------------------------------------------------------
160    /// Return the current Ignore Count.
161    /// @return
162    ///     The number of breakpoint hits to be ignored.
163    //------------------------------------------------------------------
164    uint32_t
165    GetIgnoreCount () const;
166
167    //------------------------------------------------------------------
168    /// Return the current thread spec for this option.  This will return NULL if the no thread
169    /// specifications have been set for this Option yet.
170    /// @return
171    ///     The thread specification pointer for this option, or NULL if none has
172    ///     been set yet.
173    //------------------------------------------------------------------
174    const ThreadSpec *
175    GetThreadSpecNoCreate () const;
176
177    //------------------------------------------------------------------
178    /// Returns a pointer to the ThreadSpec for this option, creating it.
179    /// if it hasn't been created already.   This API is used for setting the
180    /// ThreadSpec items for this option.
181    //------------------------------------------------------------------
182    ThreadSpec *
183    GetThreadSpec ();
184
185    void
186    SetThreadID(lldb::tid_t thread_id);
187
188    void
189    GetDescription (Stream *s, lldb::DescriptionLevel level) const;
190
191    //------------------------------------------------------------------
192    /// Returns true if the breakpoint option has a callback set.
193    //------------------------------------------------------------------
194    bool
195    HasCallback();
196
197    //------------------------------------------------------------------
198    /// This is the default empty callback.
199    /// @return
200    ///     The thread id for which the breakpoint hit will stop,
201    ///     LLDB_INVALID_THREAD_ID for all threads.
202    //------------------------------------------------------------------
203    static bool
204    NullCallback (void *baton,
205                  StoppointCallbackContext *context,
206                  lldb::user_id_t break_id,
207                  lldb::user_id_t break_loc_id);
208
209
210    struct CommandData
211    {
212        CommandData () :
213            user_source(),
214            script_source()
215        {
216        }
217
218        ~CommandData ()
219        {
220        }
221
222        StringList user_source;
223        StringList script_source;
224    };
225
226    class CommandBaton : public Baton
227    {
228    public:
229        CommandBaton (CommandData *data) :
230            Baton (data)
231        {
232        }
233
234        virtual
235        ~CommandBaton ()
236        {
237            delete ((CommandData *)m_data);
238            m_data = NULL;
239        }
240
241        virtual void
242        GetDescription (Stream *s, lldb::DescriptionLevel level) const;
243
244    };
245
246protected:
247    //------------------------------------------------------------------
248    // Classes that inherit from BreakpointOptions can see and modify these
249    //------------------------------------------------------------------
250
251private:
252    //------------------------------------------------------------------
253    // For BreakpointOptions only
254    //------------------------------------------------------------------
255    BreakpointHitCallback m_callback; // This is the callback function pointer
256    lldb::BatonSP m_callback_baton_sp; // This is the client data for the callback
257    bool m_callback_is_synchronous;
258    bool m_enabled;
259    uint32_t m_ignore_count; // Number of times to ignore this breakpoint
260    std::auto_ptr<ThreadSpec> m_thread_spec_ap; // Thread for which this breakpoint will take
261    std::auto_ptr<ClangUserExpression> m_condition_ap;  // The condition to test.
262
263};
264
265} // namespace lldb_private
266
267#endif  // liblldb_BreakpointOptions_h_
268