1 //===-- BreakpointLocation.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 // C Includes
11 // C++ Includes
12 // Other libraries and framework includes
13 // Project includes
14 #include "lldb/Breakpoint/BreakpointLocation.h"
15 #include "lldb/Breakpoint/BreakpointID.h"
16 #include "lldb/Breakpoint/StoppointCallbackContext.h"
17 #include "lldb/Core/Debugger.h"
18 #include "lldb/Core/Module.h"
19 #include "lldb/Core/ValueObject.h"
20 #include "lldb/Expression/DiagnosticManager.h"
21 #include "lldb/Expression/ExpressionVariable.h"
22 #include "lldb/Expression/UserExpression.h"
23 #include "lldb/Symbol/CompileUnit.h"
24 #include "lldb/Symbol/Symbol.h"
25 #include "lldb/Symbol/TypeSystem.h"
26 #include "lldb/Target/Process.h"
27 #include "lldb/Target/Target.h"
28 #include "lldb/Target/Thread.h"
29 #include "lldb/Target/ThreadSpec.h"
30 #include "lldb/Utility/Log.h"
31 #include "lldb/Utility/StreamString.h"
32 
33 using namespace lldb;
34 using namespace lldb_private;
35 
36 BreakpointLocation::BreakpointLocation(break_id_t loc_id, Breakpoint &owner,
37                                        const Address &addr, lldb::tid_t tid,
38                                        bool hardware, bool check_for_resolver)
39     : StoppointLocation(loc_id, addr.GetOpcodeLoadAddress(&owner.GetTarget()),
40                         hardware),
41       m_being_created(true), m_should_resolve_indirect_functions(false),
42       m_is_reexported(false), m_is_indirect(false), m_address(addr),
43       m_owner(owner), m_options_ap(), m_bp_site_sp(), m_condition_mutex() {
44   if (check_for_resolver) {
45     Symbol *symbol = m_address.CalculateSymbolContextSymbol();
46     if (symbol && symbol->IsIndirect()) {
47       SetShouldResolveIndirectFunctions(true);
48     }
49   }
50 
51   SetThreadID(tid);
52   m_being_created = false;
53 }
54 
55 BreakpointLocation::~BreakpointLocation() { ClearBreakpointSite(); }
56 
57 lldb::addr_t BreakpointLocation::GetLoadAddress() const {
58   return m_address.GetOpcodeLoadAddress(&m_owner.GetTarget());
59 }
60 
61 const BreakpointOptions *
62 BreakpointLocation::GetOptionsSpecifyingKind(BreakpointOptions::OptionKind kind)
63 const {
64     if (m_options_ap && m_options_ap->IsOptionSet(kind))
65       return m_options_ap.get();
66     else
67       return m_owner.GetOptions();
68 }
69 
70 Address &BreakpointLocation::GetAddress() { return m_address; }
71 
72 Breakpoint &BreakpointLocation::GetBreakpoint() { return m_owner; }
73 
74 Target &BreakpointLocation::GetTarget() { return m_owner.GetTarget(); }
75 
76 bool BreakpointLocation::IsEnabled() const {
77   if (!m_owner.IsEnabled())
78     return false;
79   else if (m_options_ap.get() != nullptr)
80     return m_options_ap->IsEnabled();
81   else
82     return true;
83 }
84 
85 void BreakpointLocation::SetEnabled(bool enabled) {
86   GetLocationOptions()->SetEnabled(enabled);
87   if (enabled) {
88     ResolveBreakpointSite();
89   } else {
90     ClearBreakpointSite();
91   }
92   SendBreakpointLocationChangedEvent(enabled ? eBreakpointEventTypeEnabled
93                                              : eBreakpointEventTypeDisabled);
94 }
95 
96 bool BreakpointLocation::IsAutoContinue() const {
97   if (m_options_ap
98       && m_options_ap->IsOptionSet(BreakpointOptions::eAutoContinue))
99     return m_options_ap->IsAutoContinue();
100   else
101     return m_owner.IsAutoContinue();
102 }
103 
104 void BreakpointLocation::SetAutoContinue(bool auto_continue) {
105   GetLocationOptions()->SetAutoContinue(auto_continue);
106   SendBreakpointLocationChangedEvent(eBreakpointEventTypeAutoContinueChanged);
107 }
108 
109 void BreakpointLocation::SetThreadID(lldb::tid_t thread_id) {
110   if (thread_id != LLDB_INVALID_THREAD_ID)
111     GetLocationOptions()->SetThreadID(thread_id);
112   else {
113     // If we're resetting this to an invalid thread id, then don't make an
114     // options pointer just to do that.
115     if (m_options_ap.get() != nullptr)
116       m_options_ap->SetThreadID(thread_id);
117   }
118   SendBreakpointLocationChangedEvent(eBreakpointEventTypeThreadChanged);
119 }
120 
121 lldb::tid_t BreakpointLocation::GetThreadID() {
122   const ThreadSpec *thread_spec =
123       GetOptionsSpecifyingKind(BreakpointOptions::eThreadSpec)
124           ->GetThreadSpecNoCreate();
125   if (thread_spec)
126     return thread_spec->GetTID();
127   else
128     return LLDB_INVALID_THREAD_ID;
129 }
130 
131 void BreakpointLocation::SetThreadIndex(uint32_t index) {
132   if (index != 0)
133     GetLocationOptions()->GetThreadSpec()->SetIndex(index);
134   else {
135     // If we're resetting this to an invalid thread id, then don't make an
136     // options pointer just to do that.
137     if (m_options_ap.get() != nullptr)
138       m_options_ap->GetThreadSpec()->SetIndex(index);
139   }
140   SendBreakpointLocationChangedEvent(eBreakpointEventTypeThreadChanged);
141 }
142 
143 uint32_t BreakpointLocation::GetThreadIndex() const {
144   const ThreadSpec *thread_spec =
145       GetOptionsSpecifyingKind(BreakpointOptions::eThreadSpec)
146           ->GetThreadSpecNoCreate();
147   if (thread_spec)
148     return thread_spec->GetIndex();
149   else
150     return 0;
151 }
152 
153 void BreakpointLocation::SetThreadName(const char *thread_name) {
154   if (thread_name != nullptr)
155     GetLocationOptions()->GetThreadSpec()->SetName(thread_name);
156   else {
157     // If we're resetting this to an invalid thread id, then don't make an
158     // options pointer just to do that.
159     if (m_options_ap.get() != nullptr)
160       m_options_ap->GetThreadSpec()->SetName(thread_name);
161   }
162   SendBreakpointLocationChangedEvent(eBreakpointEventTypeThreadChanged);
163 }
164 
165 const char *BreakpointLocation::GetThreadName() const {
166   const ThreadSpec *thread_spec =
167       GetOptionsSpecifyingKind(BreakpointOptions::eThreadSpec)
168           ->GetThreadSpecNoCreate();
169   if (thread_spec)
170     return thread_spec->GetName();
171   else
172     return nullptr;
173 }
174 
175 void BreakpointLocation::SetQueueName(const char *queue_name) {
176   if (queue_name != nullptr)
177     GetLocationOptions()->GetThreadSpec()->SetQueueName(queue_name);
178   else {
179     // If we're resetting this to an invalid thread id, then don't make an
180     // options pointer just to do that.
181     if (m_options_ap.get() != nullptr)
182       m_options_ap->GetThreadSpec()->SetQueueName(queue_name);
183   }
184   SendBreakpointLocationChangedEvent(eBreakpointEventTypeThreadChanged);
185 }
186 
187 const char *BreakpointLocation::GetQueueName() const {
188   const ThreadSpec *thread_spec =
189       GetOptionsSpecifyingKind(BreakpointOptions::eThreadSpec)
190           ->GetThreadSpecNoCreate();
191   if (thread_spec)
192     return thread_spec->GetQueueName();
193   else
194     return nullptr;
195 }
196 
197 bool BreakpointLocation::InvokeCallback(StoppointCallbackContext *context) {
198   if (m_options_ap.get() != nullptr && m_options_ap->HasCallback())
199     return m_options_ap->InvokeCallback(context, m_owner.GetID(), GetID());
200   else
201     return m_owner.InvokeCallback(context, GetID());
202 }
203 
204 void BreakpointLocation::SetCallback(BreakpointHitCallback callback,
205                                      void *baton, bool is_synchronous) {
206   // The default "Baton" class will keep a copy of "baton" and won't free or
207   // delete it when it goes goes out of scope.
208   GetLocationOptions()->SetCallback(
209       callback, std::make_shared<UntypedBaton>(baton), is_synchronous);
210   SendBreakpointLocationChangedEvent(eBreakpointEventTypeCommandChanged);
211 }
212 
213 void BreakpointLocation::SetCallback(BreakpointHitCallback callback,
214                                      const BatonSP &baton_sp,
215                                      bool is_synchronous) {
216   GetLocationOptions()->SetCallback(callback, baton_sp, is_synchronous);
217   SendBreakpointLocationChangedEvent(eBreakpointEventTypeCommandChanged);
218 }
219 
220 void BreakpointLocation::ClearCallback() {
221   GetLocationOptions()->ClearCallback();
222 }
223 
224 void BreakpointLocation::SetCondition(const char *condition) {
225   GetLocationOptions()->SetCondition(condition);
226   SendBreakpointLocationChangedEvent(eBreakpointEventTypeConditionChanged);
227 }
228 
229 const char *BreakpointLocation::GetConditionText(size_t *hash) const {
230   return GetOptionsSpecifyingKind(BreakpointOptions::eCondition)
231       ->GetConditionText(hash);
232 }
233 
234 bool BreakpointLocation::ConditionSaysStop(ExecutionContext &exe_ctx,
235                                            Status &error) {
236   Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_BREAKPOINTS);
237 
238   std::lock_guard<std::mutex> guard(m_condition_mutex);
239 
240   size_t condition_hash;
241   const char *condition_text = GetConditionText(&condition_hash);
242 
243   if (!condition_text) {
244     m_user_expression_sp.reset();
245     return false;
246   }
247 
248   error.Clear();
249 
250   DiagnosticManager diagnostics;
251 
252   if (condition_hash != m_condition_hash || !m_user_expression_sp ||
253       !m_user_expression_sp->MatchesContext(exe_ctx)) {
254     LanguageType language = eLanguageTypeUnknown;
255     // See if we can figure out the language from the frame, otherwise use the
256     // default language:
257     CompileUnit *comp_unit = m_address.CalculateSymbolContextCompileUnit();
258     if (comp_unit)
259       language = comp_unit->GetLanguage();
260 
261     m_user_expression_sp.reset(GetTarget().GetUserExpressionForLanguage(
262         condition_text, llvm::StringRef(), language, Expression::eResultTypeAny,
263         EvaluateExpressionOptions(), error));
264     if (error.Fail()) {
265       if (log)
266         log->Printf("Error getting condition expression: %s.",
267                     error.AsCString());
268       m_user_expression_sp.reset();
269       return true;
270     }
271 
272     if (!m_user_expression_sp->Parse(diagnostics, exe_ctx,
273                                      eExecutionPolicyOnlyWhenNeeded, true,
274                                      false)) {
275       error.SetErrorStringWithFormat(
276           "Couldn't parse conditional expression:\n%s",
277           diagnostics.GetString().c_str());
278       m_user_expression_sp.reset();
279       return true;
280     }
281 
282     m_condition_hash = condition_hash;
283   }
284 
285   // We need to make sure the user sees any parse errors in their condition, so
286   // we'll hook the constructor errors up to the debugger's Async I/O.
287 
288   ValueObjectSP result_value_sp;
289 
290   EvaluateExpressionOptions options;
291   options.SetUnwindOnError(true);
292   options.SetIgnoreBreakpoints(true);
293   options.SetTryAllThreads(true);
294   options.SetResultIsInternal(
295       true); // Don't generate a user variable for condition expressions.
296 
297   Status expr_error;
298 
299   diagnostics.Clear();
300 
301   ExpressionVariableSP result_variable_sp;
302 
303   ExpressionResults result_code = m_user_expression_sp->Execute(
304       diagnostics, exe_ctx, options, m_user_expression_sp, result_variable_sp);
305 
306   bool ret;
307 
308   if (result_code == eExpressionCompleted) {
309     if (!result_variable_sp) {
310       error.SetErrorString("Expression did not return a result");
311       return false;
312     }
313 
314     result_value_sp = result_variable_sp->GetValueObject();
315 
316     if (result_value_sp) {
317       ret = result_value_sp->IsLogicalTrue(error);
318       if (log) {
319         if (error.Success()) {
320           log->Printf("Condition successfully evaluated, result is %s.\n",
321                       ret ? "true" : "false");
322         } else {
323           error.SetErrorString(
324               "Failed to get an integer result from the expression");
325           ret = false;
326         }
327       }
328     } else {
329       ret = false;
330       error.SetErrorString("Failed to get any result from the expression");
331     }
332   } else {
333     ret = false;
334     error.SetErrorStringWithFormat("Couldn't execute expression:\n%s",
335                                    diagnostics.GetString().c_str());
336   }
337 
338   return ret;
339 }
340 
341 uint32_t BreakpointLocation::GetIgnoreCount() {
342   return GetOptionsSpecifyingKind(BreakpointOptions::eIgnoreCount)
343       ->GetIgnoreCount();
344 }
345 
346 void BreakpointLocation::SetIgnoreCount(uint32_t n) {
347   GetLocationOptions()->SetIgnoreCount(n);
348   SendBreakpointLocationChangedEvent(eBreakpointEventTypeIgnoreChanged);
349 }
350 
351 void BreakpointLocation::DecrementIgnoreCount() {
352   if (m_options_ap.get() != nullptr) {
353     uint32_t loc_ignore = m_options_ap->GetIgnoreCount();
354     if (loc_ignore != 0)
355       m_options_ap->SetIgnoreCount(loc_ignore - 1);
356   }
357 }
358 
359 bool BreakpointLocation::IgnoreCountShouldStop() {
360   if (m_options_ap.get() != nullptr) {
361     uint32_t loc_ignore = m_options_ap->GetIgnoreCount();
362     if (loc_ignore != 0) {
363       m_owner.DecrementIgnoreCount();
364       DecrementIgnoreCount(); // Have to decrement our owners' ignore count,
365                               // since it won't get a
366                               // chance to.
367       return false;
368     }
369   }
370   return true;
371 }
372 
373 BreakpointOptions *BreakpointLocation::GetLocationOptions() {
374   // If we make the copy we don't copy the callbacks because that is
375   // potentially expensive and we don't want to do that for the simple case
376   // where someone is just disabling the location.
377   if (m_options_ap.get() == nullptr)
378     m_options_ap.reset(
379         new BreakpointOptions(false));
380 
381   return m_options_ap.get();
382 }
383 
384 bool BreakpointLocation::ValidForThisThread(Thread *thread) {
385   return thread
386       ->MatchesSpec(GetOptionsSpecifyingKind(BreakpointOptions::eThreadSpec)
387       ->GetThreadSpecNoCreate());
388 }
389 
390 // RETURNS - true if we should stop at this breakpoint, false if we
391 // should continue.  Note, we don't check the thread spec for the breakpoint
392 // here, since if the breakpoint is not for this thread, then the event won't
393 // even get reported, so the check is redundant.
394 
395 bool BreakpointLocation::ShouldStop(StoppointCallbackContext *context) {
396   bool should_stop = true;
397   Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_BREAKPOINTS);
398 
399   // Do this first, if a location is disabled, it shouldn't increment its hit
400   // count.
401   if (!IsEnabled())
402     return false;
403 
404   if (!IgnoreCountShouldStop())
405     return false;
406 
407   if (!m_owner.IgnoreCountShouldStop())
408     return false;
409 
410   // We only run synchronous callbacks in ShouldStop:
411   context->is_synchronous = true;
412   should_stop = InvokeCallback(context);
413 
414   if (log) {
415     StreamString s;
416     GetDescription(&s, lldb::eDescriptionLevelVerbose);
417     log->Printf("Hit breakpoint location: %s, %s.\n", s.GetData(),
418                 should_stop ? "stopping" : "continuing");
419   }
420 
421   return should_stop;
422 }
423 
424 void BreakpointLocation::BumpHitCount() {
425   if (IsEnabled()) {
426     // Step our hit count, and also step the hit count of the owner.
427     IncrementHitCount();
428     m_owner.IncrementHitCount();
429   }
430 }
431 
432 void BreakpointLocation::UndoBumpHitCount() {
433   if (IsEnabled()) {
434     // Step our hit count, and also step the hit count of the owner.
435     DecrementHitCount();
436     m_owner.DecrementHitCount();
437   }
438 }
439 
440 bool BreakpointLocation::IsResolved() const {
441   return m_bp_site_sp.get() != nullptr;
442 }
443 
444 lldb::BreakpointSiteSP BreakpointLocation::GetBreakpointSite() const {
445   return m_bp_site_sp;
446 }
447 
448 bool BreakpointLocation::ResolveBreakpointSite() {
449   if (m_bp_site_sp)
450     return true;
451 
452   Process *process = m_owner.GetTarget().GetProcessSP().get();
453   if (process == nullptr)
454     return false;
455 
456   lldb::break_id_t new_id =
457       process->CreateBreakpointSite(shared_from_this(), m_owner.IsHardware());
458 
459   if (new_id == LLDB_INVALID_BREAK_ID) {
460     Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_BREAKPOINTS);
461     if (log)
462       log->Warning("Tried to add breakpoint site at 0x%" PRIx64
463                    " but it was already present.\n",
464                    m_address.GetOpcodeLoadAddress(&m_owner.GetTarget()));
465     return false;
466   }
467 
468   return true;
469 }
470 
471 bool BreakpointLocation::SetBreakpointSite(BreakpointSiteSP &bp_site_sp) {
472   m_bp_site_sp = bp_site_sp;
473   SendBreakpointLocationChangedEvent(eBreakpointEventTypeLocationsResolved);
474   return true;
475 }
476 
477 bool BreakpointLocation::ClearBreakpointSite() {
478   if (m_bp_site_sp.get()) {
479     ProcessSP process_sp(m_owner.GetTarget().GetProcessSP());
480     // If the process exists, get it to remove the owner, it will remove the
481     // physical implementation of the breakpoint as well if there are no more
482     // owners.  Otherwise just remove this owner.
483     if (process_sp)
484       process_sp->RemoveOwnerFromBreakpointSite(GetBreakpoint().GetID(),
485                                                 GetID(), m_bp_site_sp);
486     else
487       m_bp_site_sp->RemoveOwner(GetBreakpoint().GetID(), GetID());
488 
489     m_bp_site_sp.reset();
490     return true;
491   }
492   return false;
493 }
494 
495 void BreakpointLocation::GetDescription(Stream *s,
496                                         lldb::DescriptionLevel level) {
497   SymbolContext sc;
498 
499   // If the description level is "initial" then the breakpoint is printing out
500   // our initial state, and we should let it decide how it wants to print our
501   // label.
502   if (level != eDescriptionLevelInitial) {
503     s->Indent();
504     BreakpointID::GetCanonicalReference(s, m_owner.GetID(), GetID());
505   }
506 
507   if (level == lldb::eDescriptionLevelBrief)
508     return;
509 
510   if (level != eDescriptionLevelInitial)
511     s->PutCString(": ");
512 
513   if (level == lldb::eDescriptionLevelVerbose)
514     s->IndentMore();
515 
516   if (m_address.IsSectionOffset()) {
517     m_address.CalculateSymbolContext(&sc);
518 
519     if (level == lldb::eDescriptionLevelFull ||
520         level == eDescriptionLevelInitial) {
521       if (IsReExported())
522         s->PutCString("re-exported target = ");
523       else
524         s->PutCString("where = ");
525       sc.DumpStopContext(s, m_owner.GetTarget().GetProcessSP().get(), m_address,
526                          false, true, false, true, true);
527     } else {
528       if (sc.module_sp) {
529         s->EOL();
530         s->Indent("module = ");
531         sc.module_sp->GetFileSpec().Dump(s);
532       }
533 
534       if (sc.comp_unit != nullptr) {
535         s->EOL();
536         s->Indent("compile unit = ");
537         static_cast<FileSpec *>(sc.comp_unit)->GetFilename().Dump(s);
538 
539         if (sc.function != nullptr) {
540           s->EOL();
541           s->Indent("function = ");
542           s->PutCString(sc.function->GetName().AsCString("<unknown>"));
543         }
544 
545         if (sc.line_entry.line > 0) {
546           s->EOL();
547           s->Indent("location = ");
548           sc.line_entry.DumpStopContext(s, true);
549         }
550 
551       } else {
552         // If we don't have a comp unit, see if we have a symbol we can print.
553         if (sc.symbol) {
554           s->EOL();
555           if (IsReExported())
556             s->Indent("re-exported target = ");
557           else
558             s->Indent("symbol = ");
559           s->PutCString(sc.symbol->GetName().AsCString("<unknown>"));
560         }
561       }
562     }
563   }
564 
565   if (level == lldb::eDescriptionLevelVerbose) {
566     s->EOL();
567     s->Indent();
568   }
569 
570   if (m_address.IsSectionOffset() &&
571       (level == eDescriptionLevelFull || level == eDescriptionLevelInitial))
572     s->Printf(", ");
573   s->Printf("address = ");
574 
575   ExecutionContextScope *exe_scope = nullptr;
576   Target *target = &m_owner.GetTarget();
577   if (target)
578     exe_scope = target->GetProcessSP().get();
579   if (exe_scope == nullptr)
580     exe_scope = target;
581 
582   if (level == eDescriptionLevelInitial)
583     m_address.Dump(s, exe_scope, Address::DumpStyleLoadAddress,
584                    Address::DumpStyleFileAddress);
585   else
586     m_address.Dump(s, exe_scope, Address::DumpStyleLoadAddress,
587                    Address::DumpStyleModuleWithFileAddress);
588 
589   if (IsIndirect() && m_bp_site_sp) {
590     Address resolved_address;
591     resolved_address.SetLoadAddress(m_bp_site_sp->GetLoadAddress(), target);
592     Symbol *resolved_symbol = resolved_address.CalculateSymbolContextSymbol();
593     if (resolved_symbol) {
594       if (level == eDescriptionLevelFull || level == eDescriptionLevelInitial)
595         s->Printf(", ");
596       else if (level == lldb::eDescriptionLevelVerbose) {
597         s->EOL();
598         s->Indent();
599       }
600       s->Printf("indirect target = %s",
601                 resolved_symbol->GetName().GetCString());
602     }
603   }
604 
605   if (level == lldb::eDescriptionLevelVerbose) {
606     s->EOL();
607     s->Indent();
608     s->Printf("resolved = %s\n", IsResolved() ? "true" : "false");
609 
610     s->Indent();
611     s->Printf("hit count = %-4u\n", GetHitCount());
612 
613     if (m_options_ap.get()) {
614       s->Indent();
615       m_options_ap->GetDescription(s, level);
616       s->EOL();
617     }
618     s->IndentLess();
619   } else if (level != eDescriptionLevelInitial) {
620     s->Printf(", %sresolved, hit count = %u ", (IsResolved() ? "" : "un"),
621               GetHitCount());
622     if (m_options_ap.get()) {
623       m_options_ap->GetDescription(s, level);
624     }
625   }
626 }
627 
628 void BreakpointLocation::Dump(Stream *s) const {
629   if (s == nullptr)
630     return;
631 
632   lldb::tid_t tid = GetOptionsSpecifyingKind(BreakpointOptions::eThreadSpec)
633       ->GetThreadSpecNoCreate()->GetTID();
634   s->Printf(
635       "BreakpointLocation %u: tid = %4.4" PRIx64 "  load addr = 0x%8.8" PRIx64
636       "  state = %s  type = %s breakpoint  "
637       "hw_index = %i  hit_count = %-4u  ignore_count = %-4u",
638       GetID(), tid,
639       (uint64_t)m_address.GetOpcodeLoadAddress(&m_owner.GetTarget()),
640       (m_options_ap.get() ? m_options_ap->IsEnabled() : m_owner.IsEnabled())
641           ? "enabled "
642           : "disabled",
643       IsHardware() ? "hardware" : "software", GetHardwareIndex(), GetHitCount(),
644       GetOptionsSpecifyingKind(BreakpointOptions::eIgnoreCount)
645           ->GetIgnoreCount());
646 }
647 
648 void BreakpointLocation::SendBreakpointLocationChangedEvent(
649     lldb::BreakpointEventType eventKind) {
650   if (!m_being_created && !m_owner.IsInternal() &&
651       m_owner.GetTarget().EventTypeHasListeners(
652           Target::eBroadcastBitBreakpointChanged)) {
653     Breakpoint::BreakpointEventData *data = new Breakpoint::BreakpointEventData(
654         eventKind, m_owner.shared_from_this());
655     data->GetBreakpointLocationCollection().Add(shared_from_this());
656     m_owner.GetTarget().BroadcastEvent(Target::eBroadcastBitBreakpointChanged,
657                                        data);
658   }
659 }
660 
661 void BreakpointLocation::SwapLocation(BreakpointLocationSP swap_from) {
662   m_address = swap_from->m_address;
663   m_should_resolve_indirect_functions =
664       swap_from->m_should_resolve_indirect_functions;
665   m_is_reexported = swap_from->m_is_reexported;
666   m_is_indirect = swap_from->m_is_indirect;
667   m_user_expression_sp.reset();
668 }
669