1 //===-- llvm/BinaryFormat/Dwarf.cpp - Dwarf Framework ------------*- C++-*-===// 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 // This file contains support for generic dwarf information. 10 // 11 //===----------------------------------------------------------------------===// 12 13 #include "llvm/BinaryFormat/Dwarf.h" 14 #include "llvm/ADT/StringSwitch.h" 15 #include "llvm/ADT/Triple.h" 16 #include "llvm/Support/ErrorHandling.h" 17 18 using namespace llvm; 19 using namespace dwarf; 20 21 StringRef llvm::dwarf::TagString(unsigned Tag) { 22 switch (Tag) { 23 default: 24 return StringRef(); 25 #define HANDLE_DW_TAG(ID, NAME, VERSION, VENDOR, KIND) \ 26 case DW_TAG_##NAME: \ 27 return "DW_TAG_" #NAME; 28 #include "llvm/BinaryFormat/Dwarf.def" 29 } 30 } 31 32 unsigned llvm::dwarf::getTag(StringRef TagString) { 33 return StringSwitch<unsigned>(TagString) 34 #define HANDLE_DW_TAG(ID, NAME, VERSION, VENDOR, KIND) \ 35 .Case("DW_TAG_" #NAME, DW_TAG_##NAME) 36 #include "llvm/BinaryFormat/Dwarf.def" 37 .Default(DW_TAG_invalid); 38 } 39 40 unsigned llvm::dwarf::TagVersion(dwarf::Tag Tag) { 41 switch (Tag) { 42 default: 43 return 0; 44 #define HANDLE_DW_TAG(ID, NAME, VERSION, VENDOR, KIND) \ 45 case DW_TAG_##NAME: \ 46 return VERSION; 47 #include "llvm/BinaryFormat/Dwarf.def" 48 } 49 } 50 51 unsigned llvm::dwarf::TagVendor(dwarf::Tag Tag) { 52 switch (Tag) { 53 default: 54 return 0; 55 #define HANDLE_DW_TAG(ID, NAME, VERSION, VENDOR, KIND) \ 56 case DW_TAG_##NAME: \ 57 return DWARF_VENDOR_##VENDOR; 58 #include "llvm/BinaryFormat/Dwarf.def" 59 } 60 } 61 62 StringRef llvm::dwarf::ChildrenString(unsigned Children) { 63 switch (Children) { 64 case DW_CHILDREN_no: 65 return "DW_CHILDREN_no"; 66 case DW_CHILDREN_yes: 67 return "DW_CHILDREN_yes"; 68 } 69 return StringRef(); 70 } 71 72 StringRef llvm::dwarf::AttributeString(unsigned Attribute) { 73 switch (Attribute) { 74 default: 75 return StringRef(); 76 #define HANDLE_DW_AT(ID, NAME, VERSION, VENDOR) \ 77 case DW_AT_##NAME: \ 78 return "DW_AT_" #NAME; 79 #include "llvm/BinaryFormat/Dwarf.def" 80 } 81 } 82 83 unsigned llvm::dwarf::AttributeVersion(dwarf::Attribute Attribute) { 84 switch (Attribute) { 85 default: 86 return 0; 87 #define HANDLE_DW_AT(ID, NAME, VERSION, VENDOR) \ 88 case DW_AT_##NAME: \ 89 return VERSION; 90 #include "llvm/BinaryFormat/Dwarf.def" 91 } 92 } 93 94 unsigned llvm::dwarf::AttributeVendor(dwarf::Attribute Attribute) { 95 switch (Attribute) { 96 default: 97 return 0; 98 #define HANDLE_DW_AT(ID, NAME, VERSION, VENDOR) \ 99 case DW_AT_##NAME: \ 100 return DWARF_VENDOR_##VENDOR; 101 #include "llvm/BinaryFormat/Dwarf.def" 102 } 103 } 104 105 StringRef llvm::dwarf::FormEncodingString(unsigned Encoding) { 106 switch (Encoding) { 107 default: 108 return StringRef(); 109 #define HANDLE_DW_FORM(ID, NAME, VERSION, VENDOR) \ 110 case DW_FORM_##NAME: \ 111 return "DW_FORM_" #NAME; 112 #include "llvm/BinaryFormat/Dwarf.def" 113 } 114 } 115 116 unsigned llvm::dwarf::FormVersion(dwarf::Form Form) { 117 switch (Form) { 118 default: 119 return 0; 120 #define HANDLE_DW_FORM(ID, NAME, VERSION, VENDOR) \ 121 case DW_FORM_##NAME: \ 122 return VERSION; 123 #include "llvm/BinaryFormat/Dwarf.def" 124 } 125 } 126 127 unsigned llvm::dwarf::FormVendor(dwarf::Form Form) { 128 switch (Form) { 129 default: 130 return 0; 131 #define HANDLE_DW_FORM(ID, NAME, VERSION, VENDOR) \ 132 case DW_FORM_##NAME: \ 133 return DWARF_VENDOR_##VENDOR; 134 #include "llvm/BinaryFormat/Dwarf.def" 135 } 136 } 137 138 StringRef llvm::dwarf::OperationEncodingString(unsigned Encoding) { 139 switch (Encoding) { 140 default: 141 return StringRef(); 142 #define HANDLE_DW_OP(ID, NAME, VERSION, VENDOR) \ 143 case DW_OP_##NAME: \ 144 return "DW_OP_" #NAME; 145 #include "llvm/BinaryFormat/Dwarf.def" 146 case DW_OP_LLVM_convert: 147 return "DW_OP_LLVM_convert"; 148 case DW_OP_LLVM_fragment: 149 return "DW_OP_LLVM_fragment"; 150 case DW_OP_LLVM_tag_offset: 151 return "DW_OP_LLVM_tag_offset"; 152 case DW_OP_LLVM_entry_value: 153 return "DW_OP_LLVM_entry_value"; 154 } 155 } 156 157 unsigned llvm::dwarf::getOperationEncoding(StringRef OperationEncodingString) { 158 return StringSwitch<unsigned>(OperationEncodingString) 159 #define HANDLE_DW_OP(ID, NAME, VERSION, VENDOR) \ 160 .Case("DW_OP_" #NAME, DW_OP_##NAME) 161 #include "llvm/BinaryFormat/Dwarf.def" 162 .Case("DW_OP_LLVM_convert", DW_OP_LLVM_convert) 163 .Case("DW_OP_LLVM_fragment", DW_OP_LLVM_fragment) 164 .Case("DW_OP_LLVM_tag_offset", DW_OP_LLVM_tag_offset) 165 .Case("DW_OP_LLVM_entry_value", DW_OP_LLVM_entry_value) 166 .Default(0); 167 } 168 169 unsigned llvm::dwarf::OperationVersion(dwarf::LocationAtom Op) { 170 switch (Op) { 171 default: 172 return 0; 173 #define HANDLE_DW_OP(ID, NAME, VERSION, VENDOR) \ 174 case DW_OP_##NAME: \ 175 return VERSION; 176 #include "llvm/BinaryFormat/Dwarf.def" 177 } 178 } 179 180 unsigned llvm::dwarf::OperationVendor(dwarf::LocationAtom Op) { 181 switch (Op) { 182 default: 183 return 0; 184 #define HANDLE_DW_OP(ID, NAME, VERSION, VENDOR) \ 185 case DW_OP_##NAME: \ 186 return DWARF_VENDOR_##VENDOR; 187 #include "llvm/BinaryFormat/Dwarf.def" 188 } 189 } 190 191 StringRef llvm::dwarf::AttributeEncodingString(unsigned Encoding) { 192 switch (Encoding) { 193 default: 194 return StringRef(); 195 #define HANDLE_DW_ATE(ID, NAME, VERSION, VENDOR) \ 196 case DW_ATE_##NAME: \ 197 return "DW_ATE_" #NAME; 198 #include "llvm/BinaryFormat/Dwarf.def" 199 } 200 } 201 202 unsigned llvm::dwarf::getAttributeEncoding(StringRef EncodingString) { 203 return StringSwitch<unsigned>(EncodingString) 204 #define HANDLE_DW_ATE(ID, NAME, VERSION, VENDOR) \ 205 .Case("DW_ATE_" #NAME, DW_ATE_##NAME) 206 #include "llvm/BinaryFormat/Dwarf.def" 207 .Default(0); 208 } 209 210 unsigned llvm::dwarf::AttributeEncodingVersion(dwarf::TypeKind ATE) { 211 switch (ATE) { 212 default: 213 return 0; 214 #define HANDLE_DW_ATE(ID, NAME, VERSION, VENDOR) \ 215 case DW_ATE_##NAME: \ 216 return VERSION; 217 #include "llvm/BinaryFormat/Dwarf.def" 218 } 219 } 220 221 unsigned llvm::dwarf::AttributeEncodingVendor(dwarf::TypeKind ATE) { 222 switch (ATE) { 223 default: 224 return 0; 225 #define HANDLE_DW_ATE(ID, NAME, VERSION, VENDOR) \ 226 case DW_ATE_##NAME: \ 227 return DWARF_VENDOR_##VENDOR; 228 #include "llvm/BinaryFormat/Dwarf.def" 229 } 230 } 231 232 StringRef llvm::dwarf::DecimalSignString(unsigned Sign) { 233 switch (Sign) { 234 case DW_DS_unsigned: 235 return "DW_DS_unsigned"; 236 case DW_DS_leading_overpunch: 237 return "DW_DS_leading_overpunch"; 238 case DW_DS_trailing_overpunch: 239 return "DW_DS_trailing_overpunch"; 240 case DW_DS_leading_separate: 241 return "DW_DS_leading_separate"; 242 case DW_DS_trailing_separate: 243 return "DW_DS_trailing_separate"; 244 } 245 return StringRef(); 246 } 247 248 StringRef llvm::dwarf::EndianityString(unsigned Endian) { 249 switch (Endian) { 250 case DW_END_default: 251 return "DW_END_default"; 252 case DW_END_big: 253 return "DW_END_big"; 254 case DW_END_little: 255 return "DW_END_little"; 256 case DW_END_lo_user: 257 return "DW_END_lo_user"; 258 case DW_END_hi_user: 259 return "DW_END_hi_user"; 260 } 261 return StringRef(); 262 } 263 264 StringRef llvm::dwarf::AccessibilityString(unsigned Access) { 265 switch (Access) { 266 // Accessibility codes 267 case DW_ACCESS_public: 268 return "DW_ACCESS_public"; 269 case DW_ACCESS_protected: 270 return "DW_ACCESS_protected"; 271 case DW_ACCESS_private: 272 return "DW_ACCESS_private"; 273 } 274 return StringRef(); 275 } 276 277 StringRef llvm::dwarf::DefaultedMemberString(unsigned DefaultedEncodings) { 278 switch (DefaultedEncodings) { 279 // Defaulted Member Encodings codes 280 case DW_DEFAULTED_no: 281 return "DW_DEFAULTED_no"; 282 case DW_DEFAULTED_in_class: 283 return "DW_DEFAULTED_in_class"; 284 case DW_DEFAULTED_out_of_class: 285 return "DW_DEFAULTED_out_of_class"; 286 } 287 return StringRef(); 288 } 289 290 StringRef llvm::dwarf::VisibilityString(unsigned Visibility) { 291 switch (Visibility) { 292 case DW_VIS_local: 293 return "DW_VIS_local"; 294 case DW_VIS_exported: 295 return "DW_VIS_exported"; 296 case DW_VIS_qualified: 297 return "DW_VIS_qualified"; 298 } 299 return StringRef(); 300 } 301 302 StringRef llvm::dwarf::VirtualityString(unsigned Virtuality) { 303 switch (Virtuality) { 304 default: 305 return StringRef(); 306 #define HANDLE_DW_VIRTUALITY(ID, NAME) \ 307 case DW_VIRTUALITY_##NAME: \ 308 return "DW_VIRTUALITY_" #NAME; 309 #include "llvm/BinaryFormat/Dwarf.def" 310 } 311 } 312 313 unsigned llvm::dwarf::getVirtuality(StringRef VirtualityString) { 314 return StringSwitch<unsigned>(VirtualityString) 315 #define HANDLE_DW_VIRTUALITY(ID, NAME) \ 316 .Case("DW_VIRTUALITY_" #NAME, DW_VIRTUALITY_##NAME) 317 #include "llvm/BinaryFormat/Dwarf.def" 318 .Default(DW_VIRTUALITY_invalid); 319 } 320 321 StringRef llvm::dwarf::LanguageString(unsigned Language) { 322 switch (Language) { 323 default: 324 return StringRef(); 325 #define HANDLE_DW_LANG(ID, NAME, LOWER_BOUND, VERSION, VENDOR) \ 326 case DW_LANG_##NAME: \ 327 return "DW_LANG_" #NAME; 328 #include "llvm/BinaryFormat/Dwarf.def" 329 } 330 } 331 332 unsigned llvm::dwarf::getLanguage(StringRef LanguageString) { 333 return StringSwitch<unsigned>(LanguageString) 334 #define HANDLE_DW_LANG(ID, NAME, LOWER_BOUND, VERSION, VENDOR) \ 335 .Case("DW_LANG_" #NAME, DW_LANG_##NAME) 336 #include "llvm/BinaryFormat/Dwarf.def" 337 .Default(0); 338 } 339 340 unsigned llvm::dwarf::LanguageVersion(dwarf::SourceLanguage Lang) { 341 switch (Lang) { 342 default: 343 return 0; 344 #define HANDLE_DW_LANG(ID, NAME, LOWER_BOUND, VERSION, VENDOR) \ 345 case DW_LANG_##NAME: \ 346 return VERSION; 347 #include "llvm/BinaryFormat/Dwarf.def" 348 } 349 } 350 351 unsigned llvm::dwarf::LanguageVendor(dwarf::SourceLanguage Lang) { 352 switch (Lang) { 353 default: 354 return 0; 355 #define HANDLE_DW_LANG(ID, NAME, LOWER_BOUND, VERSION, VENDOR) \ 356 case DW_LANG_##NAME: \ 357 return DWARF_VENDOR_##VENDOR; 358 #include "llvm/BinaryFormat/Dwarf.def" 359 } 360 } 361 362 Optional<unsigned> llvm::dwarf::LanguageLowerBound(dwarf::SourceLanguage Lang) { 363 switch (Lang) { 364 default: 365 return None; 366 #define HANDLE_DW_LANG(ID, NAME, LOWER_BOUND, VERSION, VENDOR) \ 367 case DW_LANG_##NAME: \ 368 return LOWER_BOUND; 369 #include "llvm/BinaryFormat/Dwarf.def" 370 } 371 } 372 373 StringRef llvm::dwarf::CaseString(unsigned Case) { 374 switch (Case) { 375 case DW_ID_case_sensitive: 376 return "DW_ID_case_sensitive"; 377 case DW_ID_up_case: 378 return "DW_ID_up_case"; 379 case DW_ID_down_case: 380 return "DW_ID_down_case"; 381 case DW_ID_case_insensitive: 382 return "DW_ID_case_insensitive"; 383 } 384 return StringRef(); 385 } 386 387 StringRef llvm::dwarf::ConventionString(unsigned CC) { 388 switch (CC) { 389 default: 390 return StringRef(); 391 #define HANDLE_DW_CC(ID, NAME) \ 392 case DW_CC_##NAME: \ 393 return "DW_CC_" #NAME; 394 #include "llvm/BinaryFormat/Dwarf.def" 395 } 396 } 397 398 unsigned llvm::dwarf::getCallingConvention(StringRef CCString) { 399 return StringSwitch<unsigned>(CCString) 400 #define HANDLE_DW_CC(ID, NAME) .Case("DW_CC_" #NAME, DW_CC_##NAME) 401 #include "llvm/BinaryFormat/Dwarf.def" 402 .Default(0); 403 } 404 405 StringRef llvm::dwarf::InlineCodeString(unsigned Code) { 406 switch (Code) { 407 case DW_INL_not_inlined: 408 return "DW_INL_not_inlined"; 409 case DW_INL_inlined: 410 return "DW_INL_inlined"; 411 case DW_INL_declared_not_inlined: 412 return "DW_INL_declared_not_inlined"; 413 case DW_INL_declared_inlined: 414 return "DW_INL_declared_inlined"; 415 } 416 return StringRef(); 417 } 418 419 StringRef llvm::dwarf::ArrayOrderString(unsigned Order) { 420 switch (Order) { 421 case DW_ORD_row_major: 422 return "DW_ORD_row_major"; 423 case DW_ORD_col_major: 424 return "DW_ORD_col_major"; 425 } 426 return StringRef(); 427 } 428 429 StringRef llvm::dwarf::LNStandardString(unsigned Standard) { 430 switch (Standard) { 431 default: 432 return StringRef(); 433 #define HANDLE_DW_LNS(ID, NAME) \ 434 case DW_LNS_##NAME: \ 435 return "DW_LNS_" #NAME; 436 #include "llvm/BinaryFormat/Dwarf.def" 437 } 438 } 439 440 StringRef llvm::dwarf::LNExtendedString(unsigned Encoding) { 441 switch (Encoding) { 442 default: 443 return StringRef(); 444 #define HANDLE_DW_LNE(ID, NAME) \ 445 case DW_LNE_##NAME: \ 446 return "DW_LNE_" #NAME; 447 #include "llvm/BinaryFormat/Dwarf.def" 448 } 449 } 450 451 StringRef llvm::dwarf::MacinfoString(unsigned Encoding) { 452 switch (Encoding) { 453 // Macinfo Type Encodings 454 case DW_MACINFO_define: 455 return "DW_MACINFO_define"; 456 case DW_MACINFO_undef: 457 return "DW_MACINFO_undef"; 458 case DW_MACINFO_start_file: 459 return "DW_MACINFO_start_file"; 460 case DW_MACINFO_end_file: 461 return "DW_MACINFO_end_file"; 462 case DW_MACINFO_vendor_ext: 463 return "DW_MACINFO_vendor_ext"; 464 case DW_MACINFO_invalid: 465 return "DW_MACINFO_invalid"; 466 } 467 return StringRef(); 468 } 469 470 unsigned llvm::dwarf::getMacinfo(StringRef MacinfoString) { 471 return StringSwitch<unsigned>(MacinfoString) 472 .Case("DW_MACINFO_define", DW_MACINFO_define) 473 .Case("DW_MACINFO_undef", DW_MACINFO_undef) 474 .Case("DW_MACINFO_start_file", DW_MACINFO_start_file) 475 .Case("DW_MACINFO_end_file", DW_MACINFO_end_file) 476 .Case("DW_MACINFO_vendor_ext", DW_MACINFO_vendor_ext) 477 .Default(DW_MACINFO_invalid); 478 } 479 480 StringRef llvm::dwarf::MacroString(unsigned Encoding) { 481 switch (Encoding) { 482 default: 483 return StringRef(); 484 #define HANDLE_DW_MACRO(ID, NAME) \ 485 case DW_MACRO_##NAME: \ 486 return "DW_MACRO_" #NAME; 487 #include "llvm/BinaryFormat/Dwarf.def" 488 } 489 } 490 491 unsigned llvm::dwarf::getMacro(StringRef MacroString) { 492 return StringSwitch<unsigned>(MacroString) 493 #define HANDLE_DW_MACRO(ID, NAME) .Case("DW_MACRO_" #NAME, ID) 494 #include "llvm/BinaryFormat/Dwarf.def" 495 .Default(DW_MACINFO_invalid); 496 } 497 StringRef llvm::dwarf::RangeListEncodingString(unsigned Encoding) { 498 switch (Encoding) { 499 default: 500 return StringRef(); 501 #define HANDLE_DW_RLE(ID, NAME) \ 502 case DW_RLE_##NAME: \ 503 return "DW_RLE_" #NAME; 504 #include "llvm/BinaryFormat/Dwarf.def" 505 } 506 } 507 508 StringRef llvm::dwarf::LocListEncodingString(unsigned Encoding) { 509 switch (Encoding) { 510 default: 511 return StringRef(); 512 #define HANDLE_DW_LLE(ID, NAME) \ 513 case DW_LLE_##NAME: \ 514 return "DW_LLE_" #NAME; 515 #include "llvm/BinaryFormat/Dwarf.def" 516 } 517 } 518 519 StringRef llvm::dwarf::CallFrameString(unsigned Encoding, 520 Triple::ArchType Arch) { 521 assert(Arch != llvm::Triple::ArchType::UnknownArch); 522 #define SELECT_AARCH64 (Arch == llvm::Triple::aarch64_be || Arch == llvm::Triple::aarch64) 523 #define SELECT_MIPS64 Arch == llvm::Triple::mips64 524 #define SELECT_SPARC (Arch == llvm::Triple::sparc || Arch == llvm::Triple::sparcv9) 525 #define SELECT_X86 (Arch == llvm::Triple::x86 || Arch == llvm::Triple::x86_64) 526 #define HANDLE_DW_CFA(ID, NAME) 527 #define HANDLE_DW_CFA_PRED(ID, NAME, PRED) \ 528 if (ID == Encoding && PRED) \ 529 return "DW_CFA_" #NAME; 530 #include "llvm/BinaryFormat/Dwarf.def" 531 532 switch (Encoding) { 533 default: 534 return StringRef(); 535 #define HANDLE_DW_CFA_PRED(ID, NAME, PRED) 536 #define HANDLE_DW_CFA(ID, NAME) \ 537 case DW_CFA_##NAME: \ 538 return "DW_CFA_" #NAME; 539 #include "llvm/BinaryFormat/Dwarf.def" 540 541 #undef SELECT_X86 542 #undef SELECT_SPARC 543 #undef SELECT_MIPS64 544 #undef SELECT_AARCH64 545 } 546 } 547 548 StringRef llvm::dwarf::ApplePropertyString(unsigned Prop) { 549 switch (Prop) { 550 default: 551 return StringRef(); 552 #define HANDLE_DW_APPLE_PROPERTY(ID, NAME) \ 553 case DW_APPLE_PROPERTY_##NAME: \ 554 return "DW_APPLE_PROPERTY_" #NAME; 555 #include "llvm/BinaryFormat/Dwarf.def" 556 } 557 } 558 559 StringRef llvm::dwarf::UnitTypeString(unsigned UT) { 560 switch (UT) { 561 default: 562 return StringRef(); 563 #define HANDLE_DW_UT(ID, NAME) \ 564 case DW_UT_##NAME: \ 565 return "DW_UT_" #NAME; 566 #include "llvm/BinaryFormat/Dwarf.def" 567 } 568 } 569 570 StringRef llvm::dwarf::AtomTypeString(unsigned AT) { 571 switch (AT) { 572 case dwarf::DW_ATOM_null: 573 return "DW_ATOM_null"; 574 case dwarf::DW_ATOM_die_offset: 575 return "DW_ATOM_die_offset"; 576 case DW_ATOM_cu_offset: 577 return "DW_ATOM_cu_offset"; 578 case DW_ATOM_die_tag: 579 return "DW_ATOM_die_tag"; 580 case DW_ATOM_type_flags: 581 case DW_ATOM_type_type_flags: 582 return "DW_ATOM_type_flags"; 583 case DW_ATOM_qual_name_hash: 584 return "DW_ATOM_qual_name_hash"; 585 } 586 return StringRef(); 587 } 588 589 StringRef llvm::dwarf::GDBIndexEntryKindString(GDBIndexEntryKind Kind) { 590 switch (Kind) { 591 case GIEK_NONE: 592 return "NONE"; 593 case GIEK_TYPE: 594 return "TYPE"; 595 case GIEK_VARIABLE: 596 return "VARIABLE"; 597 case GIEK_FUNCTION: 598 return "FUNCTION"; 599 case GIEK_OTHER: 600 return "OTHER"; 601 case GIEK_UNUSED5: 602 return "UNUSED5"; 603 case GIEK_UNUSED6: 604 return "UNUSED6"; 605 case GIEK_UNUSED7: 606 return "UNUSED7"; 607 } 608 llvm_unreachable("Unknown GDBIndexEntryKind value"); 609 } 610 611 StringRef 612 llvm::dwarf::GDBIndexEntryLinkageString(GDBIndexEntryLinkage Linkage) { 613 switch (Linkage) { 614 case GIEL_EXTERNAL: 615 return "EXTERNAL"; 616 case GIEL_STATIC: 617 return "STATIC"; 618 } 619 llvm_unreachable("Unknown GDBIndexEntryLinkage value"); 620 } 621 622 StringRef llvm::dwarf::AttributeValueString(uint16_t Attr, unsigned Val) { 623 switch (Attr) { 624 case DW_AT_accessibility: 625 return AccessibilityString(Val); 626 case DW_AT_virtuality: 627 return VirtualityString(Val); 628 case DW_AT_language: 629 return LanguageString(Val); 630 case DW_AT_encoding: 631 return AttributeEncodingString(Val); 632 case DW_AT_decimal_sign: 633 return DecimalSignString(Val); 634 case DW_AT_endianity: 635 return EndianityString(Val); 636 case DW_AT_visibility: 637 return VisibilityString(Val); 638 case DW_AT_identifier_case: 639 return CaseString(Val); 640 case DW_AT_calling_convention: 641 return ConventionString(Val); 642 case DW_AT_inline: 643 return InlineCodeString(Val); 644 case DW_AT_ordering: 645 return ArrayOrderString(Val); 646 case DW_AT_APPLE_runtime_class: 647 return LanguageString(Val); 648 case DW_AT_defaulted: 649 return DefaultedMemberString(Val); 650 } 651 652 return StringRef(); 653 } 654 655 StringRef llvm::dwarf::AtomValueString(uint16_t Atom, unsigned Val) { 656 switch (Atom) { 657 case DW_ATOM_null: 658 return "NULL"; 659 case DW_ATOM_die_tag: 660 return TagString(Val); 661 } 662 663 return StringRef(); 664 } 665 666 StringRef llvm::dwarf::IndexString(unsigned Idx) { 667 switch (Idx) { 668 default: 669 return StringRef(); 670 #define HANDLE_DW_IDX(ID, NAME) \ 671 case DW_IDX_##NAME: \ 672 return "DW_IDX_" #NAME; 673 #include "llvm/BinaryFormat/Dwarf.def" 674 } 675 } 676 677 Optional<uint8_t> llvm::dwarf::getFixedFormByteSize(dwarf::Form Form, 678 FormParams Params) { 679 switch (Form) { 680 case DW_FORM_addr: 681 if (Params) 682 return Params.AddrSize; 683 return None; 684 685 case DW_FORM_block: // ULEB128 length L followed by L bytes. 686 case DW_FORM_block1: // 1 byte length L followed by L bytes. 687 case DW_FORM_block2: // 2 byte length L followed by L bytes. 688 case DW_FORM_block4: // 4 byte length L followed by L bytes. 689 case DW_FORM_string: // C-string with null terminator. 690 case DW_FORM_sdata: // SLEB128. 691 case DW_FORM_udata: // ULEB128. 692 case DW_FORM_ref_udata: // ULEB128. 693 case DW_FORM_indirect: // ULEB128. 694 case DW_FORM_exprloc: // ULEB128 length L followed by L bytes. 695 case DW_FORM_strx: // ULEB128. 696 case DW_FORM_addrx: // ULEB128. 697 case DW_FORM_loclistx: // ULEB128. 698 case DW_FORM_rnglistx: // ULEB128. 699 case DW_FORM_GNU_addr_index: // ULEB128. 700 case DW_FORM_GNU_str_index: // ULEB128. 701 return None; 702 703 case DW_FORM_ref_addr: 704 if (Params) 705 return Params.getRefAddrByteSize(); 706 return None; 707 708 case DW_FORM_flag: 709 case DW_FORM_data1: 710 case DW_FORM_ref1: 711 case DW_FORM_strx1: 712 case DW_FORM_addrx1: 713 return 1; 714 715 case DW_FORM_data2: 716 case DW_FORM_ref2: 717 case DW_FORM_strx2: 718 case DW_FORM_addrx2: 719 return 2; 720 721 case DW_FORM_strx3: 722 return 3; 723 724 case DW_FORM_data4: 725 case DW_FORM_ref4: 726 case DW_FORM_ref_sup4: 727 case DW_FORM_strx4: 728 case DW_FORM_addrx4: 729 return 4; 730 731 case DW_FORM_strp: 732 case DW_FORM_GNU_ref_alt: 733 case DW_FORM_GNU_strp_alt: 734 case DW_FORM_line_strp: 735 case DW_FORM_sec_offset: 736 case DW_FORM_strp_sup: 737 if (Params) 738 return Params.getDwarfOffsetByteSize(); 739 return None; 740 741 case DW_FORM_data8: 742 case DW_FORM_ref8: 743 case DW_FORM_ref_sig8: 744 case DW_FORM_ref_sup8: 745 return 8; 746 747 case DW_FORM_flag_present: 748 return 0; 749 750 case DW_FORM_data16: 751 return 16; 752 753 case DW_FORM_implicit_const: 754 // The implicit value is stored in the abbreviation as a SLEB128, and 755 // there no data in debug info. 756 return 0; 757 758 default: 759 break; 760 } 761 return None; 762 } 763 764 bool llvm::dwarf::isValidFormForVersion(Form F, unsigned Version, 765 bool ExtensionsOk) { 766 if (FormVendor(F) == DWARF_VENDOR_DWARF) { 767 unsigned FV = FormVersion(F); 768 return FV > 0 && FV <= Version; 769 } 770 return ExtensionsOk; 771 } 772 773 StringRef llvm::dwarf::FormatString(DwarfFormat Format) { 774 switch (Format) { 775 case DWARF32: 776 return "DWARF32"; 777 case DWARF64: 778 return "DWARF64"; 779 } 780 return StringRef(); 781 } 782 783 StringRef llvm::dwarf::FormatString(bool IsDWARF64) { 784 return FormatString(IsDWARF64 ? DWARF64 : DWARF32); 785 } 786 787 constexpr char llvm::dwarf::EnumTraits<Attribute>::Type[]; 788 constexpr char llvm::dwarf::EnumTraits<Form>::Type[]; 789 constexpr char llvm::dwarf::EnumTraits<Index>::Type[]; 790 constexpr char llvm::dwarf::EnumTraits<Tag>::Type[]; 791 constexpr char llvm::dwarf::EnumTraits<LineNumberOps>::Type[]; 792 constexpr char llvm::dwarf::EnumTraits<LocationAtom>::Type[]; 793