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