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