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