BreakpointLocation.h revision 28195f9e55173cd06c3c5f9e69cefeb1d03cc129
1//===-- BreakpointLocation.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_BreakpointLocation_h_
11#define liblldb_BreakpointLocation_h_
12
13// C Includes
14
15// C++ Includes
16#include <list>
17
18// Other libraries and framework includes
19
20// Project includes
21#include "lldb/lldb-private.h"
22#include "lldb/Breakpoint/StoppointLocation.h"
23#include "lldb/Core/UserID.h"
24#include "lldb/Core/Address.h"
25#include "lldb/Target/Process.h"
26#include "lldb/Core/StringList.h"
27#include "lldb/Expression/ClangUserExpression.h"
28
29namespace lldb_private {
30
31//----------------------------------------------------------------------
32/// @class BreakpointLocation BreakpointLocation.h "lldb/Breakpoint/BreakpointLocation.h"
33/// @brief Class that manages one unique (by address) instance of a logical breakpoint.
34//----------------------------------------------------------------------
35
36//----------------------------------------------------------------------
37/// General Outline:
38/// A breakpoint location is defined by the breakpoint that produces it,
39/// and the address that resulted in this particular instantiation.
40/// Each breakpoint location also may have a breakpoint site if its
41/// address has been loaded into the program.
42/// Finally it has a settable options object.
43///
44/// FIXME: Should we also store some fingerprint for the location, so
45/// we can map one location to the "equivalent location" on rerun?  This
46/// would be useful if you've set options on the locations.
47//----------------------------------------------------------------------
48
49class BreakpointLocation :
50    public std::enable_shared_from_this<BreakpointLocation>,
51    public StoppointLocation
52{
53public:
54
55    ~BreakpointLocation ();
56
57    //------------------------------------------------------------------
58    /// Gets the load address for this breakpoint location
59    /// @return
60    ///     Returns breakpoint location load address, \b
61    ///     LLDB_INVALID_ADDRESS if not yet set.
62    //------------------------------------------------------------------
63    lldb::addr_t
64    GetLoadAddress () const;
65
66    //------------------------------------------------------------------
67    /// Gets the Address for this breakpoint location
68    /// @return
69    ///     Returns breakpoint location Address.
70    //------------------------------------------------------------------
71    Address &
72    GetAddress ();
73    //------------------------------------------------------------------
74    /// Gets the Breakpoint that created this breakpoint location
75    /// @return
76    ///     Returns the owning breakpoint.
77    //------------------------------------------------------------------
78    Breakpoint &
79    GetBreakpoint ();
80
81    //------------------------------------------------------------------
82    /// Determines whether we should stop due to a hit at this
83    /// breakpoint location.
84    ///
85    /// Side Effects: This may evaluate the breakpoint condition, and
86    /// run the callback.  So this command may do a considerable amount
87    /// of work.
88    ///
89    /// @return
90    ///     \b true if this breakpoint location thinks we should stop,
91    ///     \b false otherwise.
92    //------------------------------------------------------------------
93    bool
94    ShouldStop (StoppointCallbackContext *context);
95
96    //------------------------------------------------------------------
97    // The next section deals with various breakpoint options.
98    //------------------------------------------------------------------
99
100    //------------------------------------------------------------------
101    /// If \a enable is \b true, enable the breakpoint, if \b false
102    /// disable it.
103    //------------------------------------------------------------------
104    void
105    SetEnabled(bool enabled);
106
107    //------------------------------------------------------------------
108    /// Check the Enable/Disable state.
109    ///
110    /// @return
111    ///     \b true if the breakpoint is enabled, \b false if disabled.
112    //------------------------------------------------------------------
113    bool
114    IsEnabled () const;
115
116    //------------------------------------------------------------------
117    /// Return the current Ignore Count.
118    ///
119    /// @return
120    ///     The number of breakpoint hits to be ignored.
121    //------------------------------------------------------------------
122    uint32_t
123    GetIgnoreCount ();
124
125    //------------------------------------------------------------------
126    /// Set the breakpoint to ignore the next \a count breakpoint hits.
127    ///
128    /// @param[in] count
129    ///    The number of breakpoint hits to ignore.
130    //------------------------------------------------------------------
131    void
132    SetIgnoreCount (uint32_t n);
133
134    //------------------------------------------------------------------
135    /// Set the callback action invoked when the breakpoint is hit.
136    ///
137    /// The callback will return a bool indicating whether the target
138    /// should stop at this breakpoint or not.
139    ///
140    /// @param[in] callback
141    ///     The method that will get called when the breakpoint is hit.
142    ///
143    /// @param[in] callback_baton_sp
144    ///     A shared pointer to a Baton that provides the void * needed
145    ///     for the callback.
146    ///
147    /// @see lldb_private::Baton
148    //------------------------------------------------------------------
149    void
150    SetCallback (BreakpointHitCallback callback,
151                 const lldb::BatonSP &callback_baton_sp,
152                 bool is_synchronous);
153
154    void
155    SetCallback (BreakpointHitCallback callback,
156                 void *baton,
157                 bool is_synchronous);
158
159    void
160    ClearCallback ();
161
162    //------------------------------------------------------------------
163    /// Set the breakpoint location's condition.
164    ///
165    /// @param[in] condition
166    ///    The condition expression to evaluate when the breakpoint is hit.
167    //------------------------------------------------------------------
168    void
169    SetCondition (const char *condition);
170
171    //------------------------------------------------------------------
172    /// Return a pointer to the text of the condition expression.
173    ///
174    /// @return
175    ///    A pointer to the condition expression text, or NULL if no
176    //     condition has been set.
177    //------------------------------------------------------------------
178    const char *
179    GetConditionText (size_t *hash = NULL) const;
180
181    bool
182    ConditionSaysStop (ExecutionContext &exe_ctx, Error &error);
183
184
185    //------------------------------------------------------------------
186    /// Set the valid thread to be checked when the breakpoint is hit.
187    ///
188    /// @param[in] thread_id
189    ///    If this thread hits the breakpoint, we stop, otherwise not.
190    //------------------------------------------------------------------
191    void
192    SetThreadID (lldb::tid_t thread_id);
193
194    lldb::tid_t
195    GetThreadID ();
196
197    void
198    SetThreadIndex (uint32_t index);
199
200    uint32_t
201    GetThreadIndex() const;
202
203    void
204    SetThreadName (const char *thread_name);
205
206    const char *
207    GetThreadName () const;
208
209    void
210    SetQueueName (const char *queue_name);
211
212    const char *
213    GetQueueName () const;
214
215    //------------------------------------------------------------------
216    // The next section deals with this location's breakpoint sites.
217    //------------------------------------------------------------------
218
219    //------------------------------------------------------------------
220    /// Try to resolve the breakpoint site for this location.
221    ///
222    /// @return
223    ///     \b true if we were successful at setting a breakpoint site,
224    ///     \b false otherwise.
225    //------------------------------------------------------------------
226    bool
227    ResolveBreakpointSite ();
228
229    //------------------------------------------------------------------
230    /// Clear this breakpoint location's breakpoint site - for instance
231    /// when disabling the breakpoint.
232    ///
233    /// @return
234    ///     \b true if there was a breakpoint site to be cleared, \b false
235    ///     otherwise.
236    //------------------------------------------------------------------
237    bool
238    ClearBreakpointSite ();
239
240    //------------------------------------------------------------------
241    /// Return whether this breakpoint location has a breakpoint site.
242    /// @return
243    ///     \b true if there was a breakpoint site for this breakpoint
244    ///     location, \b false otherwise.
245    //------------------------------------------------------------------
246    bool
247    IsResolved () const;
248
249    lldb::BreakpointSiteSP
250    GetBreakpointSite() const;
251
252    //------------------------------------------------------------------
253    // The next section are generic report functions.
254    //------------------------------------------------------------------
255
256    //------------------------------------------------------------------
257    /// Print a description of this breakpoint location to the stream
258    /// \a s.
259    ///
260    /// @param[in] s
261    ///     The stream to which to print the description.
262    ///
263    /// @param[in] level
264    ///     The description level that indicates the detail level to
265    ///     provide.
266    ///
267    /// @see lldb::DescriptionLevel
268    //------------------------------------------------------------------
269    void
270    GetDescription (Stream *s, lldb::DescriptionLevel level);
271
272    //------------------------------------------------------------------
273    /// Standard "Dump" method.  At present it does nothing.
274    //------------------------------------------------------------------
275    void
276    Dump (Stream *s) const;
277
278    //------------------------------------------------------------------
279    /// Use this to set location specific breakpoint options.
280    ///
281    /// It will create a copy of the containing breakpoint's options if
282    /// that hasn't been done already
283    ///
284    /// @return
285    ///    A pointer to the breakpoint options.
286    //------------------------------------------------------------------
287    BreakpointOptions *
288    GetLocationOptions ();
289
290    //------------------------------------------------------------------
291    /// Use this to access breakpoint options from this breakpoint location.
292    /// This will point to the owning breakpoint's options unless options have
293    /// been set specifically on this location.
294    ///
295    /// @return
296    ///     A pointer to the containing breakpoint's options if this
297    ///     location doesn't have its own copy.
298    //------------------------------------------------------------------
299    const BreakpointOptions *
300    GetOptionsNoCreate () const;
301
302    bool
303    ValidForThisThread (Thread *thread);
304
305
306    //------------------------------------------------------------------
307    /// Invoke the callback action when the breakpoint is hit.
308    ///
309    /// Meant to be used by the BreakpointLocation class.
310    ///
311    /// @param[in] context
312    ///    Described the breakpoint event.
313    ///
314    /// @param[in] bp_loc_id
315    ///    Which breakpoint location hit this breakpoint.
316    ///
317    /// @return
318    ///     \b true if the target should stop at this breakpoint and \b
319    ///     false not.
320    //------------------------------------------------------------------
321    bool
322    InvokeCallback (StoppointCallbackContext *context);
323
324protected:
325    friend class BreakpointLocationList;
326    friend class CommandObjectBreakpointCommandAdd;
327    friend class Process;
328
329    //------------------------------------------------------------------
330    /// Set the breakpoint site for this location to \a bp_site_sp.
331    ///
332    /// @param[in] bp_site_sp
333    ///      The breakpoint site we are setting for this location.
334    ///
335    /// @return
336    ///     \b true if we were successful at setting the breakpoint site,
337    ///     \b false otherwise.
338    //------------------------------------------------------------------
339    bool
340    SetBreakpointSite (lldb::BreakpointSiteSP& bp_site_sp);
341
342    void
343    DecrementIgnoreCount();
344
345    bool
346    IgnoreCountShouldStop();
347
348private:
349
350    //------------------------------------------------------------------
351    // Constructors and Destructors
352    //
353    // Only the Breakpoint can make breakpoint locations, and it owns
354    // them.
355    //------------------------------------------------------------------
356
357    //------------------------------------------------------------------
358    /// Constructor.
359    ///
360    /// @param[in] owner
361    ///     A back pointer to the breakpoint that owns this location.
362    ///
363    /// @param[in] addr
364    ///     The Address defining this location.
365    ///
366    /// @param[in] tid
367    ///     The thread for which this breakpoint location is valid, or
368    ///     LLDB_INVALID_THREAD_ID if it is valid for all threads.
369    ///
370    /// @param[in] hardware
371    ///     \b true if a hardware breakpoint is requested.
372    //------------------------------------------------------------------
373
374    BreakpointLocation (lldb::break_id_t bid,
375                        Breakpoint &owner,
376                        const Address &addr,
377                        lldb::tid_t tid = LLDB_INVALID_THREAD_ID,
378                        bool hardware = false);
379
380    //------------------------------------------------------------------
381    // Data members:
382    //------------------------------------------------------------------
383    bool m_being_created;
384    Address m_address; ///< The address defining this location.
385    Breakpoint &m_owner; ///< The breakpoint that produced this object.
386    std::unique_ptr<BreakpointOptions> m_options_ap; ///< Breakpoint options pointer, NULL if we're using our breakpoint's options.
387    lldb::BreakpointSiteSP m_bp_site_sp; ///< Our breakpoint site (it may be shared by more than one location.)
388    ClangUserExpression::ClangUserExpressionSP m_user_expression_sp; ///< The compiled expression to use in testing our condition.
389    size_t m_condition_hash; ///< For testing whether the condition source code changed.
390
391    void
392    SendBreakpointLocationChangedEvent (lldb::BreakpointEventType eventKind);
393
394    DISALLOW_COPY_AND_ASSIGN (BreakpointLocation);
395};
396
397} // namespace lldb_private
398
399#endif  // liblldb_BreakpointLocation_h_
400