Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- Breakpoint.cpp ------------------------------------------*- 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 | |
| 11 | // C Includes |
| 12 | // C++ Includes |
| 13 | // Other libraries and framework includes |
| 14 | // Project includes |
| 15 | |
| 16 | #include "lldb/Core/Address.h" |
| 17 | #include "lldb/Breakpoint/Breakpoint.h" |
| 18 | #include "lldb/Breakpoint/BreakpointLocation.h" |
Johnny Chen | a62ad7c | 2010-10-28 17:27:46 +0000 | [diff] [blame] | 19 | #include "lldb/Breakpoint/BreakpointLocationCollection.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 20 | #include "lldb/Breakpoint/BreakpointResolver.h" |
Johnny Chen | a62ad7c | 2010-10-28 17:27:46 +0000 | [diff] [blame] | 21 | #include "lldb/Breakpoint/BreakpointResolverFileLine.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 22 | #include "lldb/Core/Log.h" |
| 23 | #include "lldb/Core/ModuleList.h" |
| 24 | #include "lldb/Core/SearchFilter.h" |
| 25 | #include "lldb/Core/Stream.h" |
| 26 | #include "lldb/Core/StreamString.h" |
| 27 | #include "lldb/Symbol/SymbolContext.h" |
| 28 | #include "lldb/Target/Target.h" |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 29 | #include "lldb/Target/ThreadSpec.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 30 | #include "lldb/lldb-private-log.h" |
Johnny Chen | a62ad7c | 2010-10-28 17:27:46 +0000 | [diff] [blame] | 31 | #include "llvm/Support/Casting.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 32 | |
| 33 | using namespace lldb; |
| 34 | using namespace lldb_private; |
Johnny Chen | a62ad7c | 2010-10-28 17:27:46 +0000 | [diff] [blame] | 35 | using namespace llvm; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 36 | |
| 37 | const ConstString & |
| 38 | Breakpoint::GetEventIdentifier () |
| 39 | { |
| 40 | static ConstString g_identifier("event-identifier.breakpoint.changed"); |
| 41 | return g_identifier; |
| 42 | } |
| 43 | |
| 44 | //---------------------------------------------------------------------- |
| 45 | // Breakpoint constructor |
| 46 | //---------------------------------------------------------------------- |
| 47 | Breakpoint::Breakpoint(Target &target, SearchFilterSP &filter_sp, BreakpointResolverSP &resolver_sp) : |
Jim Ingham | 28e2386 | 2012-02-08 05:23:15 +0000 | [diff] [blame^] | 48 | m_being_created(true), |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 49 | m_target (target), |
| 50 | m_filter_sp (filter_sp), |
| 51 | m_resolver_sp (resolver_sp), |
| 52 | m_options (), |
Jim Ingham | 28e2386 | 2012-02-08 05:23:15 +0000 | [diff] [blame^] | 53 | m_locations (*this) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 54 | { |
Jim Ingham | 28e2386 | 2012-02-08 05:23:15 +0000 | [diff] [blame^] | 55 | m_being_created = false; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | //---------------------------------------------------------------------- |
| 59 | // Destructor |
| 60 | //---------------------------------------------------------------------- |
| 61 | Breakpoint::~Breakpoint() |
| 62 | { |
| 63 | } |
| 64 | |
| 65 | bool |
| 66 | Breakpoint::IsInternal () const |
| 67 | { |
| 68 | return LLDB_BREAK_ID_IS_INTERNAL(m_bid); |
| 69 | } |
| 70 | |
| 71 | |
| 72 | |
| 73 | Target& |
| 74 | Breakpoint::GetTarget () |
| 75 | { |
| 76 | return m_target; |
| 77 | } |
| 78 | |
| 79 | const Target& |
| 80 | Breakpoint::GetTarget () const |
| 81 | { |
| 82 | return m_target; |
| 83 | } |
| 84 | |
| 85 | BreakpointLocationSP |
Greg Clayton | 19a1ab8 | 2011-02-05 00:38:04 +0000 | [diff] [blame] | 86 | Breakpoint::AddLocation (const Address &addr, bool *new_location) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 87 | { |
Jim Ingham | 28e2386 | 2012-02-08 05:23:15 +0000 | [diff] [blame^] | 88 | return m_locations.AddLocation (addr, new_location); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | BreakpointLocationSP |
Greg Clayton | 19a1ab8 | 2011-02-05 00:38:04 +0000 | [diff] [blame] | 92 | Breakpoint::FindLocationByAddress (const Address &addr) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 93 | { |
| 94 | return m_locations.FindByAddress(addr); |
| 95 | } |
| 96 | |
| 97 | break_id_t |
Greg Clayton | 19a1ab8 | 2011-02-05 00:38:04 +0000 | [diff] [blame] | 98 | Breakpoint::FindLocationIDByAddress (const Address &addr) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 99 | { |
| 100 | return m_locations.FindIDByAddress(addr); |
| 101 | } |
| 102 | |
| 103 | BreakpointLocationSP |
| 104 | Breakpoint::FindLocationByID (break_id_t bp_loc_id) |
| 105 | { |
| 106 | return m_locations.FindByID(bp_loc_id); |
| 107 | } |
| 108 | |
| 109 | BreakpointLocationSP |
| 110 | Breakpoint::GetLocationAtIndex (uint32_t index) |
| 111 | { |
| 112 | return m_locations.GetByIndex(index); |
| 113 | } |
| 114 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 115 | // For each of the overall options we need to decide how they propagate to |
| 116 | // the location options. This will determine the precedence of options on |
Johnny Chen | 736f0d6 | 2012-01-25 23:08:23 +0000 | [diff] [blame] | 117 | // the breakpoint vs. its locations. |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 118 | |
| 119 | // Disable at the breakpoint level should override the location settings. |
| 120 | // That way you can conveniently turn off a whole breakpoint without messing |
| 121 | // up the individual settings. |
| 122 | |
| 123 | void |
| 124 | Breakpoint::SetEnabled (bool enable) |
| 125 | { |
Jim Ingham | 28e2386 | 2012-02-08 05:23:15 +0000 | [diff] [blame^] | 126 | if (enable == m_options.IsEnabled()) |
| 127 | return; |
| 128 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 129 | m_options.SetEnabled(enable); |
| 130 | if (enable) |
| 131 | m_locations.ResolveAllBreakpointSites(); |
| 132 | else |
| 133 | m_locations.ClearAllBreakpointSites(); |
Jim Ingham | 28e2386 | 2012-02-08 05:23:15 +0000 | [diff] [blame^] | 134 | |
| 135 | SendBreakpointChangedEvent (enable ? eBreakpointEventTypeEnabled : eBreakpointEventTypeDisabled); |
| 136 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | bool |
| 140 | Breakpoint::IsEnabled () |
| 141 | { |
| 142 | return m_options.IsEnabled(); |
| 143 | } |
| 144 | |
| 145 | void |
Greg Clayton | 54e7afa | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 146 | Breakpoint::SetIgnoreCount (uint32_t n) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 147 | { |
Jim Ingham | 28e2386 | 2012-02-08 05:23:15 +0000 | [diff] [blame^] | 148 | if (m_options.GetIgnoreCount() == n) |
| 149 | return; |
| 150 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 151 | m_options.SetIgnoreCount(n); |
Jim Ingham | 28e2386 | 2012-02-08 05:23:15 +0000 | [diff] [blame^] | 152 | SendBreakpointChangedEvent (eBreakpointEventTypeIgnoreChanged); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 153 | } |
| 154 | |
Greg Clayton | 54e7afa | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 155 | uint32_t |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 156 | Breakpoint::GetIgnoreCount () const |
| 157 | { |
| 158 | return m_options.GetIgnoreCount(); |
| 159 | } |
| 160 | |
Greg Clayton | c7f5d5c | 2010-07-23 23:33:17 +0000 | [diff] [blame] | 161 | uint32_t |
| 162 | Breakpoint::GetHitCount () const |
| 163 | { |
| 164 | return m_locations.GetHitCount(); |
| 165 | } |
| 166 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 167 | void |
| 168 | Breakpoint::SetThreadID (lldb::tid_t thread_id) |
| 169 | { |
Jim Ingham | 28e2386 | 2012-02-08 05:23:15 +0000 | [diff] [blame^] | 170 | if (m_options.GetThreadSpec()->GetTID() == thread_id) |
| 171 | return; |
| 172 | |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 173 | m_options.GetThreadSpec()->SetTID(thread_id); |
Jim Ingham | 28e2386 | 2012-02-08 05:23:15 +0000 | [diff] [blame^] | 174 | SendBreakpointChangedEvent (eBreakpointEventTypeThreadChanged); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | lldb::tid_t |
Jim Ingham | 28e2386 | 2012-02-08 05:23:15 +0000 | [diff] [blame^] | 178 | Breakpoint::GetThreadID () const |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 179 | { |
Jim Ingham | 28e2386 | 2012-02-08 05:23:15 +0000 | [diff] [blame^] | 180 | if (m_options.GetThreadSpecNoCreate() == NULL) |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 181 | return LLDB_INVALID_THREAD_ID; |
| 182 | else |
Jim Ingham | 28e2386 | 2012-02-08 05:23:15 +0000 | [diff] [blame^] | 183 | return m_options.GetThreadSpecNoCreate()->GetTID(); |
| 184 | } |
| 185 | |
| 186 | void |
| 187 | Breakpoint::SetThreadIndex (uint32_t index) |
| 188 | { |
| 189 | if (m_options.GetThreadSpec()->GetIndex() == index) |
| 190 | return; |
| 191 | |
| 192 | m_options.GetThreadSpec()->SetIndex(index); |
| 193 | SendBreakpointChangedEvent (eBreakpointEventTypeThreadChanged); |
| 194 | } |
| 195 | |
| 196 | uint32_t |
| 197 | Breakpoint::GetThreadIndex() const |
| 198 | { |
| 199 | if (m_options.GetThreadSpecNoCreate() == NULL) |
| 200 | return 0; |
| 201 | else |
| 202 | return m_options.GetThreadSpecNoCreate()->GetIndex(); |
| 203 | } |
| 204 | |
| 205 | void |
| 206 | Breakpoint::SetThreadName (const char *thread_name) |
| 207 | { |
| 208 | if (::strcmp (m_options.GetThreadSpec()->GetName(), thread_name) == 0) |
| 209 | return; |
| 210 | |
| 211 | m_options.GetThreadSpec()->SetName (thread_name); |
| 212 | SendBreakpointChangedEvent (eBreakpointEventTypeThreadChanged); |
| 213 | } |
| 214 | |
| 215 | const char * |
| 216 | Breakpoint::GetThreadName () const |
| 217 | { |
| 218 | if (m_options.GetThreadSpecNoCreate() == NULL) |
| 219 | return NULL; |
| 220 | else |
| 221 | return m_options.GetThreadSpecNoCreate()->GetName(); |
| 222 | } |
| 223 | |
| 224 | void |
| 225 | Breakpoint::SetQueueName (const char *queue_name) |
| 226 | { |
| 227 | if (::strcmp (m_options.GetThreadSpec()->GetQueueName(), queue_name) == 0) |
| 228 | return; |
| 229 | |
| 230 | m_options.GetThreadSpec()->SetQueueName (queue_name); |
| 231 | SendBreakpointChangedEvent (eBreakpointEventTypeThreadChanged); |
| 232 | } |
| 233 | |
| 234 | const char * |
| 235 | Breakpoint::GetQueueName () const |
| 236 | { |
| 237 | if (m_options.GetThreadSpecNoCreate() == NULL) |
| 238 | return NULL; |
| 239 | else |
| 240 | return m_options.GetThreadSpecNoCreate()->GetQueueName(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 241 | } |
| 242 | |
Jim Ingham | d168690 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 243 | void |
| 244 | Breakpoint::SetCondition (const char *condition) |
| 245 | { |
| 246 | m_options.SetCondition (condition); |
Jim Ingham | 28e2386 | 2012-02-08 05:23:15 +0000 | [diff] [blame^] | 247 | SendBreakpointChangedEvent (eBreakpointEventTypeConditionChanged); |
Jim Ingham | d168690 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | ThreadPlan * |
| 251 | Breakpoint::GetThreadPlanToTestCondition (ExecutionContext &exe_ctx, lldb::BreakpointLocationSP loc_sp, Stream &error) |
| 252 | { |
| 253 | return m_options.GetThreadPlanToTestCondition (exe_ctx, loc_sp, error); |
| 254 | } |
| 255 | |
| 256 | const char * |
Jim Ingham | ac35442 | 2011-06-15 21:16:00 +0000 | [diff] [blame] | 257 | Breakpoint::GetConditionText () const |
Jim Ingham | d168690 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 258 | { |
| 259 | return m_options.GetConditionText(); |
| 260 | } |
| 261 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 262 | // This function is used when "baton" doesn't need to be freed |
| 263 | void |
| 264 | Breakpoint::SetCallback (BreakpointHitCallback callback, void *baton, bool is_synchronous) |
| 265 | { |
| 266 | // The default "Baton" class will keep a copy of "baton" and won't free |
| 267 | // or delete it when it goes goes out of scope. |
| 268 | m_options.SetCallback(callback, BatonSP (new Baton(baton)), is_synchronous); |
Jim Ingham | 28e2386 | 2012-02-08 05:23:15 +0000 | [diff] [blame^] | 269 | |
| 270 | SendBreakpointChangedEvent (eBreakpointEventTypeCommandChanged); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | // This function is used when a baton needs to be freed and therefore is |
| 274 | // contained in a "Baton" subclass. |
| 275 | void |
| 276 | Breakpoint::SetCallback (BreakpointHitCallback callback, const BatonSP &callback_baton_sp, bool is_synchronous) |
| 277 | { |
| 278 | m_options.SetCallback(callback, callback_baton_sp, is_synchronous); |
| 279 | } |
| 280 | |
| 281 | void |
| 282 | Breakpoint::ClearCallback () |
| 283 | { |
| 284 | m_options.ClearCallback (); |
| 285 | } |
| 286 | |
| 287 | bool |
| 288 | Breakpoint::InvokeCallback (StoppointCallbackContext *context, break_id_t bp_loc_id) |
| 289 | { |
| 290 | return m_options.InvokeCallback (context, GetID(), bp_loc_id); |
| 291 | } |
| 292 | |
| 293 | BreakpointOptions * |
| 294 | Breakpoint::GetOptions () |
| 295 | { |
| 296 | return &m_options; |
| 297 | } |
| 298 | |
| 299 | void |
| 300 | Breakpoint::ResolveBreakpoint () |
| 301 | { |
| 302 | if (m_resolver_sp) |
| 303 | m_resolver_sp->ResolveBreakpoint(*m_filter_sp); |
| 304 | } |
| 305 | |
| 306 | void |
| 307 | Breakpoint::ResolveBreakpointInModules (ModuleList &module_list) |
| 308 | { |
| 309 | if (m_resolver_sp) |
| 310 | m_resolver_sp->ResolveBreakpointInModules(*m_filter_sp, module_list); |
| 311 | } |
| 312 | |
| 313 | void |
| 314 | Breakpoint::ClearAllBreakpointSites () |
| 315 | { |
| 316 | m_locations.ClearAllBreakpointSites(); |
| 317 | } |
| 318 | |
| 319 | //---------------------------------------------------------------------- |
| 320 | // ModulesChanged: Pass in a list of new modules, and |
| 321 | //---------------------------------------------------------------------- |
| 322 | |
| 323 | void |
| 324 | Breakpoint::ModulesChanged (ModuleList &module_list, bool load) |
| 325 | { |
| 326 | if (load) |
| 327 | { |
| 328 | // The logic for handling new modules is: |
| 329 | // 1) If the filter rejects this module, then skip it. |
| 330 | // 2) Run through the current location list and if there are any locations |
| 331 | // for that module, we mark the module as "seen" and we don't try to re-resolve |
| 332 | // breakpoint locations for that module. |
| 333 | // However, we do add breakpoint sites to these locations if needed. |
| 334 | // 3) If we don't see this module in our breakpoint location list, call ResolveInModules. |
| 335 | |
| 336 | ModuleList new_modules; // We'll stuff the "unseen" modules in this list, and then resolve |
Greg Clayton | 19a1ab8 | 2011-02-05 00:38:04 +0000 | [diff] [blame] | 337 | // them after the locations pass. Have to do it this way because |
| 338 | // resolving breakpoints will add new locations potentially. |
| 339 | |
| 340 | const size_t num_locs = m_locations.GetSize(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 341 | |
Greg Clayton | 54e7afa | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 342 | for (size_t i = 0; i < module_list.GetSize(); i++) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 343 | { |
| 344 | bool seen = false; |
| 345 | ModuleSP module_sp (module_list.GetModuleAtIndex (i)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 346 | if (!m_filter_sp->ModulePasses (module_sp)) |
| 347 | continue; |
| 348 | |
Greg Clayton | 19a1ab8 | 2011-02-05 00:38:04 +0000 | [diff] [blame] | 349 | for (size_t loc_idx = 0; loc_idx < num_locs; loc_idx++) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 350 | { |
Greg Clayton | 7b9fcc0 | 2010-12-06 23:51:26 +0000 | [diff] [blame] | 351 | BreakpointLocationSP break_loc = m_locations.GetByIndex(loc_idx); |
Jim Ingham | 1de036b | 2010-10-20 03:36:33 +0000 | [diff] [blame] | 352 | if (!break_loc->IsEnabled()) |
| 353 | continue; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 354 | const Section *section = break_loc->GetAddress().GetSection(); |
Greg Clayton | 19a1ab8 | 2011-02-05 00:38:04 +0000 | [diff] [blame] | 355 | if (section == NULL || section->GetModule() == module_sp.get()) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 356 | { |
| 357 | if (!seen) |
| 358 | seen = true; |
| 359 | |
| 360 | if (!break_loc->ResolveBreakpointSite()) |
| 361 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 362 | LogSP log (lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 363 | if (log) |
| 364 | log->Printf ("Warning: could not set breakpoint site for breakpoint location %d of breakpoint %d.\n", |
| 365 | break_loc->GetID(), GetID()); |
| 366 | } |
| 367 | } |
| 368 | } |
| 369 | |
| 370 | if (!seen) |
Greg Clayton | ab42902 | 2010-12-12 21:03:32 +0000 | [diff] [blame] | 371 | new_modules.AppendIfNeeded (module_sp); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 372 | |
| 373 | } |
Jim Ingham | 28e2386 | 2012-02-08 05:23:15 +0000 | [diff] [blame^] | 374 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 375 | if (new_modules.GetSize() > 0) |
| 376 | { |
Jim Ingham | 28e2386 | 2012-02-08 05:23:15 +0000 | [diff] [blame^] | 377 | // If this is not an internal breakpoint, set up to record the new locations, then dispatch |
| 378 | // an event with the new locations. |
| 379 | if (!IsInternal()) |
| 380 | { |
| 381 | BreakpointEventData *new_locations_event = new BreakpointEventData (eBreakpointEventTypeLocationsAdded, |
| 382 | shared_from_this()); |
| 383 | |
| 384 | m_locations.StartRecordingNewLocations(new_locations_event->GetBreakpointLocationCollection()); |
| 385 | |
| 386 | ResolveBreakpointInModules(new_modules); |
| 387 | |
| 388 | m_locations.StopRecordingNewLocations(); |
| 389 | if (new_locations_event->GetBreakpointLocationCollection().GetSize() != 0) |
| 390 | { |
| 391 | SendBreakpointChangedEvent (new_locations_event); |
| 392 | } |
| 393 | else |
| 394 | delete new_locations_event; |
| 395 | } |
| 396 | else |
| 397 | ResolveBreakpointInModules(new_modules); |
| 398 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 399 | } |
| 400 | } |
| 401 | else |
| 402 | { |
| 403 | // Go through the currently set locations and if any have breakpoints in |
| 404 | // the module list, then remove their breakpoint sites. |
| 405 | // FIXME: Think about this... Maybe it's better to delete the locations? |
| 406 | // Are we sure that on load-unload-reload the module pointer will remain |
| 407 | // the same? Or do we need to do an equality on modules that is an |
| 408 | // "equivalence"??? |
| 409 | |
Jim Ingham | 28e2386 | 2012-02-08 05:23:15 +0000 | [diff] [blame^] | 410 | BreakpointEventData *removed_locations_event; |
| 411 | if (!IsInternal()) |
| 412 | removed_locations_event = new BreakpointEventData (eBreakpointEventTypeLocationsRemoved, |
| 413 | shared_from_this()); |
| 414 | else |
| 415 | removed_locations_event = NULL; |
| 416 | |
Greg Clayton | 54e7afa | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 417 | for (size_t i = 0; i < module_list.GetSize(); i++) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 418 | { |
| 419 | ModuleSP module_sp (module_list.GetModuleAtIndex (i)); |
Greg Clayton | 7b9fcc0 | 2010-12-06 23:51:26 +0000 | [diff] [blame] | 420 | if (m_filter_sp->ModulePasses (module_sp)) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 421 | { |
Greg Clayton | 7b9fcc0 | 2010-12-06 23:51:26 +0000 | [diff] [blame] | 422 | const size_t num_locs = m_locations.GetSize(); |
| 423 | for (size_t loc_idx = 0; loc_idx < num_locs; ++loc_idx) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 424 | { |
Greg Clayton | 7b9fcc0 | 2010-12-06 23:51:26 +0000 | [diff] [blame] | 425 | BreakpointLocationSP break_loc = m_locations.GetByIndex(loc_idx); |
| 426 | const Section *section = break_loc->GetAddress().GetSection(); |
| 427 | if (section && section->GetModule() == module_sp.get()) |
| 428 | { |
| 429 | // Remove this breakpoint since the shared library is |
| 430 | // unloaded, but keep the breakpoint location around |
| 431 | // so we always get complete hit count and breakpoint |
| 432 | // lifetime info |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 433 | break_loc->ClearBreakpointSite(); |
Jim Ingham | 28e2386 | 2012-02-08 05:23:15 +0000 | [diff] [blame^] | 434 | if (removed_locations_event) |
| 435 | { |
| 436 | removed_locations_event->GetBreakpointLocationCollection().Add(break_loc); |
| 437 | } |
Greg Clayton | 7b9fcc0 | 2010-12-06 23:51:26 +0000 | [diff] [blame] | 438 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 439 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 440 | } |
| 441 | } |
Jim Ingham | 28e2386 | 2012-02-08 05:23:15 +0000 | [diff] [blame^] | 442 | SendBreakpointChangedEvent (removed_locations_event); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 443 | } |
| 444 | } |
| 445 | |
| 446 | void |
| 447 | Breakpoint::Dump (Stream *) |
| 448 | { |
| 449 | } |
| 450 | |
| 451 | size_t |
| 452 | Breakpoint::GetNumResolvedLocations() const |
| 453 | { |
| 454 | // Return the number of breakpoints that are actually resolved and set |
| 455 | // down in the inferior process. |
| 456 | return m_locations.GetNumResolvedLocations(); |
| 457 | } |
| 458 | |
| 459 | size_t |
| 460 | Breakpoint::GetNumLocations() const |
| 461 | { |
| 462 | return m_locations.GetSize(); |
| 463 | } |
| 464 | |
| 465 | void |
| 466 | Breakpoint::GetDescription (Stream *s, lldb::DescriptionLevel level, bool show_locations) |
| 467 | { |
| 468 | assert (s != NULL); |
Greg Clayton | 12bec71 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 469 | s->Printf("%i: ", GetID()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 470 | GetResolverDescription (s); |
Greg Clayton | 12bec71 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 471 | GetFilterDescription (s); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 472 | |
Greg Clayton | 54e7afa | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 473 | const size_t num_locations = GetNumLocations (); |
| 474 | const size_t num_resolved_locations = GetNumResolvedLocations (); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 475 | |
| 476 | switch (level) |
| 477 | { |
| 478 | case lldb::eDescriptionLevelBrief: |
| 479 | case lldb::eDescriptionLevelFull: |
| 480 | if (num_locations > 0) |
| 481 | { |
Greg Clayton | 54e7afa | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 482 | s->Printf(", locations = %zu", num_locations); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 483 | if (num_resolved_locations > 0) |
Greg Clayton | 54e7afa | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 484 | s->Printf(", resolved = %zu", num_resolved_locations); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 485 | } |
| 486 | else |
| 487 | { |
Greg Clayton | 12bec71 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 488 | s->Printf(", locations = 0 (pending)"); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 489 | } |
| 490 | |
Jim Ingham | 649492b | 2010-06-18 01:00:58 +0000 | [diff] [blame] | 491 | GetOptions()->GetDescription(s, level); |
| 492 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 493 | if (level == lldb::eDescriptionLevelFull) |
| 494 | { |
Jim Ingham | 649492b | 2010-06-18 01:00:58 +0000 | [diff] [blame] | 495 | s->IndentLess(); |
| 496 | s->EOL(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 497 | } |
| 498 | break; |
| 499 | |
| 500 | case lldb::eDescriptionLevelVerbose: |
| 501 | // Verbose mode does a debug dump of the breakpoint |
| 502 | Dump (s); |
Jim Ingham | 649492b | 2010-06-18 01:00:58 +0000 | [diff] [blame] | 503 | s->EOL (); |
Greg Clayton | b1888f2 | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 504 | //s->Indent(); |
Jim Ingham | 649492b | 2010-06-18 01:00:58 +0000 | [diff] [blame] | 505 | GetOptions()->GetDescription(s, level); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 506 | break; |
Greg Clayton | 54e7afa | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 507 | |
| 508 | default: |
| 509 | break; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 510 | } |
| 511 | |
Jim Ingham | 1cd466f | 2011-05-14 01:11:02 +0000 | [diff] [blame] | 512 | // The brief description is just the location name (1.2 or whatever). That's pointless to |
| 513 | // show in the breakpoint's description, so suppress it. |
| 514 | if (show_locations && level != lldb::eDescriptionLevelBrief) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 515 | { |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 516 | s->IndentMore(); |
Greg Clayton | 54e7afa | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 517 | for (size_t i = 0; i < num_locations; ++i) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 518 | { |
| 519 | BreakpointLocation *loc = GetLocationAtIndex(i).get(); |
| 520 | loc->GetDescription(s, level); |
| 521 | s->EOL(); |
| 522 | } |
| 523 | s->IndentLess(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 524 | } |
| 525 | } |
| 526 | |
Greg Clayton | c7f5d5c | 2010-07-23 23:33:17 +0000 | [diff] [blame] | 527 | Breakpoint::BreakpointEventData::BreakpointEventData (BreakpointEventType sub_type, |
Jim Ingham | 28e2386 | 2012-02-08 05:23:15 +0000 | [diff] [blame^] | 528 | const BreakpointSP &new_breakpoint_sp) : |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 529 | EventData (), |
Greg Clayton | c7f5d5c | 2010-07-23 23:33:17 +0000 | [diff] [blame] | 530 | m_breakpoint_event (sub_type), |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 531 | m_new_breakpoint_sp (new_breakpoint_sp) |
| 532 | { |
| 533 | } |
| 534 | |
| 535 | Breakpoint::BreakpointEventData::~BreakpointEventData () |
| 536 | { |
| 537 | } |
| 538 | |
| 539 | const ConstString & |
| 540 | Breakpoint::BreakpointEventData::GetFlavorString () |
| 541 | { |
| 542 | static ConstString g_flavor ("Breakpoint::BreakpointEventData"); |
| 543 | return g_flavor; |
| 544 | } |
| 545 | |
| 546 | const ConstString & |
| 547 | Breakpoint::BreakpointEventData::GetFlavor () const |
| 548 | { |
| 549 | return BreakpointEventData::GetFlavorString (); |
| 550 | } |
| 551 | |
| 552 | |
| 553 | BreakpointSP & |
| 554 | Breakpoint::BreakpointEventData::GetBreakpoint () |
| 555 | { |
| 556 | return m_new_breakpoint_sp; |
| 557 | } |
| 558 | |
Greg Clayton | c7f5d5c | 2010-07-23 23:33:17 +0000 | [diff] [blame] | 559 | BreakpointEventType |
| 560 | Breakpoint::BreakpointEventData::GetBreakpointEventType () const |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 561 | { |
Greg Clayton | c7f5d5c | 2010-07-23 23:33:17 +0000 | [diff] [blame] | 562 | return m_breakpoint_event; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 563 | } |
| 564 | |
| 565 | void |
| 566 | Breakpoint::BreakpointEventData::Dump (Stream *s) const |
| 567 | { |
| 568 | } |
| 569 | |
Jim Ingham | 28e2386 | 2012-02-08 05:23:15 +0000 | [diff] [blame^] | 570 | const Breakpoint::BreakpointEventData * |
| 571 | Breakpoint::BreakpointEventData::GetEventDataFromEvent (const Event *event) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 572 | { |
Jim Ingham | 28e2386 | 2012-02-08 05:23:15 +0000 | [diff] [blame^] | 573 | if (event) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 574 | { |
Jim Ingham | 28e2386 | 2012-02-08 05:23:15 +0000 | [diff] [blame^] | 575 | const EventData *event_data = event->GetData(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 576 | if (event_data && event_data->GetFlavor() == BreakpointEventData::GetFlavorString()) |
Jim Ingham | 28e2386 | 2012-02-08 05:23:15 +0000 | [diff] [blame^] | 577 | return static_cast <const BreakpointEventData *> (event->GetData()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 578 | } |
| 579 | return NULL; |
| 580 | } |
| 581 | |
Greg Clayton | c7f5d5c | 2010-07-23 23:33:17 +0000 | [diff] [blame] | 582 | BreakpointEventType |
| 583 | Breakpoint::BreakpointEventData::GetBreakpointEventTypeFromEvent (const EventSP &event_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 584 | { |
Jim Ingham | 28e2386 | 2012-02-08 05:23:15 +0000 | [diff] [blame^] | 585 | const BreakpointEventData *data = GetEventDataFromEvent (event_sp.get()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 586 | |
| 587 | if (data == NULL) |
Greg Clayton | c7f5d5c | 2010-07-23 23:33:17 +0000 | [diff] [blame] | 588 | return eBreakpointEventTypeInvalidType; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 589 | else |
Greg Clayton | c7f5d5c | 2010-07-23 23:33:17 +0000 | [diff] [blame] | 590 | return data->GetBreakpointEventType(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 591 | } |
| 592 | |
| 593 | BreakpointSP |
| 594 | Breakpoint::BreakpointEventData::GetBreakpointFromEvent (const EventSP &event_sp) |
| 595 | { |
Greg Clayton | c7f5d5c | 2010-07-23 23:33:17 +0000 | [diff] [blame] | 596 | BreakpointSP bp_sp; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 597 | |
Jim Ingham | 28e2386 | 2012-02-08 05:23:15 +0000 | [diff] [blame^] | 598 | const BreakpointEventData *data = GetEventDataFromEvent (event_sp.get()); |
Greg Clayton | c7f5d5c | 2010-07-23 23:33:17 +0000 | [diff] [blame] | 599 | if (data) |
Jim Ingham | 28e2386 | 2012-02-08 05:23:15 +0000 | [diff] [blame^] | 600 | bp_sp = data->m_new_breakpoint_sp; |
Greg Clayton | c7f5d5c | 2010-07-23 23:33:17 +0000 | [diff] [blame] | 601 | |
| 602 | return bp_sp; |
| 603 | } |
| 604 | |
Jim Ingham | 28e2386 | 2012-02-08 05:23:15 +0000 | [diff] [blame^] | 605 | uint32_t |
| 606 | Breakpoint::BreakpointEventData::GetNumBreakpointLocationsFromEvent (const EventSP &event_sp) |
| 607 | { |
| 608 | const BreakpointEventData *data = GetEventDataFromEvent (event_sp.get()); |
| 609 | if (data) |
| 610 | return data->m_locations.GetSize(); |
| 611 | |
| 612 | return 0; |
| 613 | } |
| 614 | |
Greg Clayton | c7f5d5c | 2010-07-23 23:33:17 +0000 | [diff] [blame] | 615 | lldb::BreakpointLocationSP |
| 616 | Breakpoint::BreakpointEventData::GetBreakpointLocationAtIndexFromEvent (const lldb::EventSP &event_sp, uint32_t bp_loc_idx) |
| 617 | { |
| 618 | lldb::BreakpointLocationSP bp_loc_sp; |
| 619 | |
Jim Ingham | 28e2386 | 2012-02-08 05:23:15 +0000 | [diff] [blame^] | 620 | const BreakpointEventData *data = GetEventDataFromEvent (event_sp.get()); |
Greg Clayton | c7f5d5c | 2010-07-23 23:33:17 +0000 | [diff] [blame] | 621 | if (data) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 622 | { |
Jim Ingham | 28e2386 | 2012-02-08 05:23:15 +0000 | [diff] [blame^] | 623 | bp_loc_sp = data->m_locations.GetByIndex(bp_loc_idx); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 624 | } |
Greg Clayton | c7f5d5c | 2010-07-23 23:33:17 +0000 | [diff] [blame] | 625 | |
| 626 | return bp_loc_sp; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 627 | } |
| 628 | |
| 629 | |
| 630 | void |
| 631 | Breakpoint::GetResolverDescription (Stream *s) |
| 632 | { |
| 633 | if (m_resolver_sp) |
| 634 | m_resolver_sp->GetDescription (s); |
| 635 | } |
| 636 | |
Johnny Chen | a62ad7c | 2010-10-28 17:27:46 +0000 | [diff] [blame] | 637 | |
| 638 | bool |
| 639 | Breakpoint::GetMatchingFileLine (const ConstString &filename, uint32_t line_number, BreakpointLocationCollection &loc_coll) |
| 640 | { |
| 641 | // TODO: To be correct, this method needs to fill the breakpoint location collection |
| 642 | // with the location IDs which match the filename and line_number. |
| 643 | // |
| 644 | |
| 645 | if (m_resolver_sp) |
| 646 | { |
| 647 | BreakpointResolverFileLine *resolverFileLine = dyn_cast<BreakpointResolverFileLine>(m_resolver_sp.get()); |
| 648 | if (resolverFileLine && |
| 649 | resolverFileLine->m_file_spec.GetFilename() == filename && |
| 650 | resolverFileLine->m_line_number == line_number) |
| 651 | { |
| 652 | return true; |
| 653 | } |
| 654 | } |
| 655 | return false; |
| 656 | } |
| 657 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 658 | void |
| 659 | Breakpoint::GetFilterDescription (Stream *s) |
| 660 | { |
| 661 | m_filter_sp->GetDescription (s); |
| 662 | } |
Jim Ingham | 28e2386 | 2012-02-08 05:23:15 +0000 | [diff] [blame^] | 663 | |
| 664 | void |
| 665 | Breakpoint::SendBreakpointChangedEvent (lldb::BreakpointEventType eventKind) |
| 666 | { |
| 667 | if (!m_being_created |
| 668 | && !IsInternal() |
| 669 | && GetTarget().EventTypeHasListeners(Target::eBroadcastBitBreakpointChanged)) |
| 670 | { |
| 671 | BreakpointEventData *data = new Breakpoint::BreakpointEventData (eventKind, shared_from_this()); |
| 672 | |
| 673 | GetTarget().BroadcastEvent (Target::eBroadcastBitBreakpointChanged, data); |
| 674 | } |
| 675 | } |
| 676 | |
| 677 | void |
| 678 | Breakpoint::SendBreakpointChangedEvent (BreakpointEventData *data) |
| 679 | { |
| 680 | |
| 681 | if (data == NULL) |
| 682 | return; |
| 683 | |
| 684 | if (!m_being_created |
| 685 | && !IsInternal() |
| 686 | && GetTarget().EventTypeHasListeners(Target::eBroadcastBitBreakpointChanged)) |
| 687 | GetTarget().BroadcastEvent (Target::eBroadcastBitBreakpointChanged, data); |
| 688 | else |
| 689 | delete data; |
| 690 | } |