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