BreakpointOptions.h revision 24943d2ee8bfaa7cf5893e4709143924157a5c1e
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// Other libraries and framework includes
16// Project includes
17#include "lldb/lldb-private.h"
18#include "lldb/Core/Baton.h"
19#include "lldb/Core/StringList.h"
20
21namespace lldb_private {
22
23//----------------------------------------------------------------------
24/// @class BreakpointOptions BreakpointOptions.h "lldb/Breakpoint/BreakpointOptions.h"
25/// @brief Class that manages the options on a breakpoint or breakpoint location.
26//----------------------------------------------------------------------
27
28class BreakpointOptions
29{
30public:
31    //------------------------------------------------------------------
32    // Constructors and Destructors
33    //------------------------------------------------------------------
34    //------------------------------------------------------------------
35    /// Default constructor.  The breakpoint is enabled, and has no condition,
36    /// callback, ignore count, etc...
37    //------------------------------------------------------------------
38    BreakpointOptions();
39    BreakpointOptions(const BreakpointOptions& rhs);
40
41
42    //------------------------------------------------------------------
43    /// This constructor allows you to specify all the breakpoint options.
44    ///
45    /// @param[in] condition
46    ///    The expression which if it evaluates to \b true if we are to stop
47    ///
48    /// @param[in] callback
49    ///    This is the plugin for some code that gets run, returns \b true if we are to stop.
50    ///
51    /// @param[in] baton
52    ///    Client data that will get passed to the callback.
53    ///
54    /// @param[in] enabled
55    ///    Is this breakpoint enabled.
56    ///
57    /// @param[in] ignore
58    ///    How many breakpoint hits we should ignore before stopping.
59    ///
60    /// @param[in] thread_id
61    ///    Only stop if \a thread_id hits the breakpoint.
62    //------------------------------------------------------------------
63    BreakpointOptions(void *condition,
64                      BreakpointHitCallback callback,
65                      void *baton,
66                      bool enabled = true,
67                      int32_t ignore = 0,
68                      lldb::tid_t thread_id = LLDB_INVALID_THREAD_ID);
69
70    virtual ~BreakpointOptions();
71
72    //------------------------------------------------------------------
73    // Operators
74    //------------------------------------------------------------------
75    const BreakpointOptions&
76    operator=(const BreakpointOptions& rhs);
77
78    //------------------------------------------------------------------
79    // Callbacks
80    //------------------------------------------------------------------
81    void SetCallback (BreakpointHitCallback callback, const lldb::BatonSP &baton_sp, bool synchronous = false);
82    bool InvokeCallback (StoppointCallbackContext *context, lldb::user_id_t break_id, lldb::user_id_t break_loc_id);
83    bool IsCallbackSynchronous () {
84        return m_callback_is_synchronous;
85    };
86    Baton *GetBaton ();
87    void ClearCallback ();
88
89    //------------------------------------------------------------------
90    // Enabled/Ignore Count
91    //------------------------------------------------------------------
92
93    //------------------------------------------------------------------
94    /// Check the Enable/Disable state.
95    /// @return
96    ///     \b true if the breakpoint is enabled, \b false if disabled.
97    //------------------------------------------------------------------
98    bool
99    IsEnabled () const;
100
101    //------------------------------------------------------------------
102    /// If \a enable is \b true, enable the breakpoint, if \b false disable it.
103    //------------------------------------------------------------------
104    void
105    SetEnabled (bool enabled);
106
107    void
108    SetIgnoreCount (int32_t n);
109
110    //------------------------------------------------------------------
111    /// Return the current Ignore Count.
112    /// @return
113    ///     The number of breakpoint hits to be ignored.
114    //------------------------------------------------------------------
115    int32_t
116    GetIgnoreCount () const;
117
118    //------------------------------------------------------------------
119    /// Set the breakpoint to ignore the next \a count breakpoint hits.
120    /// @param[in] count
121    ///    The number of breakpoint hits to ignore.
122    //------------------------------------------------------------------
123
124    //------------------------------------------------------------------
125    /// Return the current stop thread value.
126    /// @return
127    ///     The thread id for which the breakpoint hit will stop,
128    ///     LLDB_INVALID_THREAD_ID for all threads.
129    //------------------------------------------------------------------
130    lldb::tid_t
131    GetThreadID () const;
132
133    //------------------------------------------------------------------
134    /// Set the valid thread to be checked when the breakpoint is hit.
135    /// @param[in] thread_id
136    ///    If this thread hits the breakpoint, we stop, otherwise not.
137    //------------------------------------------------------------------
138    void
139    SetThreadID (lldb::tid_t thread_id);
140
141    //------------------------------------------------------------------
142    /// This is the default empty callback.
143    /// @return
144    ///     The thread id for which the breakpoint hit will stop,
145    ///     LLDB_INVALID_THREAD_ID for all threads.
146    //------------------------------------------------------------------
147    static bool
148    NullCallback (void *baton,
149                  StoppointCallbackContext *context,
150                  lldb::user_id_t break_id,
151                  lldb::user_id_t break_loc_id);
152
153
154    struct CommandData
155    {
156        CommandData () :
157            user_source(),
158            script_source()
159        {
160        }
161
162        ~CommandData ()
163        {
164        }
165
166        StringList user_source;
167        StringList script_source;
168    };
169
170    class CommandBaton : public Baton
171    {
172    public:
173        CommandBaton (CommandData *data) :
174            Baton (data)
175        {
176        }
177
178        virtual
179        ~CommandBaton ()
180        {
181            delete ((CommandData *)m_data);
182            m_data = NULL;
183        }
184
185        virtual void
186        GetDescription (Stream *s, lldb::DescriptionLevel level) const;
187
188    };
189
190protected:
191    //------------------------------------------------------------------
192    // Classes that inherit from BreakpointOptions can see and modify these
193    //------------------------------------------------------------------
194
195private:
196    //------------------------------------------------------------------
197    // For BreakpointOptions only
198    //------------------------------------------------------------------
199    BreakpointHitCallback m_callback; // This is the callback function pointer
200    lldb::BatonSP m_callback_baton_sp; // This is the client data for the callback
201    bool m_callback_is_synchronous;
202    bool m_enabled;
203    int32_t m_ignore_count; // Number of times to ignore this breakpoint
204    lldb::tid_t m_thread_id; // Thread for which this breakpoint will take
205
206};
207
208} // namespace lldb_private
209
210#endif  // liblldb_BreakpointOptions_h_
211