| 1 | //===-- Breakpoint.h --------------------------------------------*- C++ -*-===// | 
|---|
| 2 | // | 
|---|
| 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 | 
|---|
| 6 | // | 
|---|
| 7 | //===----------------------------------------------------------------------===// | 
|---|
| 8 |  | 
|---|
| 9 | #ifndef LLDB_BREAKPOINT_BREAKPOINT_H | 
|---|
| 10 | #define LLDB_BREAKPOINT_BREAKPOINT_H | 
|---|
| 11 |  | 
|---|
| 12 | #include <memory> | 
|---|
| 13 | #include <string> | 
|---|
| 14 | #include <unordered_set> | 
|---|
| 15 | #include <vector> | 
|---|
| 16 |  | 
|---|
| 17 | #include "lldb/Breakpoint/BreakpointID.h" | 
|---|
| 18 | #include "lldb/Breakpoint/BreakpointLocationCollection.h" | 
|---|
| 19 | #include "lldb/Breakpoint/BreakpointLocationList.h" | 
|---|
| 20 | #include "lldb/Breakpoint/BreakpointName.h" | 
|---|
| 21 | #include "lldb/Breakpoint/BreakpointOptions.h" | 
|---|
| 22 | #include "lldb/Breakpoint/Stoppoint.h" | 
|---|
| 23 | #include "lldb/Breakpoint/StoppointHitCounter.h" | 
|---|
| 24 | #include "lldb/Core/SearchFilter.h" | 
|---|
| 25 | #include "lldb/Target/Statistics.h" | 
|---|
| 26 | #include "lldb/Utility/Event.h" | 
|---|
| 27 | #include "lldb/Utility/StringList.h" | 
|---|
| 28 | #include "lldb/Utility/StructuredData.h" | 
|---|
| 29 |  | 
|---|
| 30 | namespace lldb_private { | 
|---|
| 31 |  | 
|---|
| 32 | /// \class Breakpoint Breakpoint.h "lldb/Breakpoint/Breakpoint.h" Class that | 
|---|
| 33 | /// manages logical breakpoint setting. | 
|---|
| 34 |  | 
|---|
| 35 | /// General Outline: | 
|---|
| 36 | /// A breakpoint has four main parts, a filter, a resolver, the list of | 
|---|
| 37 | /// breakpoint | 
|---|
| 38 | /// locations that have been determined for the filter/resolver pair, and | 
|---|
| 39 | /// finally a set of options for the breakpoint. | 
|---|
| 40 | /// | 
|---|
| 41 | /// \b Filter: | 
|---|
| 42 | /// This is an object derived from SearchFilter.  It manages the search for | 
|---|
| 43 | /// breakpoint location matches through the symbols in the module list of the | 
|---|
| 44 | /// target that owns it.  It also filters out locations based on whatever | 
|---|
| 45 | /// logic it wants. | 
|---|
| 46 | /// | 
|---|
| 47 | /// \b Resolver: | 
|---|
| 48 | /// This is an object derived from BreakpointResolver.  It provides a callback | 
|---|
| 49 | /// to the filter that will find breakpoint locations.  How it does this is | 
|---|
| 50 | /// determined by what kind of resolver it is. | 
|---|
| 51 | /// | 
|---|
| 52 | /// The Breakpoint class also provides constructors for the common breakpoint | 
|---|
| 53 | /// cases which make the appropriate filter and resolver for you. | 
|---|
| 54 | /// | 
|---|
| 55 | /// \b Location List: | 
|---|
| 56 | /// This stores the breakpoint locations that have been determined to date. | 
|---|
| 57 | /// For a given breakpoint, there will be only one location with a given | 
|---|
| 58 | /// address.  Adding a location at an already taken address will just return | 
|---|
| 59 | /// the location already at that address.  Locations can be looked up by ID, | 
|---|
| 60 | /// or by address. | 
|---|
| 61 | /// | 
|---|
| 62 | /// \b Options: | 
|---|
| 63 | /// This includes: | 
|---|
| 64 | ///    \b Enabled/Disabled | 
|---|
| 65 | ///    \b Ignore Count | 
|---|
| 66 | ///    \b Callback | 
|---|
| 67 | ///    \b Condition | 
|---|
| 68 | /// Note, these options can be set on the breakpoint, and they can also be set | 
|---|
| 69 | /// on the individual locations.  The options set on the breakpoint take | 
|---|
| 70 | /// precedence over the options set on the individual location. So for | 
|---|
| 71 | /// instance disabling the breakpoint will cause NONE of the locations to get | 
|---|
| 72 | /// hit. But if the breakpoint is enabled, then the location's enabled state | 
|---|
| 73 | /// will be checked to determine whether to insert that breakpoint location. | 
|---|
| 74 | /// Similarly, if the breakpoint condition says "stop", we won't check the | 
|---|
| 75 | /// location's condition. But if the breakpoint condition says "continue", | 
|---|
| 76 | /// then we will check the location for whether to actually stop or not. One | 
|---|
| 77 | /// subtle point worth observing here is that you don't actually stop at a | 
|---|
| 78 | /// Breakpoint, you always stop at one of its locations.  So the "should stop" | 
|---|
| 79 | /// tests are done by the location, not by the breakpoint. | 
|---|
| 80 | class Breakpoint : public std::enable_shared_from_this<Breakpoint>, | 
|---|
| 81 | public Stoppoint { | 
|---|
| 82 | public: | 
|---|
| 83 | static const char * | 
|---|
| 84 | BreakpointEventTypeAsCString(lldb::BreakpointEventType type); | 
|---|
| 85 |  | 
|---|
| 86 | /// An enum specifying the match style for breakpoint settings.  At present | 
|---|
| 87 | /// only used for function name style breakpoints. | 
|---|
| 88 | enum MatchType { Exact, Regexp, Glob }; | 
|---|
| 89 |  | 
|---|
| 90 | private: | 
|---|
| 91 | enum class OptionNames : uint32_t { Names = 0, Hardware, LastOptionName }; | 
|---|
| 92 |  | 
|---|
| 93 | static const char | 
|---|
| 94 | *g_option_names[static_cast<uint32_t>(OptionNames::LastOptionName)]; | 
|---|
| 95 |  | 
|---|
| 96 | static const char *GetKey(OptionNames enum_value) { | 
|---|
| 97 | return g_option_names[static_cast<uint32_t>(enum_value)]; | 
|---|
| 98 | } | 
|---|
| 99 |  | 
|---|
| 100 | public: | 
|---|
| 101 | class BreakpointEventData : public EventData { | 
|---|
| 102 | public: | 
|---|
| 103 | BreakpointEventData(lldb::BreakpointEventType sub_type, | 
|---|
| 104 | const lldb::BreakpointSP &new_breakpoint_sp); | 
|---|
| 105 |  | 
|---|
| 106 | ~BreakpointEventData() override; | 
|---|
| 107 |  | 
|---|
| 108 | static llvm::StringRef GetFlavorString(); | 
|---|
| 109 |  | 
|---|
| 110 | Log *GetLogChannel() override; | 
|---|
| 111 |  | 
|---|
| 112 | llvm::StringRef GetFlavor() const override; | 
|---|
| 113 |  | 
|---|
| 114 | lldb::BreakpointEventType GetBreakpointEventType() const; | 
|---|
| 115 |  | 
|---|
| 116 | lldb::BreakpointSP GetBreakpoint() const; | 
|---|
| 117 |  | 
|---|
| 118 | BreakpointLocationCollection &GetBreakpointLocationCollection() { | 
|---|
| 119 | return m_locations; | 
|---|
| 120 | } | 
|---|
| 121 |  | 
|---|
| 122 | void Dump(Stream *s) const override; | 
|---|
| 123 |  | 
|---|
| 124 | static lldb::BreakpointEventType | 
|---|
| 125 | GetBreakpointEventTypeFromEvent(const lldb::EventSP &event_sp); | 
|---|
| 126 |  | 
|---|
| 127 | static lldb::BreakpointSP | 
|---|
| 128 | GetBreakpointFromEvent(const lldb::EventSP &event_sp); | 
|---|
| 129 |  | 
|---|
| 130 | static lldb::BreakpointLocationSP | 
|---|
| 131 | GetBreakpointLocationAtIndexFromEvent(const lldb::EventSP &event_sp, | 
|---|
| 132 | uint32_t loc_idx); | 
|---|
| 133 |  | 
|---|
| 134 | static size_t | 
|---|
| 135 | GetNumBreakpointLocationsFromEvent(const lldb::EventSP &event_sp); | 
|---|
| 136 |  | 
|---|
| 137 | static const BreakpointEventData * | 
|---|
| 138 | GetEventDataFromEvent(const Event *event_sp); | 
|---|
| 139 |  | 
|---|
| 140 | private: | 
|---|
| 141 | lldb::BreakpointEventType m_breakpoint_event; | 
|---|
| 142 | lldb::BreakpointSP m_new_breakpoint_sp; | 
|---|
| 143 | BreakpointLocationCollection m_locations; | 
|---|
| 144 |  | 
|---|
| 145 | BreakpointEventData(const BreakpointEventData &) = delete; | 
|---|
| 146 | const BreakpointEventData &operator=(const BreakpointEventData &) = delete; | 
|---|
| 147 | }; | 
|---|
| 148 |  | 
|---|
| 149 | // Saving & restoring breakpoints: | 
|---|
| 150 | static lldb::BreakpointSP CreateFromStructuredData( | 
|---|
| 151 | lldb::TargetSP target_sp, StructuredData::ObjectSP &data_object_sp, | 
|---|
| 152 | Status &error); | 
|---|
| 153 |  | 
|---|
| 154 | static bool | 
|---|
| 155 | SerializedBreakpointMatchesNames(StructuredData::ObjectSP &bkpt_object_sp, | 
|---|
| 156 | std::vector<std::string> &names); | 
|---|
| 157 |  | 
|---|
| 158 | virtual StructuredData::ObjectSP SerializeToStructuredData(); | 
|---|
| 159 |  | 
|---|
| 160 | static const char *GetSerializationKey() { return "Breakpoint"; } | 
|---|
| 161 | /// Destructor. | 
|---|
| 162 | /// | 
|---|
| 163 | /// The destructor is not virtual since there should be no reason to | 
|---|
| 164 | /// subclass breakpoints.  The varieties of breakpoints are specified | 
|---|
| 165 | /// instead by providing different resolvers & filters. | 
|---|
| 166 | ~Breakpoint() override; | 
|---|
| 167 |  | 
|---|
| 168 | // Methods | 
|---|
| 169 |  | 
|---|
| 170 | /// Tell whether this breakpoint is an "internal" breakpoint. \return | 
|---|
| 171 | ///     Returns \b true if this is an internal breakpoint, \b false otherwise. | 
|---|
| 172 | bool IsInternal() const; | 
|---|
| 173 |  | 
|---|
| 174 | /// Standard "Dump" method.  At present it does nothing. | 
|---|
| 175 | void Dump(Stream *s) override; | 
|---|
| 176 |  | 
|---|
| 177 | // The next set of methods provide ways to tell the breakpoint to update it's | 
|---|
| 178 | // location list - usually done when modules appear or disappear. | 
|---|
| 179 |  | 
|---|
| 180 | /// Tell this breakpoint to clear all its breakpoint sites.  Done when the | 
|---|
| 181 | /// process holding the breakpoint sites is destroyed. | 
|---|
| 182 | void ClearAllBreakpointSites(); | 
|---|
| 183 |  | 
|---|
| 184 | /// Tell this breakpoint to scan it's target's module list and resolve any | 
|---|
| 185 | /// new locations that match the breakpoint's specifications. | 
|---|
| 186 | void ResolveBreakpoint(); | 
|---|
| 187 |  | 
|---|
| 188 | /// Tell this breakpoint to scan a given module list and resolve any new | 
|---|
| 189 | /// locations that match the breakpoint's specifications. | 
|---|
| 190 | /// | 
|---|
| 191 | /// \param[in] module_list | 
|---|
| 192 | ///    The list of modules to look in for new locations. | 
|---|
| 193 | /// | 
|---|
| 194 | /// \param[in]  send_event | 
|---|
| 195 | ///     If \b true, send a breakpoint location added event for non-internal | 
|---|
| 196 | ///     breakpoints. | 
|---|
| 197 | void ResolveBreakpointInModules(ModuleList &module_list, | 
|---|
| 198 | bool send_event = true); | 
|---|
| 199 |  | 
|---|
| 200 | /// Tell this breakpoint to scan a given module list and resolve any new | 
|---|
| 201 | /// locations that match the breakpoint's specifications. | 
|---|
| 202 | /// | 
|---|
| 203 | /// \param[in] module_list | 
|---|
| 204 | ///    The list of modules to look in for new locations. | 
|---|
| 205 | /// | 
|---|
| 206 | /// \param[in]  new_locations | 
|---|
| 207 | ///     Fills new_locations with the new locations that were made. | 
|---|
| 208 | void ResolveBreakpointInModules(ModuleList &module_list, | 
|---|
| 209 | BreakpointLocationCollection &new_locations); | 
|---|
| 210 |  | 
|---|
| 211 | /// Like ResolveBreakpointInModules, but allows for "unload" events, in | 
|---|
| 212 | /// which case we will remove any locations that are in modules that got | 
|---|
| 213 | /// unloaded. | 
|---|
| 214 | /// | 
|---|
| 215 | /// \param[in] changed_modules | 
|---|
| 216 | ///    The list of modules to look in for new locations. | 
|---|
| 217 | /// \param[in] load_event | 
|---|
| 218 | ///    If \b true then the modules were loaded, if \b false, unloaded. | 
|---|
| 219 | /// \param[in] delete_locations | 
|---|
| 220 | ///    If \b true then the modules were unloaded delete any locations in the | 
|---|
| 221 | ///    changed modules. | 
|---|
| 222 | void ModulesChanged(ModuleList &changed_modules, bool load_event, | 
|---|
| 223 | bool delete_locations = false); | 
|---|
| 224 |  | 
|---|
| 225 | /// Tells the breakpoint the old module \a old_module_sp has been replaced | 
|---|
| 226 | /// by new_module_sp (usually because the underlying file has been rebuilt, | 
|---|
| 227 | /// and the old version is gone.) | 
|---|
| 228 | /// | 
|---|
| 229 | /// \param[in] old_module_sp | 
|---|
| 230 | ///    The old module that is going away. | 
|---|
| 231 | /// \param[in] new_module_sp | 
|---|
| 232 | ///    The new module that is replacing it. | 
|---|
| 233 | void ModuleReplaced(lldb::ModuleSP old_module_sp, | 
|---|
| 234 | lldb::ModuleSP new_module_sp); | 
|---|
| 235 |  | 
|---|
| 236 | // The next set of methods provide access to the breakpoint locations for | 
|---|
| 237 | // this breakpoint. | 
|---|
| 238 |  | 
|---|
| 239 | /// Add a location to the breakpoint's location list.  This is only meant to | 
|---|
| 240 | /// be called by the breakpoint's resolver.  FIXME: how do I ensure that? | 
|---|
| 241 | /// | 
|---|
| 242 | /// \param[in] addr | 
|---|
| 243 | ///    The Address specifying the new location. | 
|---|
| 244 | /// \param[out] new_location | 
|---|
| 245 | ///    Set to \b true if a new location was created, to \b false if there | 
|---|
| 246 | ///    already was a location at this Address. | 
|---|
| 247 | /// \return | 
|---|
| 248 | ///    Returns a pointer to the new location. | 
|---|
| 249 | lldb::BreakpointLocationSP AddLocation(const Address &addr, | 
|---|
| 250 | bool *new_location = nullptr); | 
|---|
| 251 |  | 
|---|
| 252 | /// Find a breakpoint location by Address. | 
|---|
| 253 | /// | 
|---|
| 254 | /// \param[in] addr | 
|---|
| 255 | ///    The Address specifying the location. | 
|---|
| 256 | /// \return | 
|---|
| 257 | ///    Returns a shared pointer to the location at \a addr.  The pointer | 
|---|
| 258 | ///    in the shared pointer will be nullptr if there is no location at that | 
|---|
| 259 | ///    address. | 
|---|
| 260 | lldb::BreakpointLocationSP FindLocationByAddress(const Address &addr); | 
|---|
| 261 |  | 
|---|
| 262 | /// Find a breakpoint location ID by Address. | 
|---|
| 263 | /// | 
|---|
| 264 | /// \param[in] addr | 
|---|
| 265 | ///    The Address specifying the location. | 
|---|
| 266 | /// \return | 
|---|
| 267 | ///    Returns the UID of the location at \a addr, or \b LLDB_INVALID_ID if | 
|---|
| 268 | ///    there is no breakpoint location at that address. | 
|---|
| 269 | lldb::break_id_t FindLocationIDByAddress(const Address &addr); | 
|---|
| 270 |  | 
|---|
| 271 | /// Find a breakpoint location for a given breakpoint location ID. | 
|---|
| 272 | /// | 
|---|
| 273 | /// \param[in] bp_loc_id | 
|---|
| 274 | ///    The ID specifying the location. | 
|---|
| 275 | /// \return | 
|---|
| 276 | ///    Returns a shared pointer to the location with ID \a bp_loc_id.  The | 
|---|
| 277 | ///    pointer | 
|---|
| 278 | ///    in the shared pointer will be nullptr if there is no location with that | 
|---|
| 279 | ///    ID. | 
|---|
| 280 | lldb::BreakpointLocationSP FindLocationByID(lldb::break_id_t bp_loc_id); | 
|---|
| 281 |  | 
|---|
| 282 | /// Get breakpoint locations by index. | 
|---|
| 283 | /// | 
|---|
| 284 | /// \param[in] index | 
|---|
| 285 | ///    The location index. | 
|---|
| 286 | /// | 
|---|
| 287 | /// \return | 
|---|
| 288 | ///     Returns a shared pointer to the location with index \a | 
|---|
| 289 | ///     index. The shared pointer might contain nullptr if \a index is | 
|---|
| 290 | ///     greater than then number of actual locations. | 
|---|
| 291 | lldb::BreakpointLocationSP GetLocationAtIndex(size_t index); | 
|---|
| 292 |  | 
|---|
| 293 | /// Removes all invalid breakpoint locations. | 
|---|
| 294 | /// | 
|---|
| 295 | /// Removes all breakpoint locations with architectures that aren't | 
|---|
| 296 | /// compatible with \a arch. Also remove any breakpoint locations with whose | 
|---|
| 297 | /// locations have address where the section has been deleted (module and | 
|---|
| 298 | /// object files no longer exist). | 
|---|
| 299 | /// | 
|---|
| 300 | /// This is typically used after the process calls exec, or anytime the | 
|---|
| 301 | /// architecture of the target changes. | 
|---|
| 302 | /// | 
|---|
| 303 | /// \param[in] arch | 
|---|
| 304 | ///     If valid, check the module in each breakpoint to make sure | 
|---|
| 305 | ///     they are compatible, otherwise, ignore architecture. | 
|---|
| 306 | void RemoveInvalidLocations(const ArchSpec &arch); | 
|---|
| 307 |  | 
|---|
| 308 | // The next section deals with various breakpoint options. | 
|---|
| 309 |  | 
|---|
| 310 | /// If \a enable is \b true, enable the breakpoint, if \b false disable it. | 
|---|
| 311 | void SetEnabled(bool enable) override; | 
|---|
| 312 |  | 
|---|
| 313 | /// Check the Enable/Disable state. | 
|---|
| 314 | /// \return | 
|---|
| 315 | ///     \b true if the breakpoint is enabled, \b false if disabled. | 
|---|
| 316 | bool IsEnabled() override; | 
|---|
| 317 |  | 
|---|
| 318 | /// Set the breakpoint to ignore the next \a count breakpoint hits. | 
|---|
| 319 | /// \param[in] count | 
|---|
| 320 | ///    The number of breakpoint hits to ignore. | 
|---|
| 321 | void SetIgnoreCount(uint32_t count); | 
|---|
| 322 |  | 
|---|
| 323 | /// Return the current ignore count/ | 
|---|
| 324 | /// \return | 
|---|
| 325 | ///     The number of breakpoint hits to be ignored. | 
|---|
| 326 | uint32_t GetIgnoreCount() const; | 
|---|
| 327 |  | 
|---|
| 328 | /// Return the current hit count for all locations. \return | 
|---|
| 329 | ///     The current hit count for all locations. | 
|---|
| 330 | uint32_t GetHitCount() const; | 
|---|
| 331 |  | 
|---|
| 332 | /// Resets the current hit count for all locations. | 
|---|
| 333 | void ResetHitCount(); | 
|---|
| 334 |  | 
|---|
| 335 | /// If \a one_shot is \b true, breakpoint will be deleted on first hit. | 
|---|
| 336 | void SetOneShot(bool one_shot); | 
|---|
| 337 |  | 
|---|
| 338 | /// Check the OneShot state. | 
|---|
| 339 | /// \return | 
|---|
| 340 | ///     \b true if the breakpoint is one shot, \b false otherwise. | 
|---|
| 341 | bool IsOneShot() const; | 
|---|
| 342 |  | 
|---|
| 343 | /// If \a auto_continue is \b true, breakpoint will auto-continue when on | 
|---|
| 344 | /// hit. | 
|---|
| 345 | void SetAutoContinue(bool auto_continue); | 
|---|
| 346 |  | 
|---|
| 347 | /// Check the AutoContinue state. | 
|---|
| 348 | /// \return | 
|---|
| 349 | ///     \b true if the breakpoint is set to auto-continue, \b false otherwise. | 
|---|
| 350 | bool IsAutoContinue() const; | 
|---|
| 351 |  | 
|---|
| 352 | /// Set the valid thread to be checked when the breakpoint is hit. | 
|---|
| 353 | /// \param[in] thread_id | 
|---|
| 354 | ///    If this thread hits the breakpoint, we stop, otherwise not. | 
|---|
| 355 | void SetThreadID(lldb::tid_t thread_id); | 
|---|
| 356 |  | 
|---|
| 357 | /// Return the current stop thread value. | 
|---|
| 358 | /// \return | 
|---|
| 359 | ///     The thread id for which the breakpoint hit will stop, | 
|---|
| 360 | ///     LLDB_INVALID_THREAD_ID for all threads. | 
|---|
| 361 | lldb::tid_t GetThreadID() const; | 
|---|
| 362 |  | 
|---|
| 363 | void SetThreadIndex(uint32_t index); | 
|---|
| 364 |  | 
|---|
| 365 | uint32_t GetThreadIndex() const; | 
|---|
| 366 |  | 
|---|
| 367 | void SetThreadName(const char *thread_name); | 
|---|
| 368 |  | 
|---|
| 369 | const char *GetThreadName() const; | 
|---|
| 370 |  | 
|---|
| 371 | void SetQueueName(const char *queue_name); | 
|---|
| 372 |  | 
|---|
| 373 | const char *GetQueueName() const; | 
|---|
| 374 |  | 
|---|
| 375 | /// Set the callback action invoked when the breakpoint is hit. | 
|---|
| 376 | /// | 
|---|
| 377 | /// \param[in] callback | 
|---|
| 378 | ///    The method that will get called when the breakpoint is hit. | 
|---|
| 379 | /// \param[in] baton | 
|---|
| 380 | ///    A void * pointer that will get passed back to the callback function. | 
|---|
| 381 | /// \param[in] is_synchronous | 
|---|
| 382 | ///    If \b true the callback will be run on the private event thread | 
|---|
| 383 | ///    before the stop event gets reported.  If false, the callback will get | 
|---|
| 384 | ///    handled on the public event thread while the stop event is being | 
|---|
| 385 | ///    pulled off the event queue. | 
|---|
| 386 | ///    Note: synchronous callbacks cannot cause the target to run, in | 
|---|
| 387 | ///    particular, they should not try to run the expression evaluator. | 
|---|
| 388 | void SetCallback(BreakpointHitCallback callback, void *baton, | 
|---|
| 389 | bool is_synchronous = false); | 
|---|
| 390 |  | 
|---|
| 391 | void SetCallback(BreakpointHitCallback callback, | 
|---|
| 392 | const lldb::BatonSP &callback_baton_sp, | 
|---|
| 393 | bool is_synchronous = false); | 
|---|
| 394 |  | 
|---|
| 395 | void ClearCallback(); | 
|---|
| 396 |  | 
|---|
| 397 | /// Set the breakpoint's condition. | 
|---|
| 398 | /// | 
|---|
| 399 | /// \param[in] condition | 
|---|
| 400 | ///    The condition expression to evaluate when the breakpoint is hit. | 
|---|
| 401 | ///    Pass in nullptr to clear the condition. | 
|---|
| 402 | void SetCondition(const char *condition); | 
|---|
| 403 |  | 
|---|
| 404 | /// Return a pointer to the text of the condition expression. | 
|---|
| 405 | /// | 
|---|
| 406 | /// \return | 
|---|
| 407 | ///    A pointer to the condition expression text, or nullptr if no | 
|---|
| 408 | //     condition has been set. | 
|---|
| 409 | const char *GetConditionText() const; | 
|---|
| 410 |  | 
|---|
| 411 | // The next section are various utility functions. | 
|---|
| 412 |  | 
|---|
| 413 | /// Return the number of breakpoint locations that have resolved to actual | 
|---|
| 414 | /// breakpoint sites. | 
|---|
| 415 | /// | 
|---|
| 416 | /// \return | 
|---|
| 417 | ///     The number locations resolved breakpoint sites. | 
|---|
| 418 | size_t GetNumResolvedLocations() const; | 
|---|
| 419 |  | 
|---|
| 420 | /// Return whether this breakpoint has any resolved locations. | 
|---|
| 421 | /// | 
|---|
| 422 | /// \return | 
|---|
| 423 | ///     True if GetNumResolvedLocations > 0 | 
|---|
| 424 | bool HasResolvedLocations() const; | 
|---|
| 425 |  | 
|---|
| 426 | /// Return the number of breakpoint locations. | 
|---|
| 427 | /// | 
|---|
| 428 | /// \return | 
|---|
| 429 | ///     The number breakpoint locations. | 
|---|
| 430 | size_t GetNumLocations() const; | 
|---|
| 431 |  | 
|---|
| 432 | /// Put a description of this breakpoint into the stream \a s. | 
|---|
| 433 | /// | 
|---|
| 434 | /// \param[in] s | 
|---|
| 435 | ///     Stream into which to dump the description. | 
|---|
| 436 | /// | 
|---|
| 437 | /// \param[in] level | 
|---|
| 438 | ///     The description level that indicates the detail level to | 
|---|
| 439 | ///     provide. | 
|---|
| 440 | /// | 
|---|
| 441 | /// \see lldb::DescriptionLevel | 
|---|
| 442 | void GetDescription(Stream *s, lldb::DescriptionLevel level, | 
|---|
| 443 | bool show_locations = false); | 
|---|
| 444 |  | 
|---|
| 445 | /// Set the "kind" description for a breakpoint.  If the breakpoint is hit | 
|---|
| 446 | /// the stop info will show this "kind" description instead of the | 
|---|
| 447 | /// breakpoint number.  Mostly useful for internal breakpoints, where the | 
|---|
| 448 | /// breakpoint number doesn't have meaning to the user. | 
|---|
| 449 | /// | 
|---|
| 450 | /// \param[in] kind | 
|---|
| 451 | ///     New "kind" description. | 
|---|
| 452 | void SetBreakpointKind(const char *kind) { m_kind_description.assign(s: kind); } | 
|---|
| 453 |  | 
|---|
| 454 | /// Return the "kind" description for a breakpoint. | 
|---|
| 455 | /// | 
|---|
| 456 | /// \return | 
|---|
| 457 | ///     The breakpoint kind, or nullptr if none is set. | 
|---|
| 458 | const char *GetBreakpointKind() const { return m_kind_description.c_str(); } | 
|---|
| 459 |  | 
|---|
| 460 | /// Accessor for the breakpoint Target. | 
|---|
| 461 | /// \return | 
|---|
| 462 | ///     This breakpoint's Target. | 
|---|
| 463 | Target &GetTarget() { return m_target; } | 
|---|
| 464 |  | 
|---|
| 465 | const Target &GetTarget() const { return m_target; } | 
|---|
| 466 |  | 
|---|
| 467 | const lldb::TargetSP GetTargetSP(); | 
|---|
| 468 |  | 
|---|
| 469 | void GetResolverDescription(Stream *s); | 
|---|
| 470 |  | 
|---|
| 471 | /// Find breakpoint locations which match the (filename, line_number) | 
|---|
| 472 | /// description. The breakpoint location collection is to be filled with the | 
|---|
| 473 | /// matching locations. It should be initialized with 0 size by the API | 
|---|
| 474 | /// client. | 
|---|
| 475 | /// | 
|---|
| 476 | /// \return | 
|---|
| 477 | ///     True if there is a match | 
|---|
| 478 | /// | 
|---|
| 479 | ///     The locations which match the filename and line_number in loc_coll. | 
|---|
| 480 | ///     If its | 
|---|
| 481 | ///     size is 0 and true is returned, it means the breakpoint fully matches | 
|---|
| 482 | ///     the | 
|---|
| 483 | ///     description. | 
|---|
| 484 | bool GetMatchingFileLine(ConstString filename, uint32_t line_number, | 
|---|
| 485 | BreakpointLocationCollection &loc_coll); | 
|---|
| 486 |  | 
|---|
| 487 | void GetFilterDescription(Stream *s); | 
|---|
| 488 |  | 
|---|
| 489 | /// Returns the BreakpointOptions structure set at the breakpoint level. | 
|---|
| 490 | /// | 
|---|
| 491 | /// Meant to be used by the BreakpointLocation class. | 
|---|
| 492 | /// | 
|---|
| 493 | /// \return | 
|---|
| 494 | ///     A reference to this breakpoint's BreakpointOptions. | 
|---|
| 495 | BreakpointOptions &GetOptions(); | 
|---|
| 496 |  | 
|---|
| 497 | /// Returns the BreakpointOptions structure set at the breakpoint level. | 
|---|
| 498 | /// | 
|---|
| 499 | /// Meant to be used by the BreakpointLocation class. | 
|---|
| 500 | /// | 
|---|
| 501 | /// \return | 
|---|
| 502 | ///     A reference to this breakpoint's BreakpointOptions. | 
|---|
| 503 | const BreakpointOptions &GetOptions() const; | 
|---|
| 504 |  | 
|---|
| 505 | /// Invoke the callback action when the breakpoint is hit. | 
|---|
| 506 | /// | 
|---|
| 507 | /// Meant to be used by the BreakpointLocation class. | 
|---|
| 508 | /// | 
|---|
| 509 | /// \param[in] context | 
|---|
| 510 | ///     Described the breakpoint event. | 
|---|
| 511 | /// | 
|---|
| 512 | /// \param[in] bp_loc_id | 
|---|
| 513 | ///     Which breakpoint location hit this breakpoint. | 
|---|
| 514 | /// | 
|---|
| 515 | /// \return | 
|---|
| 516 | ///     \b true if the target should stop at this breakpoint and \b false not. | 
|---|
| 517 | bool InvokeCallback(StoppointCallbackContext *context, | 
|---|
| 518 | lldb::break_id_t bp_loc_id); | 
|---|
| 519 |  | 
|---|
| 520 | bool IsHardware() const { return m_hardware; } | 
|---|
| 521 |  | 
|---|
| 522 | lldb::BreakpointResolverSP GetResolver() { return m_resolver_sp; } | 
|---|
| 523 |  | 
|---|
| 524 | lldb::SearchFilterSP GetSearchFilter() { return m_filter_sp; } | 
|---|
| 525 |  | 
|---|
| 526 | private: | 
|---|
| 527 | void AddName(llvm::StringRef new_name); | 
|---|
| 528 |  | 
|---|
| 529 | void RemoveName(const char *name_to_remove) { | 
|---|
| 530 | if (name_to_remove) | 
|---|
| 531 | m_name_list.erase(x: name_to_remove); | 
|---|
| 532 | } | 
|---|
| 533 |  | 
|---|
| 534 | public: | 
|---|
| 535 | bool MatchesName(const char *name) { | 
|---|
| 536 | return m_name_list.find(x: name) != m_name_list.end(); | 
|---|
| 537 | } | 
|---|
| 538 |  | 
|---|
| 539 | void GetNames(std::vector<std::string> &names) { | 
|---|
| 540 | names.clear(); | 
|---|
| 541 | for (auto name : m_name_list) { | 
|---|
| 542 | names.push_back(x: name); | 
|---|
| 543 | } | 
|---|
| 544 | } | 
|---|
| 545 |  | 
|---|
| 546 | /// Set a pre-condition filter that overrides all user provided | 
|---|
| 547 | /// filters/callbacks etc. | 
|---|
| 548 | /// | 
|---|
| 549 | /// Used to define fancy breakpoints that can do dynamic hit detection | 
|---|
| 550 | /// without taking up the condition slot - which really belongs to the user | 
|---|
| 551 | /// anyway... | 
|---|
| 552 | /// | 
|---|
| 553 | /// The Precondition should not continue the target, it should return true | 
|---|
| 554 | /// if the condition says to stop and false otherwise. | 
|---|
| 555 | /// | 
|---|
| 556 | void SetPrecondition(lldb::BreakpointPreconditionSP precondition_sp) { | 
|---|
| 557 | m_precondition_sp = std::move(precondition_sp); | 
|---|
| 558 | } | 
|---|
| 559 |  | 
|---|
| 560 | bool EvaluatePrecondition(StoppointCallbackContext &context); | 
|---|
| 561 |  | 
|---|
| 562 | lldb::BreakpointPreconditionSP GetPrecondition() { return m_precondition_sp; } | 
|---|
| 563 |  | 
|---|
| 564 | // Produces the OR'ed values for all the names assigned to this breakpoint. | 
|---|
| 565 | const BreakpointName::Permissions &GetPermissions() const { | 
|---|
| 566 | return m_permissions; | 
|---|
| 567 | } | 
|---|
| 568 |  | 
|---|
| 569 | BreakpointName::Permissions &GetPermissions() { | 
|---|
| 570 | return m_permissions; | 
|---|
| 571 | } | 
|---|
| 572 |  | 
|---|
| 573 | bool AllowList() const { | 
|---|
| 574 | return GetPermissions().GetAllowList(); | 
|---|
| 575 | } | 
|---|
| 576 | bool AllowDisable() const { | 
|---|
| 577 | return GetPermissions().GetAllowDisable(); | 
|---|
| 578 | } | 
|---|
| 579 | bool AllowDelete() const { | 
|---|
| 580 | return GetPermissions().GetAllowDelete(); | 
|---|
| 581 | } | 
|---|
| 582 |  | 
|---|
| 583 | // This one should only be used by Target to copy breakpoints from target to | 
|---|
| 584 | // target - primarily from the dummy target to prime new targets. | 
|---|
| 585 | static lldb::BreakpointSP CopyFromBreakpoint(lldb::TargetSP new_target, | 
|---|
| 586 | const Breakpoint &bp_to_copy_from); | 
|---|
| 587 |  | 
|---|
| 588 | /// Get statistics associated with this breakpoint in JSON format. | 
|---|
| 589 | llvm::json::Value GetStatistics(); | 
|---|
| 590 |  | 
|---|
| 591 | void ResetStatistics(); | 
|---|
| 592 |  | 
|---|
| 593 | /// Get the time it took to resolve all locations in this breakpoint. | 
|---|
| 594 | StatsDuration::Duration GetResolveTime() const { return m_resolve_time; } | 
|---|
| 595 |  | 
|---|
| 596 | protected: | 
|---|
| 597 | friend class Target; | 
|---|
| 598 | // Protected Methods | 
|---|
| 599 |  | 
|---|
| 600 | /// Constructors and Destructors | 
|---|
| 601 | /// Only the Target can make a breakpoint, and it owns the breakpoint | 
|---|
| 602 | /// lifespans. The constructor takes a filter and a resolver.  Up in Target | 
|---|
| 603 | /// there are convenience variants that make breakpoints for some common | 
|---|
| 604 | /// cases. | 
|---|
| 605 | /// | 
|---|
| 606 | /// \param[in] target | 
|---|
| 607 | ///    The target in which the breakpoint will be set. | 
|---|
| 608 | /// | 
|---|
| 609 | /// \param[in] filter_sp | 
|---|
| 610 | ///    Shared pointer to the search filter that restricts the search domain of | 
|---|
| 611 | ///    the breakpoint. | 
|---|
| 612 | /// | 
|---|
| 613 | /// \param[in] resolver_sp | 
|---|
| 614 | ///    Shared pointer to the resolver object that will determine breakpoint | 
|---|
| 615 | ///    matches. | 
|---|
| 616 | /// | 
|---|
| 617 | /// \param hardware | 
|---|
| 618 | ///    If true, request a hardware breakpoint to be used to implement the | 
|---|
| 619 | ///    breakpoint locations. | 
|---|
| 620 | /// | 
|---|
| 621 | /// \param resolve_indirect_symbols | 
|---|
| 622 | ///    If true, and the address of a given breakpoint location in this | 
|---|
| 623 | ///    breakpoint is set on an | 
|---|
| 624 | ///    indirect symbol (i.e. Symbol::IsIndirect returns true) then the actual | 
|---|
| 625 | ///    breakpoint site will | 
|---|
| 626 | ///    be set on the target of the indirect symbol. | 
|---|
| 627 | // This is the generic constructor | 
|---|
| 628 | Breakpoint(Target &target, lldb::SearchFilterSP &filter_sp, | 
|---|
| 629 | lldb::BreakpointResolverSP &resolver_sp, bool hardware, | 
|---|
| 630 | bool resolve_indirect_symbols = true); | 
|---|
| 631 |  | 
|---|
| 632 | friend class BreakpointLocation; // To call the following two when determining | 
|---|
| 633 | // whether to stop. | 
|---|
| 634 |  | 
|---|
| 635 | void DecrementIgnoreCount(); | 
|---|
| 636 |  | 
|---|
| 637 | private: | 
|---|
| 638 | // To call from CopyFromBreakpoint. | 
|---|
| 639 | Breakpoint(Target &new_target, const Breakpoint &bp_to_copy_from); | 
|---|
| 640 |  | 
|---|
| 641 | // For Breakpoint only | 
|---|
| 642 | bool | 
|---|
| 643 | m_hardware; // If this breakpoint is required to use a hardware breakpoint | 
|---|
| 644 | Target &m_target; // The target that holds this breakpoint. | 
|---|
| 645 | std::unordered_set<std::string> m_name_list; // If not empty, this is the name | 
|---|
| 646 | // of this breakpoint (many | 
|---|
| 647 | // breakpoints can share the same | 
|---|
| 648 | // name.) | 
|---|
| 649 | lldb::SearchFilterSP | 
|---|
| 650 | m_filter_sp; // The filter that constrains the breakpoint's domain. | 
|---|
| 651 | lldb::BreakpointResolverSP | 
|---|
| 652 | m_resolver_sp; // The resolver that defines this breakpoint. | 
|---|
| 653 | lldb::BreakpointPreconditionSP m_precondition_sp; // The precondition is a | 
|---|
| 654 | // breakpoint-level hit | 
|---|
| 655 | // filter that can be used | 
|---|
| 656 | // to skip certain breakpoint hits.  For instance, exception breakpoints use | 
|---|
| 657 | // this to limit the stop to certain exception classes, while leaving the | 
|---|
| 658 | // condition & callback free for user specification. | 
|---|
| 659 | BreakpointOptions m_options; // Settable breakpoint options | 
|---|
| 660 | BreakpointLocationList | 
|---|
| 661 | m_locations; // The list of locations currently found for this breakpoint. | 
|---|
| 662 | std::string m_kind_description; | 
|---|
| 663 | bool m_resolve_indirect_symbols; | 
|---|
| 664 |  | 
|---|
| 665 | /// Number of times this breakpoint has been hit. This is kept separately | 
|---|
| 666 | /// from the locations hit counts, since locations can go away when their | 
|---|
| 667 | /// backing library gets unloaded, and we would lose hit counts. | 
|---|
| 668 | StoppointHitCounter m_hit_counter; | 
|---|
| 669 |  | 
|---|
| 670 | BreakpointName::Permissions m_permissions; | 
|---|
| 671 |  | 
|---|
| 672 | StatsDuration m_resolve_time; | 
|---|
| 673 |  | 
|---|
| 674 | void SendBreakpointChangedEvent(lldb::BreakpointEventType eventKind); | 
|---|
| 675 |  | 
|---|
| 676 | void SendBreakpointChangedEvent(const lldb::EventDataSP &breakpoint_data_sp); | 
|---|
| 677 |  | 
|---|
| 678 | Breakpoint(const Breakpoint &) = delete; | 
|---|
| 679 | const Breakpoint &operator=(const Breakpoint &) = delete; | 
|---|
| 680 | }; | 
|---|
| 681 |  | 
|---|
| 682 | } // namespace lldb_private | 
|---|
| 683 |  | 
|---|
| 684 | #endif // LLDB_BREAKPOINT_BREAKPOINT_H | 
|---|
| 685 |  | 
|---|