LLDB mainline
BreakpointLocation.cpp
Go to the documentation of this file.
1//===-- BreakpointLocation.cpp --------------------------------------------===//
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
14#include "lldb/Core/Debugger.h"
15#include "lldb/Core/Module.h"
20#include "lldb/Symbol/Symbol.h"
22#include "lldb/Target/Process.h"
23#include "lldb/Target/Target.h"
24#include "lldb/Target/Thread.h"
27#include "lldb/Utility/Log.h"
33
34using namespace lldb;
35using namespace lldb_private;
36
38 const Address &addr, lldb::tid_t tid,
39 bool check_for_resolver)
40 : m_address(addr), m_owner(owner), m_loc_id(loc_id) {
41 if (check_for_resolver) {
42 const Symbol *symbol = m_address.CalculateSymbolContextSymbol();
43 if (symbol && symbol->IsIndirect()) {
44 SetShouldResolveIndirectFunctions(true);
45 }
46 }
47
48 SetThreadIDInternal(tid);
49}
50
52 : m_owner(owner), m_loc_id(loc_id) {
53 SetThreadIDInternal(LLDB_INVALID_THREAD_ID);
54}
55
59
61 return m_address.GetOpcodeLoadAddress(&m_owner.GetTarget());
62}
63
66 if (m_options_up && m_options_up->IsOptionSet(kind))
67 return *m_options_up;
68 return m_owner.GetOptions();
69}
70
72
74
76
78 if (!m_owner.IsEnabled())
79 return false;
80 if (m_options_up != nullptr)
81 return m_options_up->IsEnabled();
82 return true;
83}
84
85llvm::Error BreakpointLocation::SetEnabled(bool enabled) {
87 llvm::Error error = enabled ? ResolveBreakpointSite() : ClearBreakpointSite();
88 SendBreakpointLocationChangedEvent(enabled ? eBreakpointEventTypeEnabled
89 : eBreakpointEventTypeDisabled);
90 return error;
91}
92
94 if (m_options_up &&
96 return m_options_up->IsAutoContinue();
97 return m_owner.IsAutoContinue();
98}
99
100void BreakpointLocation::SetAutoContinue(bool auto_continue) {
101 GetLocationOptions().SetAutoContinue(auto_continue);
102 SendBreakpointLocationChangedEvent(eBreakpointEventTypeAutoContinueChanged);
103}
104
106 SetThreadIDInternal(thread_id);
107 SendBreakpointLocationChangedEvent(eBreakpointEventTypeThreadChanged);
108}
109
111 const ThreadSpec *thread_spec =
114 if (thread_spec)
115 return thread_spec->GetTID();
117}
118
120 if (index != 0)
122 else {
123 // If we're resetting this to an invalid thread id, then don't make an
124 // options pointer just to do that.
125 if (m_options_up != nullptr)
126 m_options_up->GetThreadSpec()->SetIndex(index);
127 }
128 SendBreakpointLocationChangedEvent(eBreakpointEventTypeThreadChanged);
129}
130
132 const ThreadSpec *thread_spec =
135 if (thread_spec)
136 return thread_spec->GetIndex();
137 return 0;
138}
139
140void BreakpointLocation::SetThreadName(const char *thread_name) {
141 if (thread_name != nullptr)
142 GetLocationOptions().GetThreadSpec()->SetName(thread_name);
143 else {
144 // If we're resetting this to an invalid thread id, then don't make an
145 // options pointer just to do that.
146 if (m_options_up != nullptr)
147 m_options_up->GetThreadSpec()->SetName(thread_name);
148 }
149 SendBreakpointLocationChangedEvent(eBreakpointEventTypeThreadChanged);
150}
151
153 const ThreadSpec *thread_spec =
156 if (thread_spec)
157 return thread_spec->GetName();
158 return nullptr;
159}
160
161void BreakpointLocation::SetQueueName(const char *queue_name) {
162 if (queue_name != nullptr)
164 else {
165 // If we're resetting this to an invalid thread id, then don't make an
166 // options pointer just to do that.
167 if (m_options_up != nullptr)
168 m_options_up->GetThreadSpec()->SetQueueName(queue_name);
169 }
170 SendBreakpointLocationChangedEvent(eBreakpointEventTypeThreadChanged);
171}
172
174 const ThreadSpec *thread_spec =
177 if (thread_spec)
178 return thread_spec->GetQueueName();
179 return nullptr;
180}
181
183 if (m_options_up != nullptr && m_options_up->HasCallback())
184 return m_options_up->InvokeCallback(context, m_owner.GetID(), GetID());
185 return m_owner.InvokeCallback(context, GetID());
186}
187
189 if (m_options_up != nullptr && m_options_up->HasCallback())
190 return m_options_up->IsCallbackSynchronous();
191 return m_owner.GetOptions().IsCallbackSynchronous();
192}
193
195 void *baton, bool is_synchronous) {
196 // The default "Baton" class will keep a copy of "baton" and won't free or
197 // delete it when it goes out of scope.
199 callback, std::make_shared<UntypedBaton>(baton), is_synchronous);
200 SendBreakpointLocationChangedEvent(eBreakpointEventTypeCommandChanged);
201}
202
204 const BatonSP &baton_sp,
205 bool is_synchronous) {
206 GetLocationOptions().SetCallback(callback, baton_sp, is_synchronous);
207 SendBreakpointLocationChangedEvent(eBreakpointEventTypeCommandChanged);
208}
209
213
215 GetLocationOptions().SetCondition(std::move(condition));
216 SendBreakpointLocationChangedEvent(eBreakpointEventTypeConditionChanged);
217}
218
222
224 Status &error) {
226
227 std::lock_guard<std::mutex> guard(m_condition_mutex);
228
229 StopCondition condition = GetCondition();
230
231 if (!condition) {
232 m_dil_expr_tree.reset();
233 m_user_expression_sp.reset();
234 return false;
235 }
236
237 // If the condition evaluation mode for this breakpoint is not specified,
238 // use the value from the target setting.
239 lldb::BreakpointConditionMode condition_mode =
241 ? condition.GetMode()
243
244 // Attempt to parse the condition using Data Inspection Language (DIL).
245 if (condition.GetHash() != m_condition_hash && exe_ctx.HasFrameScope() &&
246 condition_mode != lldb::eBreakpointConditionModeExpr) {
247 // Lex the expression.
248 auto lex_or_err = dil::DILLexer::Create(condition.GetText(), eDILModeFull);
249 if (lex_or_err) {
250 // Parse the expression.
251 auto tree_or_error = dil::DILParser::Parse(
252 exe_ctx, condition.GetText(), std::move(*lex_or_err),
254 if (tree_or_error) {
255 m_dil_expr_tree = std::move(*tree_or_error);
256 m_condition_hash = condition.GetHash();
257 LLDB_LOG(log, "DIL successfully parsed the condition: {0}.",
258 condition.GetText());
259 } else {
260 m_dil_expr_tree.reset();
261 error = Status::FromError(tree_or_error.takeError());
262 LLDB_LOG(log, "Parsing condition with DIL failed:\n{0}.", error);
263 }
264 } else {
265 m_dil_expr_tree.reset();
266 error = Status::FromError(lex_or_err.takeError());
267 LLDB_LOG(log, "Lexing condition with DIL failed:\n{0}.", error);
268 }
269 }
270 // If the expression was parsed successfully, it can be evaluated separately
271 // at every breakpoint location hit without having to parse it again.
272 if (m_dil_expr_tree) {
273 dil::Interpreter interpreter(exe_ctx, condition.GetText(),
275 // Evaluate the expression by DIL.
276 auto valobj_or_error = interpreter.EvaluateTree(m_dil_expr_tree);
277 if (valobj_or_error) {
278 ValueObjectSP value_sp = *valobj_or_error;
279 if (value_sp && value_sp->GetError().Success()) {
280 llvm::Expected<bool> bool_result = value_sp->GetValueAsBool();
281 if (bool_result) {
282 LLDB_LOG(log,
283 "Condition successfully evaluated by DIL, result is {0}.\n",
284 *bool_result ? "true" : "false");
285 return *bool_result;
286 }
287 error = Status::FromError(bool_result.takeError());
288 }
289 } else {
290 error = Status::FromError(valobj_or_error.takeError());
291 }
292 // Evaluation failed.
293 LLDB_LOG(log, "Evaluating condition with DIL failed:\n{0}.", error);
294 m_dil_expr_tree.reset();
296 }
297 // DIL evaluation failed, trigger the breakpoint and return the error.
298 if (condition_mode == lldb::eBreakpointConditionModeDIL)
299 return true;
300
301 // The condition evaluation proceeds to UserExpression here.
302 error.Clear();
303
304 DiagnosticManager diagnostics;
305
306 if (condition.GetHash() != m_condition_hash || !m_user_expression_sp ||
307 !m_user_expression_sp->IsParseCacheable() ||
308 !m_user_expression_sp->MatchesContext(exe_ctx)) {
309 LanguageType language = condition.GetLanguage();
310 if (language == lldb::eLanguageTypeUnknown) {
311 // See if we can figure out the language from the frame, otherwise use the
312 // default language:
313 if (CompileUnit *comp_unit =
314 m_address.CalculateSymbolContextCompileUnit())
315 language = comp_unit->GetLanguage();
316 }
317
318 m_user_expression_sp.reset(GetTarget().GetUserExpressionForLanguage(
319 condition.GetText(), llvm::StringRef(), SourceLanguage{language},
321 error));
322 if (error.Fail()) {
323 LLDB_LOGF(log, "Error getting condition expression: %s.",
324 error.AsCString());
325 m_user_expression_sp.reset();
326 return true;
327 }
328
329 if (!m_user_expression_sp->Parse(diagnostics, exe_ctx,
331 false)) {
334 "Couldn't parse conditional expression:"));
335
336 m_user_expression_sp.reset();
337 return true;
338 }
339
340 m_condition_hash = condition.GetHash();
341 }
342
343 // We need to make sure the user sees any parse errors in their condition, so
344 // we'll hook the constructor errors up to the debugger's Async I/O.
345
346 ValueObjectSP result_value_sp;
347
349 options.SetUnwindOnError(true);
350 options.SetIgnoreBreakpoints(true);
351 options.SetTryAllThreads(true);
353 true); // Don't generate a user variable for condition expressions.
354
355 Status expr_error;
356
357 diagnostics.Clear();
358
359 ExpressionVariableSP result_variable_sp;
360
361 ExpressionResults result_code = m_user_expression_sp->Execute(
362 diagnostics, exe_ctx, options, m_user_expression_sp, result_variable_sp);
363
364 bool ret;
365
366 if (result_code == eExpressionCompleted) {
367 if (!result_variable_sp) {
368 error = Status::FromErrorString("Expression did not return a result");
369 return false;
370 }
371
372 result_value_sp = result_variable_sp->GetValueObject();
373
374 if (result_value_sp) {
375 ret = result_value_sp->IsLogicalTrue(error);
376 if (log) {
377 if (error.Success()) {
378 LLDB_LOGF(log,
379 "Condition successfully evaluated by UserExpression, "
380 "result is %s.\n",
381 ret ? "true" : "false");
382 } else {
384 "Failed to get an integer result from the expression");
385 ret = false;
386 }
387 }
388 } else {
389 ret = false;
391 "Failed to get any result from the expression");
392 }
393 } else {
394 ret = false;
395 error = Status::FromError(diagnostics.GetAsError(
396 lldb::eExpressionParseError, "Couldn't execute expression:"));
397 }
398
399 return ret;
400}
401
406
409 SendBreakpointLocationChangedEvent(eBreakpointEventTypeIgnoreChanged);
410}
411
413 if (m_options_up != nullptr) {
414 uint32_t loc_ignore = m_options_up->GetIgnoreCount();
415 if (loc_ignore != 0)
416 m_options_up->SetIgnoreCount(loc_ignore - 1);
417 }
418}
419
421 uint32_t owner_ignore = GetBreakpoint().GetIgnoreCount();
422 uint32_t loc_ignore = 0;
423 if (m_options_up != nullptr)
424 loc_ignore = m_options_up->GetIgnoreCount();
425
426 if (loc_ignore != 0 || owner_ignore != 0) {
427 m_owner.DecrementIgnoreCount();
428 DecrementIgnoreCount(); // Have to decrement our owners' ignore count,
429 // since it won't get a chance to.
430 return false;
431 }
432 return true;
433}
434
436 // If we make the copy we don't copy the callbacks because that is
437 // potentially expensive and we don't want to do that for the simple case
438 // where someone is just disabling the location.
439 if (m_options_up == nullptr)
440 m_options_up = std::make_unique<BreakpointOptions>(false);
441
442 return *m_options_up;
443}
444
446 return thread.MatchesSpec(
448 .GetThreadSpecNoCreate());
449}
450
453 // Only the BreakpointResolverScripted provides WasHit.
456 llvm::dyn_cast<BreakpointResolverScripted>(resolver_sp.get());
457 if (!scripted)
458 return shared_from_this();
459
460 StackFrameSP frame_sp = context->exe_ctx_ref.GetFrameSP();
461 if (!frame_sp)
462 return shared_from_this();
463
464 BreakpointLocationSP return_loc_sp =
465 scripted->WasHit(frame_sp, shared_from_this());
466 // If this is a facade location, then we won't have bumped its hit count
467 // while processing the original location hit. Do so here. We don't need
468 // to bump the breakpoint's hit count, however, since hitting the real
469 // location would have already done that.
470 // Also we have to check the enabled state here, since we would never have
471 // gotten here with a real location...
472 if (return_loc_sp && return_loc_sp->IsFacade()) {
473 if (return_loc_sp->IsEnabled())
474 return_loc_sp->m_hit_counter.Increment();
475 else
476 return {};
477 }
478 return return_loc_sp;
479}
480
481// RETURNS - true if we should stop at this breakpoint, false if we
482// should continue. Note, we don't check the thread spec for the breakpoint
483// here, since if the breakpoint is not for this thread, then the event won't
484// even get reported, so the check is redundant.
485
487 lldb::BreakpointLocationSP &facade_loc_sp) {
488 bool should_stop = true;
490
491 // Do this first, if a location is disabled, it shouldn't increment its hit
492 // count.
493 if (!IsEnabled())
494 return false;
495
496 // Next check WasHit:
497 BreakpointLocationSP loc_hit_sp = WasHit(context);
498
499 if (!loc_hit_sp) {
500 // We bump the hit counts in StopInfoBreakpoint::ShouldStopSynchronous,
501 // before we call into each location's ShouldStop. So we need to undo
502 // that here.
504 return false;
505 }
506
507 // If the location hit was not us, it was a facade location, in which case
508 // we should use the facade location's callbacks, etc. Those will all be
509 // run in the asynchronous phase, so for now we just have to record the fact
510 // that we should treat this as a facade hit. This is strictly an out
511 // parameter, so clear it if this isn't a facade hit.
512 if (loc_hit_sp.get() != this)
513 facade_loc_sp = loc_hit_sp;
514 else
515 facade_loc_sp.reset();
516
517 // We only run synchronous callbacks in ShouldStop:
518 context->is_synchronous = true;
519 should_stop = InvokeCallback(context);
520
521 if (log) {
522 StreamString s;
524 LLDB_LOGF(log, "Hit breakpoint location: %s, %s.\n", s.GetData(),
525 should_stop ? "stopping" : "continuing");
526 if (facade_loc_sp) {
527 s.Clear();
528 facade_loc_sp->GetDescription(&s, lldb::eDescriptionLevelVerbose);
529 LLDB_LOGF(log, "Attributing to facade location: %s.\n", s.GetData());
530 }
531 }
532
533 return should_stop;
534}
535
537 if (IsEnabled()) {
538 // Step our hit count, and also step the hit count of the owner.
539 m_hit_counter.Increment();
540 m_owner.m_hit_counter.Increment();
541 }
542}
543
545 if (IsEnabled()) {
546 // Step our hit count, and also step the hit count of the owner.
547 m_hit_counter.Decrement();
548 m_owner.m_hit_counter.Decrement();
549 }
550}
551
553
554 bool has_site = m_bp_site_sp.get() != nullptr;
555 // Facade locations are currently always considered resolved.
556 return has_site || IsFacade();
557}
558
562
564 // This might be a facade location, which doesn't have an address.
565 // In that case, don't attempt to make a site.
566 if (m_bp_site_sp || IsFacade())
567 return llvm::Error::success();
568
569 Process *process = m_owner.GetTarget().GetProcessSP().get();
570 if (process == nullptr)
571 return llvm::createStringError("no process");
572
573 lldb::break_id_t new_id =
574 process->CreateBreakpointSite(shared_from_this(), m_owner.IsHardware());
575
576 if (new_id == LLDB_INVALID_BREAK_ID)
577 return llvm::createStringError(
578 llvm::formatv("Failed to add breakpoint site at {0:x}",
579 m_address.GetOpcodeLoadAddress(&m_owner.GetTarget())));
580
581 if (!IsResolved())
582 return llvm::createStringError(
583 "breakpoint site created but location is still unresolved");
584
585 return llvm::Error::success();
586}
587
589 m_bp_site_sp = bp_site_sp;
590 SendBreakpointLocationChangedEvent(eBreakpointEventTypeLocationsResolved);
591 return true;
592}
593
595 if (!m_bp_site_sp) {
596 // This might be a Facade Location, which don't have sites or addresses
597 if (IsFacade())
598 return llvm::Error::success();
599 return llvm::createStringError("no breakpoint site to clear");
600 }
601
602 // If the process exists, get it to remove the owner, it will remove the
603 // physical implementation of the breakpoint as well if there are no more
604 // owners. Otherwise just remove this owner.
605 if (ProcessSP process_sp = m_owner.GetTarget().GetProcessSP())
606 process_sp->RemoveConstituentFromBreakpointSite(GetBreakpoint().GetID(),
608 else
609 m_bp_site_sp->RemoveConstituent(GetBreakpoint().GetID(), GetID());
610
611 m_bp_site_sp.reset();
612 return llvm::Error::success();
613}
614
617 SymbolContext sc;
618
619 // If this is a scripted breakpoint, give it a chance to describe its
620 // locations:
621 std::optional<std::string> scripted_opt;
624 llvm::dyn_cast<BreakpointResolverScripted>(resolver_sp.get());
625 if (scripted)
626 scripted_opt = scripted->GetLocationDescription(shared_from_this(), level);
627
628 bool is_scripted_desc = scripted_opt.has_value();
629
630 // If the description level is "initial" then the breakpoint is printing out
631 // our initial state, and we should let it decide how it wants to print our
632 // label.
633 if (level != eDescriptionLevelInitial) {
634 s->Indent();
636 }
637
638 if (level == lldb::eDescriptionLevelBrief)
639 return;
640
641 if (level != eDescriptionLevelInitial)
642 s->PutCString(": ");
643
645 s->IndentMore();
646
647 if (is_scripted_desc) {
648 s->PutCString(scripted_opt->c_str());
649 } else if (m_address.IsSectionOffset()) {
650 m_address.CalculateSymbolContext(&sc);
651
652 if (level == lldb::eDescriptionLevelFull ||
653 level == eDescriptionLevelInitial) {
654 if (IsReExported())
655 s->PutCString("re-exported>);
656 else
657 s->PutCString("where = ");
658
659 // If there's a preferred line entry for printing, use that.
660 bool show_function_info = true;
661 if (auto preferred = GetPreferredLineEntry()) {
662 sc.line_entry = *preferred;
663 // FIXME: We're going to get the function name wrong when the preferred
664 // line entry is not the lowest one. For now, just leave the function
665 // out in this case, but we really should also figure out how to easily
666 // fake the function name here.
667 show_function_info = false;
668 }
669 sc.DumpStopContext(s, m_owner.GetTarget().GetProcessSP().get(), m_address,
670 false, true, false, show_function_info,
671 show_function_info, show_function_info);
672 } else {
673 if (sc.module_sp) {
674 s->EOL();
675 s->Indent("module = ");
676 sc.module_sp->GetFileSpec().Dump(s->AsRawOstream());
677 }
678
679 if (sc.comp_unit != nullptr) {
680 s->EOL();
681 s->Indent("compile unit = ");
683
684 if (sc.function != nullptr) {
685 s->EOL();
686 s->Indent("function = ");
687 s->PutCString(sc.function->GetName().AsCString("<unknown>"));
688 if (ConstString mangled_name =
690 s->EOL();
691 s->Indent("mangled function = ");
692 s->PutCString(mangled_name);
693 }
694 }
695
696 if (sc.line_entry.line > 0) {
697 s->EOL();
698 s->Indent("location = ");
699 if (auto preferred = GetPreferredLineEntry())
700 preferred->DumpStopContext(s, true);
701 else
702 sc.line_entry.DumpStopContext(s, true);
703 }
704
705 } else {
706 // If we don't have a comp unit, see if we have a symbol we can print.
707 if (sc.symbol) {
708 s->EOL();
709 if (IsReExported())
710 s->Indent("re-exported>);
711 else
712 s->Indent("symbol = ");
713 s->PutCString(sc.symbol->GetName().AsCString("<unknown>"));
714 }
715 }
716 }
717 }
718
719 if (level == lldb::eDescriptionLevelVerbose) {
720 s->EOL();
721 s->Indent();
722 }
723
724 if (!is_scripted_desc) {
725 if (m_address.IsSectionOffset() &&
726 (level == eDescriptionLevelFull || level == eDescriptionLevelInitial))
727 s->PutCString(", ");
728 s->PutCString("address = ");
729
730 ExecutionContextScope *exe_scope = nullptr;
731 Target *target = &m_owner.GetTarget();
732 if (target)
733 exe_scope = target->GetProcessSP().get();
734 if (exe_scope == nullptr)
735 exe_scope = target;
736
737 if (level == eDescriptionLevelInitial)
738 m_address.Dump(s, exe_scope, Address::DumpStyleLoadAddress,
740 else
741 m_address.Dump(s, exe_scope, Address::DumpStyleLoadAddress,
743
744 if (IsIndirect() && m_bp_site_sp) {
745 Address resolved_address;
746 resolved_address.SetLoadAddress(m_bp_site_sp->GetLoadAddress(), target);
747 const Symbol *resolved_symbol =
748 resolved_address.CalculateSymbolContextSymbol();
749 if (resolved_symbol) {
750 if (level == eDescriptionLevelFull || level == eDescriptionLevelInitial)
751 s->PutCString(", ");
752 else if (level == lldb::eDescriptionLevelVerbose) {
753 s->EOL();
754 s->Indent();
755 }
756 s->Printf("indirect>,
757 resolved_symbol->GetName().GetCString());
758 }
759 }
760 }
761
762 // FIXME: scripted breakpoint are currently always resolved. Does this seem
763 // right? If they don't add any scripted locations, we shouldn't consider them
764 // resolved.
765 bool is_resolved = is_scripted_desc || IsResolved();
766 // A scripted breakpoint might be resolved but not have a site. Be sure to
767 // check for that.
768 bool is_hardware = !is_scripted_desc && IsResolved() && m_bp_site_sp &&
769 m_bp_site_sp->IsHardware();
770
771 if (level == lldb::eDescriptionLevelVerbose) {
772 s->EOL();
773 s->Indent();
774 s->Printf("resolved = %s\n", is_resolved ? "true" : "false");
775 s->Indent();
776 s->Printf("hardware = %s\n", is_hardware ? "true" : "false");
777 s->Indent();
778 s->Printf("hit count = %-4u\n", GetHitCount());
779
780 if (m_options_up) {
781 s->Indent();
782 m_options_up->GetDescription(s, level);
783 s->EOL();
784 }
785 s->IndentLess();
786 } else if (level != eDescriptionLevelInitial) {
787 s->Printf(", %sresolved, %shit count = %u ", (is_resolved ? "" : "un"),
788 (is_hardware ? "hardware, " : ""), GetHitCount());
789 if (m_options_up) {
790 m_options_up->GetDescription(s, level);
791 }
792 }
793}
794
796 if (s == nullptr)
797 return;
798
799 bool is_resolved = IsResolved();
800 bool is_hardware = is_resolved && m_bp_site_sp->IsHardware();
801
804 ->GetTID();
805 s->Printf("BreakpointLocation %u: tid = %4.4" PRIx64
806 " load addr = 0x%8.8" PRIx64 " state = %s type = %s breakpoint "
807 "hit_count = %-4u ignore_count = %-4u",
808 GetID(), tid,
809 (uint64_t)m_address.GetOpcodeLoadAddress(&m_owner.GetTarget()),
810 (m_options_up ? m_options_up->IsEnabled() : m_owner.IsEnabled())
811 ? "enabled "
812 : "disabled",
813 is_hardware ? "hardware" : "software", GetHitCount(),
815 .GetIgnoreCount());
816}
817
819 lldb::BreakpointEventType eventKind) {
820 if (!m_owner.IsInternal()) {
821 auto data_sp = std::make_shared<Breakpoint::BreakpointEventData>(
822 eventKind, m_owner.shared_from_this());
823 data_sp->GetBreakpointLocationCollection().Add(shared_from_this());
824 m_owner.GetTarget().NotifyBreakpointChanged(m_owner, data_sp);
825 }
826}
827
829 auto preferred_opt = GetPreferredLineEntry();
830 if (!preferred_opt)
831 return {};
832 LineEntry preferred = *preferred_opt;
833 SymbolContext sc;
834 if (!m_address.CalculateSymbolContext(&sc))
835 return {};
836 // Don't return anything special if frame 0 is the preferred line entry.
837 // We not really telling the stack frame list to do anything special in that
838 // case.
839 if (!LineEntry::Compare(sc.line_entry, preferred))
840 return {};
841
842 if (!sc.block)
843 return {};
844
845 // Blocks have their line info in Declaration form, so make one here:
846 Declaration preferred_decl(preferred.GetFile(), preferred.line,
847 preferred.column);
848
849 uint32_t depth = 0;
850 Block *inlined_block = sc.block->GetContainingInlinedBlock();
851 while (inlined_block) {
852 // If we've moved to a block that this isn't the start of, that's not
853 // our inlining info or call site, so we can stop here.
854 Address start_address;
855 if (!inlined_block->GetStartAddress(start_address) ||
856 start_address != m_address)
857 return {};
858
859 const InlineFunctionInfo *info = inlined_block->GetInlinedFunctionInfo();
860 if (info) {
861 if (preferred_decl == info->GetDeclaration())
862 return depth;
863 if (preferred_decl == info->GetCallSite())
864 return depth + 1;
865 }
866 inlined_block = inlined_block->GetInlinedParent();
867 depth++;
868 }
869 return {};
870}
871
873 m_address = swap_from->m_address;
875 swap_from->m_should_resolve_indirect_functions;
876 m_is_reexported = swap_from->m_is_reexported;
877 m_is_indirect = swap_from->m_is_indirect;
878 m_dil_expr_tree.reset();
879 m_user_expression_sp.reset();
881}
882
884 if (thread_id != LLDB_INVALID_THREAD_ID) {
885 GetLocationOptions().SetThreadID(thread_id);
886 } else {
887 // If we're resetting this to an invalid thread id, then don't make an
888 // options pointer just to do that.
889 if (m_options_up != nullptr)
890 m_options_up->SetThreadID(thread_id);
891 }
892}
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
Definition Log.h:375
#define LLDB_LOGF(log,...)
Definition Log.h:389
A section + offset based address class.
Definition Address.h:62
bool SetLoadAddress(lldb::addr_t load_addr, Target *target, bool allow_section_end=false)
Set the address to represent load_addr.
Definition Address.cpp:1029
@ DumpStyleFileAddress
Display as the file address (if any).
Definition Address.h:87
@ DumpStyleModuleWithFileAddress
Display as the file address with the module name prepended (if any).
Definition Address.h:93
@ DumpStyleLoadAddress
Display as the load address (if resolved).
Definition Address.h:99
Symbol * CalculateSymbolContextSymbol() const
Definition Address.cpp:888
A class that describes a single lexical block.
Definition Block.h:41
Block * GetContainingInlinedBlock()
Get the inlined block that contains this block.
Definition Block.cpp:206
const InlineFunctionInfo * GetInlinedFunctionInfo() const
Get const accessor for any inlined function information.
Definition Block.h:268
bool GetStartAddress(Address &addr)
Definition Block.cpp:317
Block * GetInlinedParent()
Get the inlined parent block for this block.
Definition Block.cpp:212
static void GetCanonicalReference(Stream *s, lldb::break_id_t break_id, lldb::break_id_t break_loc_id)
Takes a breakpoint ID and the breakpoint location id and returns a string containing the canonical de...
size_t m_condition_hash
Breakpoint location ID.
void SetCondition(StopCondition condition)
Set the breakpoint location's condition.
const std::optional< LineEntry > GetPreferredLineEntry()
void SwapLocation(lldb::BreakpointLocationSP swap_from)
BreakpointLocation(lldb::break_id_t loc_id, Breakpoint &owner, const Address &addr, lldb::tid_t tid, bool check_for_resolver=true)
Constructor.
bool IsIndirect()
Returns whether the address set in the breakpoint site for this location was found by resolving an in...
uint32_t GetHitCount() const
Return the current Hit Count.
std::mutex m_condition_mutex
For testing whether the condition source code changed.
lldb::BreakpointSiteSP m_bp_site_sp
The compiled expression to use in testing our condition.
llvm::Error ClearBreakpointSite()
Clear this breakpoint location's breakpoint site - for instance when disabling the breakpoint.
Breakpoint & m_owner
Breakpoint options pointer, nullptr if we're using our breakpoint's options.
bool SetBreakpointSite(lldb::BreakpointSiteSP &bp_site_sp)
Set the breakpoint site for this location to bp_site_sp.
void SetIgnoreCount(uint32_t n)
Set the breakpoint to ignore the next count breakpoint hits.
void SetThreadIDInternal(lldb::tid_t thread_id)
Updates the thread ID internally.
void SetQueueName(const char *queue_name)
llvm::Error SetEnabled(bool enabled)
If enabled is true, enable the breakpoint, if false disable it.
bool IsReExported()
Returns whether the address set in the breakpoint location was re-routed to the target of a re-export...
lldb::addr_t GetLoadAddress() const
Gets the load address for this breakpoint location.
BreakpointOptions & GetLocationOptions()
Use this to set location specific breakpoint options.
bool InvokeCallback(StoppointCallbackContext *context)
Invoke the callback action when the breakpoint is hit.
void GetDescription(Stream *s, lldb::DescriptionLevel level)
Print a description of this breakpoint location to the stream s.
Address m_address
The breakpoint that produced this object.
bool IsEnabled() const
Check the Enable/Disable state.
bool IgnoreCountShouldStop()
BreakpointLocation::IgnoreCountShouldStop can only be called once per stop.
const StopCondition & GetCondition() const
Return the breakpoint condition.
bool IsResolved() const
Return whether this breakpoint location has a breakpoint site.
lldb::break_id_t GetID() const
Returns the breakpoint location ID.
void Dump(Stream *s) const
Standard "Dump" method. At present it does nothing.
bool IsCallbackSynchronous()
Report whether the callback for this location is synchronous or not.
void SendBreakpointLocationChangedEvent(lldb::BreakpointEventType eventKind)
void SetAutoContinue(bool auto_continue)
If auto_continue is true, set the breakpoint to continue when hit.
void SetThreadID(lldb::tid_t thread_id)
Set the valid thread to be checked when the breakpoint is hit.
lldb::UserExpressionSP m_user_expression_sp
The expression parsed by Data Inspection Language (DIL).
dil::ASTNodeUP m_dil_expr_tree
Guards parsing and evaluation of the condition, which could be evaluated by multiple processes.
void SetCallback(BreakpointHitCallback callback, const lldb::BatonSP &callback_baton_sp, bool is_synchronous)
Set the callback action invoked when the breakpoint is hit.
uint32_t GetIgnoreCount() const
Return the current Ignore Count.
bool m_is_indirect
The address defining this location.
bool ConditionSaysStop(ExecutionContext &exe_ctx, Status &error)
std::unique_ptr< BreakpointOptions > m_options_up
Our breakpoint site (it may be shared by more than one location.)
Address & GetAddress()
Gets the Address for this breakpoint location.
bool IsAutoContinue() const
Check the AutoContinue state.
std::optional< uint32_t > GetSuggestedStackFrameIndex()
If this location knows that the virtual stack frame it represents is not frame 0, return the suggeste...
void SetThreadName(const char *thread_name)
Breakpoint & GetBreakpoint()
Gets the Breakpoint that created this breakpoint location.
const BreakpointOptions & GetOptionsSpecifyingKind(BreakpointOptions::OptionKind kind) const
Use this to access breakpoint options from this breakpoint location.
llvm::Error ResolveBreakpointSite()
Try to resolve the breakpoint site for this location.
lldb::BreakpointLocationSP WasHit(StoppointCallbackContext *context)
This is a programmatic version of a breakpoint "condition".
lldb::BreakpointSiteSP GetBreakpointSite() const
bool ShouldStop(StoppointCallbackContext *context, lldb::BreakpointLocationSP &facade_loc_sp)
Determines whether we should stop due to a hit at this breakpoint location.
"lldb/Breakpoint/BreakpointOptions.h" Class that manages the options on a breakpoint or breakpoint lo...
void ClearCallback()
Remove the callback from this option set.
void SetIgnoreCount(uint32_t n)
Set the breakpoint to ignore the next count breakpoint hits.
void SetCondition(StopCondition condition)
Set the breakpoint stop condition.
void SetEnabled(bool enabled)
If enable is true, enable the breakpoint, if false disable it.
const StopCondition & GetCondition() const
Return the breakpoint condition.
uint32_t GetIgnoreCount() const
Return the current Ignore Count.
ThreadSpec * GetThreadSpec()
Returns a pointer to the ThreadSpec for this option, creating it.
const ThreadSpec * GetThreadSpecNoCreate() const
Return the current thread spec for this option.
void SetAutoContinue(bool auto_continue)
Set the auto-continue state.
void SetThreadID(lldb::tid_t thread_id)
void SetCallback(BreakpointHitCallback callback, const lldb::BatonSP &baton_sp, bool synchronous=false)
Adds a callback to the breakpoint option set.
"lldb/Breakpoint/BreakpointResolverScripted.h" This class sets breakpoints on a given Address.
std::optional< std::string > GetLocationDescription(lldb::BreakpointLocationSP bp_loc_sp, lldb::DescriptionLevel level)
lldb::BreakpointLocationSP WasHit(lldb::StackFrameSP frame_sp, lldb::BreakpointLocationSP bp_loc_sp)
General Outline: A breakpoint has four main parts, a filter, a resolver, the list of breakpoint locat...
Definition Breakpoint.h:83
uint32_t GetIgnoreCount() const
Return the current ignore count/.
lldb::BreakpointResolverSP GetResolver()
Definition Breakpoint.h:557
A class that describes a compilation unit.
Definition CompileUnit.h:43
const FileSpec & GetPrimaryFile() const
Return the primary source spec associated with this compile unit.
A uniqued constant string class.
Definition ConstString.h:40
const char * GetCString() const
Get the string value as a C string.
const char * AsCString(const char *value_if_empty) const
Get the string value as a C string.
A class that describes the declaration location of a lldb object.
Definition Declaration.h:24
llvm::Error GetAsError(lldb::ExpressionResults result, llvm::Twine message={}) const
Returns an ExpressionError with arg as error code.
void SetUnwindOnError(bool unwind=false)
Definition Target.h:407
void SetTryAllThreads(bool try_others=true)
Definition Target.h:440
void SetIgnoreBreakpoints(bool ignore=false)
Definition Target.h:411
lldb::StackFrameSP GetFrameSP() const
Get accessor that creates a strong reference from the weak frame reference contained in this object.
"lldb/Target/ExecutionContextScope.h" Inherit from this if your object can reconstruct its execution ...
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
bool HasFrameScope() const
Returns true the ExecutionContext object contains a valid target, process, thread and frame.
llvm::StringRef GetFilename() const
Filename string const get accessor.
Definition FileSpec.h:248
Declaration & GetDeclaration()
Get accessor for the declaration information.
Definition Function.cpp:54
ConstString GetName() const
Definition Function.cpp:724
const Mangled & GetMangled() const
Definition Function.h:541
A class that describes information for an inlined function.
Definition Function.h:120
Declaration & GetCallSite()
Get accessor for the call site declaration information.
Definition Function.cpp:105
ConstString GetMangledName() const
Mangled name get accessor.
Definition Mangled.h:146
lldb::break_id_t CreateBreakpointSite(const lldb::BreakpointLocationSP &owner, bool use_hardware)
Definition Process.cpp:1805
An error handling class.
Definition Status.h:118
static Status FromErrorString(const char *str)
Definition Status.h:141
static Status FromError(llvm::Error error)
Avoid using this in new code. Migrate APIs to llvm::Expected instead.
Definition Status.cpp:136
lldb::LanguageType GetLanguage() const
lldb::BreakpointConditionMode GetMode() const
llvm::StringRef GetText() const
General Outline: When we hit a breakpoint we need to package up whatever information is needed to eva...
const char * GetData() const
A stream class that can stream formatted output to a file.
Definition Stream.h:28
llvm::raw_ostream & AsRawOstream()
Returns a raw_ostream that forwards the data to this Stream object.
Definition Stream.h:405
size_t Indent(llvm::StringRef s="")
Indent the current line in the stream.
Definition Stream.cpp:157
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition Stream.cpp:134
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition Stream.cpp:63
size_t EOL()
Output and End of Line character to the stream.
Definition Stream.cpp:155
void IndentLess(unsigned amount=2)
Decrement the current indentation level.
Definition Stream.cpp:204
void IndentMore(unsigned amount=2)
Increment the current indentation level.
Definition Stream.cpp:201
Defines a symbol context baton that can be handed other debug core functions.
Function * function
The Function for a given query.
Block * block
The Block for a given query.
lldb::ModuleSP module_sp
The Module for a given query.
CompileUnit * comp_unit
The CompileUnit for a given query.
bool DumpStopContext(Stream *s, ExecutionContextScope *exe_scope, const Address &so_addr, bool show_fullpaths, bool show_module, bool show_inlined_frames, bool show_function_arguments, bool show_function_name, bool show_function_display_name=false, std::optional< Stream::HighlightSettings > settings=std::nullopt) const
Dump the stop context in this object to a Stream.
Symbol * symbol
The Symbol for a given query.
LineEntry line_entry
The LineEntry for a given query.
bool IsIndirect() const
Definition Symbol.cpp:249
ConstString GetName() const
Definition Symbol.cpp:612
Symbol * CalculateSymbolContextSymbol() override
Definition Symbol.cpp:452
lldb::BreakpointConditionMode GetBreakpointsConditionMode() const
Definition Target.cpp:5788
const lldb::ProcessSP & GetProcessSP() const
Definition Target.cpp:330
void SetIndex(uint32_t index)
Definition ThreadSpec.h:47
void SetName(llvm::StringRef name)
Definition ThreadSpec.h:51
uint32_t GetIndex() const
Definition ThreadSpec.h:57
const char * GetName() const
void SetQueueName(llvm::StringRef queue_name)
Definition ThreadSpec.h:53
const char * GetQueueName() const
lldb::tid_t GetTID() const
Definition ThreadSpec.h:59
static llvm::Expected< DILLexer > Create(llvm::StringRef expr, lldb::DILMode mode=lldb::eDILModeFull)
Lexes all the tokens in expr and calls the private constructor with the lexed tokens.
Definition DILLexer.cpp:200
static llvm::Expected< ASTNodeUP > Parse(ExecutionContext &exe_ctx, llvm::StringRef dil_input_expr, DILLexer lexer, lldb::DynamicValueType use_dynamic, lldb::DILMode mode)
Parse the lexed tokens.
Definition DILParser.cpp:92
llvm::Expected< lldb::ValueObjectSP > EvaluateTree(const ASTNodeUP &tree)
Evaluate an ASTNode tree.
Definition DILEval.cpp:485
#define LLDB_INVALID_BREAK_ID
#define LLDB_INVALID_THREAD_ID
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition Log.h:338
std::function< bool(void *baton, StoppointCallbackContext *context, lldb::user_id_t break_id, lldb::user_id_t break_loc_id)> BreakpointHitCallback
BreakpointConditionMode
Modes for evaluating breakpoint conditions.
@ eBreakpointConditionModeExpr
Use UserExpression to evaluate the condition.
@ eBreakpointConditionModeDIL
Use Data Inspection Language (DIL) to evaluate the condition.
@ eBreakpointConditionModeDefault
Use the mode specified by the target.breakpoints-condition-mode setting.
std::shared_ptr< lldb_private::StackFrame > StackFrameSP
std::shared_ptr< lldb_private::BreakpointSite > BreakpointSiteSP
std::shared_ptr< lldb_private::BreakpointResolver > BreakpointResolverSP
std::shared_ptr< lldb_private::BreakpointLocation > BreakpointLocationSP
DescriptionLevel
Description levels for "void GetDescription(Stream *, DescriptionLevel)" calls.
@ eDescriptionLevelBrief
@ eDescriptionLevelInitial
@ eDescriptionLevelFull
@ eDescriptionLevelVerbose
std::shared_ptr< lldb_private::ValueObject > ValueObjectSP
std::shared_ptr< lldb_private::ExpressionVariable > ExpressionVariableSP
LanguageType
Programming language type.
@ eLanguageTypeUnknown
Unknown or invalid language value.
ExpressionResults
The results of expression evaluation.
@ eExpressionCompleted
@ eExpressionParseError
int32_t break_id_t
Definition lldb-types.h:88
std::shared_ptr< lldb_private::Process > ProcessSP
std::shared_ptr< lldb_private::Baton > BatonSP
uint64_t addr_t
Definition lldb-types.h:80
@ eDILModeFull
Allowed: everything supported by DIL.
uint64_t tid_t
Definition lldb-types.h:85
A line table entry class.
Definition LineEntry.h:21
uint16_t column
The column number of the source line, or zero if there is no column information.
Definition LineEntry.h:155
static int Compare(const LineEntry &lhs, const LineEntry &rhs)
Compare two LineEntry objects.
uint32_t line
The source line number, or LLDB_INVALID_LINE_NUMBER if there is no line number information.
Definition LineEntry.h:151
bool DumpStopContext(Stream *s, bool show_fullpaths) const
Dumps information specific to a process that stops at this line entry to the supplied stream s.
Definition LineEntry.cpp:40
const FileSpec & GetFile() const
Helper to access the file.
Definition LineEntry.h:134
A type-erased pair of llvm::dwarf::SourceLanguageName and version.