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 condition.GetText(), std::move(*lex_or_err), exe_ctx.GetFrameRef(),
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.GetTargetSP(), condition.GetText(),
275 0);
276 // Evaluate the expression by DIL.
277 auto valobj_or_error = interpreter.EvaluateTree(m_dil_expr_tree);
278 if (valobj_or_error) {
279 ValueObjectSP value_sp = *valobj_or_error;
280 if (value_sp && value_sp->GetError().Success()) {
281 llvm::Expected<bool> bool_result = value_sp->GetValueAsBool();
282 if (bool_result) {
283 LLDB_LOG(log,
284 "Condition successfully evaluated by DIL, result is {0}.\n",
285 *bool_result ? "true" : "false");
286 return *bool_result;
287 }
288 error = Status::FromError(bool_result.takeError());
289 }
290 } else {
291 error = Status::FromError(valobj_or_error.takeError());
292 }
293 // Evaluation failed.
294 LLDB_LOG(log, "Evaluating condition with DIL failed:\n{0}.", error);
295 m_dil_expr_tree.reset();
297 }
298 // DIL evaluation failed, trigger the breakpoint and return the error.
299 if (condition_mode == lldb::eBreakpointConditionModeDIL)
300 return true;
301
302 // The condition evaluation proceeds to UserExpression here.
303 error.Clear();
304
305 DiagnosticManager diagnostics;
306
307 if (condition.GetHash() != m_condition_hash || !m_user_expression_sp ||
308 !m_user_expression_sp->IsParseCacheable() ||
309 !m_user_expression_sp->MatchesContext(exe_ctx)) {
310 LanguageType language = condition.GetLanguage();
311 if (language == lldb::eLanguageTypeUnknown) {
312 // See if we can figure out the language from the frame, otherwise use the
313 // default language:
314 if (CompileUnit *comp_unit =
315 m_address.CalculateSymbolContextCompileUnit())
316 language = comp_unit->GetLanguage();
317 }
318
319 m_user_expression_sp.reset(GetTarget().GetUserExpressionForLanguage(
320 condition.GetText(), llvm::StringRef(), SourceLanguage{language},
322 error));
323 if (error.Fail()) {
324 LLDB_LOGF(log, "Error getting condition expression: %s.",
325 error.AsCString());
326 m_user_expression_sp.reset();
327 return true;
328 }
329
330 if (!m_user_expression_sp->Parse(diagnostics, exe_ctx,
332 false)) {
335 "Couldn't parse conditional expression:"));
336
337 m_user_expression_sp.reset();
338 return true;
339 }
340
341 m_condition_hash = condition.GetHash();
342 }
343
344 // We need to make sure the user sees any parse errors in their condition, so
345 // we'll hook the constructor errors up to the debugger's Async I/O.
346
347 ValueObjectSP result_value_sp;
348
350 options.SetUnwindOnError(true);
351 options.SetIgnoreBreakpoints(true);
352 options.SetTryAllThreads(true);
354 true); // Don't generate a user variable for condition expressions.
355
356 Status expr_error;
357
358 diagnostics.Clear();
359
360 ExpressionVariableSP result_variable_sp;
361
362 ExpressionResults result_code = m_user_expression_sp->Execute(
363 diagnostics, exe_ctx, options, m_user_expression_sp, result_variable_sp);
364
365 bool ret;
366
367 if (result_code == eExpressionCompleted) {
368 if (!result_variable_sp) {
369 error = Status::FromErrorString("Expression did not return a result");
370 return false;
371 }
372
373 result_value_sp = result_variable_sp->GetValueObject();
374
375 if (result_value_sp) {
376 ret = result_value_sp->IsLogicalTrue(error);
377 if (log) {
378 if (error.Success()) {
379 LLDB_LOGF(log,
380 "Condition successfully evaluated by UserExpression, "
381 "result is %s.\n",
382 ret ? "true" : "false");
383 } else {
385 "Failed to get an integer result from the expression");
386 ret = false;
387 }
388 }
389 } else {
390 ret = false;
392 "Failed to get any result from the expression");
393 }
394 } else {
395 ret = false;
396 error = Status::FromError(diagnostics.GetAsError(
397 lldb::eExpressionParseError, "Couldn't execute expression:"));
398 }
399
400 return ret;
401}
402
407
410 SendBreakpointLocationChangedEvent(eBreakpointEventTypeIgnoreChanged);
411}
412
414 if (m_options_up != nullptr) {
415 uint32_t loc_ignore = m_options_up->GetIgnoreCount();
416 if (loc_ignore != 0)
417 m_options_up->SetIgnoreCount(loc_ignore - 1);
418 }
419}
420
422 uint32_t owner_ignore = GetBreakpoint().GetIgnoreCount();
423 uint32_t loc_ignore = 0;
424 if (m_options_up != nullptr)
425 loc_ignore = m_options_up->GetIgnoreCount();
426
427 if (loc_ignore != 0 || owner_ignore != 0) {
428 m_owner.DecrementIgnoreCount();
429 DecrementIgnoreCount(); // Have to decrement our owners' ignore count,
430 // since it won't get a chance to.
431 return false;
432 }
433 return true;
434}
435
437 // If we make the copy we don't copy the callbacks because that is
438 // potentially expensive and we don't want to do that for the simple case
439 // where someone is just disabling the location.
440 if (m_options_up == nullptr)
441 m_options_up = std::make_unique<BreakpointOptions>(false);
442
443 return *m_options_up;
444}
445
447 return thread.MatchesSpec(
449 .GetThreadSpecNoCreate());
450}
451
454 // Only the BreakpointResolverScripted provides WasHit.
457 llvm::dyn_cast<BreakpointResolverScripted>(resolver_sp.get());
458 if (!scripted)
459 return shared_from_this();
460
461 StackFrameSP frame_sp = context->exe_ctx_ref.GetFrameSP();
462 if (!frame_sp)
463 return shared_from_this();
464
465 BreakpointLocationSP return_loc_sp =
466 scripted->WasHit(frame_sp, shared_from_this());
467 // If this is a facade location, then we won't have bumped its hit count
468 // while processing the original location hit. Do so here. We don't need
469 // to bump the breakpoint's hit count, however, since hitting the real
470 // location would have already done that.
471 // Also we have to check the enabled state here, since we would never have
472 // gotten here with a real location...
473 if (return_loc_sp && return_loc_sp->IsFacade()) {
474 if (return_loc_sp->IsEnabled())
475 return_loc_sp->m_hit_counter.Increment();
476 else
477 return {};
478 }
479 return return_loc_sp;
480}
481
482// RETURNS - true if we should stop at this breakpoint, false if we
483// should continue. Note, we don't check the thread spec for the breakpoint
484// here, since if the breakpoint is not for this thread, then the event won't
485// even get reported, so the check is redundant.
486
488 lldb::BreakpointLocationSP &facade_loc_sp) {
489 bool should_stop = true;
491
492 // Do this first, if a location is disabled, it shouldn't increment its hit
493 // count.
494 if (!IsEnabled())
495 return false;
496
497 // Next check WasHit:
498 BreakpointLocationSP loc_hit_sp = WasHit(context);
499
500 if (!loc_hit_sp) {
501 // We bump the hit counts in StopInfoBreakpoint::ShouldStopSynchronous,
502 // before we call into each location's ShouldStop. So we need to undo
503 // that here.
505 return false;
506 }
507
508 // If the location hit was not us, it was a facade location, in which case
509 // we should use the facade location's callbacks, etc. Those will all be
510 // run in the asynchronous phase, so for now we just have to record the fact
511 // that we should treat this as a facade hit. This is strictly an out
512 // parameter, so clear it if this isn't a facade hit.
513 if (loc_hit_sp.get() != this)
514 facade_loc_sp = loc_hit_sp;
515 else
516 facade_loc_sp.reset();
517
518 // We only run synchronous callbacks in ShouldStop:
519 context->is_synchronous = true;
520 should_stop = InvokeCallback(context);
521
522 if (log) {
523 StreamString s;
525 LLDB_LOGF(log, "Hit breakpoint location: %s, %s.\n", s.GetData(),
526 should_stop ? "stopping" : "continuing");
527 if (facade_loc_sp) {
528 s.Clear();
529 facade_loc_sp->GetDescription(&s, lldb::eDescriptionLevelVerbose);
530 LLDB_LOGF(log, "Attributing to facade location: %s.\n", s.GetData());
531 }
532 }
533
534 return should_stop;
535}
536
538 if (IsEnabled()) {
539 // Step our hit count, and also step the hit count of the owner.
540 m_hit_counter.Increment();
541 m_owner.m_hit_counter.Increment();
542 }
543}
544
546 if (IsEnabled()) {
547 // Step our hit count, and also step the hit count of the owner.
548 m_hit_counter.Decrement();
549 m_owner.m_hit_counter.Decrement();
550 }
551}
552
554
555 bool has_site = m_bp_site_sp.get() != nullptr;
556 // Facade locations are currently always considered resolved.
557 return has_site || IsFacade();
558}
559
563
565 // This might be a facade location, which doesn't have an address.
566 // In that case, don't attempt to make a site.
567 if (m_bp_site_sp || IsFacade())
568 return llvm::Error::success();
569
570 Process *process = m_owner.GetTarget().GetProcessSP().get();
571 if (process == nullptr)
572 return llvm::createStringError("no process");
573
574 lldb::break_id_t new_id =
575 process->CreateBreakpointSite(shared_from_this(), m_owner.IsHardware());
576
577 if (new_id == LLDB_INVALID_BREAK_ID)
578 return llvm::createStringError(
579 llvm::formatv("Failed to add breakpoint site at {0:x}",
580 m_address.GetOpcodeLoadAddress(&m_owner.GetTarget())));
581
582 if (!IsResolved())
583 return llvm::createStringError(
584 "breakpoint site created but location is still unresolved");
585
586 return llvm::Error::success();
587}
588
590 m_bp_site_sp = bp_site_sp;
591 SendBreakpointLocationChangedEvent(eBreakpointEventTypeLocationsResolved);
592 return true;
593}
594
596 if (!m_bp_site_sp) {
597 // This might be a Facade Location, which don't have sites or addresses
598 if (IsFacade())
599 return llvm::Error::success();
600 return llvm::createStringError("no breakpoint site to clear");
601 }
602
603 // If the process exists, get it to remove the owner, it will remove the
604 // physical implementation of the breakpoint as well if there are no more
605 // owners. Otherwise just remove this owner.
606 if (ProcessSP process_sp = m_owner.GetTarget().GetProcessSP())
607 process_sp->RemoveConstituentFromBreakpointSite(GetBreakpoint().GetID(),
609 else
610 m_bp_site_sp->RemoveConstituent(GetBreakpoint().GetID(), GetID());
611
612 m_bp_site_sp.reset();
613 return llvm::Error::success();
614}
615
618 SymbolContext sc;
619
620 // If this is a scripted breakpoint, give it a chance to describe its
621 // locations:
622 std::optional<std::string> scripted_opt;
625 llvm::dyn_cast<BreakpointResolverScripted>(resolver_sp.get());
626 if (scripted)
627 scripted_opt = scripted->GetLocationDescription(shared_from_this(), level);
628
629 bool is_scripted_desc = scripted_opt.has_value();
630
631 // If the description level is "initial" then the breakpoint is printing out
632 // our initial state, and we should let it decide how it wants to print our
633 // label.
634 if (level != eDescriptionLevelInitial) {
635 s->Indent();
637 }
638
639 if (level == lldb::eDescriptionLevelBrief)
640 return;
641
642 if (level != eDescriptionLevelInitial)
643 s->PutCString(": ");
644
646 s->IndentMore();
647
648 if (is_scripted_desc) {
649 s->PutCString(scripted_opt->c_str());
650 } else if (m_address.IsSectionOffset()) {
651 m_address.CalculateSymbolContext(&sc);
652
653 if (level == lldb::eDescriptionLevelFull ||
654 level == eDescriptionLevelInitial) {
655 if (IsReExported())
656 s->PutCString("re-exported target = ");
657 else
658 s->PutCString("where = ");
659
660 // If there's a preferred line entry for printing, use that.
661 bool show_function_info = true;
662 if (auto preferred = GetPreferredLineEntry()) {
663 sc.line_entry = *preferred;
664 // FIXME: We're going to get the function name wrong when the preferred
665 // line entry is not the lowest one. For now, just leave the function
666 // out in this case, but we really should also figure out how to easily
667 // fake the function name here.
668 show_function_info = false;
669 }
670 sc.DumpStopContext(s, m_owner.GetTarget().GetProcessSP().get(), m_address,
671 false, true, false, show_function_info,
672 show_function_info, show_function_info);
673 } else {
674 if (sc.module_sp) {
675 s->EOL();
676 s->Indent("module = ");
677 sc.module_sp->GetFileSpec().Dump(s->AsRawOstream());
678 }
679
680 if (sc.comp_unit != nullptr) {
681 s->EOL();
682 s->Indent("compile unit = ");
684
685 if (sc.function != nullptr) {
686 s->EOL();
687 s->Indent("function = ");
688 s->PutCString(sc.function->GetName().AsCString("<unknown>"));
689 if (ConstString mangled_name =
691 s->EOL();
692 s->Indent("mangled function = ");
693 s->PutCString(mangled_name);
694 }
695 }
696
697 if (sc.line_entry.line > 0) {
698 s->EOL();
699 s->Indent("location = ");
700 if (auto preferred = GetPreferredLineEntry())
701 preferred->DumpStopContext(s, true);
702 else
703 sc.line_entry.DumpStopContext(s, true);
704 }
705
706 } else {
707 // If we don't have a comp unit, see if we have a symbol we can print.
708 if (sc.symbol) {
709 s->EOL();
710 if (IsReExported())
711 s->Indent("re-exported target = ");
712 else
713 s->Indent("symbol = ");
714 s->PutCString(sc.symbol->GetName().AsCString("<unknown>"));
715 }
716 }
717 }
718 }
719
720 if (level == lldb::eDescriptionLevelVerbose) {
721 s->EOL();
722 s->Indent();
723 }
724
725 if (!is_scripted_desc) {
726 if (m_address.IsSectionOffset() &&
727 (level == eDescriptionLevelFull || level == eDescriptionLevelInitial))
728 s->PutCString(", ");
729 s->PutCString("address = ");
730
731 ExecutionContextScope *exe_scope = nullptr;
732 Target *target = &m_owner.GetTarget();
733 if (target)
734 exe_scope = target->GetProcessSP().get();
735 if (exe_scope == nullptr)
736 exe_scope = target;
737
738 if (level == eDescriptionLevelInitial)
739 m_address.Dump(s, exe_scope, Address::DumpStyleLoadAddress,
741 else
742 m_address.Dump(s, exe_scope, Address::DumpStyleLoadAddress,
744
745 if (IsIndirect() && m_bp_site_sp) {
746 Address resolved_address;
747 resolved_address.SetLoadAddress(m_bp_site_sp->GetLoadAddress(), target);
748 const Symbol *resolved_symbol =
749 resolved_address.CalculateSymbolContextSymbol();
750 if (resolved_symbol) {
751 if (level == eDescriptionLevelFull || level == eDescriptionLevelInitial)
752 s->PutCString(", ");
753 else if (level == lldb::eDescriptionLevelVerbose) {
754 s->EOL();
755 s->Indent();
756 }
757 s->Printf("indirect target = %s",
758 resolved_symbol->GetName().GetCString());
759 }
760 }
761 }
762
763 // FIXME: scripted breakpoint are currently always resolved. Does this seem
764 // right? If they don't add any scripted locations, we shouldn't consider them
765 // resolved.
766 bool is_resolved = is_scripted_desc || IsResolved();
767 // A scripted breakpoint might be resolved but not have a site. Be sure to
768 // check for that.
769 bool is_hardware = !is_scripted_desc && IsResolved() && m_bp_site_sp &&
770 m_bp_site_sp->IsHardware();
771
772 if (level == lldb::eDescriptionLevelVerbose) {
773 s->EOL();
774 s->Indent();
775 s->Printf("resolved = %s\n", is_resolved ? "true" : "false");
776 s->Indent();
777 s->Printf("hardware = %s\n", is_hardware ? "true" : "false");
778 s->Indent();
779 s->Printf("hit count = %-4u\n", GetHitCount());
780
781 if (m_options_up) {
782 s->Indent();
783 m_options_up->GetDescription(s, level);
784 s->EOL();
785 }
786 s->IndentLess();
787 } else if (level != eDescriptionLevelInitial) {
788 s->Printf(", %sresolved, %shit count = %u ", (is_resolved ? "" : "un"),
789 (is_hardware ? "hardware, " : ""), GetHitCount());
790 if (m_options_up) {
791 m_options_up->GetDescription(s, level);
792 }
793 }
794}
795
797 if (s == nullptr)
798 return;
799
800 bool is_resolved = IsResolved();
801 bool is_hardware = is_resolved && m_bp_site_sp->IsHardware();
802
805 ->GetTID();
806 s->Printf("BreakpointLocation %u: tid = %4.4" PRIx64
807 " load addr = 0x%8.8" PRIx64 " state = %s type = %s breakpoint "
808 "hit_count = %-4u ignore_count = %-4u",
809 GetID(), tid,
810 (uint64_t)m_address.GetOpcodeLoadAddress(&m_owner.GetTarget()),
811 (m_options_up ? m_options_up->IsEnabled() : m_owner.IsEnabled())
812 ? "enabled "
813 : "disabled",
814 is_hardware ? "hardware" : "software", GetHitCount(),
816 .GetIgnoreCount());
817}
818
820 lldb::BreakpointEventType eventKind) {
821 if (!m_owner.IsInternal()) {
822 auto data_sp = std::make_shared<Breakpoint::BreakpointEventData>(
823 eventKind, m_owner.shared_from_this());
824 data_sp->GetBreakpointLocationCollection().Add(shared_from_this());
825 m_owner.GetTarget().NotifyBreakpointChanged(m_owner, data_sp);
826 }
827}
828
830 auto preferred_opt = GetPreferredLineEntry();
831 if (!preferred_opt)
832 return {};
833 LineEntry preferred = *preferred_opt;
834 SymbolContext sc;
835 if (!m_address.CalculateSymbolContext(&sc))
836 return {};
837 // Don't return anything special if frame 0 is the preferred line entry.
838 // We not really telling the stack frame list to do anything special in that
839 // case.
840 if (!LineEntry::Compare(sc.line_entry, preferred))
841 return {};
842
843 if (!sc.block)
844 return {};
845
846 // Blocks have their line info in Declaration form, so make one here:
847 Declaration preferred_decl(preferred.GetFile(), preferred.line,
848 preferred.column);
849
850 uint32_t depth = 0;
851 Block *inlined_block = sc.block->GetContainingInlinedBlock();
852 while (inlined_block) {
853 // If we've moved to a block that this isn't the start of, that's not
854 // our inlining info or call site, so we can stop here.
855 Address start_address;
856 if (!inlined_block->GetStartAddress(start_address) ||
857 start_address != m_address)
858 return {};
859
860 const InlineFunctionInfo *info = inlined_block->GetInlinedFunctionInfo();
861 if (info) {
862 if (preferred_decl == info->GetDeclaration())
863 return depth;
864 if (preferred_decl == info->GetCallSite())
865 return depth + 1;
866 }
867 inlined_block = inlined_block->GetInlinedParent();
868 depth++;
869 }
870 return {};
871}
872
874 m_address = swap_from->m_address;
876 swap_from->m_should_resolve_indirect_functions;
877 m_is_reexported = swap_from->m_is_reexported;
878 m_is_indirect = swap_from->m_is_indirect;
879 m_dil_expr_tree.reset();
880 m_user_expression_sp.reset();
882}
883
885 if (thread_id != LLDB_INVALID_THREAD_ID) {
886 GetLocationOptions().SetThreadID(thread_id);
887 } else {
888 // If we're resetting this to an invalid thread id, then don't make an
889 // options pointer just to do that.
890 if (m_options_up != nullptr)
891 m_options_up->SetThreadID(thread_id);
892 }
893}
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.
const lldb::TargetSP & GetTargetSP() const
Get accessor to get the target shared pointer.
StackFrame & GetFrameRef() const
Returns a reference to the thread object.
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:174
lldb::break_id_t CreateBreakpointSite(const lldb::BreakpointLocationSP &owner, bool use_hardware)
Definition Process.cpp:1801
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:5786
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(llvm::StringRef dil_input_expr, DILLexer lexer, StackFrame &stack_frame, lldb::DynamicValueType use_dynamic, lldb::DILMode mode)
Parse the lexed tokens.
Definition DILParser.cpp:94
llvm::Expected< lldb::ValueObjectSP > EvaluateTree(const ASTNodeUP &tree)
Evaluate an ASTNode tree.
Definition DILEval.cpp:463
#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.