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