BreakpointLocation.h revision b5d55cf7a00d0f9e31a1664d372f8e570d562777
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/Breakpoint/StoppointLocation.h" 24#include "lldb/Core/UserID.h" 25#include "lldb/Core/Address.h" 26#include "lldb/Target/Process.h" 27#include "lldb/Core/StringList.h" 28 29namespace lldb_private { 30 31//---------------------------------------------------------------------- 32/// @class BreakpointLocation BreakpointLocation.h "lldb/Breakpoint/BreakpointLocation.h" 33/// @brief Class that manages one unique (by address) instance of a logical breakpoint. 34//---------------------------------------------------------------------- 35 36//---------------------------------------------------------------------- 37/// General Outline: 38/// A breakpoint location is defined by the breakpoint that produces it, 39/// and the address that resulted in this particular instantiation. 40/// Each breakpoint location also may have a breakpoint site if its 41/// address has been loaded into the program. 42/// Finally it has a settable options object. 43/// 44/// FIXME: Should we also store some fingerprint for the location, so 45/// we can map one location to the "equivalent location" on rerun? This 46/// would be useful if you've set options on the locations. 47//---------------------------------------------------------------------- 48 49class BreakpointLocation : 50 public STD_ENABLE_SHARED_FROM_THIS(BreakpointLocation), 51 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 () const; 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 breakpoint location's condition. 164 /// 165 /// @param[in] condition 166 /// The condition expression to evaluate when the breakpoint is hit. 167 //------------------------------------------------------------------ 168 void 169 SetCondition (const char *condition); 170 171 //------------------------------------------------------------------ 172 /// Return a pointer to the text of the condition expression. 173 /// 174 /// @return 175 /// A pointer to the condition expression text, or NULL if no 176 // condition has been set. 177 //------------------------------------------------------------------ 178 const char * 179 GetConditionText () const; 180 181 182 //------------------------------------------------------------------ 183 /// Set the valid thread to be checked when the breakpoint is hit. 184 /// 185 /// @param[in] thread_id 186 /// If this thread hits the breakpoint, we stop, otherwise not. 187 //------------------------------------------------------------------ 188 void 189 SetThreadID (lldb::tid_t thread_id); 190 191 lldb::tid_t 192 GetThreadID (); 193 194 void 195 SetThreadIndex (uint32_t index); 196 197 uint32_t 198 GetThreadIndex() const; 199 200 void 201 SetThreadName (const char *thread_name); 202 203 const char * 204 GetThreadName () const; 205 206 void 207 SetQueueName (const char *queue_name); 208 209 const char * 210 GetQueueName () const; 211 212 //------------------------------------------------------------------ 213 // The next section deals with this location's breakpoint sites. 214 //------------------------------------------------------------------ 215 216 //------------------------------------------------------------------ 217 /// Try to resolve the breakpoint site for this location. 218 /// 219 /// @return 220 /// \b true if we were successful at setting a breakpoint site, 221 /// \b false otherwise. 222 //------------------------------------------------------------------ 223 bool 224 ResolveBreakpointSite (); 225 226 //------------------------------------------------------------------ 227 /// Clear this breakpoint location's breakpoint site - for instance 228 /// when disabling the breakpoint. 229 /// 230 /// @return 231 /// \b true if there was a breakpoint site to be cleared, \b false 232 /// otherwise. 233 //------------------------------------------------------------------ 234 bool 235 ClearBreakpointSite (); 236 237 //------------------------------------------------------------------ 238 /// Return whether this breakpoint location has a breakpoint site. 239 /// @return 240 /// \b true if there was a breakpoint site for this breakpoint 241 /// location, \b false otherwise. 242 //------------------------------------------------------------------ 243 bool 244 IsResolved () const; 245 246 lldb::BreakpointSiteSP 247 GetBreakpointSite() const; 248 249 //------------------------------------------------------------------ 250 // The next section are generic report functions. 251 //------------------------------------------------------------------ 252 253 //------------------------------------------------------------------ 254 /// Print a description of this breakpoint location to the stream 255 /// \a s. 256 /// 257 /// @param[in] s 258 /// The stream to which to print the description. 259 /// 260 /// @param[in] level 261 /// The description level that indicates the detail level to 262 /// provide. 263 /// 264 /// @see lldb::DescriptionLevel 265 //------------------------------------------------------------------ 266 void 267 GetDescription (Stream *s, lldb::DescriptionLevel level); 268 269 //------------------------------------------------------------------ 270 /// Standard "Dump" method. At present it does nothing. 271 //------------------------------------------------------------------ 272 void 273 Dump (Stream *s) const; 274 275 //------------------------------------------------------------------ 276 /// Use this to set location specific breakpoint options. 277 /// 278 /// It will create a copy of the containing breakpoint's options if 279 /// that hasn't been done already 280 /// 281 /// @return 282 /// A pointer to the breakpoint options. 283 //------------------------------------------------------------------ 284 BreakpointOptions * 285 GetLocationOptions (); 286 287 //------------------------------------------------------------------ 288 /// Use this to access breakpoint options from this breakpoint location. 289 /// This will point to the owning breakpoint's options unless options have 290 /// been set specifically on this location. 291 /// 292 /// @return 293 /// A pointer to the containing breakpoint's options if this 294 /// location doesn't have its own copy. 295 //------------------------------------------------------------------ 296 const BreakpointOptions * 297 GetOptionsNoCreate () const; 298 299 bool 300 ValidForThisThread (Thread *thread); 301 302 303 //------------------------------------------------------------------ 304 /// Invoke the callback action when the breakpoint is hit. 305 /// 306 /// Meant to be used by the BreakpointLocation class. 307 /// 308 /// @param[in] context 309 /// Described the breakpoint event. 310 /// 311 /// @param[in] bp_loc_id 312 /// Which breakpoint location hit this breakpoint. 313 /// 314 /// @return 315 /// \b true if the target should stop at this breakpoint and \b 316 /// false not. 317 //------------------------------------------------------------------ 318 bool 319 InvokeCallback (StoppointCallbackContext *context); 320 321protected: 322 friend class BreakpointLocationList; 323 friend class CommandObjectBreakpointCommandAdd; 324 friend class Process; 325 326 //------------------------------------------------------------------ 327 /// Set the breakpoint site for this location to \a bp_site_sp. 328 /// 329 /// @param[in] bp_site_sp 330 /// The breakpoint site we are setting for this location. 331 /// 332 /// @return 333 /// \b true if we were successful at setting the breakpoint site, 334 /// \b false otherwise. 335 //------------------------------------------------------------------ 336 bool 337 SetBreakpointSite (lldb::BreakpointSiteSP& bp_site_sp); 338 339private: 340 341 //------------------------------------------------------------------ 342 // Constructors and Destructors 343 // 344 // Only the Breakpoint can make breakpoint locations, and it owns 345 // them. 346 //------------------------------------------------------------------ 347 348 //------------------------------------------------------------------ 349 /// Constructor. 350 /// 351 /// @param[in] owner 352 /// A back pointer to the breakpoint that owns this location. 353 /// 354 /// @param[in] addr 355 /// The Address defining this location. 356 /// 357 /// @param[in] tid 358 /// The thread for which this breakpoint location is valid, or 359 /// LLDB_INVALID_THREAD_ID if it is valid for all threads. 360 /// 361 /// @param[in] hardware 362 /// \b true if a hardware breakpoint is requested. 363 //------------------------------------------------------------------ 364 365 BreakpointLocation (lldb::break_id_t bid, 366 Breakpoint &owner, 367 const Address &addr, 368 lldb::tid_t tid = LLDB_INVALID_THREAD_ID, 369 bool hardware = false); 370 371 //------------------------------------------------------------------ 372 // Data members: 373 //------------------------------------------------------------------ 374 bool m_being_created; 375 Address m_address; ///< The address defining this location. 376 Breakpoint &m_owner; ///< The breakpoint that produced this object. 377 std::auto_ptr<BreakpointOptions> m_options_ap; ///< Breakpoint options pointer, NULL if we're using our breakpoint's options. 378 lldb::BreakpointSiteSP m_bp_site_sp; ///< Our breakpoint site (it may be shared by more than one location.) 379 380 void 381 SendBreakpointLocationChangedEvent (lldb::BreakpointEventType eventKind); 382 383 DISALLOW_COPY_AND_ASSIGN (BreakpointLocation); 384}; 385 386} // namespace lldb_private 387 388#endif // liblldb_BreakpointLocation_h_ 389