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