1 //===-- BreakpointLocation.h ------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_BreakpointLocation_h_
11 #define liblldb_BreakpointLocation_h_
18 // Other libraries and framework includes
21 #include "lldb/lldb-private.h"
22 #include "lldb/Breakpoint/StoppointLocation.h"
23 #include "lldb/Core/Address.h"
24 #include "lldb/Core/StringList.h"
25 #include "lldb/Core/UserID.h"
26 #include "lldb/Host/Mutex.h"
27 #include "lldb/Target/Process.h"
28 #include "lldb/Expression/ClangUserExpression.h"
30 namespace lldb_private {
32 //----------------------------------------------------------------------
33 /// @class BreakpointLocation BreakpointLocation.h "lldb/Breakpoint/BreakpointLocation.h"
34 /// @brief Class that manages one unique (by address) instance of a logical breakpoint.
35 //----------------------------------------------------------------------
37 //----------------------------------------------------------------------
39 /// A breakpoint location is defined by the breakpoint that produces it,
40 /// and the address that resulted in this particular instantiation.
41 /// Each breakpoint location also may have a breakpoint site if its
42 /// address has been loaded into the program.
43 /// Finally it has a settable options object.
45 /// FIXME: Should we also store some fingerprint for the location, so
46 /// we can map one location to the "equivalent location" on rerun? This
47 /// would be useful if you've set options on the locations.
48 //----------------------------------------------------------------------
50 class BreakpointLocation :
51 public std::enable_shared_from_this<BreakpointLocation>,
52 public StoppointLocation
56 ~BreakpointLocation ();
58 //------------------------------------------------------------------
59 /// Gets the load address for this breakpoint location
61 /// Returns breakpoint location load address, \b
62 /// LLDB_INVALID_ADDRESS if not yet set.
63 //------------------------------------------------------------------
65 GetLoadAddress () const;
67 //------------------------------------------------------------------
68 /// Gets the Address for this breakpoint location
70 /// Returns breakpoint location Address.
71 //------------------------------------------------------------------
74 //------------------------------------------------------------------
75 /// Gets the Breakpoint that created this breakpoint location
77 /// Returns the owning breakpoint.
78 //------------------------------------------------------------------
82 //------------------------------------------------------------------
83 /// Determines whether we should stop due to a hit at this
84 /// breakpoint location.
86 /// Side Effects: This may evaluate the breakpoint condition, and
87 /// run the callback. So this command may do a considerable amount
91 /// \b true if this breakpoint location thinks we should stop,
92 /// \b false otherwise.
93 //------------------------------------------------------------------
95 ShouldStop (StoppointCallbackContext *context);
97 //------------------------------------------------------------------
98 // The next section deals with various breakpoint options.
99 //------------------------------------------------------------------
101 //------------------------------------------------------------------
102 /// If \a enable is \b true, enable the breakpoint, if \b false
104 //------------------------------------------------------------------
106 SetEnabled(bool enabled);
108 //------------------------------------------------------------------
109 /// Check the Enable/Disable state.
112 /// \b true if the breakpoint is enabled, \b false if disabled.
113 //------------------------------------------------------------------
117 //------------------------------------------------------------------
118 /// Return the current Ignore Count.
121 /// The number of breakpoint hits to be ignored.
122 //------------------------------------------------------------------
126 //------------------------------------------------------------------
127 /// Set the breakpoint to ignore the next \a count breakpoint hits.
130 /// The number of breakpoint hits to ignore.
131 //------------------------------------------------------------------
133 SetIgnoreCount (uint32_t n);
135 //------------------------------------------------------------------
136 /// Set the callback action invoked when the breakpoint is hit.
138 /// The callback will return a bool indicating whether the target
139 /// should stop at this breakpoint or not.
141 /// @param[in] callback
142 /// The method that will get called when the breakpoint is hit.
144 /// @param[in] callback_baton_sp
145 /// A shared pointer to a Baton that provides the void * needed
146 /// for the callback.
148 /// @see lldb_private::Baton
149 //------------------------------------------------------------------
151 SetCallback (BreakpointHitCallback callback,
152 const lldb::BatonSP &callback_baton_sp,
153 bool is_synchronous);
156 SetCallback (BreakpointHitCallback callback,
158 bool is_synchronous);
163 //------------------------------------------------------------------
164 /// Set the breakpoint location's condition.
166 /// @param[in] condition
167 /// The condition expression to evaluate when the breakpoint is hit.
168 //------------------------------------------------------------------
170 SetCondition (const char *condition);
172 //------------------------------------------------------------------
173 /// Return a pointer to the text of the condition expression.
176 /// A pointer to the condition expression text, or NULL if no
177 // condition has been set.
178 //------------------------------------------------------------------
180 GetConditionText (size_t *hash = NULL) const;
183 ConditionSaysStop (ExecutionContext &exe_ctx, Error &error);
186 //------------------------------------------------------------------
187 /// Set the valid thread to be checked when the breakpoint is hit.
189 /// @param[in] thread_id
190 /// If this thread hits the breakpoint, we stop, otherwise not.
191 //------------------------------------------------------------------
193 SetThreadID (lldb::tid_t thread_id);
199 SetThreadIndex (uint32_t index);
202 GetThreadIndex() const;
205 SetThreadName (const char *thread_name);
208 GetThreadName () const;
211 SetQueueName (const char *queue_name);
214 GetQueueName () const;
216 //------------------------------------------------------------------
217 // The next section deals with this location's breakpoint sites.
218 //------------------------------------------------------------------
220 //------------------------------------------------------------------
221 /// Try to resolve the breakpoint site for this location.
224 /// \b true if we were successful at setting a breakpoint site,
225 /// \b false otherwise.
226 //------------------------------------------------------------------
228 ResolveBreakpointSite ();
230 //------------------------------------------------------------------
231 /// Clear this breakpoint location's breakpoint site - for instance
232 /// when disabling the breakpoint.
235 /// \b true if there was a breakpoint site to be cleared, \b false
237 //------------------------------------------------------------------
239 ClearBreakpointSite ();
241 //------------------------------------------------------------------
242 /// Return whether this breakpoint location has a breakpoint site.
244 /// \b true if there was a breakpoint site for this breakpoint
245 /// location, \b false otherwise.
246 //------------------------------------------------------------------
250 lldb::BreakpointSiteSP
251 GetBreakpointSite() const;
253 //------------------------------------------------------------------
254 // The next section are generic report functions.
255 //------------------------------------------------------------------
257 //------------------------------------------------------------------
258 /// Print a description of this breakpoint location to the stream
262 /// The stream to which to print the description.
265 /// The description level that indicates the detail level to
268 /// @see lldb::DescriptionLevel
269 //------------------------------------------------------------------
271 GetDescription (Stream *s, lldb::DescriptionLevel level);
273 //------------------------------------------------------------------
274 /// Standard "Dump" method. At present it does nothing.
275 //------------------------------------------------------------------
277 Dump (Stream *s) const;
279 //------------------------------------------------------------------
280 /// Use this to set location specific breakpoint options.
282 /// It will create a copy of the containing breakpoint's options if
283 /// that hasn't been done already
286 /// A pointer to the breakpoint options.
287 //------------------------------------------------------------------
289 GetLocationOptions ();
291 //------------------------------------------------------------------
292 /// Use this to access breakpoint options from this breakpoint location.
293 /// This will point to the owning breakpoint's options unless options have
294 /// been set specifically on this location.
297 /// A pointer to the containing breakpoint's options if this
298 /// location doesn't have its own copy.
299 //------------------------------------------------------------------
300 const BreakpointOptions *
301 GetOptionsNoCreate () const;
304 ValidForThisThread (Thread *thread);
307 //------------------------------------------------------------------
308 /// Invoke the callback action when the breakpoint is hit.
310 /// Meant to be used by the BreakpointLocation class.
312 /// @param[in] context
313 /// Described the breakpoint event.
315 /// @param[in] bp_loc_id
316 /// Which breakpoint location hit this breakpoint.
319 /// \b true if the target should stop at this breakpoint and \b
321 //------------------------------------------------------------------
323 InvokeCallback (StoppointCallbackContext *context);
325 //------------------------------------------------------------------
326 /// Returns whether we should resolve Indirect functions in setting the breakpoint site
327 /// for this location.
330 /// \b true if the breakpoint SITE for this location should be set on the
331 /// resolved location for Indirect functions.
332 //------------------------------------------------------------------
334 ShouldResolveIndirectFunctions ()
336 return m_should_resolve_indirect_functions;
339 //------------------------------------------------------------------
340 /// Returns whether the address set in the breakpoint site for this location was found by resolving
341 /// an indirect symbol.
344 /// \b true or \b false as given in the description above.
345 //------------------------------------------------------------------
349 return m_is_indirect;
353 SetIsIndirect (bool is_indirect)
355 m_is_indirect = is_indirect;
358 //------------------------------------------------------------------
359 /// Returns whether the address set in the breakpoint location was re-routed to the target of a
360 /// re-exported symbol.
363 /// \b true or \b false as given in the description above.
364 //------------------------------------------------------------------
368 return m_is_reexported;
372 SetIsReExported (bool is_reexported)
374 m_is_reexported = is_reexported;
378 friend class BreakpointLocationList;
379 friend class Process;
381 //------------------------------------------------------------------
382 /// Set the breakpoint site for this location to \a bp_site_sp.
384 /// @param[in] bp_site_sp
385 /// The breakpoint site we are setting for this location.
388 /// \b true if we were successful at setting the breakpoint site,
389 /// \b false otherwise.
390 //------------------------------------------------------------------
392 SetBreakpointSite (lldb::BreakpointSiteSP& bp_site_sp);
395 DecrementIgnoreCount();
398 IgnoreCountShouldStop();
402 //------------------------------------------------------------------
403 // Constructors and Destructors
405 // Only the Breakpoint can make breakpoint locations, and it owns
407 //------------------------------------------------------------------
409 //------------------------------------------------------------------
413 /// A back pointer to the breakpoint that owns this location.
416 /// The Address defining this location.
419 /// The thread for which this breakpoint location is valid, or
420 /// LLDB_INVALID_THREAD_ID if it is valid for all threads.
422 /// @param[in] hardware
423 /// \b true if a hardware breakpoint is requested.
424 //------------------------------------------------------------------
426 BreakpointLocation (lldb::break_id_t bid,
431 bool check_for_resolver = true);
433 //------------------------------------------------------------------
435 //------------------------------------------------------------------
436 bool m_being_created;
437 bool m_should_resolve_indirect_functions;
438 bool m_is_reexported;
440 Address m_address; ///< The address defining this location.
441 Breakpoint &m_owner; ///< The breakpoint that produced this object.
442 std::unique_ptr<BreakpointOptions> m_options_ap; ///< Breakpoint options pointer, NULL if we're using our breakpoint's options.
443 lldb::BreakpointSiteSP m_bp_site_sp; ///< Our breakpoint site (it may be shared by more than one location.)
444 ClangUserExpression::ClangUserExpressionSP m_user_expression_sp; ///< The compiled expression to use in testing our condition.
445 Mutex m_condition_mutex; ///< Guards parsing and evaluation of the condition, which could be evaluated by multiple processes.
446 size_t m_condition_hash; ///< For testing whether the condition source code changed.
449 SetShouldResolveIndirectFunctions (bool do_resolve)
451 m_should_resolve_indirect_functions = do_resolve;
455 SendBreakpointLocationChangedEvent (lldb::BreakpointEventType eventKind);
457 DISALLOW_COPY_AND_ASSIGN (BreakpointLocation);
460 } // namespace lldb_private
462 #endif // liblldb_BreakpointLocation_h_