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 
9 #include "llvm/DebugInfo/DWARF/DWARFDie.h"
10 #include "llvm/ADT/None.h"
11 #include "llvm/ADT/Optional.h"
12 #include "llvm/ADT/SmallSet.h"
13 #include "llvm/ADT/StringRef.h"
14 #include "llvm/BinaryFormat/Dwarf.h"
15 #include "llvm/DebugInfo/DWARF/DWARFAbbreviationDeclaration.h"
16 #include "llvm/DebugInfo/DWARF/DWARFContext.h"
17 #include "llvm/DebugInfo/DWARF/DWARFDebugRangeList.h"
18 #include "llvm/DebugInfo/DWARF/DWARFExpression.h"
19 #include "llvm/DebugInfo/DWARF/DWARFFormValue.h"
20 #include "llvm/DebugInfo/DWARF/DWARFUnit.h"
21 #include "llvm/Object/ObjectFile.h"
22 #include "llvm/Support/DataExtractor.h"
23 #include "llvm/Support/Format.h"
24 #include "llvm/Support/FormatAdapters.h"
25 #include "llvm/Support/FormatVariadic.h"
26 #include "llvm/Support/MathExtras.h"
27 #include "llvm/Support/WithColor.h"
28 #include "llvm/Support/raw_ostream.h"
29 #include <algorithm>
30 #include <cassert>
31 #include <cinttypes>
32 #include <cstdint>
33 #include <string>
34 #include <utility>
35 
36 using namespace llvm;
37 using namespace dwarf;
38 using namespace object;
39 
40 static void dumpApplePropertyAttribute(raw_ostream &OS, uint64_t Val) {
41   OS << " (";
42   do {
43     uint64_t Shift = countTrailingZeros(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 
58 static 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 
72 static void dumpLocationList(raw_ostream &OS, const DWARFFormValue &FormValue,
73                              DWARFUnit *U, unsigned Indent,
74                              DIDumpOptions DumpOpts) {
75   assert(FormValue.isFormClass(DWARFFormValue::FC_SectionOffset) &&
76          "bad FORM for location list");
77   DWARFContext &Ctx = U->getContext();
78   const MCRegisterInfo *MRI = Ctx.getRegisterInfo();
79   uint64_t Offset = *FormValue.getAsSectionOffset();
80 
81   if (FormValue.getForm() == DW_FORM_loclistx) {
82     FormValue.dump(OS, DumpOpts);
83 
84     if (auto LoclistOffset = U->getLoclistOffset(Offset))
85       Offset = *LoclistOffset;
86     else
87       return;
88   }
89   U->getLocationTable().dumpLocationList(&Offset, OS, U->getBaseAddress(), MRI,
90                                          Ctx.getDWARFObj(), U, DumpOpts,
91                                          Indent);
92 }
93 
94 static void dumpLocationExpr(raw_ostream &OS, const DWARFFormValue &FormValue,
95                              DWARFUnit *U, unsigned Indent,
96                              DIDumpOptions DumpOpts) {
97   assert((FormValue.isFormClass(DWARFFormValue::FC_Block) ||
98           FormValue.isFormClass(DWARFFormValue::FC_Exprloc)) &&
99          "bad FORM for location expression");
100   DWARFContext &Ctx = U->getContext();
101   const MCRegisterInfo *MRI = Ctx.getRegisterInfo();
102   ArrayRef<uint8_t> Expr = *FormValue.getAsBlock();
103   DataExtractor Data(StringRef((const char *)Expr.data(), Expr.size()),
104                      Ctx.isLittleEndian(), 0);
105   DWARFExpression(Data, U->getAddressByteSize(), U->getFormParams().Format)
106       .print(OS, DumpOpts, MRI, U);
107 }
108 
109 static DWARFDie resolveReferencedType(DWARFDie D,
110                                       dwarf::Attribute Attr = DW_AT_type) {
111   return D.getAttributeValueAsReferencedDie(Attr).resolveTypeUnitReference();
112 }
113 static DWARFDie resolveReferencedType(DWARFDie D, DWARFFormValue F) {
114   return D.getAttributeValueAsReferencedDie(F).resolveTypeUnitReference();
115 }
116 
117 namespace {
118 
119 // FIXME: We should have pretty printers per language. Currently we print
120 // everything as if it was C++ and fall back to the TAG type name.
121 struct DWARFTypePrinter {
122   raw_ostream &OS;
123   bool Word = true;
124   bool EndedWithTemplate = false;
125 
126   DWARFTypePrinter(raw_ostream &OS) : OS(OS) {}
127 
128   /// Dump the name encoded in the type tag.
129   void appendTypeTagName(dwarf::Tag T) {
130     StringRef TagStr = TagString(T);
131     static constexpr StringRef Prefix = "DW_TAG_";
132     static constexpr StringRef Suffix = "_type";
133     if (!TagStr.startswith(Prefix) || !TagStr.endswith(Suffix))
134       return;
135     OS << TagStr.substr(Prefix.size(),
136                         TagStr.size() - (Prefix.size() + Suffix.size()))
137        << " ";
138   }
139 
140   void appendArrayType(const DWARFDie &D) {
141     for (const DWARFDie &C : D.children()) {
142       if (C.getTag() != DW_TAG_subrange_type)
143         continue;
144       Optional<uint64_t> LB;
145       Optional<uint64_t> Count;
146       Optional<uint64_t> UB;
147       Optional<unsigned> DefaultLB;
148       if (Optional<DWARFFormValue> L = C.find(DW_AT_lower_bound))
149         LB = L->getAsUnsignedConstant();
150       if (Optional<DWARFFormValue> CountV = C.find(DW_AT_count))
151         Count = CountV->getAsUnsignedConstant();
152       if (Optional<DWARFFormValue> UpperV = C.find(DW_AT_upper_bound))
153         UB = UpperV->getAsUnsignedConstant();
154       if (Optional<DWARFFormValue> LV =
155               D.getDwarfUnit()->getUnitDIE().find(DW_AT_language))
156         if (Optional<uint64_t> LC = LV->getAsUnsignedConstant())
157           if ((DefaultLB =
158                    LanguageLowerBound(static_cast<dwarf::SourceLanguage>(*LC))))
159             if (LB && *LB == *DefaultLB)
160               LB = None;
161       if (!LB && !Count && !UB)
162         OS << "[]";
163       else if (!LB && (Count || UB) && DefaultLB)
164         OS << '[' << (Count ? *Count : *UB - *DefaultLB + 1) << ']';
165       else {
166         OS << "[[";
167         if (LB)
168           OS << *LB;
169         else
170           OS << '?';
171         OS << ", ";
172         if (Count)
173           if (LB)
174             OS << *LB + *Count;
175           else
176             OS << "? + " << *Count;
177         else if (UB)
178           OS << *UB + 1;
179         else
180           OS << '?';
181         OS << ")]";
182       }
183     }
184     EndedWithTemplate = false;
185   }
186 
187   DWARFDie skipQualifiers(DWARFDie D) {
188     while (D && (D.getTag() == DW_TAG_const_type ||
189                  D.getTag() == DW_TAG_volatile_type))
190       D = resolveReferencedType(D);
191     return D;
192   }
193 
194   bool needsParens(DWARFDie D) {
195     D = skipQualifiers(D);
196     return D && (D.getTag() == DW_TAG_subroutine_type || D.getTag() == DW_TAG_array_type);
197   }
198 
199   void appendPointerLikeTypeBefore(DWARFDie D, DWARFDie Inner, StringRef Ptr) {
200     appendQualifiedNameBefore(Inner);
201     if (Word)
202       OS << ' ';
203     if (needsParens(Inner))
204       OS << '(';
205     OS << Ptr;
206     Word = false;
207     EndedWithTemplate = false;
208   }
209 
210   DWARFDie
211   appendUnqualifiedNameBefore(DWARFDie D,
212                               std::string *OriginalFullName = nullptr) {
213     Word = true;
214     if (!D) {
215       OS << "void";
216       return DWARFDie();
217     }
218     DWARFDie InnerDIE;
219     auto Inner = [&] { return InnerDIE = resolveReferencedType(D); };
220     const dwarf::Tag T = D.getTag();
221     switch (T) {
222     case DW_TAG_pointer_type: {
223       appendPointerLikeTypeBefore(D, Inner(), "*");
224       break;
225     }
226     case DW_TAG_subroutine_type: {
227       appendQualifiedNameBefore(Inner());
228       if (Word) {
229         OS << ' ';
230       }
231       Word = false;
232       break;
233     }
234     case DW_TAG_array_type: {
235       appendQualifiedNameBefore(Inner());
236       break;
237     }
238     case DW_TAG_reference_type:
239       appendPointerLikeTypeBefore(D, Inner(), "&");
240       break;
241     case DW_TAG_rvalue_reference_type:
242       appendPointerLikeTypeBefore(D, Inner(), "&&");
243       break;
244     case DW_TAG_ptr_to_member_type: {
245       appendQualifiedNameBefore(Inner());
246       if (needsParens(InnerDIE))
247         OS << '(';
248       else if (Word)
249         OS << ' ';
250       if (DWARFDie Cont = resolveReferencedType(D, DW_AT_containing_type)) {
251         appendQualifiedName(Cont);
252         OS << "::";
253       }
254       OS << "*";
255       Word = false;
256       break;
257     }
258     case DW_TAG_const_type:
259     case DW_TAG_volatile_type:
260       appendConstVolatileQualifierBefore(D);
261       break;
262     case DW_TAG_namespace: {
263       if (const char *Name = dwarf::toString(D.find(DW_AT_name), nullptr))
264         OS << Name;
265       else
266         OS << "(anonymous namespace)";
267       break;
268     }
269     case DW_TAG_unspecified_type: {
270       StringRef TypeName = D.getShortName();
271       if (TypeName == "decltype(nullptr)")
272         TypeName = "std::nullptr_t";
273       Word = true;
274       OS << TypeName;
275       EndedWithTemplate = false;
276       break;
277     }
278       /*
279     case DW_TAG_structure_type:
280     case DW_TAG_class_type:
281     case DW_TAG_enumeration_type:
282     case DW_TAG_base_type:
283     */
284     default: {
285       const char *NamePtr = dwarf::toString(D.find(DW_AT_name), nullptr);
286       if (!NamePtr) {
287         appendTypeTagName(D.getTag());
288         return DWARFDie();
289       }
290       Word = true;
291       StringRef Name = NamePtr;
292       static constexpr StringRef MangledPrefix = "_STN";
293       if (Name.startswith(MangledPrefix)) {
294         Name = Name.drop_front(MangledPrefix.size());
295         auto Separator = Name.find('|');
296         assert(Separator != StringRef::npos);
297         StringRef BaseName = Name.substr(0, Separator);
298         StringRef TemplateArgs = Name.substr(Separator + 1);
299         if (OriginalFullName)
300           *OriginalFullName = (BaseName + TemplateArgs).str();
301         Name = BaseName;
302       } else
303         EndedWithTemplate = Name.endswith(">");
304       OS << Name;
305       // This check would be insufficient for operator overloads like
306       // "operator>>" - but for now Clang doesn't try to simplify them, so this
307       // is OK. Add more nuanced operator overload handling here if/when needed.
308       if (Name.endswith(">"))
309         break;
310       if (!appendTemplateParameters(D))
311         break;
312 
313       if (EndedWithTemplate)
314         OS << ' ';
315       OS << '>';
316       EndedWithTemplate = true;
317       Word = true;
318       break;
319     }
320     }
321     return InnerDIE;
322   }
323 
324   void appendUnqualifiedNameAfter(DWARFDie D, DWARFDie Inner,
325                                   bool SkipFirstParamIfArtificial = false) {
326     if (!D)
327       return;
328     switch (D.getTag()) {
329     case DW_TAG_subroutine_type: {
330       appendSubroutineNameAfter(D, Inner, SkipFirstParamIfArtificial, false,
331                                 false);
332       break;
333     }
334     case DW_TAG_array_type: {
335       appendArrayType(D);
336       break;
337     }
338     case DW_TAG_const_type:
339     case DW_TAG_volatile_type:
340       appendConstVolatileQualifierAfter(D);
341       break;
342     case DW_TAG_ptr_to_member_type:
343     case DW_TAG_reference_type:
344     case DW_TAG_rvalue_reference_type:
345     case DW_TAG_pointer_type: {
346       if (needsParens(Inner))
347         OS << ')';
348       appendUnqualifiedNameAfter(Inner, resolveReferencedType(Inner),
349                                  /*SkipFirstParamIfArtificial=*/D.getTag() ==
350                                      DW_TAG_ptr_to_member_type);
351       break;
352     }
353       /*
354     case DW_TAG_structure_type:
355     case DW_TAG_class_type:
356     case DW_TAG_enumeration_type:
357     case DW_TAG_base_type:
358     case DW_TAG_namespace:
359     */
360     default:
361       break;
362     }
363   }
364 
365   void appendQualifiedName(DWARFDie D) {
366     if (D)
367       appendScopes(D.getParent());
368     appendUnqualifiedName(D);
369   }
370   DWARFDie appendQualifiedNameBefore(DWARFDie D) {
371     if (D)
372       appendScopes(D.getParent());
373     return appendUnqualifiedNameBefore(D);
374   }
375   bool appendTemplateParameters(DWARFDie D, bool *FirstParameter = nullptr) {
376     bool FirstParameterValue = true;
377     bool IsTemplate = false;
378     if (!FirstParameter)
379       FirstParameter = &FirstParameterValue;
380     for (const DWARFDie &C : D) {
381       auto Sep = [&] {
382         if (*FirstParameter)
383           OS << '<';
384         else
385           OS << ", ";
386         IsTemplate = true;
387         EndedWithTemplate = false;
388         *FirstParameter = false;
389       };
390       if (C.getTag() == dwarf::DW_TAG_GNU_template_parameter_pack) {
391         IsTemplate = true;
392         appendTemplateParameters(C, FirstParameter);
393       }
394       if (C.getTag() == dwarf::DW_TAG_template_value_parameter) {
395         DWARFDie T = resolveReferencedType(C);
396         Sep();
397         if (T.getTag() == DW_TAG_enumeration_type) {
398           auto V = C.find(DW_AT_const_value);
399           bool FoundEnumerator = false;
400           for (const DWARFDie &Enumerator : T) {
401             auto EV = Enumerator.find(DW_AT_const_value);
402             if (V && EV &&
403                 V->getAsSignedConstant() == EV->getAsSignedConstant()) {
404               if (T.find(DW_AT_enum_class)) {
405                 appendQualifiedName(T);
406                 OS << "::";
407               } else
408                 appendScopes(T.getParent());
409               OS << Enumerator.getShortName();
410               FoundEnumerator = true;
411               break;
412             }
413           }
414           if (FoundEnumerator)
415             continue;
416           OS << '(';
417           appendQualifiedName(T);
418           OS << ')';
419           OS << to_string(*V->getAsSignedConstant());
420           continue;
421         }
422         // /Maybe/ we could do pointer type parameters, looking for the
423         // symbol in the ELF symbol table to get back to the variable...
424         // but probably not worth it.
425         if (T.getTag() == DW_TAG_pointer_type)
426           continue;
427         const char *RawName = dwarf::toString(T.find(DW_AT_name), nullptr);
428         assert(RawName);
429         StringRef Name = RawName;
430         auto V = C.find(DW_AT_const_value);
431         bool IsQualifiedChar = false;
432         if (Name == "bool") {
433           OS << (*V->getAsUnsignedConstant() ? "true" : "false");
434         } else if (Name == "short") {
435           OS << "(short)";
436           OS << to_string(*V->getAsSignedConstant());
437         } else if (Name == "unsigned short") {
438           OS << "(unsigned short)";
439           OS << to_string(*V->getAsSignedConstant());
440         } else if (Name == "int")
441           OS << to_string(*V->getAsSignedConstant());
442         else if (Name == "long") {
443           OS << to_string(*V->getAsSignedConstant());
444           OS << "L";
445         } else if (Name == "long long") {
446           OS << to_string(*V->getAsSignedConstant());
447           OS << "LL";
448         } else if (Name == "unsigned int") {
449           OS << to_string(*V->getAsUnsignedConstant());
450           OS << "U";
451         } else if (Name == "unsigned long") {
452           OS << to_string(*V->getAsUnsignedConstant());
453           OS << "UL";
454         } else if (Name == "unsigned long long") {
455           OS << to_string(*V->getAsUnsignedConstant());
456           OS << "ULL";
457         } else if (Name == "char" ||
458                    (IsQualifiedChar =
459                         (Name == "unsigned char" || Name == "signed char"))) {
460           // FIXME: check T's DW_AT_type to see if it's signed or not (since
461           // char signedness is implementation defined).
462           auto Val = *V->getAsSignedConstant();
463           // Copied/hacked up from Clang's CharacterLiteral::print - incomplete
464           // (doesn't actually support different character types/widths, sign
465           // handling's not done, and doesn't correctly test if a character is
466           // printable or needs to use a numeric escape sequence instead)
467           if (IsQualifiedChar) {
468             OS << '(';
469             OS << Name;
470             OS << ')';
471           }
472           switch (Val) {
473           case '\\':
474             OS << "'\\\\'";
475             break;
476           case '\'':
477             OS << "'\\''";
478             break;
479           case '\a':
480             // TODO: K&R: the meaning of '\\a' is different in traditional C
481             OS << "'\\a'";
482             break;
483           case '\b':
484             OS << "'\\b'";
485             break;
486           case '\f':
487             OS << "'\\f'";
488             break;
489           case '\n':
490             OS << "'\\n'";
491             break;
492           case '\r':
493             OS << "'\\r'";
494             break;
495           case '\t':
496             OS << "'\\t'";
497             break;
498           case '\v':
499             OS << "'\\v'";
500             break;
501           default:
502             if ((Val & ~0xFFu) == ~0xFFu)
503               Val &= 0xFFu;
504             if (Val < 127 && Val >= 32) {
505               OS << "'";
506               OS << (char)Val;
507               OS << "'";
508             } else if (Val < 256)
509               OS << to_string(llvm::format("'\\x%02x'", Val));
510             else if (Val <= 0xFFFF)
511               OS << to_string(llvm::format("'\\u%04x'", Val));
512             else
513               OS << to_string(llvm::format("'\\U%08x'", Val));
514           }
515         }
516         continue;
517       }
518       if (C.getTag() == dwarf::DW_TAG_GNU_template_template_param) {
519         const char *RawName =
520             dwarf::toString(C.find(DW_AT_GNU_template_name), nullptr);
521         assert(RawName);
522         StringRef Name = RawName;
523         Sep();
524         OS << Name;
525         continue;
526       }
527       if (C.getTag() != dwarf::DW_TAG_template_type_parameter)
528         continue;
529       auto TypeAttr = C.find(DW_AT_type);
530       Sep();
531       appendQualifiedName(TypeAttr ? resolveReferencedType(C, *TypeAttr)
532                                    : DWARFDie());
533     }
534     if (IsTemplate && *FirstParameter && FirstParameter == &FirstParameterValue)
535       OS << '<';
536     return IsTemplate;
537   }
538   void decomposeConstVolatile(DWARFDie &N, DWARFDie &T, DWARFDie &C,
539                               DWARFDie &V) {
540     (N.getTag() == DW_TAG_const_type ? C : V) = N;
541     T = resolveReferencedType(N);
542     if (T) {
543       auto Tag = T.getTag();
544       if (Tag == DW_TAG_const_type) {
545         C = T;
546         T = resolveReferencedType(T);
547       } else if (Tag == DW_TAG_volatile_type) {
548         V = T;
549         T = resolveReferencedType(T);
550       }
551     }
552   }
553   void appendConstVolatileQualifierAfter(DWARFDie N) {
554     DWARFDie C;
555     DWARFDie V;
556     DWARFDie T;
557     decomposeConstVolatile(N, T, C, V);
558     if (T && T.getTag() == DW_TAG_subroutine_type)
559       appendSubroutineNameAfter(T, resolveReferencedType(T), false, C.isValid(),
560                                 V.isValid());
561     else
562       appendUnqualifiedNameAfter(T, resolveReferencedType(T));
563   }
564   void appendConstVolatileQualifierBefore(DWARFDie N) {
565     DWARFDie C;
566     DWARFDie V;
567     DWARFDie T;
568     decomposeConstVolatile(N, T, C, V);
569     bool Subroutine = T && T.getTag() == DW_TAG_subroutine_type;
570     DWARFDie A = T;
571     while (A && A.getTag() == DW_TAG_array_type)
572       A = resolveReferencedType(A);
573     bool Leading =
574         (!A || (A.getTag() != DW_TAG_pointer_type &&
575                 A.getTag() != llvm::dwarf::DW_TAG_ptr_to_member_type)) &&
576         !Subroutine;
577     if (Leading) {
578       if (C)
579         OS << "const ";
580       if (V)
581         OS << "volatile ";
582     }
583     appendQualifiedNameBefore(T);
584     if (!Leading && !Subroutine) {
585       Word = true;
586       if (C)
587         OS << "const";
588       if (V) {
589         if (C)
590           OS << ' ';
591         OS << "volatile";
592       }
593     }
594   }
595 
596   /// Recursively append the DIE type name when applicable.
597   void appendUnqualifiedName(DWARFDie D,
598                              std::string *OriginalFullName = nullptr) {
599     // FIXME: We should have pretty printers per language. Currently we print
600     // everything as if it was C++ and fall back to the TAG type name.
601     DWARFDie Inner = appendUnqualifiedNameBefore(D, OriginalFullName);
602     appendUnqualifiedNameAfter(D, Inner);
603   }
604 
605   void appendSubroutineNameAfter(DWARFDie D, DWARFDie Inner,
606                                  bool SkipFirstParamIfArtificial, bool Const,
607                                  bool Volatile) {
608     DWARFDie FirstParamIfArtificial;
609     OS << '(';
610     EndedWithTemplate = false;
611     bool First = true;
612     bool RealFirst = true;
613     for (DWARFDie P : D) {
614       if (P.getTag() != DW_TAG_formal_parameter)
615         return;
616       DWARFDie T = resolveReferencedType(P);
617       if (SkipFirstParamIfArtificial && RealFirst && P.find(DW_AT_artificial)) {
618         FirstParamIfArtificial = T;
619         RealFirst = false;
620         continue;
621       }
622       if (!First) {
623         OS << ", ";
624       }
625       First = false;
626       appendQualifiedName(T);
627     }
628     EndedWithTemplate = false;
629     OS << ')';
630     if (FirstParamIfArtificial) {
631       if (DWARFDie P = FirstParamIfArtificial) {
632         if (P.getTag() == DW_TAG_pointer_type) {
633           DWARFDie C;
634           DWARFDie V;
635           auto CVStep = [&](DWARFDie CV) {
636             if (DWARFDie U = resolveReferencedType(CV)) {
637               if (U.getTag() == DW_TAG_const_type)
638                 return C = U;
639               if (U.getTag() == DW_TAG_volatile_type)
640                 return V = U;
641             }
642             return DWARFDie();
643           };
644           if (DWARFDie CV = CVStep(P)) {
645             CVStep(CV);
646           }
647           if (C)
648             OS << " const";
649           if (V)
650             OS << " volatile";
651         }
652       }
653     } else {
654       if (Const)
655         OS << " const";
656       if (Volatile)
657         OS << " volatile";
658     }
659     if (D.find(DW_AT_reference))
660       OS << " &";
661     if (D.find(DW_AT_rvalue_reference))
662       OS << " &&";
663     appendUnqualifiedNameAfter(Inner, resolveReferencedType(Inner));
664   }
665   void appendScopes(DWARFDie D) {
666     if (D.getTag() == DW_TAG_compile_unit)
667       return;
668     if (D.getTag() == DW_TAG_type_unit)
669       return;
670     if (D.getTag() == DW_TAG_skeleton_unit)
671       return;
672     if (D.getTag() == DW_TAG_subprogram)
673       return;
674     if (D.getTag() == DW_TAG_lexical_block)
675       return;
676     D = D.resolveTypeUnitReference();
677     if (DWARFDie P = D.getParent())
678       appendScopes(P);
679     appendUnqualifiedName(D);
680     OS << "::";
681   }
682 };
683 } // anonymous namespace
684 
685 static void dumpAttribute(raw_ostream &OS, const DWARFDie &Die,
686                           const DWARFAttribute &AttrValue, unsigned Indent,
687                           DIDumpOptions DumpOpts) {
688   if (!Die.isValid())
689     return;
690   const char BaseIndent[] = "            ";
691   OS << BaseIndent;
692   OS.indent(Indent + 2);
693   dwarf::Attribute Attr = AttrValue.Attr;
694   WithColor(OS, HighlightColor::Attribute) << formatv("{0}", Attr);
695 
696   dwarf::Form Form = AttrValue.Value.getForm();
697   if (DumpOpts.Verbose || DumpOpts.ShowForm)
698     OS << formatv(" [{0}]", Form);
699 
700   DWARFUnit *U = Die.getDwarfUnit();
701   const DWARFFormValue &FormValue = AttrValue.Value;
702 
703   OS << "\t(";
704 
705   StringRef Name;
706   std::string File;
707   auto Color = HighlightColor::Enumerator;
708   if (Attr == DW_AT_decl_file || Attr == DW_AT_call_file) {
709     Color = HighlightColor::String;
710     if (const auto *LT = U->getContext().getLineTableForUnit(U))
711       if (LT->getFileNameByIndex(
712               FormValue.getAsUnsignedConstant().getValue(),
713               U->getCompilationDir(),
714               DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath, File)) {
715         File = '"' + File + '"';
716         Name = File;
717       }
718   } else if (Optional<uint64_t> Val = FormValue.getAsUnsignedConstant())
719     Name = AttributeValueString(Attr, *Val);
720 
721   if (!Name.empty())
722     WithColor(OS, Color) << Name;
723   else if (Attr == DW_AT_decl_line || Attr == DW_AT_call_line)
724     OS << *FormValue.getAsUnsignedConstant();
725   else if (Attr == DW_AT_low_pc &&
726            (FormValue.getAsAddress() ==
727             dwarf::computeTombstoneAddress(U->getAddressByteSize()))) {
728     if (DumpOpts.Verbose) {
729       FormValue.dump(OS, DumpOpts);
730       OS << " (";
731     }
732     OS << "dead code";
733     if (DumpOpts.Verbose)
734       OS << ')';
735   } else if (Attr == DW_AT_high_pc && !DumpOpts.ShowForm && !DumpOpts.Verbose &&
736              FormValue.getAsUnsignedConstant()) {
737     if (DumpOpts.ShowAddresses) {
738       // Print the actual address rather than the offset.
739       uint64_t LowPC, HighPC, Index;
740       if (Die.getLowAndHighPC(LowPC, HighPC, Index))
741         DWARFFormValue::dumpAddress(OS, U->getAddressByteSize(), HighPC);
742       else
743         FormValue.dump(OS, DumpOpts);
744     }
745   } else if (DWARFAttribute::mayHaveLocationList(Attr) &&
746              FormValue.isFormClass(DWARFFormValue::FC_SectionOffset))
747     dumpLocationList(OS, FormValue, U, sizeof(BaseIndent) + Indent + 4,
748                      DumpOpts);
749   else if (FormValue.isFormClass(DWARFFormValue::FC_Exprloc) ||
750            (DWARFAttribute::mayHaveLocationExpr(Attr) &&
751             FormValue.isFormClass(DWARFFormValue::FC_Block)))
752     dumpLocationExpr(OS, FormValue, U, sizeof(BaseIndent) + Indent + 4,
753                      DumpOpts);
754   else
755     FormValue.dump(OS, DumpOpts);
756 
757   std::string Space = DumpOpts.ShowAddresses ? " " : "";
758 
759   // We have dumped the attribute raw value. For some attributes
760   // having both the raw value and the pretty-printed value is
761   // interesting. These attributes are handled below.
762   if (Attr == DW_AT_specification || Attr == DW_AT_abstract_origin) {
763     if (const char *Name =
764             Die.getAttributeValueAsReferencedDie(FormValue).getName(
765                 DINameKind::LinkageName))
766       OS << Space << "\"" << Name << '\"';
767   } else if (Attr == DW_AT_type) {
768     DWARFDie D = resolveReferencedType(Die, FormValue);
769     if (D && !D.isNULL()) {
770       OS << Space << "\"";
771       DWARFTypePrinter(OS).appendQualifiedName(D);
772       OS << '"';
773     }
774   } else if (Attr == DW_AT_APPLE_property_attribute) {
775     if (Optional<uint64_t> OptVal = FormValue.getAsUnsignedConstant())
776       dumpApplePropertyAttribute(OS, *OptVal);
777   } else if (Attr == DW_AT_ranges) {
778     const DWARFObject &Obj = Die.getDwarfUnit()->getContext().getDWARFObj();
779     // For DW_FORM_rnglistx we need to dump the offset separately, since
780     // we have only dumped the index so far.
781     if (FormValue.getForm() == DW_FORM_rnglistx)
782       if (auto RangeListOffset =
783               U->getRnglistOffset(*FormValue.getAsSectionOffset())) {
784         DWARFFormValue FV = DWARFFormValue::createFromUValue(
785             dwarf::DW_FORM_sec_offset, *RangeListOffset);
786         FV.dump(OS, DumpOpts);
787       }
788     if (auto RangesOrError = Die.getAddressRanges())
789       dumpRanges(Obj, OS, RangesOrError.get(), U->getAddressByteSize(),
790                  sizeof(BaseIndent) + Indent + 4, DumpOpts);
791     else
792       DumpOpts.RecoverableErrorHandler(createStringError(
793           errc::invalid_argument, "decoding address ranges: %s",
794           toString(RangesOrError.takeError()).c_str()));
795   }
796 
797   OS << ")\n";
798 }
799 
800 void DWARFDie::getFullName(raw_string_ostream &OS,
801                            std::string *OriginalFullName) const {
802   const char *NamePtr = getShortName();
803   if (!NamePtr)
804     return;
805   if (getTag() == DW_TAG_GNU_template_parameter_pack)
806     return;
807   DWARFTypePrinter(OS).appendUnqualifiedName(*this, OriginalFullName);
808 }
809 
810 bool DWARFDie::isSubprogramDIE() const { return getTag() == DW_TAG_subprogram; }
811 
812 bool DWARFDie::isSubroutineDIE() const {
813   auto Tag = getTag();
814   return Tag == DW_TAG_subprogram || Tag == DW_TAG_inlined_subroutine;
815 }
816 
817 Optional<DWARFFormValue> DWARFDie::find(dwarf::Attribute Attr) const {
818   if (!isValid())
819     return None;
820   auto AbbrevDecl = getAbbreviationDeclarationPtr();
821   if (AbbrevDecl)
822     return AbbrevDecl->getAttributeValue(getOffset(), Attr, *U);
823   return None;
824 }
825 
826 Optional<DWARFFormValue>
827 DWARFDie::find(ArrayRef<dwarf::Attribute> Attrs) const {
828   if (!isValid())
829     return None;
830   auto AbbrevDecl = getAbbreviationDeclarationPtr();
831   if (AbbrevDecl) {
832     for (auto Attr : Attrs) {
833       if (auto Value = AbbrevDecl->getAttributeValue(getOffset(), Attr, *U))
834         return Value;
835     }
836   }
837   return None;
838 }
839 
840 Optional<DWARFFormValue>
841 DWARFDie::findRecursively(ArrayRef<dwarf::Attribute> Attrs) const {
842   SmallVector<DWARFDie, 3> Worklist;
843   Worklist.push_back(*this);
844 
845   // Keep track if DIEs already seen to prevent infinite recursion.
846   // Empirically we rarely see a depth of more than 3 when dealing with valid
847   // DWARF. This corresponds to following the DW_AT_abstract_origin and
848   // DW_AT_specification just once.
849   SmallSet<DWARFDie, 3> Seen;
850   Seen.insert(*this);
851 
852   while (!Worklist.empty()) {
853     DWARFDie Die = Worklist.pop_back_val();
854 
855     if (!Die.isValid())
856       continue;
857 
858     if (auto Value = Die.find(Attrs))
859       return Value;
860 
861     if (auto D = Die.getAttributeValueAsReferencedDie(DW_AT_abstract_origin))
862       if (Seen.insert(D).second)
863         Worklist.push_back(D);
864 
865     if (auto D = Die.getAttributeValueAsReferencedDie(DW_AT_specification))
866       if (Seen.insert(D).second)
867         Worklist.push_back(D);
868   }
869 
870   return None;
871 }
872 
873 DWARFDie
874 DWARFDie::getAttributeValueAsReferencedDie(dwarf::Attribute Attr) const {
875   if (Optional<DWARFFormValue> F = find(Attr))
876     return getAttributeValueAsReferencedDie(*F);
877   return DWARFDie();
878 }
879 
880 DWARFDie
881 DWARFDie::getAttributeValueAsReferencedDie(const DWARFFormValue &V) const {
882   DWARFDie Result;
883   if (auto SpecRef = V.getAsRelativeReference()) {
884     if (SpecRef->Unit)
885       Result = SpecRef->Unit->getDIEForOffset(SpecRef->Unit->getOffset() +
886                                               SpecRef->Offset);
887     else if (auto SpecUnit =
888                  U->getUnitVector().getUnitForOffset(SpecRef->Offset))
889       Result = SpecUnit->getDIEForOffset(SpecRef->Offset);
890   }
891   return Result;
892 }
893 
894 DWARFDie DWARFDie::resolveTypeUnitReference() const {
895   if (auto Attr = find(DW_AT_signature)) {
896     if (Optional<uint64_t> Sig = Attr->getAsReferenceUVal()) {
897       if (DWARFTypeUnit *TU = U->getContext().getTypeUnitForHash(
898               U->getVersion(), *Sig, U->isDWOUnit()))
899         return TU->getDIEForOffset(TU->getTypeOffset() + TU->getOffset());
900     }
901   }
902   return *this;
903 }
904 
905 Optional<uint64_t> DWARFDie::getRangesBaseAttribute() const {
906   return toSectionOffset(find({DW_AT_rnglists_base, DW_AT_GNU_ranges_base}));
907 }
908 
909 Optional<uint64_t> DWARFDie::getLocBaseAttribute() const {
910   return toSectionOffset(find(DW_AT_loclists_base));
911 }
912 
913 Optional<uint64_t> DWARFDie::getHighPC(uint64_t LowPC) const {
914   uint64_t Tombstone = dwarf::computeTombstoneAddress(U->getAddressByteSize());
915   if (LowPC == Tombstone)
916     return None;
917   if (auto FormValue = find(DW_AT_high_pc)) {
918     if (auto Address = FormValue->getAsAddress()) {
919       // High PC is an address.
920       return Address;
921     }
922     if (auto Offset = FormValue->getAsUnsignedConstant()) {
923       // High PC is an offset from LowPC.
924       return LowPC + *Offset;
925     }
926   }
927   return None;
928 }
929 
930 bool DWARFDie::getLowAndHighPC(uint64_t &LowPC, uint64_t &HighPC,
931                                uint64_t &SectionIndex) const {
932   auto F = find(DW_AT_low_pc);
933   auto LowPcAddr = toSectionedAddress(F);
934   if (!LowPcAddr)
935     return false;
936   if (auto HighPcAddr = getHighPC(LowPcAddr->Address)) {
937     LowPC = LowPcAddr->Address;
938     HighPC = *HighPcAddr;
939     SectionIndex = LowPcAddr->SectionIndex;
940     return true;
941   }
942   return false;
943 }
944 
945 Expected<DWARFAddressRangesVector> DWARFDie::getAddressRanges() const {
946   if (isNULL())
947     return DWARFAddressRangesVector();
948   // Single range specified by low/high PC.
949   uint64_t LowPC, HighPC, Index;
950   if (getLowAndHighPC(LowPC, HighPC, Index))
951     return DWARFAddressRangesVector{{LowPC, HighPC, Index}};
952 
953   Optional<DWARFFormValue> Value = find(DW_AT_ranges);
954   if (Value) {
955     if (Value->getForm() == DW_FORM_rnglistx)
956       return U->findRnglistFromIndex(*Value->getAsSectionOffset());
957     return U->findRnglistFromOffset(*Value->getAsSectionOffset());
958   }
959   return DWARFAddressRangesVector();
960 }
961 
962 bool DWARFDie::addressRangeContainsAddress(const uint64_t Address) const {
963   auto RangesOrError = getAddressRanges();
964   if (!RangesOrError) {
965     llvm::consumeError(RangesOrError.takeError());
966     return false;
967   }
968 
969   for (const auto &R : RangesOrError.get())
970     if (R.LowPC <= Address && Address < R.HighPC)
971       return true;
972   return false;
973 }
974 
975 Expected<DWARFLocationExpressionsVector>
976 DWARFDie::getLocations(dwarf::Attribute Attr) const {
977   Optional<DWARFFormValue> Location = find(Attr);
978   if (!Location)
979     return createStringError(inconvertibleErrorCode(), "No %s",
980                              dwarf::AttributeString(Attr).data());
981 
982   if (Optional<uint64_t> Off = Location->getAsSectionOffset()) {
983     uint64_t Offset = *Off;
984 
985     if (Location->getForm() == DW_FORM_loclistx) {
986       if (auto LoclistOffset = U->getLoclistOffset(Offset))
987         Offset = *LoclistOffset;
988       else
989         return createStringError(inconvertibleErrorCode(),
990                                  "Loclist table not found");
991     }
992     return U->findLoclistFromOffset(Offset);
993   }
994 
995   if (Optional<ArrayRef<uint8_t>> Expr = Location->getAsBlock()) {
996     return DWARFLocationExpressionsVector{
997         DWARFLocationExpression{None, to_vector<4>(*Expr)}};
998   }
999 
1000   return createStringError(
1001       inconvertibleErrorCode(), "Unsupported %s encoding: %s",
1002       dwarf::AttributeString(Attr).data(),
1003       dwarf::FormEncodingString(Location->getForm()).data());
1004 }
1005 
1006 const char *DWARFDie::getSubroutineName(DINameKind Kind) const {
1007   if (!isSubroutineDIE())
1008     return nullptr;
1009   return getName(Kind);
1010 }
1011 
1012 const char *DWARFDie::getName(DINameKind Kind) const {
1013   if (!isValid() || Kind == DINameKind::None)
1014     return nullptr;
1015   // Try to get mangled name only if it was asked for.
1016   if (Kind == DINameKind::LinkageName) {
1017     if (auto Name = getLinkageName())
1018       return Name;
1019   }
1020   return getShortName();
1021 }
1022 
1023 const char *DWARFDie::getShortName() const {
1024   if (!isValid())
1025     return nullptr;
1026 
1027   return dwarf::toString(findRecursively(dwarf::DW_AT_name), nullptr);
1028 }
1029 
1030 const char *DWARFDie::getLinkageName() const {
1031   if (!isValid())
1032     return nullptr;
1033 
1034   return dwarf::toString(findRecursively({dwarf::DW_AT_MIPS_linkage_name,
1035                                           dwarf::DW_AT_linkage_name}),
1036                          nullptr);
1037 }
1038 
1039 uint64_t DWARFDie::getDeclLine() const {
1040   return toUnsigned(findRecursively(DW_AT_decl_line), 0);
1041 }
1042 
1043 std::string
1044 DWARFDie::getDeclFile(DILineInfoSpecifier::FileLineInfoKind Kind) const {
1045   if (auto FormValue = findRecursively(DW_AT_decl_file))
1046     if (auto OptString = FormValue->getAsFile(Kind))
1047       return *OptString;
1048   return {};
1049 }
1050 
1051 void DWARFDie::getCallerFrame(uint32_t &CallFile, uint32_t &CallLine,
1052                               uint32_t &CallColumn,
1053                               uint32_t &CallDiscriminator) const {
1054   CallFile = toUnsigned(find(DW_AT_call_file), 0);
1055   CallLine = toUnsigned(find(DW_AT_call_line), 0);
1056   CallColumn = toUnsigned(find(DW_AT_call_column), 0);
1057   CallDiscriminator = toUnsigned(find(DW_AT_GNU_discriminator), 0);
1058 }
1059 
1060 /// Helper to dump a DIE with all of its parents, but no siblings.
1061 static unsigned dumpParentChain(DWARFDie Die, raw_ostream &OS, unsigned Indent,
1062                                 DIDumpOptions DumpOpts, unsigned Depth = 0) {
1063   if (!Die)
1064     return Indent;
1065   if (DumpOpts.ParentRecurseDepth > 0 && Depth >= DumpOpts.ParentRecurseDepth)
1066     return Indent;
1067   Indent = dumpParentChain(Die.getParent(), OS, Indent, DumpOpts, Depth + 1);
1068   Die.dump(OS, Indent, DumpOpts);
1069   return Indent + 2;
1070 }
1071 
1072 void DWARFDie::dump(raw_ostream &OS, unsigned Indent,
1073                     DIDumpOptions DumpOpts) const {
1074   if (!isValid())
1075     return;
1076   DWARFDataExtractor debug_info_data = U->getDebugInfoExtractor();
1077   const uint64_t Offset = getOffset();
1078   uint64_t offset = Offset;
1079   if (DumpOpts.ShowParents) {
1080     DIDumpOptions ParentDumpOpts = DumpOpts;
1081     ParentDumpOpts.ShowParents = false;
1082     ParentDumpOpts.ShowChildren = false;
1083     Indent = dumpParentChain(getParent(), OS, Indent, ParentDumpOpts);
1084   }
1085 
1086   if (debug_info_data.isValidOffset(offset)) {
1087     uint32_t abbrCode = debug_info_data.getULEB128(&offset);
1088     if (DumpOpts.ShowAddresses)
1089       WithColor(OS, HighlightColor::Address).get()
1090           << format("\n0x%8.8" PRIx64 ": ", Offset);
1091 
1092     if (abbrCode) {
1093       auto AbbrevDecl = getAbbreviationDeclarationPtr();
1094       if (AbbrevDecl) {
1095         WithColor(OS, HighlightColor::Tag).get().indent(Indent)
1096             << formatv("{0}", getTag());
1097         if (DumpOpts.Verbose) {
1098           OS << format(" [%u] %c", abbrCode,
1099                        AbbrevDecl->hasChildren() ? '*' : ' ');
1100           if (Optional<uint32_t> ParentIdx = Die->getParentIdx())
1101             OS << format(" (0x%8.8" PRIx64 ")",
1102                          U->getDIEAtIndex(*ParentIdx).getOffset());
1103         }
1104         OS << '\n';
1105 
1106         // Dump all data in the DIE for the attributes.
1107         for (const DWARFAttribute &AttrValue : attributes())
1108           dumpAttribute(OS, *this, AttrValue, Indent, DumpOpts);
1109 
1110         if (DumpOpts.ShowChildren && DumpOpts.ChildRecurseDepth > 0) {
1111           DWARFDie Child = getFirstChild();
1112           DumpOpts.ChildRecurseDepth--;
1113           DIDumpOptions ChildDumpOpts = DumpOpts;
1114           ChildDumpOpts.ShowParents = false;
1115           while (Child) {
1116             Child.dump(OS, Indent + 2, ChildDumpOpts);
1117             Child = Child.getSibling();
1118           }
1119         }
1120       } else {
1121         OS << "Abbreviation code not found in 'debug_abbrev' class for code: "
1122            << abbrCode << '\n';
1123       }
1124     } else {
1125       OS.indent(Indent) << "NULL\n";
1126     }
1127   }
1128 }
1129 
1130 LLVM_DUMP_METHOD void DWARFDie::dump() const { dump(llvm::errs(), 0); }
1131 
1132 DWARFDie DWARFDie::getParent() const {
1133   if (isValid())
1134     return U->getParent(Die);
1135   return DWARFDie();
1136 }
1137 
1138 DWARFDie DWARFDie::getSibling() const {
1139   if (isValid())
1140     return U->getSibling(Die);
1141   return DWARFDie();
1142 }
1143 
1144 DWARFDie DWARFDie::getPreviousSibling() const {
1145   if (isValid())
1146     return U->getPreviousSibling(Die);
1147   return DWARFDie();
1148 }
1149 
1150 DWARFDie DWARFDie::getFirstChild() const {
1151   if (isValid())
1152     return U->getFirstChild(Die);
1153   return DWARFDie();
1154 }
1155 
1156 DWARFDie DWARFDie::getLastChild() const {
1157   if (isValid())
1158     return U->getLastChild(Die);
1159   return DWARFDie();
1160 }
1161 
1162 iterator_range<DWARFDie::attribute_iterator> DWARFDie::attributes() const {
1163   return make_range(attribute_iterator(*this, false),
1164                     attribute_iterator(*this, true));
1165 }
1166 
1167 DWARFDie::attribute_iterator::attribute_iterator(DWARFDie D, bool End)
1168     : Die(D), Index(0) {
1169   auto AbbrDecl = Die.getAbbreviationDeclarationPtr();
1170   assert(AbbrDecl && "Must have abbreviation declaration");
1171   if (End) {
1172     // This is the end iterator so we set the index to the attribute count.
1173     Index = AbbrDecl->getNumAttributes();
1174   } else {
1175     // This is the begin iterator so we extract the value for this->Index.
1176     AttrValue.Offset = D.getOffset() + AbbrDecl->getCodeByteSize();
1177     updateForIndex(*AbbrDecl, 0);
1178   }
1179 }
1180 
1181 void DWARFDie::attribute_iterator::updateForIndex(
1182     const DWARFAbbreviationDeclaration &AbbrDecl, uint32_t I) {
1183   Index = I;
1184   // AbbrDecl must be valid before calling this function.
1185   auto NumAttrs = AbbrDecl.getNumAttributes();
1186   if (Index < NumAttrs) {
1187     AttrValue.Attr = AbbrDecl.getAttrByIndex(Index);
1188     // Add the previous byte size of any previous attribute value.
1189     AttrValue.Offset += AttrValue.ByteSize;
1190     uint64_t ParseOffset = AttrValue.Offset;
1191     if (AbbrDecl.getAttrIsImplicitConstByIndex(Index))
1192       AttrValue.Value = DWARFFormValue::createFromSValue(
1193           AbbrDecl.getFormByIndex(Index),
1194           AbbrDecl.getAttrImplicitConstValueByIndex(Index));
1195     else {
1196       auto U = Die.getDwarfUnit();
1197       assert(U && "Die must have valid DWARF unit");
1198       AttrValue.Value = DWARFFormValue::createFromUnit(
1199           AbbrDecl.getFormByIndex(Index), U, &ParseOffset);
1200     }
1201     AttrValue.ByteSize = ParseOffset - AttrValue.Offset;
1202   } else {
1203     assert(Index == NumAttrs && "Indexes should be [0, NumAttrs) only");
1204     AttrValue = {};
1205   }
1206 }
1207 
1208 DWARFDie::attribute_iterator &DWARFDie::attribute_iterator::operator++() {
1209   if (auto AbbrDecl = Die.getAbbreviationDeclarationPtr())
1210     updateForIndex(*AbbrDecl, Index + 1);
1211   return *this;
1212 }
1213 
1214 bool DWARFAttribute::mayHaveLocationList(dwarf::Attribute Attr) {
1215   switch(Attr) {
1216   case DW_AT_location:
1217   case DW_AT_string_length:
1218   case DW_AT_return_addr:
1219   case DW_AT_data_member_location:
1220   case DW_AT_frame_base:
1221   case DW_AT_static_link:
1222   case DW_AT_segment:
1223   case DW_AT_use_location:
1224   case DW_AT_vtable_elem_location:
1225     return true;
1226   default:
1227     return false;
1228   }
1229 }
1230 
1231 bool DWARFAttribute::mayHaveLocationExpr(dwarf::Attribute Attr) {
1232   switch (Attr) {
1233   // From the DWARF v5 specification.
1234   case DW_AT_location:
1235   case DW_AT_byte_size:
1236   case DW_AT_bit_offset:
1237   case DW_AT_bit_size:
1238   case DW_AT_string_length:
1239   case DW_AT_lower_bound:
1240   case DW_AT_return_addr:
1241   case DW_AT_bit_stride:
1242   case DW_AT_upper_bound:
1243   case DW_AT_count:
1244   case DW_AT_data_member_location:
1245   case DW_AT_frame_base:
1246   case DW_AT_segment:
1247   case DW_AT_static_link:
1248   case DW_AT_use_location:
1249   case DW_AT_vtable_elem_location:
1250   case DW_AT_allocated:
1251   case DW_AT_associated:
1252   case DW_AT_data_location:
1253   case DW_AT_byte_stride:
1254   case DW_AT_rank:
1255   case DW_AT_call_value:
1256   case DW_AT_call_origin:
1257   case DW_AT_call_target:
1258   case DW_AT_call_target_clobbered:
1259   case DW_AT_call_data_location:
1260   case DW_AT_call_data_value:
1261   // Extensions.
1262   case DW_AT_GNU_call_site_value:
1263   case DW_AT_GNU_call_site_target:
1264     return true;
1265   default:
1266     return false;
1267   }
1268 }
1269