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
20 #include "lldb/Breakpoint/StoppointLocation.h"
21 #include "lldb/Core/Address.h"
22 #include "lldb/Utility/UserID.h"
23 #include "lldb/lldb-private.h"
25 namespace lldb_private {
27 //----------------------------------------------------------------------
28 /// @class BreakpointLocation BreakpointLocation.h
29 /// "lldb/Breakpoint/BreakpointLocation.h"
30 /// @brief Class that manages one unique (by address) instance of a logical
32 //----------------------------------------------------------------------
34 //----------------------------------------------------------------------
36 /// A breakpoint location is defined by the breakpoint that produces it,
37 /// and the address that resulted in this particular instantiation.
38 /// Each breakpoint location also may have a breakpoint site if its
39 /// address has been loaded into the program.
40 /// Finally it has a settable options object.
42 /// FIXME: Should we also store some fingerprint for the location, so
43 /// we can map one location to the "equivalent location" on rerun? This
44 /// would be useful if you've set options on the locations.
45 //----------------------------------------------------------------------
47 class BreakpointLocation
48 : public std::enable_shared_from_this<BreakpointLocation>,
49 public StoppointLocation {
51 ~BreakpointLocation() override;
53 //------------------------------------------------------------------
54 /// Gets the load address for this breakpoint location
56 /// Returns breakpoint location load address, \b
57 /// LLDB_INVALID_ADDRESS if not yet set.
58 //------------------------------------------------------------------
59 lldb::addr_t GetLoadAddress() const override;
61 //------------------------------------------------------------------
62 /// Gets the Address for this breakpoint location
64 /// Returns breakpoint location Address.
65 //------------------------------------------------------------------
66 Address &GetAddress();
67 //------------------------------------------------------------------
68 /// Gets the Breakpoint that created this breakpoint location
70 /// Returns the owning breakpoint.
71 //------------------------------------------------------------------
72 Breakpoint &GetBreakpoint();
76 //------------------------------------------------------------------
77 /// Determines whether we should stop due to a hit at this
78 /// breakpoint location.
80 /// Side Effects: This may evaluate the breakpoint condition, and
81 /// run the callback. So this command may do a considerable amount
85 /// \b true if this breakpoint location thinks we should stop,
86 /// \b false otherwise.
87 //------------------------------------------------------------------
88 bool ShouldStop(StoppointCallbackContext *context) override;
90 //------------------------------------------------------------------
91 // The next section deals with various breakpoint options.
92 //------------------------------------------------------------------
94 //------------------------------------------------------------------
95 /// If \a enable is \b true, enable the breakpoint, if \b false
97 //------------------------------------------------------------------
98 void SetEnabled(bool enabled);
100 //------------------------------------------------------------------
101 /// Check the Enable/Disable state.
104 /// \b true if the breakpoint is enabled, \b false if disabled.
105 //------------------------------------------------------------------
106 bool IsEnabled() const;
108 //------------------------------------------------------------------
109 /// Return the current Ignore Count.
112 /// The number of breakpoint hits to be ignored.
113 //------------------------------------------------------------------
114 uint32_t GetIgnoreCount();
116 //------------------------------------------------------------------
117 /// Set the breakpoint to ignore the next \a count breakpoint hits.
120 /// The number of breakpoint hits to ignore.
121 //------------------------------------------------------------------
122 void SetIgnoreCount(uint32_t n);
124 //------------------------------------------------------------------
125 /// Set the callback action invoked when the breakpoint is hit.
127 /// The callback will return a bool indicating whether the target
128 /// should stop at this breakpoint or not.
130 /// @param[in] callback
131 /// The method that will get called when the breakpoint is hit.
133 /// @param[in] callback_baton_sp
134 /// A shared pointer to a Baton that provides the void * needed
135 /// for the callback.
137 /// @see lldb_private::Baton
138 //------------------------------------------------------------------
139 void SetCallback(BreakpointHitCallback callback,
140 const lldb::BatonSP &callback_baton_sp, bool is_synchronous);
142 void SetCallback(BreakpointHitCallback callback, void *baton,
143 bool is_synchronous);
145 void ClearCallback();
147 //------------------------------------------------------------------
148 /// Set the breakpoint location's condition.
150 /// @param[in] condition
151 /// The condition expression to evaluate when the breakpoint is hit.
152 //------------------------------------------------------------------
153 void SetCondition(const char *condition);
155 //------------------------------------------------------------------
156 /// Return a pointer to the text of the condition expression.
159 /// A pointer to the condition expression text, or nullptr if no
160 // condition has been set.
161 //------------------------------------------------------------------
162 const char *GetConditionText(size_t *hash = nullptr) const;
164 bool ConditionSaysStop(ExecutionContext &exe_ctx, Status &error);
166 //------------------------------------------------------------------
167 /// Set the valid thread to be checked when the breakpoint is hit.
169 /// @param[in] thread_id
170 /// If this thread hits the breakpoint, we stop, otherwise not.
171 //------------------------------------------------------------------
172 void SetThreadID(lldb::tid_t thread_id);
174 lldb::tid_t GetThreadID();
176 void SetThreadIndex(uint32_t index);
178 uint32_t GetThreadIndex() const;
180 void SetThreadName(const char *thread_name);
182 const char *GetThreadName() const;
184 void SetQueueName(const char *queue_name);
186 const char *GetQueueName() const;
188 //------------------------------------------------------------------
189 // The next section deals with this location's breakpoint sites.
190 //------------------------------------------------------------------
192 //------------------------------------------------------------------
193 /// Try to resolve the breakpoint site for this location.
196 /// \b true if we were successful at setting a breakpoint site,
197 /// \b false otherwise.
198 //------------------------------------------------------------------
199 bool ResolveBreakpointSite();
201 //------------------------------------------------------------------
202 /// Clear this breakpoint location's breakpoint site - for instance
203 /// when disabling the breakpoint.
206 /// \b true if there was a breakpoint site to be cleared, \b false
208 //------------------------------------------------------------------
209 bool ClearBreakpointSite();
211 //------------------------------------------------------------------
212 /// Return whether this breakpoint location has a breakpoint site.
214 /// \b true if there was a breakpoint site for this breakpoint
215 /// location, \b false otherwise.
216 //------------------------------------------------------------------
217 bool IsResolved() const;
219 lldb::BreakpointSiteSP GetBreakpointSite() const;
221 //------------------------------------------------------------------
222 // The next section are generic report functions.
223 //------------------------------------------------------------------
225 //------------------------------------------------------------------
226 /// Print a description of this breakpoint location to the stream
230 /// The stream to which to print the description.
233 /// The description level that indicates the detail level to
236 /// @see lldb::DescriptionLevel
237 //------------------------------------------------------------------
238 void GetDescription(Stream *s, lldb::DescriptionLevel level);
240 //------------------------------------------------------------------
241 /// Standard "Dump" method. At present it does nothing.
242 //------------------------------------------------------------------
243 void Dump(Stream *s) const override;
245 //------------------------------------------------------------------
246 /// Use this to set location specific breakpoint options.
248 /// It will create a copy of the containing breakpoint's options if
249 /// that hasn't been done already
252 /// A pointer to the breakpoint options.
253 //------------------------------------------------------------------
254 BreakpointOptions *GetLocationOptions();
256 //------------------------------------------------------------------
257 /// Use this to access breakpoint options from this breakpoint location.
258 /// This will point to the owning breakpoint's options unless options have
259 /// been set specifically on this location.
262 /// A pointer to the containing breakpoint's options if this
263 /// location doesn't have its own copy.
264 //------------------------------------------------------------------
265 const BreakpointOptions *GetOptionsNoCreate() const;
267 bool ValidForThisThread(Thread *thread);
269 //------------------------------------------------------------------
270 /// Invoke the callback action when the breakpoint is hit.
272 /// Meant to be used by the BreakpointLocation class.
274 /// @param[in] context
275 /// Described the breakpoint event.
277 /// @param[in] bp_loc_id
278 /// Which breakpoint location hit this breakpoint.
281 /// \b true if the target should stop at this breakpoint and \b
283 //------------------------------------------------------------------
284 bool InvokeCallback(StoppointCallbackContext *context);
286 //------------------------------------------------------------------
287 /// Returns whether we should resolve Indirect functions in setting the
289 /// for this location.
292 /// \b true if the breakpoint SITE for this location should be set on the
293 /// resolved location for Indirect functions.
294 //------------------------------------------------------------------
295 bool ShouldResolveIndirectFunctions() {
296 return m_should_resolve_indirect_functions;
299 //------------------------------------------------------------------
300 /// Returns whether the address set in the breakpoint site for this location
301 /// was found by resolving
302 /// an indirect symbol.
305 /// \b true or \b false as given in the description above.
306 //------------------------------------------------------------------
307 bool IsIndirect() { return m_is_indirect; }
309 void SetIsIndirect(bool is_indirect) { m_is_indirect = is_indirect; }
311 //------------------------------------------------------------------
312 /// Returns whether the address set in the breakpoint location was re-routed
313 /// to the target of a
314 /// re-exported symbol.
317 /// \b true or \b false as given in the description above.
318 //------------------------------------------------------------------
319 bool IsReExported() { return m_is_reexported; }
321 void SetIsReExported(bool is_reexported) { m_is_reexported = is_reexported; }
323 //------------------------------------------------------------------
324 /// Returns whether the two breakpoint locations might represent "equivalent
326 /// This is used when modules changed to determine if a Location in the old
328 /// be the "same as" the input location.
330 /// @param[in] location
331 /// The location to compare against.
334 /// \b true or \b false as given in the description above.
335 //------------------------------------------------------------------
336 bool EquivalentToLocation(BreakpointLocation &location);
339 friend class BreakpointSite;
340 friend class BreakpointLocationList;
341 friend class Process;
342 friend class StopInfoBreakpoint;
344 //------------------------------------------------------------------
345 /// Set the breakpoint site for this location to \a bp_site_sp.
347 /// @param[in] bp_site_sp
348 /// The breakpoint site we are setting for this location.
351 /// \b true if we were successful at setting the breakpoint site,
352 /// \b false otherwise.
353 //------------------------------------------------------------------
354 bool SetBreakpointSite(lldb::BreakpointSiteSP &bp_site_sp);
356 void DecrementIgnoreCount();
358 bool IgnoreCountShouldStop();
361 void SwapLocation(lldb::BreakpointLocationSP swap_from);
365 void UndoBumpHitCount();
367 //------------------------------------------------------------------
368 // Constructors and Destructors
370 // Only the Breakpoint can make breakpoint locations, and it owns
372 //------------------------------------------------------------------
374 //------------------------------------------------------------------
378 /// A back pointer to the breakpoint that owns this location.
381 /// The Address defining this location.
384 /// The thread for which this breakpoint location is valid, or
385 /// LLDB_INVALID_THREAD_ID if it is valid for all threads.
387 /// @param[in] hardware
388 /// \b true if a hardware breakpoint is requested.
389 //------------------------------------------------------------------
391 BreakpointLocation(lldb::break_id_t bid, Breakpoint &owner,
392 const Address &addr, lldb::tid_t tid, bool hardware,
393 bool check_for_resolver = true);
395 //------------------------------------------------------------------
397 //------------------------------------------------------------------
398 bool m_being_created;
399 bool m_should_resolve_indirect_functions;
400 bool m_is_reexported;
402 Address m_address; ///< The address defining this location.
403 Breakpoint &m_owner; ///< The breakpoint that produced this object.
404 std::unique_ptr<BreakpointOptions> m_options_ap; ///< Breakpoint options
405 ///pointer, nullptr if we're
406 ///using our breakpoint's
408 lldb::BreakpointSiteSP m_bp_site_sp; ///< Our breakpoint site (it may be
409 ///shared by more than one location.)
410 lldb::UserExpressionSP m_user_expression_sp; ///< The compiled expression to
411 ///use in testing our condition.
412 std::mutex m_condition_mutex; ///< Guards parsing and evaluation of the
413 ///condition, which could be evaluated by
414 /// multiple processes.
415 size_t m_condition_hash; ///< For testing whether the condition source code
418 void SetShouldResolveIndirectFunctions(bool do_resolve) {
419 m_should_resolve_indirect_functions = do_resolve;
422 void SendBreakpointLocationChangedEvent(lldb::BreakpointEventType eventKind);
424 DISALLOW_COPY_AND_ASSIGN(BreakpointLocation);
427 } // namespace lldb_private
429 #endif // liblldb_BreakpointLocation_h_