1 //===-- BreakpointLocation.h ------------------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #ifndef liblldb_BreakpointLocation_h_
10 #define liblldb_BreakpointLocation_h_
15 #include "lldb/Breakpoint/BreakpointOptions.h"
16 #include "lldb/Breakpoint/StoppointLocation.h"
17 #include "lldb/Core/Address.h"
18 #include "lldb/Utility/UserID.h"
19 #include "lldb/lldb-private.h"
21 namespace lldb_private {
23 /// \class BreakpointLocation BreakpointLocation.h
24 /// "lldb/Breakpoint/BreakpointLocation.h" Class that manages one unique (by
25 /// address) instance of a logical breakpoint.
28 /// A breakpoint location is defined by the breakpoint that produces it,
29 /// and the address that resulted in this particular instantiation. Each
30 /// breakpoint location also may have a breakpoint site if its address has
31 /// been loaded into the program. Finally it has a settable options object.
33 /// FIXME: Should we also store some fingerprint for the location, so
34 /// we can map one location to the "equivalent location" on rerun? This would
35 /// be useful if you've set options on the locations.
37 class BreakpointLocation
38 : public std::enable_shared_from_this<BreakpointLocation>,
39 public StoppointLocation {
41 ~BreakpointLocation() override;
43 /// Gets the load address for this breakpoint location \return
44 /// Returns breakpoint location load address, \b
45 /// LLDB_INVALID_ADDRESS if not yet set.
46 lldb::addr_t GetLoadAddress() const override;
48 /// Gets the Address for this breakpoint location \return
49 /// Returns breakpoint location Address.
50 Address &GetAddress();
51 /// Gets the Breakpoint that created this breakpoint location \return
52 /// Returns the owning breakpoint.
53 Breakpoint &GetBreakpoint();
57 /// Determines whether we should stop due to a hit at this breakpoint
60 /// Side Effects: This may evaluate the breakpoint condition, and run the
61 /// callback. So this command may do a considerable amount of work.
64 /// \b true if this breakpoint location thinks we should stop,
65 /// \b false otherwise.
66 bool ShouldStop(StoppointCallbackContext *context) override;
68 // The next section deals with various breakpoint options.
70 /// If \a enable is \b true, enable the breakpoint, if \b false disable it.
71 void SetEnabled(bool enabled);
73 /// Check the Enable/Disable state.
76 /// \b true if the breakpoint is enabled, \b false if disabled.
77 bool IsEnabled() const;
79 /// If \a auto_continue is \b true, set the breakpoint to continue when hit.
80 void SetAutoContinue(bool auto_continue);
82 /// Check the AutoContinue state.
85 /// \b true if the breakpoint is set to auto-continue, \b false if not.
86 bool IsAutoContinue() const;
88 /// Return the current Ignore Count.
91 /// The number of breakpoint hits to be ignored.
92 uint32_t GetIgnoreCount();
94 /// Set the breakpoint to ignore the next \a count breakpoint hits.
97 /// The number of breakpoint hits to ignore.
98 void SetIgnoreCount(uint32_t n);
100 /// Set the callback action invoked when the breakpoint is hit.
102 /// The callback will return a bool indicating whether the target should
103 /// stop at this breakpoint or not.
105 /// \param[in] callback
106 /// The method that will get called when the breakpoint is hit.
108 /// \param[in] callback_baton_sp
109 /// A shared pointer to a Baton that provides the void * needed
110 /// for the callback.
112 /// \see lldb_private::Baton
113 void SetCallback(BreakpointHitCallback callback,
114 const lldb::BatonSP &callback_baton_sp, bool is_synchronous);
116 void SetCallback(BreakpointHitCallback callback, void *baton,
117 bool is_synchronous);
119 void ClearCallback();
121 /// Set the breakpoint location's condition.
123 /// \param[in] condition
124 /// The condition expression to evaluate when the breakpoint is hit.
125 void SetCondition(const char *condition);
127 /// Return a pointer to the text of the condition expression.
130 /// A pointer to the condition expression text, or nullptr if no
131 // condition has been set.
132 const char *GetConditionText(size_t *hash = nullptr) const;
134 bool ConditionSaysStop(ExecutionContext &exe_ctx, Status &error);
136 /// Set the valid thread to be checked when the breakpoint is hit.
138 /// \param[in] thread_id
139 /// If this thread hits the breakpoint, we stop, otherwise not.
140 void SetThreadID(lldb::tid_t thread_id);
142 lldb::tid_t GetThreadID();
144 void SetThreadIndex(uint32_t index);
146 uint32_t GetThreadIndex() const;
148 void SetThreadName(const char *thread_name);
150 const char *GetThreadName() const;
152 void SetQueueName(const char *queue_name);
154 const char *GetQueueName() const;
156 // The next section deals with this location's breakpoint sites.
158 /// Try to resolve the breakpoint site for this location.
161 /// \b true if we were successful at setting a breakpoint site,
162 /// \b false otherwise.
163 bool ResolveBreakpointSite();
165 /// Clear this breakpoint location's breakpoint site - for instance when
166 /// disabling the breakpoint.
169 /// \b true if there was a breakpoint site to be cleared, \b false
171 bool ClearBreakpointSite();
173 /// Return whether this breakpoint location has a breakpoint site. \return
174 /// \b true if there was a breakpoint site for this breakpoint
175 /// location, \b false otherwise.
176 bool IsResolved() const;
178 lldb::BreakpointSiteSP GetBreakpointSite() const;
180 // The next section are generic report functions.
182 /// Print a description of this breakpoint location to the stream \a s.
185 /// The stream to which to print the description.
188 /// The description level that indicates the detail level to
191 /// \see lldb::DescriptionLevel
192 void GetDescription(Stream *s, lldb::DescriptionLevel level);
194 /// Standard "Dump" method. At present it does nothing.
195 void Dump(Stream *s) const override;
197 /// Use this to set location specific breakpoint options.
199 /// It will create a copy of the containing breakpoint's options if that
200 /// hasn't been done already
203 /// A pointer to the breakpoint options.
204 BreakpointOptions *GetLocationOptions();
206 /// Use this to access breakpoint options from this breakpoint location.
207 /// This will return the options that have a setting for the specified
208 /// BreakpointOptions kind.
211 /// The particular option you are looking up.
213 /// A pointer to the containing breakpoint's options if this
214 /// location doesn't have its own copy.
215 const BreakpointOptions *GetOptionsSpecifyingKind(
216 BreakpointOptions::OptionKind kind) const;
218 bool ValidForThisThread(Thread *thread);
220 /// Invoke the callback action when the breakpoint is hit.
222 /// Meant to be used by the BreakpointLocation class.
224 /// \param[in] context
225 /// Described the breakpoint event.
227 /// \param[in] bp_loc_id
228 /// Which breakpoint location hit this breakpoint.
231 /// \b true if the target should stop at this breakpoint and \b
233 bool InvokeCallback(StoppointCallbackContext *context);
235 /// Returns whether we should resolve Indirect functions in setting the
236 /// breakpoint site for this location.
239 /// \b true if the breakpoint SITE for this location should be set on the
240 /// resolved location for Indirect functions.
241 bool ShouldResolveIndirectFunctions() {
242 return m_should_resolve_indirect_functions;
245 /// Returns whether the address set in the breakpoint site for this location
246 /// was found by resolving an indirect symbol.
249 /// \b true or \b false as given in the description above.
250 bool IsIndirect() { return m_is_indirect; }
252 void SetIsIndirect(bool is_indirect) { m_is_indirect = is_indirect; }
254 /// Returns whether the address set in the breakpoint location was re-routed
255 /// to the target of a re-exported symbol.
258 /// \b true or \b false as given in the description above.
259 bool IsReExported() { return m_is_reexported; }
261 void SetIsReExported(bool is_reexported) { m_is_reexported = is_reexported; }
263 /// Returns whether the two breakpoint locations might represent "equivalent
264 /// locations". This is used when modules changed to determine if a Location
265 /// in the old module might be the "same as" the input location.
267 /// \param[in] location
268 /// The location to compare against.
271 /// \b true or \b false as given in the description above.
272 bool EquivalentToLocation(BreakpointLocation &location);
275 friend class BreakpointSite;
276 friend class BreakpointLocationList;
277 friend class Process;
278 friend class StopInfoBreakpoint;
280 /// Set the breakpoint site for this location to \a bp_site_sp.
282 /// \param[in] bp_site_sp
283 /// The breakpoint site we are setting for this location.
286 /// \b true if we were successful at setting the breakpoint site,
287 /// \b false otherwise.
288 bool SetBreakpointSite(lldb::BreakpointSiteSP &bp_site_sp);
290 void DecrementIgnoreCount();
292 bool IgnoreCountShouldStop();
295 void SwapLocation(lldb::BreakpointLocationSP swap_from);
299 void UndoBumpHitCount();
301 // Constructors and Destructors
303 // Only the Breakpoint can make breakpoint locations, and it owns them.
308 /// A back pointer to the breakpoint that owns this location.
311 /// The Address defining this location.
314 /// The thread for which this breakpoint location is valid, or
315 /// LLDB_INVALID_THREAD_ID if it is valid for all threads.
317 /// \param[in] hardware
318 /// \b true if a hardware breakpoint is requested.
320 BreakpointLocation(lldb::break_id_t bid, Breakpoint &owner,
321 const Address &addr, lldb::tid_t tid, bool hardware,
322 bool check_for_resolver = true);
325 bool m_being_created;
326 bool m_should_resolve_indirect_functions;
327 bool m_is_reexported;
329 Address m_address; ///< The address defining this location.
330 Breakpoint &m_owner; ///< The breakpoint that produced this object.
331 std::unique_ptr<BreakpointOptions> m_options_up; ///< Breakpoint options
332 /// pointer, nullptr if we're
333 /// using our breakpoint's
335 lldb::BreakpointSiteSP m_bp_site_sp; ///< Our breakpoint site (it may be
336 ///shared by more than one location.)
337 lldb::UserExpressionSP m_user_expression_sp; ///< The compiled expression to
338 ///use in testing our condition.
339 std::mutex m_condition_mutex; ///< Guards parsing and evaluation of the
340 ///condition, which could be evaluated by
341 /// multiple processes.
342 size_t m_condition_hash; ///< For testing whether the condition source code
345 void SetShouldResolveIndirectFunctions(bool do_resolve) {
346 m_should_resolve_indirect_functions = do_resolve;
349 void SendBreakpointLocationChangedEvent(lldb::BreakpointEventType eventKind);
351 DISALLOW_COPY_AND_ASSIGN(BreakpointLocation);
354 } // namespace lldb_private
356 #endif // liblldb_BreakpointLocation_h_