LLVM 22.0.0git
DWARFDie.cpp
Go to the documentation of this file.
1//===- DWARFDie.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
11#include "llvm/ADT/SmallSet.h"
12#include "llvm/ADT/StringRef.h"
26#include "llvm/Support/Format.h"
30#include <cassert>
31#include <cinttypes>
32#include <cstdint>
33#include <string>
34#include <utility>
35
36using namespace llvm;
37using namespace dwarf;
38using namespace object;
39
41 OS << " (";
42 do {
43 uint64_t Shift = llvm::countr_zero(Val);
44 assert(Shift < 64 && "undefined behavior");
45 uint64_t Bit = 1ULL << Shift;
46 auto PropName = ApplePropertyString(Bit);
47 if (!PropName.empty())
48 OS << PropName;
49 else
50 OS << format("DW_APPLE_PROPERTY_0x%" PRIx64, Bit);
51 if (!(Val ^= Bit))
52 break;
53 OS << ", ";
54 } while (true);
55 OS << ")";
56}
57
58static void dumpRanges(const DWARFObject &Obj, raw_ostream &OS,
59 const DWARFAddressRangesVector &Ranges,
60 unsigned AddressSize, unsigned Indent,
61 const DIDumpOptions &DumpOpts) {
62 if (!DumpOpts.ShowAddresses)
63 return;
64
65 for (const DWARFAddressRange &R : Ranges) {
66 OS << '\n';
67 OS.indent(Indent);
68 R.dump(OS, AddressSize, DumpOpts, &Obj);
69 }
70}
71
72static void dumpLocationList(raw_ostream &OS, const DWARFFormValue &FormValue,
73 DWARFUnit *U, unsigned Indent,
74 DIDumpOptions DumpOpts) {
76 "bad FORM for location list");
77 DWARFContext &Ctx = U->getContext();
78 uint64_t Offset = *FormValue.getAsSectionOffset();
79
80 if (FormValue.getForm() == DW_FORM_loclistx) {
81 FormValue.dump(OS, DumpOpts);
82
83 if (auto LoclistOffset = U->getLoclistOffset(Offset))
84 Offset = *LoclistOffset;
85 else
86 return;
87 }
88 U->getLocationTable().dumpLocationList(
89 &Offset, OS, U->getBaseAddress(), Ctx.getDWARFObj(), U, DumpOpts, Indent);
90}
91
92static void dumpLocationExpr(raw_ostream &OS, const DWARFFormValue &FormValue,
93 DWARFUnit *U, unsigned Indent,
94 DIDumpOptions DumpOpts) {
97 "bad FORM for location expression");
98 DWARFContext &Ctx = U->getContext();
99 ArrayRef<uint8_t> Expr = *FormValue.getAsBlock();
100 DataExtractor Data(StringRef((const char *)Expr.data(), Expr.size()),
101 Ctx.isLittleEndian(), 0);
102 DWARFExpression DE(Data, U->getAddressByteSize(), U->getFormParams().Format);
103 printDwarfExpression(&DE, OS, DumpOpts, U);
104}
105
107 return D.getAttributeValueAsReferencedDie(F).resolveTypeUnitReference();
108}
109
110static void dumpAttribute(raw_ostream &OS, const DWARFDie &Die,
111 const DWARFAttribute &AttrValue, unsigned Indent,
112 DIDumpOptions DumpOpts) {
113 if (!Die.isValid())
114 return;
115 const char BaseIndent[] = " ";
116 OS << BaseIndent;
117 OS.indent(Indent + 2);
118 dwarf::Attribute Attr = AttrValue.Attr;
119 WithColor(OS, HighlightColor::Attribute) << formatv("{0}", Attr);
120
121 dwarf::Form Form = AttrValue.Value.getForm();
122 if (DumpOpts.Verbose || DumpOpts.ShowForm)
123 OS << formatv(" [{0}]", Form);
124
125 DWARFUnit *U = Die.getDwarfUnit();
126 const DWARFFormValue &FormValue = AttrValue.Value;
127
128 OS << "\t(";
129
130 StringRef Name;
131 std::string File;
132 auto Color = HighlightColor::Enumerator;
133 if (Attr == DW_AT_decl_file || Attr == DW_AT_call_file) {
135 if (const auto *LT = U->getContext().getLineTableForUnit(U)) {
136 if (std::optional<uint64_t> Val = FormValue.getAsUnsignedConstant()) {
137 if (LT->getFileNameByIndex(
138 *Val, U->getCompilationDir(),
140 File)) {
141 File = '"' + File + '"';
142 Name = File;
143 }
144 }
145 }
146 } else if (std::optional<uint64_t> Val = FormValue.getAsUnsignedConstant())
147 Name = AttributeValueString(Attr, *Val);
148
149 if (!Name.empty())
150 WithColor(OS, Color) << Name;
151 else if (Attr == DW_AT_decl_line || Attr == DW_AT_decl_column ||
152 Attr == DW_AT_call_line || Attr == DW_AT_call_column ||
153 Attr == DW_AT_language_version) {
154 if (std::optional<uint64_t> Val = FormValue.getAsUnsignedConstant())
155 OS << *Val;
156 else
157 FormValue.dump(OS, DumpOpts);
158 } else if (Attr == DW_AT_low_pc &&
159 (FormValue.getAsAddress() ==
160 dwarf::computeTombstoneAddress(U->getAddressByteSize()))) {
161 if (DumpOpts.Verbose) {
162 FormValue.dump(OS, DumpOpts);
163 OS << " (";
164 }
165 OS << "dead code";
166 if (DumpOpts.Verbose)
167 OS << ')';
168 } else if (Attr == DW_AT_high_pc && !DumpOpts.ShowForm && !DumpOpts.Verbose &&
169 FormValue.getAsUnsignedConstant()) {
170 if (DumpOpts.ShowAddresses) {
171 // Print the actual address rather than the offset.
172 uint64_t LowPC, HighPC, Index;
173 if (Die.getLowAndHighPC(LowPC, HighPC, Index))
174 DWARFFormValue::dumpAddress(OS, U->getAddressByteSize(), HighPC);
175 else
176 FormValue.dump(OS, DumpOpts);
177 }
178 } else if (DWARFAttribute::mayHaveLocationList(Attr) &&
180 dumpLocationList(OS, FormValue, U, sizeof(BaseIndent) + Indent + 4,
181 DumpOpts);
182 else if (FormValue.isFormClass(DWARFFormValue::FC_Exprloc) ||
185 dumpLocationExpr(OS, FormValue, U, sizeof(BaseIndent) + Indent + 4,
186 DumpOpts);
187 else
188 FormValue.dump(OS, DumpOpts);
189
190 std::string Space = DumpOpts.ShowAddresses ? " " : "";
191
192 // We have dumped the attribute raw value. For some attributes
193 // having both the raw value and the pretty-printed value is
194 // interesting. These attributes are handled below.
195 if (Attr == DW_AT_specification || Attr == DW_AT_abstract_origin ||
196 Attr == DW_AT_call_origin) {
197 if (const char *Name =
200 OS << Space << "\"" << Name << '\"';
201 } else if (Attr == DW_AT_type || Attr == DW_AT_containing_type) {
202 DWARFDie D = resolveReferencedType(Die, FormValue);
203 if (D && !D.isNULL()) {
204 OS << Space << "\"";
206 OS << '"';
207 }
208 } else if (Attr == DW_AT_APPLE_property_attribute) {
209 if (std::optional<uint64_t> OptVal = FormValue.getAsUnsignedConstant())
210 dumpApplePropertyAttribute(OS, *OptVal);
211 } else if (Attr == DW_AT_ranges) {
212 const DWARFObject &Obj = Die.getDwarfUnit()->getContext().getDWARFObj();
213 // For DW_FORM_rnglistx we need to dump the offset separately, since
214 // we have only dumped the index so far.
215 if (FormValue.getForm() == DW_FORM_rnglistx)
216 if (auto RangeListOffset =
217 U->getRnglistOffset(*FormValue.getAsSectionOffset())) {
219 dwarf::DW_FORM_sec_offset, *RangeListOffset);
220 FV.dump(OS, DumpOpts);
221 }
222 if (auto RangesOrError = Die.getAddressRanges())
223 dumpRanges(Obj, OS, RangesOrError.get(), U->getAddressByteSize(),
224 sizeof(BaseIndent) + Indent + 4, DumpOpts);
225 else
227 errc::invalid_argument, "decoding address ranges: %s",
228 toString(RangesOrError.takeError()).c_str()));
229 }
230
231 OS << ")\n";
232}
233
235 std::string *OriginalFullName) const {
236 const char *NamePtr = getShortName();
237 if (!NamePtr)
238 return;
239 if (getTag() == DW_TAG_GNU_template_parameter_pack)
240 return;
241 dumpTypeUnqualifiedName(*this, OS, OriginalFullName);
242}
243
244bool DWARFDie::isSubprogramDIE() const { return getTag() == DW_TAG_subprogram; }
245
247 auto Tag = getTag();
248 return Tag == DW_TAG_subprogram || Tag == DW_TAG_inlined_subroutine;
249}
250
251std::optional<DWARFFormValue> DWARFDie::find(dwarf::Attribute Attr) const {
252 if (!isValid())
253 return std::nullopt;
254 auto AbbrevDecl = getAbbreviationDeclarationPtr();
255 if (AbbrevDecl)
256 return AbbrevDecl->getAttributeValue(getOffset(), Attr, *U);
257 return std::nullopt;
258}
259
260std::optional<DWARFFormValue>
262 if (!isValid())
263 return std::nullopt;
264 auto AbbrevDecl = getAbbreviationDeclarationPtr();
265 if (AbbrevDecl) {
266 for (auto Attr : Attrs) {
267 if (auto Value = AbbrevDecl->getAttributeValue(getOffset(), Attr, *U))
268 return Value;
269 }
270 }
271 return std::nullopt;
272}
273
274std::optional<DWARFFormValue>
277 Worklist.push_back(*this);
278
279 // Keep track if DIEs already seen to prevent infinite recursion.
280 // Empirically we rarely see a depth of more than 3 when dealing with valid
281 // DWARF. This corresponds to following the DW_AT_abstract_origin and
282 // DW_AT_specification just once.
284 Seen.insert(*this);
285
286 while (!Worklist.empty()) {
287 DWARFDie Die = Worklist.pop_back_val();
288
289 if (!Die.isValid())
290 continue;
291
292 if (auto Value = Die.find(Attrs))
293 return Value;
294
295 for (dwarf::Attribute Attr :
296 {DW_AT_abstract_origin, DW_AT_specification, DW_AT_signature}) {
297 if (auto D = Die.getAttributeValueAsReferencedDie(Attr))
298 if (Seen.insert(D).second)
299 Worklist.push_back(D);
300 }
301 }
302
303 return std::nullopt;
304}
305
308 if (std::optional<DWARFFormValue> F = find(Attr))
310 return DWARFDie();
311}
312
315 DWARFDie Result;
316 if (std::optional<uint64_t> Offset = V.getAsRelativeReference()) {
317 Result = const_cast<DWARFUnit *>(V.getUnit())
318 ->getDIEForOffset(V.getUnit()->getOffset() + *Offset);
319 } else if (Offset = V.getAsDebugInfoReference(); Offset) {
320 if (DWARFUnit *SpecUnit = U->getUnitVector().getUnitForOffset(*Offset))
321 Result = SpecUnit->getDIEForOffset(*Offset);
322 } else if (std::optional<uint64_t> Sig = V.getAsSignatureReference()) {
323 if (DWARFTypeUnit *TU =
324 U->getContext().getTypeUnitForHash(*Sig, U->isDWOUnit()))
325 Result = TU->getDIEForOffset(TU->getTypeOffset() + TU->getOffset());
326 }
327 return Result;
328}
329
331 if (auto Attr = find(DW_AT_signature)) {
332 if (std::optional<uint64_t> Sig = Attr->getAsReferenceUVal()) {
333 if (DWARFTypeUnit *TU =
334 U->getContext().getTypeUnitForHash(*Sig, U->isDWOUnit()))
335 return TU->getDIEForOffset(TU->getTypeOffset() + TU->getOffset());
336 }
337 }
338 return *this;
339}
340
347
348std::optional<uint64_t> DWARFDie::getRangesBaseAttribute() const {
349 return toSectionOffset(find({DW_AT_rnglists_base, DW_AT_GNU_ranges_base}));
350}
351
352std::optional<uint64_t> DWARFDie::getLocBaseAttribute() const {
353 return toSectionOffset(find(DW_AT_loclists_base));
354}
355
356std::optional<uint64_t> DWARFDie::getHighPC(uint64_t LowPC) const {
357 uint64_t Tombstone = dwarf::computeTombstoneAddress(U->getAddressByteSize());
358 if (LowPC == Tombstone)
359 return std::nullopt;
360 if (auto FormValue = find(DW_AT_high_pc)) {
361 if (auto Address = FormValue->getAsAddress()) {
362 // High PC is an address.
363 return Address;
364 }
365 if (auto Offset = FormValue->getAsUnsignedConstant()) {
366 // High PC is an offset from LowPC.
367 return LowPC + *Offset;
368 }
369 }
370 return std::nullopt;
371}
372
374 uint64_t &SectionIndex) const {
375 auto F = find(DW_AT_low_pc);
376 auto LowPcAddr = toSectionedAddress(F);
377 if (!LowPcAddr)
378 return false;
379 if (auto HighPcAddr = getHighPC(LowPcAddr->Address)) {
380 LowPC = LowPcAddr->Address;
381 HighPC = *HighPcAddr;
382 SectionIndex = LowPcAddr->SectionIndex;
383 return true;
384 }
385 return false;
386}
387
389 if (isNULL())
391 // Single range specified by low/high PC.
392 uint64_t LowPC, HighPC, Index;
393 if (getLowAndHighPC(LowPC, HighPC, Index))
394 return DWARFAddressRangesVector{{LowPC, HighPC, Index}};
395
396 std::optional<DWARFFormValue> Value = find(DW_AT_ranges);
397 if (Value) {
398 if (Value->getForm() == DW_FORM_rnglistx)
399 return U->findRnglistFromIndex(*Value->getAsSectionOffset());
400 return U->findRnglistFromOffset(*Value->getAsSectionOffset());
401 }
403}
404
406 auto RangesOrError = getAddressRanges();
407 if (!RangesOrError) {
408 llvm::consumeError(RangesOrError.takeError());
409 return false;
410 }
411
412 for (const auto &R : RangesOrError.get())
413 if (R.LowPC <= Address && Address < R.HighPC)
414 return true;
415 return false;
416}
417
418std::optional<uint64_t> DWARFDie::getLanguage() const {
419 if (isValid()) {
420 if (std::optional<DWARFFormValue> LV =
421 U->getUnitDIE().find(dwarf::DW_AT_language))
422 return LV->getAsUnsignedConstant();
423 }
424 return std::nullopt;
425}
426
429 std::optional<DWARFFormValue> Location = find(Attr);
430 if (!Location)
433
434 if (std::optional<uint64_t> Off = Location->getAsSectionOffset()) {
435 uint64_t Offset = *Off;
436
437 if (Location->getForm() == DW_FORM_loclistx) {
438 if (auto LoclistOffset = U->getLoclistOffset(Offset))
439 Offset = *LoclistOffset;
440 else
442 "Loclist table not found");
443 }
444 return U->findLoclistFromOffset(Offset);
445 }
446
447 if (std::optional<ArrayRef<uint8_t>> Expr = Location->getAsBlock()) {
449 DWARFLocationExpression{std::nullopt, to_vector<4>(*Expr)}};
450 }
451
452 return createStringError(
453 inconvertibleErrorCode(), "Unsupported %s encoding: %s",
455 dwarf::FormEncodingString(Location->getForm()).data());
456}
457
459 if (!isSubroutineDIE())
460 return nullptr;
461 return getName(Kind);
462}
463
465 if (!isValid() || Kind == DINameKind::None)
466 return nullptr;
467 // Try to get mangled name only if it was asked for.
469 if (auto Name = getLinkageName())
470 return Name;
471 }
472 return getShortName();
473}
474
475const char *DWARFDie::getShortName() const {
476 if (!isValid())
477 return nullptr;
478
479 return dwarf::toString(findRecursively(dwarf::DW_AT_name), nullptr);
480}
481
482const char *DWARFDie::getLinkageName() const {
483 if (!isValid())
484 return nullptr;
485
486 return dwarf::toString(findRecursively({dwarf::DW_AT_MIPS_linkage_name,
487 dwarf::DW_AT_linkage_name}),
488 nullptr);
489}
490
492 return toUnsigned(findRecursively(DW_AT_decl_line), 0);
493}
494
495std::string
497 if (auto FormValue = findRecursively(DW_AT_decl_file))
498 if (auto OptString = FormValue->getAsFile(Kind))
499 return *OptString;
500 return {};
501}
502
504 uint32_t &CallColumn,
505 uint32_t &CallDiscriminator) const {
506 CallFile = toUnsigned(find(DW_AT_call_file), 0);
507 CallLine = toUnsigned(find(DW_AT_call_line), 0);
508 CallColumn = toUnsigned(find(DW_AT_call_column), 0);
509 CallDiscriminator = toUnsigned(find(DW_AT_GNU_discriminator), 0);
510}
511
512static std::optional<uint64_t>
515 // Cycle detected?
516 if (!Visited.insert(Die.getDebugInfoEntry()).second)
517 return {};
518 if (auto SizeAttr = Die.find(DW_AT_byte_size))
519 if (std::optional<uint64_t> Size = SizeAttr->getAsUnsignedConstant())
520 return Size;
521
522 switch (Die.getTag()) {
523 case DW_TAG_pointer_type:
524 case DW_TAG_reference_type:
525 case DW_TAG_rvalue_reference_type:
526 return PointerSize;
527 case DW_TAG_ptr_to_member_type: {
529 if (BaseType.getTag() == DW_TAG_subroutine_type)
530 return 2 * PointerSize;
531 return PointerSize;
532 }
533 case DW_TAG_const_type:
534 case DW_TAG_immutable_type:
535 case DW_TAG_volatile_type:
536 case DW_TAG_restrict_type:
537 case DW_TAG_template_alias:
538 case DW_TAG_typedef: {
540 return getTypeSizeImpl(BaseType, PointerSize, Visited);
541 break;
542 }
543 case DW_TAG_array_type: {
545 if (!BaseType)
546 return std::nullopt;
547 std::optional<uint64_t> BaseSize =
548 getTypeSizeImpl(BaseType, PointerSize, Visited);
549 if (!BaseSize)
550 return std::nullopt;
551 uint64_t Size = *BaseSize;
552 for (DWARFDie Child : Die) {
553 if (Child.getTag() != DW_TAG_subrange_type)
554 continue;
555
556 if (auto ElemCountAttr = Child.find(DW_AT_count))
557 if (std::optional<uint64_t> ElemCount =
558 ElemCountAttr->getAsUnsignedConstant())
559 Size *= *ElemCount;
560 if (auto UpperBoundAttr = Child.find(DW_AT_upper_bound))
561 if (std::optional<int64_t> UpperBound =
562 UpperBoundAttr->getAsSignedConstant()) {
563 int64_t LowerBound = 0;
564 if (auto LowerBoundAttr = Child.find(DW_AT_lower_bound))
565 LowerBound = LowerBoundAttr->getAsSignedConstant().value_or(0);
566 Size *= *UpperBound - LowerBound + 1;
567 }
568 }
569 return Size;
570 }
571 default:
573 return getTypeSizeImpl(BaseType, PointerSize, Visited);
574 break;
575 }
576 return std::nullopt;
577}
578
579std::optional<uint64_t> DWARFDie::getTypeSize(uint64_t PointerSize) {
581 return getTypeSizeImpl(*this, PointerSize, Visited);
582}
583
584/// Helper to dump a DIE with all of its parents, but no siblings.
585static unsigned dumpParentChain(DWARFDie Die, raw_ostream &OS, unsigned Indent,
586 DIDumpOptions DumpOpts, unsigned Depth = 0) {
587 if (!Die)
588 return Indent;
589 if (DumpOpts.ParentRecurseDepth > 0 && Depth >= DumpOpts.ParentRecurseDepth)
590 return Indent;
591 Indent = dumpParentChain(Die.getParent(), OS, Indent, DumpOpts, Depth + 1);
592 Die.dump(OS, Indent, DumpOpts);
593 return Indent + 2;
594}
595
596void DWARFDie::dump(raw_ostream &OS, unsigned Indent,
597 DIDumpOptions DumpOpts) const {
598 if (!isValid())
599 return;
600 DWARFDataExtractor debug_info_data = U->getDebugInfoExtractor();
601 const uint64_t Offset = getOffset();
602 uint64_t offset = Offset;
603 if (DumpOpts.ShowParents) {
604 DIDumpOptions ParentDumpOpts = DumpOpts;
605 ParentDumpOpts.ShowParents = false;
606 ParentDumpOpts.ShowChildren = false;
607 Indent = dumpParentChain(getParent(), OS, Indent, ParentDumpOpts);
608 }
609
610 if (debug_info_data.isValidOffset(offset)) {
611 uint32_t abbrCode = debug_info_data.getULEB128(&offset);
612 if (DumpOpts.ShowAddresses)
614 << format("\n0x%8.8" PRIx64 ": ", Offset);
615
616 if (abbrCode) {
617 auto AbbrevDecl = getAbbreviationDeclarationPtr();
618 if (AbbrevDecl) {
620 << formatv("{0}", getTag());
621 if (DumpOpts.Verbose) {
622 OS << format(" [%u] %c", abbrCode,
623 AbbrevDecl->hasChildren() ? '*' : ' ');
624 if (std::optional<uint32_t> ParentIdx = Die->getParentIdx())
625 OS << format(" (0x%8.8" PRIx64 ")",
626 U->getDIEAtIndex(*ParentIdx).getOffset());
627 }
628 OS << '\n';
629
630 // Dump all data in the DIE for the attributes.
631 for (const DWARFAttribute &AttrValue : attributes())
632 dumpAttribute(OS, *this, AttrValue, Indent, DumpOpts);
633
634 if (DumpOpts.ShowChildren && DumpOpts.ChildRecurseDepth > 0) {
635 DWARFDie Child = getFirstChild();
636 DumpOpts.ChildRecurseDepth--;
637 DIDumpOptions ChildDumpOpts = DumpOpts;
638 ChildDumpOpts.ShowParents = false;
639 while (Child) {
640 Child.dump(OS, Indent + 2, ChildDumpOpts);
641 Child = Child.getSibling();
642 }
643 }
644 } else {
645 OS << "Abbreviation code not found in 'debug_abbrev' class for code: "
646 << abbrCode << '\n';
647 }
648 } else {
649 OS.indent(Indent) << "NULL\n";
650 }
651 }
652}
653
655
657 if (isValid())
658 return U->getParent(Die);
659 return DWARFDie();
660}
661
663 if (isValid())
664 return U->getSibling(Die);
665 return DWARFDie();
666}
667
669 if (isValid())
670 return U->getPreviousSibling(Die);
671 return DWARFDie();
672}
673
675 if (isValid())
676 return U->getFirstChild(Die);
677 return DWARFDie();
678}
679
681 if (isValid())
682 return U->getLastChild(Die);
683 return DWARFDie();
684}
685
690
692 : Die(D), Index(0) {
693 auto AbbrDecl = Die.getAbbreviationDeclarationPtr();
694 assert(AbbrDecl && "Must have abbreviation declaration");
695 if (End) {
696 // This is the end iterator so we set the index to the attribute count.
697 Index = AbbrDecl->getNumAttributes();
698 } else {
699 // This is the begin iterator so we extract the value for this->Index.
700 AttrValue.Offset = D.getOffset() + AbbrDecl->getCodeByteSize();
701 updateForIndex(*AbbrDecl, 0);
702 }
703}
704
705void DWARFDie::attribute_iterator::updateForIndex(
706 const DWARFAbbreviationDeclaration &AbbrDecl, uint32_t I) {
707 Index = I;
708 // AbbrDecl must be valid before calling this function.
709 auto NumAttrs = AbbrDecl.getNumAttributes();
710 if (Index < NumAttrs) {
711 AttrValue.Attr = AbbrDecl.getAttrByIndex(Index);
712 // Add the previous byte size of any previous attribute value.
713 AttrValue.Offset += AttrValue.ByteSize;
714 uint64_t ParseOffset = AttrValue.Offset;
716 AttrValue.Value = DWARFFormValue::createFromSValue(
717 AbbrDecl.getFormByIndex(Index),
719 else {
720 auto U = Die.getDwarfUnit();
721 assert(U && "Die must have valid DWARF unit");
722 AttrValue.Value = DWARFFormValue::createFromUnit(
723 AbbrDecl.getFormByIndex(Index), U, &ParseOffset);
724 }
725 AttrValue.ByteSize = ParseOffset - AttrValue.Offset;
726 } else {
727 assert(Index == NumAttrs && "Indexes should be [0, NumAttrs) only");
728 AttrValue = {};
729 }
730}
731
733 if (auto AbbrDecl = Die.getAbbreviationDeclarationPtr())
734 updateForIndex(*AbbrDecl, Index + 1);
735 return *this;
736}
737
739 switch(Attr) {
740 case DW_AT_location:
741 case DW_AT_string_length:
742 case DW_AT_return_addr:
743 case DW_AT_data_member_location:
744 case DW_AT_frame_base:
745 case DW_AT_static_link:
746 case DW_AT_segment:
747 case DW_AT_use_location:
748 case DW_AT_vtable_elem_location:
749 return true;
750 default:
751 return false;
752 }
753}
754
756 switch (Attr) {
757 // From the DWARF v5 specification.
758 case DW_AT_location:
759 case DW_AT_byte_size:
760 case DW_AT_bit_offset:
761 case DW_AT_bit_size:
762 case DW_AT_string_length:
763 case DW_AT_lower_bound:
764 case DW_AT_return_addr:
765 case DW_AT_bit_stride:
766 case DW_AT_upper_bound:
767 case DW_AT_count:
768 case DW_AT_data_member_location:
769 case DW_AT_frame_base:
770 case DW_AT_segment:
771 case DW_AT_static_link:
772 case DW_AT_use_location:
773 case DW_AT_vtable_elem_location:
774 case DW_AT_allocated:
775 case DW_AT_associated:
776 case DW_AT_data_location:
777 case DW_AT_byte_stride:
778 case DW_AT_rank:
779 case DW_AT_call_value:
780 case DW_AT_call_origin:
781 case DW_AT_call_target:
782 case DW_AT_call_target_clobbered:
783 case DW_AT_call_data_location:
784 case DW_AT_call_data_value:
785 // Extensions.
786 case DW_AT_GNU_call_site_value:
787 case DW_AT_GNU_call_site_target:
788 return true;
789 default:
790 return false;
791 }
792}
793
794namespace llvm {
795
799
801 std::string *OriginalFullName) {
803}
804
805} // namespace llvm
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition Compiler.h:638
static void dumpAttribute(raw_ostream &OS, const DWARFDie &Die, const DWARFAttribute &AttrValue, unsigned Indent, DIDumpOptions DumpOpts)
Definition DWARFDie.cpp:110
static void dumpLocationExpr(raw_ostream &OS, const DWARFFormValue &FormValue, DWARFUnit *U, unsigned Indent, DIDumpOptions DumpOpts)
Definition DWARFDie.cpp:92
static unsigned dumpParentChain(DWARFDie Die, raw_ostream &OS, unsigned Indent, DIDumpOptions DumpOpts, unsigned Depth=0)
Helper to dump a DIE with all of its parents, but no siblings.
Definition DWARFDie.cpp:585
static DWARFDie resolveReferencedType(DWARFDie D, DWARFFormValue F)
Definition DWARFDie.cpp:106
static void dumpLocationList(raw_ostream &OS, const DWARFFormValue &FormValue, DWARFUnit *U, unsigned Indent, DIDumpOptions DumpOpts)
Definition DWARFDie.cpp:72
static std::optional< uint64_t > getTypeSizeImpl(DWARFDie Die, uint64_t PointerSize, SmallPtrSetImpl< const DWARFDebugInfoEntry * > &Visited)
Definition DWARFDie.cpp:513
static void dumpApplePropertyAttribute(raw_ostream &OS, uint64_t Val)
Definition DWARFDie.cpp:40
static void dumpRanges(const DWARFObject &Obj, raw_ostream &OS, const DWARFAddressRangesVector &Ranges, unsigned AddressSize, unsigned Indent, const DIDumpOptions &DumpOpts)
Definition DWARFDie.cpp:58
This file contains constants used for implementing Dwarf debug support.
#define F(x, y, z)
Definition MD5.cpp:55
#define I(x, y, z)
Definition MD5.cpp:58
BaseType
A given derived pointer can have multiple base pointers through phi/selects.
This file defines the SmallPtrSet class.
This file defines the SmallSet class.
static Split data
LocallyHashedType DenseMapInfo< LocallyHashedType >::Tombstone
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:41
size_t size() const
size - Get the array size.
Definition ArrayRef.h:147
const T * data() const
Definition ArrayRef.h:144
A structured debug information entry.
Definition DIE.h:828
dwarf::Attribute getAttrByIndex(uint32_t idx) const
int64_t getAttrImplicitConstValueByIndex(uint32_t idx) const
dwarf::Form getFormByIndex(uint32_t idx) const
DWARFContext This data structure is the top level entity that deals with dwarf debug information pars...
DWARFTypeUnit * getTypeUnitForHash(uint64_t Hash, bool IsDWO)
const DWARFObject & getDWARFObj() const
A DWARFDataExtractor (typically for an in-memory copy of an object-file section) plus a relocation ma...
LLVM_ABI attribute_iterator & operator++()
Definition DWARFDie.cpp:732
Utility class that carries the DWARF compile/type unit and the debug info entry in an object.
Definition DWARFDie.h:43
LLVM_ABI void getFullName(raw_string_ostream &, std::string *OriginalFullName=nullptr) const
Definition DWARFDie.cpp:234
LLVM_ABI DWARFDie resolveTypeUnitReference() const
Definition DWARFDie.cpp:330
LLVM_ABI std::optional< uint64_t > getLocBaseAttribute() const
Definition DWARFDie.cpp:352
uint64_t getOffset() const
Get the absolute offset into the debug info or types section.
Definition DWARFDie.h:68
LLVM_ABI const char * getShortName() const
Return the DIE short name resolving DW_AT_specification or DW_AT_abstract_origin references if necess...
Definition DWARFDie.cpp:475
LLVM_ABI Expected< DWARFAddressRangesVector > getAddressRanges() const
Get the address ranges for this DIE.
Definition DWARFDie.cpp:388
LLVM_ABI DWARFDie getAttributeValueAsReferencedDie(dwarf::Attribute Attr) const
Extract the specified attribute from this DIE as the referenced DIE.
Definition DWARFDie.cpp:307
LLVM_ABI DWARFDie getParent() const
Get the parent of this DIE object.
Definition DWARFDie.cpp:656
LLVM_ABI std::optional< DWARFFormValue > find(dwarf::Attribute Attr) const
Extract the specified attribute from this DIE.
Definition DWARFDie.cpp:251
DWARFUnit * getDwarfUnit() const
Definition DWARFDie.h:55
const DWARFDebugInfoEntry * getDebugInfoEntry() const
Definition DWARFDie.h:54
LLVM_ABI const char * getSubroutineName(DINameKind Kind) const
If a DIE represents a subprogram (or inlined subroutine), returns its mangled name (or short name,...
Definition DWARFDie.cpp:458
LLVM_ABI DWARFDie getSibling() const
Get the sibling of this DIE object.
Definition DWARFDie.cpp:662
LLVM_ABI bool isSubroutineDIE() const
Returns true if DIE represents a subprogram or an inlined subroutine.
Definition DWARFDie.cpp:246
LLVM_ABI bool getLowAndHighPC(uint64_t &LowPC, uint64_t &HighPC, uint64_t &SectionIndex) const
Retrieves DW_AT_low_pc and DW_AT_high_pc from CU.
Definition DWARFDie.cpp:373
LLVM_ABI LLVM_DUMP_METHOD void dump() const
Convenience zero-argument overload for debugging.
Definition DWARFDie.cpp:654
LLVM_ABI void getCallerFrame(uint32_t &CallFile, uint32_t &CallLine, uint32_t &CallColumn, uint32_t &CallDiscriminator) const
Retrieves values of DW_AT_call_file, DW_AT_call_line and DW_AT_call_column from DIE (or zeroes if the...
Definition DWARFDie.cpp:503
LLVM_ABI bool isSubprogramDIE() const
Returns true if DIE represents a subprogram (not inlined).
Definition DWARFDie.cpp:244
LLVM_ABI bool addressRangeContainsAddress(const uint64_t Address) const
Definition DWARFDie.cpp:405
LLVM_ABI std::optional< DWARFFormValue > findRecursively(ArrayRef< dwarf::Attribute > Attrs) const
Extract the first value of any attribute in Attrs from this DIE and recurse into any DW_AT_specificat...
Definition DWARFDie.cpp:275
llvm::DWARFFormValue DWARFFormValue
Definition DWARFDie.h:48
LLVM_ABI std::optional< uint64_t > getHighPC(uint64_t LowPC) const
Get the DW_AT_high_pc attribute value as an address.
Definition DWARFDie.cpp:356
LLVM_ABI std::optional< uint64_t > getTypeSize(uint64_t PointerSize)
Gets the type size (in bytes) for this DIE.
Definition DWARFDie.cpp:579
LLVM_ABI DWARFDie resolveReferencedType(dwarf::Attribute Attr) const
Definition DWARFDie.cpp:341
LLVM_ABI const char * getName(DINameKind Kind) const
Return the DIE name resolving DW_AT_specification or DW_AT_abstract_origin references if necessary.
Definition DWARFDie.cpp:464
LLVM_ABI DWARFDie getLastChild() const
Get the last child of this DIE object.
Definition DWARFDie.cpp:680
LLVM_ABI DWARFDie getPreviousSibling() const
Get the previous sibling of this DIE object.
Definition DWARFDie.cpp:668
const DWARFAbbreviationDeclaration * getAbbreviationDeclarationPtr() const
Get the abbreviation declaration for this DIE.
Definition DWARFDie.h:60
DWARFDie()=default
LLVM_ABI std::string getDeclFile(DILineInfoSpecifier::FileLineInfoKind Kind) const
Definition DWARFDie.cpp:496
LLVM_ABI DWARFDie getFirstChild() const
Get the first child of this DIE object.
Definition DWARFDie.cpp:674
LLVM_ABI uint64_t getDeclLine() const
Returns the declaration line (start line) for a DIE, assuming it specifies a subprogram.
Definition DWARFDie.cpp:491
dwarf::Tag getTag() const
Definition DWARFDie.h:73
LLVM_ABI const char * getLinkageName() const
Return the DIE linkage name resolving DW_AT_specification or DW_AT_abstract_origin references if nece...
Definition DWARFDie.cpp:482
LLVM_ABI Expected< DWARFLocationExpressionsVector > getLocations(dwarf::Attribute Attr) const
Definition DWARFDie.cpp:428
LLVM_ABI std::optional< uint64_t > getRangesBaseAttribute() const
Extract the range base attribute from this DIE as absolute section offset.
Definition DWARFDie.cpp:348
bool isNULL() const
Returns true for a valid DIE that terminates a sibling chain.
Definition DWARFDie.h:86
LLVM_ABI std::optional< uint64_t > getLanguage() const
Definition DWARFDie.cpp:418
bool isValid() const
Definition DWARFDie.h:52
LLVM_ABI iterator_range< attribute_iterator > attributes() const
Get an iterator range to all attributes in the current DIE only.
Definition DWARFDie.cpp:686
LLVM_ABI void dump(raw_ostream &OS, unsigned indent=0, DIDumpOptions DumpOpts=DIDumpOptions()) const
Dump the DIE and all of its attributes to the supplied stream.
Definition DWARFDie.cpp:596
static LLVM_ABI DWARFFormValue createFromUValue(dwarf::Form F, uint64_t V)
LLVM_ABI std::optional< ArrayRef< uint8_t > > getAsBlock() const
LLVM_ABI std::optional< uint64_t > getAsSectionOffset() const
LLVM_ABI bool isFormClass(FormClass FC) const
LLVM_ABI void dumpAddress(raw_ostream &OS, uint64_t Address) const
LLVM_ABI std::optional< uint64_t > getAsAddress() const
LLVM_ABI void dump(raw_ostream &OS, DIDumpOptions DumpOpts=DIDumpOptions()) const
static LLVM_ABI DWARFFormValue createFromSValue(dwarf::Form F, int64_t V)
LLVM_ABI std::optional< uint64_t > getAsUnsignedConstant() const
static LLVM_ABI DWARFFormValue createFromUnit(dwarf::Form F, const DWARFUnit *Unit, uint64_t *OffsetPtr)
dwarf::Form getForm() const
LLVM_ABI DWARFUnit * getUnitForOffset(uint64_t Offset) const
DWARFContext & getContext() const
Definition DWARFUnit.h:323
DWARFDie getDIEForOffset(uint64_t Offset)
Return the DIE object for a given offset Offset inside the unit's DIE vector.
Definition DWARFUnit.h:537
const DWARFUnitVector & getUnitVector() const
Return the DWARFUnitVector containing this unit.
Definition DWARFUnit.h:505
LLVM_ABI uint64_t getULEB128(uint64_t *offset_ptr, llvm::Error *Err=nullptr) const
Extract a unsigned LEB128 value from *offset_ptr.
bool isValidOffset(uint64_t offset) const
Test the validity of offset.
Tagged union holding either a T or a Error.
Definition Error.h:485
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
Definition SmallSet.h:133
std::pair< const_iterator, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
Definition SmallSet.h:183
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
LLVM Value Representation.
Definition Value.h:75
An RAII object that temporarily switches an output stream to a specific color.
Definition WithColor.h:54
raw_ostream & get()
Definition WithColor.h:79
A range adaptor for a pair of iterators.
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
raw_ostream & indent(unsigned NumSpaces)
indent - Insert 'NumSpaces' spaces.
A raw_ostream that writes to an std::string.
LLVM_ABI StringRef AttributeString(unsigned Attribute)
Definition Dwarf.cpp:72
LLVM_ABI StringRef FormEncodingString(unsigned Encoding)
Definition Dwarf.cpp:105
LLVM_ABI StringRef ApplePropertyString(unsigned)
Definition Dwarf.cpp:792
Calculates the starting offsets for various sections within the .debug_names section.
Definition Dwarf.h:35
Attribute
Attributes.
Definition Dwarf.h:125
std::optional< const char * > toString(const std::optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract a string value from it.
std::optional< object::SectionedAddress > toSectionedAddress(const std::optional< DWARFFormValue > &V)
std::optional< uint64_t > toSectionOffset(const std::optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract an section offset.
LLVM_ABI StringRef AttributeValueString(uint16_t Attr, unsigned Val)
Returns the symbolic string representing Val when used as a value for attribute Attr.
Definition Dwarf.cpp:866
uint64_t computeTombstoneAddress(uint8_t AddressByteSize)
Definition Dwarf.h:1239
std::optional< uint64_t > toUnsigned(const std::optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract an unsigned constant.
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:477
LLVM_ABI std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Definition Error.cpp:98
LLVM_ABI void printDwarfExpression(const DWARFExpression *E, raw_ostream &OS, DIDumpOptions DumpOpts, DWARFUnit *U, bool IsEH=false)
Print a Dwarf expression/.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Definition Error.h:1305
int countr_zero(T Val)
Count number of 0's from the least significant bit to the most stopping at the first 1.
Definition bit.h:186
@ invalid_argument
Definition Errc.h:56
auto formatv(bool Validate, const char *Fmt, Ts &&...Vals)
SmallVector< ValueTypeFromRangeType< R >, Size > to_vector(R &&Range)
Given a range of type R, iterate the entire range and return a SmallVector with elements of the vecto...
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
Definition Format.h:118
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
LLVM_ABI void dumpTypeQualifiedName(const DWARFDie &DIE, raw_ostream &OS)
Definition DWARFDie.cpp:796
FunctionAddr VTableAddr uintptr_t uintptr_t Data
Definition InstrProf.h:189
DINameKind
A DINameKind is passed to name search methods to specify a preference regarding the type of name reso...
Definition DIContext.h:142
std::string toString(const APInt &I, unsigned Radix, bool Signed, bool formatAsCLiteral=false, bool UpperCase=true, bool InsertSeparators=false)
LLVM_ABI void dumpTypeUnqualifiedName(const DWARFDie &DIE, raw_ostream &OS, std::string *OriginalFullName=nullptr)
Definition DWARFDie.cpp:800
void consumeError(Error Err)
Consume a Error without doing anything.
Definition Error.h:1083
std::vector< DWARFAddressRange > DWARFAddressRangesVector
DWARFAddressRangesVector - represents a set of absolute address ranges.
std::vector< DWARFLocationExpression > DWARFLocationExpressionsVector
Represents a set of absolute location expressions.
Container for dump options that control which debug information will be dumped.
Definition DIContext.h:196
std::function< void(Error)> RecoverableErrorHandler
Definition DIContext.h:235
unsigned ChildRecurseDepth
Definition DIContext.h:198
unsigned ParentRecurseDepth
Definition DIContext.h:199
Encapsulates a DWARF attribute value and all of the data required to describe the attribute value.
static LLVM_ABI bool mayHaveLocationList(dwarf::Attribute Attr)
Identify DWARF attributes that may contain a pointer to a location list.
Definition DWARFDie.cpp:738
DWARFFormValue Value
The form and value for this attribute.
static LLVM_ABI bool mayHaveLocationExpr(dwarf::Attribute Attr)
Identifies DWARF attributes that may contain a reference to a DWARF expression.
Definition DWARFDie.cpp:755
dwarf::Attribute Attr
The attribute enumeration of this attribute.
Represents a single DWARF expression, whose value is location-dependent.
void appendQualifiedName(DieType D)
void appendUnqualifiedName(DieType D, std::string *OriginalFullName=nullptr)
Recursively append the DIE type name when applicable.