xref: /freebsd/contrib/llvm-project/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp (revision 84823cc70824c8d842f503d8c2e6d7b0c2d95b61)
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           P.getTag() != DW_TAG_unspecified_parameters)
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       if (P.getTag() == DW_TAG_unspecified_parameters)
628         OS << "...";
629       else
630         appendQualifiedName(T);
631     }
632     EndedWithTemplate = false;
633     OS << ')';
634     if (FirstParamIfArtificial) {
635       if (DWARFDie P = FirstParamIfArtificial) {
636         if (P.getTag() == DW_TAG_pointer_type) {
637           DWARFDie C;
638           DWARFDie V;
639           auto CVStep = [&](DWARFDie CV) {
640             if (DWARFDie U = resolveReferencedType(CV)) {
641               if (U.getTag() == DW_TAG_const_type)
642                 return C = U;
643               if (U.getTag() == DW_TAG_volatile_type)
644                 return V = U;
645             }
646             return DWARFDie();
647           };
648           if (DWARFDie CV = CVStep(P)) {
649             CVStep(CV);
650           }
651           if (C)
652             OS << " const";
653           if (V)
654             OS << " volatile";
655         }
656       }
657     } else {
658       if (Const)
659         OS << " const";
660       if (Volatile)
661         OS << " volatile";
662     }
663     if (D.find(DW_AT_reference))
664       OS << " &";
665     if (D.find(DW_AT_rvalue_reference))
666       OS << " &&";
667     appendUnqualifiedNameAfter(Inner, resolveReferencedType(Inner));
668   }
669   void appendScopes(DWARFDie D) {
670     if (D.getTag() == DW_TAG_compile_unit)
671       return;
672     if (D.getTag() == DW_TAG_type_unit)
673       return;
674     if (D.getTag() == DW_TAG_skeleton_unit)
675       return;
676     if (D.getTag() == DW_TAG_subprogram)
677       return;
678     if (D.getTag() == DW_TAG_lexical_block)
679       return;
680     D = D.resolveTypeUnitReference();
681     if (DWARFDie P = D.getParent())
682       appendScopes(P);
683     appendUnqualifiedName(D);
684     OS << "::";
685   }
686 };
687 } // anonymous namespace
688 
689 static void dumpAttribute(raw_ostream &OS, const DWARFDie &Die,
690                           const DWARFAttribute &AttrValue, unsigned Indent,
691                           DIDumpOptions DumpOpts) {
692   if (!Die.isValid())
693     return;
694   const char BaseIndent[] = "            ";
695   OS << BaseIndent;
696   OS.indent(Indent + 2);
697   dwarf::Attribute Attr = AttrValue.Attr;
698   WithColor(OS, HighlightColor::Attribute) << formatv("{0}", Attr);
699 
700   dwarf::Form Form = AttrValue.Value.getForm();
701   if (DumpOpts.Verbose || DumpOpts.ShowForm)
702     OS << formatv(" [{0}]", Form);
703 
704   DWARFUnit *U = Die.getDwarfUnit();
705   const DWARFFormValue &FormValue = AttrValue.Value;
706 
707   OS << "\t(";
708 
709   StringRef Name;
710   std::string File;
711   auto Color = HighlightColor::Enumerator;
712   if (Attr == DW_AT_decl_file || Attr == DW_AT_call_file) {
713     Color = HighlightColor::String;
714     if (const auto *LT = U->getContext().getLineTableForUnit(U))
715       if (LT->getFileNameByIndex(
716               FormValue.getAsUnsignedConstant().getValue(),
717               U->getCompilationDir(),
718               DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath, File)) {
719         File = '"' + File + '"';
720         Name = File;
721       }
722   } else if (Optional<uint64_t> Val = FormValue.getAsUnsignedConstant())
723     Name = AttributeValueString(Attr, *Val);
724 
725   if (!Name.empty())
726     WithColor(OS, Color) << Name;
727   else if (Attr == DW_AT_decl_line || Attr == DW_AT_call_line)
728     OS << *FormValue.getAsUnsignedConstant();
729   else if (Attr == DW_AT_low_pc &&
730            (FormValue.getAsAddress() ==
731             dwarf::computeTombstoneAddress(U->getAddressByteSize()))) {
732     if (DumpOpts.Verbose) {
733       FormValue.dump(OS, DumpOpts);
734       OS << " (";
735     }
736     OS << "dead code";
737     if (DumpOpts.Verbose)
738       OS << ')';
739   } else if (Attr == DW_AT_high_pc && !DumpOpts.ShowForm && !DumpOpts.Verbose &&
740              FormValue.getAsUnsignedConstant()) {
741     if (DumpOpts.ShowAddresses) {
742       // Print the actual address rather than the offset.
743       uint64_t LowPC, HighPC, Index;
744       if (Die.getLowAndHighPC(LowPC, HighPC, Index))
745         DWARFFormValue::dumpAddress(OS, U->getAddressByteSize(), HighPC);
746       else
747         FormValue.dump(OS, DumpOpts);
748     }
749   } else if (DWARFAttribute::mayHaveLocationList(Attr) &&
750              FormValue.isFormClass(DWARFFormValue::FC_SectionOffset))
751     dumpLocationList(OS, FormValue, U, sizeof(BaseIndent) + Indent + 4,
752                      DumpOpts);
753   else if (FormValue.isFormClass(DWARFFormValue::FC_Exprloc) ||
754            (DWARFAttribute::mayHaveLocationExpr(Attr) &&
755             FormValue.isFormClass(DWARFFormValue::FC_Block)))
756     dumpLocationExpr(OS, FormValue, U, sizeof(BaseIndent) + Indent + 4,
757                      DumpOpts);
758   else
759     FormValue.dump(OS, DumpOpts);
760 
761   std::string Space = DumpOpts.ShowAddresses ? " " : "";
762 
763   // We have dumped the attribute raw value. For some attributes
764   // having both the raw value and the pretty-printed value is
765   // interesting. These attributes are handled below.
766   if (Attr == DW_AT_specification || Attr == DW_AT_abstract_origin) {
767     if (const char *Name =
768             Die.getAttributeValueAsReferencedDie(FormValue).getName(
769                 DINameKind::LinkageName))
770       OS << Space << "\"" << Name << '\"';
771   } else if (Attr == DW_AT_type) {
772     DWARFDie D = resolveReferencedType(Die, FormValue);
773     if (D && !D.isNULL()) {
774       OS << Space << "\"";
775       dumpTypeQualifiedName(D, OS);
776       OS << '"';
777     }
778   } else if (Attr == DW_AT_APPLE_property_attribute) {
779     if (Optional<uint64_t> OptVal = FormValue.getAsUnsignedConstant())
780       dumpApplePropertyAttribute(OS, *OptVal);
781   } else if (Attr == DW_AT_ranges) {
782     const DWARFObject &Obj = Die.getDwarfUnit()->getContext().getDWARFObj();
783     // For DW_FORM_rnglistx we need to dump the offset separately, since
784     // we have only dumped the index so far.
785     if (FormValue.getForm() == DW_FORM_rnglistx)
786       if (auto RangeListOffset =
787               U->getRnglistOffset(*FormValue.getAsSectionOffset())) {
788         DWARFFormValue FV = DWARFFormValue::createFromUValue(
789             dwarf::DW_FORM_sec_offset, *RangeListOffset);
790         FV.dump(OS, DumpOpts);
791       }
792     if (auto RangesOrError = Die.getAddressRanges())
793       dumpRanges(Obj, OS, RangesOrError.get(), U->getAddressByteSize(),
794                  sizeof(BaseIndent) + Indent + 4, DumpOpts);
795     else
796       DumpOpts.RecoverableErrorHandler(createStringError(
797           errc::invalid_argument, "decoding address ranges: %s",
798           toString(RangesOrError.takeError()).c_str()));
799   }
800 
801   OS << ")\n";
802 }
803 
804 void DWARFDie::getFullName(raw_string_ostream &OS,
805                            std::string *OriginalFullName) const {
806   const char *NamePtr = getShortName();
807   if (!NamePtr)
808     return;
809   if (getTag() == DW_TAG_GNU_template_parameter_pack)
810     return;
811   dumpTypeUnqualifiedName(*this, OS, OriginalFullName);
812 }
813 
814 bool DWARFDie::isSubprogramDIE() const { return getTag() == DW_TAG_subprogram; }
815 
816 bool DWARFDie::isSubroutineDIE() const {
817   auto Tag = getTag();
818   return Tag == DW_TAG_subprogram || Tag == DW_TAG_inlined_subroutine;
819 }
820 
821 Optional<DWARFFormValue> DWARFDie::find(dwarf::Attribute Attr) const {
822   if (!isValid())
823     return None;
824   auto AbbrevDecl = getAbbreviationDeclarationPtr();
825   if (AbbrevDecl)
826     return AbbrevDecl->getAttributeValue(getOffset(), Attr, *U);
827   return None;
828 }
829 
830 Optional<DWARFFormValue>
831 DWARFDie::find(ArrayRef<dwarf::Attribute> Attrs) const {
832   if (!isValid())
833     return None;
834   auto AbbrevDecl = getAbbreviationDeclarationPtr();
835   if (AbbrevDecl) {
836     for (auto Attr : Attrs) {
837       if (auto Value = AbbrevDecl->getAttributeValue(getOffset(), Attr, *U))
838         return Value;
839     }
840   }
841   return None;
842 }
843 
844 Optional<DWARFFormValue>
845 DWARFDie::findRecursively(ArrayRef<dwarf::Attribute> Attrs) const {
846   SmallVector<DWARFDie, 3> Worklist;
847   Worklist.push_back(*this);
848 
849   // Keep track if DIEs already seen to prevent infinite recursion.
850   // Empirically we rarely see a depth of more than 3 when dealing with valid
851   // DWARF. This corresponds to following the DW_AT_abstract_origin and
852   // DW_AT_specification just once.
853   SmallSet<DWARFDie, 3> Seen;
854   Seen.insert(*this);
855 
856   while (!Worklist.empty()) {
857     DWARFDie Die = Worklist.pop_back_val();
858 
859     if (!Die.isValid())
860       continue;
861 
862     if (auto Value = Die.find(Attrs))
863       return Value;
864 
865     if (auto D = Die.getAttributeValueAsReferencedDie(DW_AT_abstract_origin))
866       if (Seen.insert(D).second)
867         Worklist.push_back(D);
868 
869     if (auto D = Die.getAttributeValueAsReferencedDie(DW_AT_specification))
870       if (Seen.insert(D).second)
871         Worklist.push_back(D);
872   }
873 
874   return None;
875 }
876 
877 DWARFDie
878 DWARFDie::getAttributeValueAsReferencedDie(dwarf::Attribute Attr) const {
879   if (Optional<DWARFFormValue> F = find(Attr))
880     return getAttributeValueAsReferencedDie(*F);
881   return DWARFDie();
882 }
883 
884 DWARFDie
885 DWARFDie::getAttributeValueAsReferencedDie(const DWARFFormValue &V) const {
886   DWARFDie Result;
887   if (auto SpecRef = V.getAsRelativeReference()) {
888     if (SpecRef->Unit)
889       Result = SpecRef->Unit->getDIEForOffset(SpecRef->Unit->getOffset() +
890                                               SpecRef->Offset);
891     else if (auto SpecUnit =
892                  U->getUnitVector().getUnitForOffset(SpecRef->Offset))
893       Result = SpecUnit->getDIEForOffset(SpecRef->Offset);
894   }
895   return Result;
896 }
897 
898 DWARFDie DWARFDie::resolveTypeUnitReference() const {
899   if (auto Attr = find(DW_AT_signature)) {
900     if (Optional<uint64_t> Sig = Attr->getAsReferenceUVal()) {
901       if (DWARFTypeUnit *TU = U->getContext().getTypeUnitForHash(
902               U->getVersion(), *Sig, U->isDWOUnit()))
903         return TU->getDIEForOffset(TU->getTypeOffset() + TU->getOffset());
904     }
905   }
906   return *this;
907 }
908 
909 Optional<uint64_t> DWARFDie::getRangesBaseAttribute() const {
910   return toSectionOffset(find({DW_AT_rnglists_base, DW_AT_GNU_ranges_base}));
911 }
912 
913 Optional<uint64_t> DWARFDie::getLocBaseAttribute() const {
914   return toSectionOffset(find(DW_AT_loclists_base));
915 }
916 
917 Optional<uint64_t> DWARFDie::getHighPC(uint64_t LowPC) const {
918   uint64_t Tombstone = dwarf::computeTombstoneAddress(U->getAddressByteSize());
919   if (LowPC == Tombstone)
920     return None;
921   if (auto FormValue = find(DW_AT_high_pc)) {
922     if (auto Address = FormValue->getAsAddress()) {
923       // High PC is an address.
924       return Address;
925     }
926     if (auto Offset = FormValue->getAsUnsignedConstant()) {
927       // High PC is an offset from LowPC.
928       return LowPC + *Offset;
929     }
930   }
931   return None;
932 }
933 
934 bool DWARFDie::getLowAndHighPC(uint64_t &LowPC, uint64_t &HighPC,
935                                uint64_t &SectionIndex) const {
936   auto F = find(DW_AT_low_pc);
937   auto LowPcAddr = toSectionedAddress(F);
938   if (!LowPcAddr)
939     return false;
940   if (auto HighPcAddr = getHighPC(LowPcAddr->Address)) {
941     LowPC = LowPcAddr->Address;
942     HighPC = *HighPcAddr;
943     SectionIndex = LowPcAddr->SectionIndex;
944     return true;
945   }
946   return false;
947 }
948 
949 Expected<DWARFAddressRangesVector> DWARFDie::getAddressRanges() const {
950   if (isNULL())
951     return DWARFAddressRangesVector();
952   // Single range specified by low/high PC.
953   uint64_t LowPC, HighPC, Index;
954   if (getLowAndHighPC(LowPC, HighPC, Index))
955     return DWARFAddressRangesVector{{LowPC, HighPC, Index}};
956 
957   Optional<DWARFFormValue> Value = find(DW_AT_ranges);
958   if (Value) {
959     if (Value->getForm() == DW_FORM_rnglistx)
960       return U->findRnglistFromIndex(*Value->getAsSectionOffset());
961     return U->findRnglistFromOffset(*Value->getAsSectionOffset());
962   }
963   return DWARFAddressRangesVector();
964 }
965 
966 bool DWARFDie::addressRangeContainsAddress(const uint64_t Address) const {
967   auto RangesOrError = getAddressRanges();
968   if (!RangesOrError) {
969     llvm::consumeError(RangesOrError.takeError());
970     return false;
971   }
972 
973   for (const auto &R : RangesOrError.get())
974     if (R.LowPC <= Address && Address < R.HighPC)
975       return true;
976   return false;
977 }
978 
979 Expected<DWARFLocationExpressionsVector>
980 DWARFDie::getLocations(dwarf::Attribute Attr) const {
981   Optional<DWARFFormValue> Location = find(Attr);
982   if (!Location)
983     return createStringError(inconvertibleErrorCode(), "No %s",
984                              dwarf::AttributeString(Attr).data());
985 
986   if (Optional<uint64_t> Off = Location->getAsSectionOffset()) {
987     uint64_t Offset = *Off;
988 
989     if (Location->getForm() == DW_FORM_loclistx) {
990       if (auto LoclistOffset = U->getLoclistOffset(Offset))
991         Offset = *LoclistOffset;
992       else
993         return createStringError(inconvertibleErrorCode(),
994                                  "Loclist table not found");
995     }
996     return U->findLoclistFromOffset(Offset);
997   }
998 
999   if (Optional<ArrayRef<uint8_t>> Expr = Location->getAsBlock()) {
1000     return DWARFLocationExpressionsVector{
1001         DWARFLocationExpression{None, to_vector<4>(*Expr)}};
1002   }
1003 
1004   return createStringError(
1005       inconvertibleErrorCode(), "Unsupported %s encoding: %s",
1006       dwarf::AttributeString(Attr).data(),
1007       dwarf::FormEncodingString(Location->getForm()).data());
1008 }
1009 
1010 const char *DWARFDie::getSubroutineName(DINameKind Kind) const {
1011   if (!isSubroutineDIE())
1012     return nullptr;
1013   return getName(Kind);
1014 }
1015 
1016 const char *DWARFDie::getName(DINameKind Kind) const {
1017   if (!isValid() || Kind == DINameKind::None)
1018     return nullptr;
1019   // Try to get mangled name only if it was asked for.
1020   if (Kind == DINameKind::LinkageName) {
1021     if (auto Name = getLinkageName())
1022       return Name;
1023   }
1024   return getShortName();
1025 }
1026 
1027 const char *DWARFDie::getShortName() const {
1028   if (!isValid())
1029     return nullptr;
1030 
1031   return dwarf::toString(findRecursively(dwarf::DW_AT_name), nullptr);
1032 }
1033 
1034 const char *DWARFDie::getLinkageName() const {
1035   if (!isValid())
1036     return nullptr;
1037 
1038   return dwarf::toString(findRecursively({dwarf::DW_AT_MIPS_linkage_name,
1039                                           dwarf::DW_AT_linkage_name}),
1040                          nullptr);
1041 }
1042 
1043 uint64_t DWARFDie::getDeclLine() const {
1044   return toUnsigned(findRecursively(DW_AT_decl_line), 0);
1045 }
1046 
1047 std::string
1048 DWARFDie::getDeclFile(DILineInfoSpecifier::FileLineInfoKind Kind) const {
1049   if (auto FormValue = findRecursively(DW_AT_decl_file))
1050     if (auto OptString = FormValue->getAsFile(Kind))
1051       return *OptString;
1052   return {};
1053 }
1054 
1055 void DWARFDie::getCallerFrame(uint32_t &CallFile, uint32_t &CallLine,
1056                               uint32_t &CallColumn,
1057                               uint32_t &CallDiscriminator) const {
1058   CallFile = toUnsigned(find(DW_AT_call_file), 0);
1059   CallLine = toUnsigned(find(DW_AT_call_line), 0);
1060   CallColumn = toUnsigned(find(DW_AT_call_column), 0);
1061   CallDiscriminator = toUnsigned(find(DW_AT_GNU_discriminator), 0);
1062 }
1063 
1064 /// Helper to dump a DIE with all of its parents, but no siblings.
1065 static unsigned dumpParentChain(DWARFDie Die, raw_ostream &OS, unsigned Indent,
1066                                 DIDumpOptions DumpOpts, unsigned Depth = 0) {
1067   if (!Die)
1068     return Indent;
1069   if (DumpOpts.ParentRecurseDepth > 0 && Depth >= DumpOpts.ParentRecurseDepth)
1070     return Indent;
1071   Indent = dumpParentChain(Die.getParent(), OS, Indent, DumpOpts, Depth + 1);
1072   Die.dump(OS, Indent, DumpOpts);
1073   return Indent + 2;
1074 }
1075 
1076 void DWARFDie::dump(raw_ostream &OS, unsigned Indent,
1077                     DIDumpOptions DumpOpts) const {
1078   if (!isValid())
1079     return;
1080   DWARFDataExtractor debug_info_data = U->getDebugInfoExtractor();
1081   const uint64_t Offset = getOffset();
1082   uint64_t offset = Offset;
1083   if (DumpOpts.ShowParents) {
1084     DIDumpOptions ParentDumpOpts = DumpOpts;
1085     ParentDumpOpts.ShowParents = false;
1086     ParentDumpOpts.ShowChildren = false;
1087     Indent = dumpParentChain(getParent(), OS, Indent, ParentDumpOpts);
1088   }
1089 
1090   if (debug_info_data.isValidOffset(offset)) {
1091     uint32_t abbrCode = debug_info_data.getULEB128(&offset);
1092     if (DumpOpts.ShowAddresses)
1093       WithColor(OS, HighlightColor::Address).get()
1094           << format("\n0x%8.8" PRIx64 ": ", Offset);
1095 
1096     if (abbrCode) {
1097       auto AbbrevDecl = getAbbreviationDeclarationPtr();
1098       if (AbbrevDecl) {
1099         WithColor(OS, HighlightColor::Tag).get().indent(Indent)
1100             << formatv("{0}", getTag());
1101         if (DumpOpts.Verbose) {
1102           OS << format(" [%u] %c", abbrCode,
1103                        AbbrevDecl->hasChildren() ? '*' : ' ');
1104           if (Optional<uint32_t> ParentIdx = Die->getParentIdx())
1105             OS << format(" (0x%8.8" PRIx64 ")",
1106                          U->getDIEAtIndex(*ParentIdx).getOffset());
1107         }
1108         OS << '\n';
1109 
1110         // Dump all data in the DIE for the attributes.
1111         for (const DWARFAttribute &AttrValue : attributes())
1112           dumpAttribute(OS, *this, AttrValue, Indent, DumpOpts);
1113 
1114         if (DumpOpts.ShowChildren && DumpOpts.ChildRecurseDepth > 0) {
1115           DWARFDie Child = getFirstChild();
1116           DumpOpts.ChildRecurseDepth--;
1117           DIDumpOptions ChildDumpOpts = DumpOpts;
1118           ChildDumpOpts.ShowParents = false;
1119           while (Child) {
1120             Child.dump(OS, Indent + 2, ChildDumpOpts);
1121             Child = Child.getSibling();
1122           }
1123         }
1124       } else {
1125         OS << "Abbreviation code not found in 'debug_abbrev' class for code: "
1126            << abbrCode << '\n';
1127       }
1128     } else {
1129       OS.indent(Indent) << "NULL\n";
1130     }
1131   }
1132 }
1133 
1134 LLVM_DUMP_METHOD void DWARFDie::dump() const { dump(llvm::errs(), 0); }
1135 
1136 DWARFDie DWARFDie::getParent() const {
1137   if (isValid())
1138     return U->getParent(Die);
1139   return DWARFDie();
1140 }
1141 
1142 DWARFDie DWARFDie::getSibling() const {
1143   if (isValid())
1144     return U->getSibling(Die);
1145   return DWARFDie();
1146 }
1147 
1148 DWARFDie DWARFDie::getPreviousSibling() const {
1149   if (isValid())
1150     return U->getPreviousSibling(Die);
1151   return DWARFDie();
1152 }
1153 
1154 DWARFDie DWARFDie::getFirstChild() const {
1155   if (isValid())
1156     return U->getFirstChild(Die);
1157   return DWARFDie();
1158 }
1159 
1160 DWARFDie DWARFDie::getLastChild() const {
1161   if (isValid())
1162     return U->getLastChild(Die);
1163   return DWARFDie();
1164 }
1165 
1166 iterator_range<DWARFDie::attribute_iterator> DWARFDie::attributes() const {
1167   return make_range(attribute_iterator(*this, false),
1168                     attribute_iterator(*this, true));
1169 }
1170 
1171 DWARFDie::attribute_iterator::attribute_iterator(DWARFDie D, bool End)
1172     : Die(D), Index(0) {
1173   auto AbbrDecl = Die.getAbbreviationDeclarationPtr();
1174   assert(AbbrDecl && "Must have abbreviation declaration");
1175   if (End) {
1176     // This is the end iterator so we set the index to the attribute count.
1177     Index = AbbrDecl->getNumAttributes();
1178   } else {
1179     // This is the begin iterator so we extract the value for this->Index.
1180     AttrValue.Offset = D.getOffset() + AbbrDecl->getCodeByteSize();
1181     updateForIndex(*AbbrDecl, 0);
1182   }
1183 }
1184 
1185 void DWARFDie::attribute_iterator::updateForIndex(
1186     const DWARFAbbreviationDeclaration &AbbrDecl, uint32_t I) {
1187   Index = I;
1188   // AbbrDecl must be valid before calling this function.
1189   auto NumAttrs = AbbrDecl.getNumAttributes();
1190   if (Index < NumAttrs) {
1191     AttrValue.Attr = AbbrDecl.getAttrByIndex(Index);
1192     // Add the previous byte size of any previous attribute value.
1193     AttrValue.Offset += AttrValue.ByteSize;
1194     uint64_t ParseOffset = AttrValue.Offset;
1195     if (AbbrDecl.getAttrIsImplicitConstByIndex(Index))
1196       AttrValue.Value = DWARFFormValue::createFromSValue(
1197           AbbrDecl.getFormByIndex(Index),
1198           AbbrDecl.getAttrImplicitConstValueByIndex(Index));
1199     else {
1200       auto U = Die.getDwarfUnit();
1201       assert(U && "Die must have valid DWARF unit");
1202       AttrValue.Value = DWARFFormValue::createFromUnit(
1203           AbbrDecl.getFormByIndex(Index), U, &ParseOffset);
1204     }
1205     AttrValue.ByteSize = ParseOffset - AttrValue.Offset;
1206   } else {
1207     assert(Index == NumAttrs && "Indexes should be [0, NumAttrs) only");
1208     AttrValue = {};
1209   }
1210 }
1211 
1212 DWARFDie::attribute_iterator &DWARFDie::attribute_iterator::operator++() {
1213   if (auto AbbrDecl = Die.getAbbreviationDeclarationPtr())
1214     updateForIndex(*AbbrDecl, Index + 1);
1215   return *this;
1216 }
1217 
1218 bool DWARFAttribute::mayHaveLocationList(dwarf::Attribute Attr) {
1219   switch(Attr) {
1220   case DW_AT_location:
1221   case DW_AT_string_length:
1222   case DW_AT_return_addr:
1223   case DW_AT_data_member_location:
1224   case DW_AT_frame_base:
1225   case DW_AT_static_link:
1226   case DW_AT_segment:
1227   case DW_AT_use_location:
1228   case DW_AT_vtable_elem_location:
1229     return true;
1230   default:
1231     return false;
1232   }
1233 }
1234 
1235 bool DWARFAttribute::mayHaveLocationExpr(dwarf::Attribute Attr) {
1236   switch (Attr) {
1237   // From the DWARF v5 specification.
1238   case DW_AT_location:
1239   case DW_AT_byte_size:
1240   case DW_AT_bit_offset:
1241   case DW_AT_bit_size:
1242   case DW_AT_string_length:
1243   case DW_AT_lower_bound:
1244   case DW_AT_return_addr:
1245   case DW_AT_bit_stride:
1246   case DW_AT_upper_bound:
1247   case DW_AT_count:
1248   case DW_AT_data_member_location:
1249   case DW_AT_frame_base:
1250   case DW_AT_segment:
1251   case DW_AT_static_link:
1252   case DW_AT_use_location:
1253   case DW_AT_vtable_elem_location:
1254   case DW_AT_allocated:
1255   case DW_AT_associated:
1256   case DW_AT_data_location:
1257   case DW_AT_byte_stride:
1258   case DW_AT_rank:
1259   case DW_AT_call_value:
1260   case DW_AT_call_origin:
1261   case DW_AT_call_target:
1262   case DW_AT_call_target_clobbered:
1263   case DW_AT_call_data_location:
1264   case DW_AT_call_data_value:
1265   // Extensions.
1266   case DW_AT_GNU_call_site_value:
1267   case DW_AT_GNU_call_site_target:
1268     return true;
1269   default:
1270     return false;
1271   }
1272 }
1273 
1274 namespace llvm {
1275 
1276 void dumpTypeQualifiedName(const DWARFDie &DIE, raw_ostream &OS) {
1277   DWARFTypePrinter(OS).appendQualifiedName(DIE);
1278 }
1279 
1280 void dumpTypeUnqualifiedName(const DWARFDie &DIE, raw_ostream &OS,
1281                              std::string *OriginalFullName) {
1282   DWARFTypePrinter(OS).appendUnqualifiedName(DIE, OriginalFullName);
1283 }
1284 
1285 } // namespace llvm
1286