debug-info.yaml 47.5 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026
## Test that yaml2obj emits .debug_info section.

## a) Generate the .debug_info section from the "DWARF" entry.

## Generate and verify a DWARF32 little endian .debug_info (DWARFv5) section.

# RUN: yaml2obj --docnum=1 -DENDIAN=ELFDATA2LSB %s -o %t1.le.o
# RUN: llvm-readobj --sections --section-data %t1.le.o | \
# RUN:   FileCheck -DINDEX=2 -DNAME=15 -DOFFSET=0x9B -DSIZE=179 -DADDRALIGN=1 %s --check-prefixes=SHDR,DWARF32-LE-CONTENT

#                    SHDR: Index: [[INDEX]]
#               SHDR-NEXT: Name: .debug_info ([[NAME]])
#               SHDR-NEXT: Type: SHT_PROGBITS (0x1)
#               SHDR-NEXT: Flags [ (0x0)
#               SHDR-NEXT: ]
#               SHDR-NEXT: Address: 0x0
#               SHDR-NEXT: Offset: [[OFFSET]]
#               SHDR-NEXT: Size: [[SIZE]]
#               SHDR-NEXT: Link: 0
#               SHDR-NEXT: Info: 0
#               SHDR-NEXT: AddressAlignment: [[ADDRALIGN]]
#               SHDR-NEXT: EntrySize: 0
# DWARF32-LE-CONTENT-NEXT: SectionData (
# DWARF32-LE-CONTENT-NEXT:   0000: 34120000 05000204 34120000 01785634
##                                 ^-------                            unit_length (4-byte)
##                                          ^---                       version (2-byte)
##                                              ^-                     unit_type (1-byte) DW_UT_type
##                                                ^-                   address_size (1-byte)
##                                                   ^-------          debug_abbrev_offset (4-byte)
##                                                            ^-       abbreviation code (LEB128) 0x01
##                                                              ^----- Form: DW_FORM_addr (4-byte)
# DWARF32-LE-CONTENT-NEXT:   0010: 12020012 34020000 00123434 12785634
##                                 --
##                                   ^---                              Form: DW_FORM_block2 size (2-byte)
##                                       ^- ^-                         Form: DW_FORM_block2 body (2-byte)
##                                            ^--------                Form: DW_FORM_block4 size (4-byte)
##                                                     ^-^-            Form: DW_FORM_block4 body (2-byte)
##                                                         ^----       Form: DW_FORM_data2 (2-byte)
##                                                              ^----- Form: DW_FORM_data4 (4-byte)
# DWARF32-LE-CONTENT-NEXT:   0020: 12F0DEBC 9A785634 12616263 64000212
##                                 --
##                                   ^-----------------                Form: DW_FORM_data8 (8-byte)
##                                                     ^----------     Form: DW_FORM_string "abcd\0"
##                                                                ^-   Form: DW_FORM_block size (ULEB128)
##                                                                  ^- Form: DW_FORM_block body (2-byte)
# DWARF32-LE-CONTENT-NEXT:   0030: 34021234 1201B424 78563412 B4247856
##                                 ^-                                  Form: DW_FORM_block body
##                                   ^-                                Form: DW_FORM_block1 size (1-byte)
##                                     ^-^-                            Form: DW_FORM_block1 body (2-byte)
##                                          ^-                         Form: DW_FORM_data1 (1-byte)
##                                            ^-                       Form: DW_FORM_flag (1-byte)
##                                              ^---                   Form: DW_FORM_sdata (SLEB128) 0x1234
##                                                   ^-------          Form: DW_FORM_strp (4-byte)
##                                                            ^---     Form: DW_FORM_udata (ULEB128) 0x1234
##                                                                ^--- Form: DW_FORM_ref_addr (4-byte)
# DWARF32-LE-CONTENT-NEXT:   0040: 34121234 12785634 12F0DEBC 9A785634
##                                 ----
##                                     ^-                              Form: DW_FORM_ref1 (1-byte)
##                                       ^----                         Form: DW_FORM_ref2 (2-byte)
##                                            ^--------                Form: DW_FORM_ref4 (4-byte)
##                                                     ^-------------- Form: DW_FORM_ref8 (8-byte)
# DWARF32-LE-CONTENT-NEXT:   0050: 12B42408 65666768 00341200 00021234
##                                 --
##                                   ^---                              Form: DW_FORM_ref_udata (ULEB128) 0x1234
##                                       ^-                            Form: DW_FORM_indirect (ULEB128) DW_FORM_string
##                                          ^----------                "efgh\0"
##                                                     ^--------       Form: DW_FORM_sec_offset (4-byte)
##                                                              ^-     Form: DW_FORM_exprloc size (ULEB128) 0x02
##                                                                ^-^- Form: DW_FORM_exprloc body (2-byte)
# DWARF32-LE-CONTENT-NEXT:   0060: B424B424 78563412 78563412 78563412
##                                 ^---                                Form: DW_FORM_strx (ULEB128)
##                                     ^---                            Form: DW_FORM_addrx (ULEB128)
##                                          ^-------                   Form: DW_FORM_ref_sup4 (4-byte)
##                                                   ^-------          Form: DW_FORM_strp_sup (4-byte)
##                                                            ^------- Form: DW_FORM_line_strp (4-byte)
# DWARF32-LE-CONTENT-NEXT:   0070: F0DEBC9A 78563412 B424B424 F0DEBC9A
##                                 ^----------------                   Form: DW_FORM_ref_sig8 (8-byte)
##                                                   ^---              Form: DW_FORM_loclistx (ULEB128)
##                                                       ^---          Form: DW_FORM_rnglistx (ULEB128)
##                                                            ^------- Form: DW_FORM_ref_sup8 (8-byte)
# DWARF32-LE-CONTENT-NEXT:   0080: 78563412 12341278 56341212 34127856
##                                 --------
##                                          ^-                         Form: DW_FORM_strx1 (1-byte)
##                                            ^---                     Form: DW_FORM_strx2 (2-byte)
##                                                ^--------            Form: DW_FORM_strx4 (4-byte)
##                                                         ^-          Form: DW_FORM_addrx1 (1-byte)
##                                                            ^---     Form: DW_FORM_addrx2 (1-byte)
##                                                                ^--- Form: DW_FORM_addrx4 (4-byte)
# DWARF32-LE-CONTENT-NEXT:   0090: 34123412 00000500 01043412 00000078
##                                 ----
##                                     ^--------                       unit_length (4-byte)
##                                              ^---                   version (2-byte)
##                                                   ^-                unit_type (1-byte)
##                                                     ^-              address_size (1-byte)
##                                                       ^--------     debug_abbrev_offset (4-byte)
##                                                                ^-   abbrev code (ULEB128) 0x00
##                                                                  ^- unit_length (4-byte)
# DWARF32-LE-CONTENT-NEXT:   00A0: 56000004 00785600 00040178 56341202
##                                 ------
##                                       ^----                         version (2-byte)
##                                            ^--------                debug_abbrev_offset (4-byte)
##                                                     ^-              address_size (1-byte)
##                                                       ^-            abbrev code (ULEB128) 0x01
##                                                         ^--------   Form: DW_FORM_addr
##                                                                  ^- Form: DW_FORM_block2 size (2-byte)
# DWARF32-LE-CONTENT-NEXT:   00B0: 001234
##                                 --
##                                   ^-^-                              Form: DW_FORM_block2 body (2-byte)
# DWARF32-LE-CONTENT-NEXT: )

--- !ELF
FileHeader:
  Class: ELFCLASS64
  Data:  [[ENDIAN]]
  Type:  ET_EXEC
DWARF:
  debug_abbrev:
    - Table:
        - Code:     1
          Tag:      DW_TAG_compile_unit
          Children: DW_CHILDREN_no
          Attributes:
            - Attribute: 0x01
              Form:      DW_FORM_addr           ## 0x01
            - Attribute: 0x01
              Form:      DW_FORM_block2         ## 0x03
            - Attribute: 0x01
              Form:      DW_FORM_block4         ## 0x04
            - Attribute: 0x01
              Form:      DW_FORM_data2          ## 0x05
            - Attribute: 0x01
              Form:      DW_FORM_data4          ## 0x06
            - Attribute: 0x01
              Form:      DW_FORM_data8          ## 0x07
            - Attribute: 0x01
              Form:      DW_FORM_string         ## 0x08
            - Attribute: 0x01
              Form:      DW_FORM_block          ## 0x09
            - Attribute: 0x01
              Form:      DW_FORM_block1         ## 0x0a
            - Attribute: 0x01
              Form:      DW_FORM_data1          ## 0x0b
            - Attribute: 0x01
              Form:      DW_FORM_flag           ## 0x0c
            - Attribute: 0x01
              Form:      DW_FORM_sdata          ## 0x0d
            - Attribute: 0x01
              Form:      DW_FORM_strp           ## 0x0e
            - Attribute: 0x01
              Form:      DW_FORM_udata          ## 0x0f
            - Attribute: 0x01
              Form:      DW_FORM_ref_addr       ## 0x10
            - Attribute: 0x01
              Form:      DW_FORM_ref1           ## 0x11
            - Attribute: 0x01
              Form:      DW_FORM_ref2           ## 0x12
            - Attribute: 0x01
              Form:      DW_FORM_ref4           ## 0x13
            - Attribute: 0x01
              Form:      DW_FORM_ref8           ## 0x14
            - Attribute: 0x01
              Form:      DW_FORM_ref_udata      ## 0x15
            - Attribute: 0x01
              Form:      DW_FORM_indirect       ## 0x16
            - Attribute: 0x01
              Form:      DW_FORM_sec_offset     ## 0x17
            - Attribute: 0x01
              Form:      DW_FORM_exprloc        ## 0x18
            - Attribute: 0x01
              Form:      DW_FORM_strx           ## 0x1a
            - Attribute: 0x01
              Form:      DW_FORM_addrx          ## 0x1b
            - Attribute: 0x01
              Form:      DW_FORM_ref_sup4       ## 0x1c
            - Attribute: 0x01
              Form:      DW_FORM_strp_sup       ## 0x1d
            - Attribute: 0x01
              Form:      DW_FORM_data16         ## 0x1e
            - Attribute: 0x01
              Form:      DW_FORM_line_strp      ## 0x1f
            - Attribute: 0x01
              Form:      DW_FORM_ref_sig8       ## 0x20
            - Attribute: 0x01
              Form:      DW_FORM_implicit_const ## 0x21
              Value:     0x01
            - Attribute: 0x01
              Form:      DW_FORM_loclistx       ## 0x22
            - Attribute: 0x01
              Form:      DW_FORM_rnglistx       ## 0x23
            - Attribute: 0x01
              Form:      DW_FORM_ref_sup8       ## 0x24
            - Attribute: 0x01
              Form:      DW_FORM_strx1          ## 0x25
            - Attribute: 0x01
              Form:      DW_FORM_strx2          ## 0x26
            - Attribute: 0x01
              Form:      DW_FORM_strx3          ## 0x27
            - Attribute: 0x01
              Form:      DW_FORM_strx4          ## 0x28
            - Attribute: 0x01
              Form:      DW_FORM_addrx1         ## 0x29
            - Attribute: 0x01
              Form:      DW_FORM_addrx2         ## 0x2a
            - Attribute: 0x01
              Form:      DW_FORM_addrx3         ## 0x2b
            - Attribute: 0x01
              Form:      DW_FORM_addrx4         ## 0x2c
  debug_info:
    - Length:     0x1234
      Version:    5
      UnitType:   DW_UT_type
      AbbrOffset: 0x1234
      AddrSize:   4
      Entries:
        - AbbrCode: 1
          Values:
            - Value: 0x12345678         ## DW_FORM_addr
            - BlockData:                ## DW_FORM_block2
                - 0x12
                - 0x34
            - BlockData:                ## DW_FORM_block4
                - 0x12
                - 0x34
            - Value: 0x1234             ## DW_FORM_data2
            - Value: 0x12345678         ## DW_FORM_data4
            - Value: 0x123456789abcdef0 ## DW_FORM_data8
            - CStr:  abcd               ## DW_FORM_string
            - BlockData:                ## DW_FORM_block
                - 0x12
                - 0x34
            - BlockData:                ## DW_FORM_block1
                - 0x12
                - 0x34
            - Value: 0x12               ## DW_FORM_data1
            - Value: 0x01               ## DW_FORM_flag
            - Value: 0x1234             ## DW_FORM_sdata
            - Value: 0x12345678         ## DW_FORM_strp
            - Value: 0x1234             ## DW_FORM_udata
            - Value: 0x12345678         ## DW_FORM_ref_addr
            - Value: 0x12               ## DW_FORM_ref1
            - Value: 0x1234             ## DW_FORM_ref2
            - Value: 0x12345678         ## DW_FORM_ref4
            - Value: 0x123456789abcdef0 ## DW_FORM_ref8
            - Value: 0x1234             ## DW_FORM_ref_udata
            - Value: 0x08               ## DW_FORM_indirect. The following value's form is 0x08, which is DW_FORM_string.
            - CStr:  efgh
            - Value: 0x1234             ## DW_FORM_sec_offset
            - BlockData:                ## DW_FORM_exprloc
                - 0x12
                - 0x34
            - Value: 0x1234             ## DW_FORM_strx
            - Value: 0x1234             ## DW_FORM_addrx
            - Value: 0x12345678         ## DW_FORM_ref_sup4
            - Value: 0x12345678         ## DW_FORM_strp_sup
            - Value: 0x1234             ## DW_FORM_data16 (unimplemented)
            - Value: 0x12345678         ## DW_FORM_line_strp
            - Value: 0x123456789abcdef0 ## DW_FORM_ref_sig8
            - Value: 0x1234             ## DW_FORM_implicit_const (unimplemented)
            - Value: 0x1234             ## DW_FORM_loclistx
            - Value: 0x1234             ## DW_FORM_rnglistx
            - Value: 0x123456789abcdef0 ## DW_FORM_ref_sup8
            - Value: 0x12               ## DW_FORM_strx1
            - Value: 0x1234             ## DW_FORM_strx2
            - Value: 0x123456           ## DW_FORM_strx3 (unimplemented)
            - Value: 0x12345678         ## DW_FORM_strx4
            - Value: 0x12               ## DW_FORM_addrx1
            - Value: 0x1234             ## DW_FORM_addrx2
            - Value: 0x123456           ## DW_FORM_addrx3 (unimplemented)
            - Value: 0x12345678         ## DW_FORM_addrx4
    - Length:        0x1234
      Version:       5
      ## Test another unit type.
      UnitType:      DW_UT_compile
      AbbrOffset:    0x1234
      AddrSize:      4
      Entries:
        - AbbrCode: 0
          Values:   []
    - Length:        0x5678
      ## Test DWARFv4
      Version:       4
      AbbrevTableID: 0
      AbbrOffset:    0x5678
      AddrSize:      4
      Entries:
        - AbbrCode: 1
          Values:
            - Value: 0x12345678 ## DW_FORM_addr
            - BlockData:        ## DW_FORM_block2
                - 0x12
                - 0x34

## Generate and verify a DWARF32 big endian .debug_info (DWARFv4) section.

# RUN: yaml2obj --docnum=1 -DENDIAN=ELFDATA2MSB %s -o %t1.be.o
# RUN: llvm-readobj --sections --section-data %t1.be.o | \
# RUN:   FileCheck -DINDEX=2 -DNAME=15 -DOFFSET=0x9B -DSIZE=179 -DADDRALIGN=1 %s --check-prefixes=SHDR,DWARF32-BE-CONTENT

# DWARF32-BE-CONTENT-NEXT: SectionData (
# DWARF32-BE-CONTENT-NEXT:   0000: 00001234 00050204 00001234 01123456
##                                 ^-------                            unit_length (4-byte)
##                                          ^---                       version (2-byte)
##                                              ^-                     unit_type (1-byte) DW_UT_type
##                                                ^-                   address_size (1-byte)
##                                                   ^-------          debug_abbrev_offset (4-byte)
##                                                            ^-       abbreviation code (LEB128) 0x01
##                                                              ^----- Form: DW_FORM_addr (4-byte)
# DWARF32-BE-CONTENT-NEXT:   0010: 78000212 34000000 02123412 34123456
##                                 --
##                                   ^---                              Form: DW_FORM_block2 size (2-byte)
##                                       ^- ^-                         Form: DW_FORM_block2 body (2-byte)
##                                            ^--------                Form: DW_FORM_block4 size (4-byte)
##                                                     ^-^-            Form: DW_FORM_block4 body (2-byte)
##                                                         ^----       Form: DW_FORM_data2 (2-byte)
##                                                              ^----- Form: DW_FORM_data4 (4-byte)
# DWARF32-BE-CONTENT-NEXT:   0020: 78123456 789ABCDE F0616263 64000212
##                                 --
##                                   ^-----------------                Form: DW_FORM_data8 (8-byte)
##                                                     ^----------     Form: DW_FORM_string "abcd\0"
##                                                                ^-   Form: DW_FORM_block size (ULEB128)
##                                                                  ^- Form: DW_FORM_block body (2-byte)
# DWARF32-BE-CONTENT-NEXT:   0030: 34021234 1201B424 12345678 B4241234
##                                 ^-                                  Form: DW_FORM_block body
##                                   ^-                                Form: DW_FORM_block1 size (1-byte)
##                                     ^-^-                            Form: DW_FORM_block1 body (2-byte)
##                                          ^-                         Form: DW_FORM_data1 (1-byte)
##                                            ^-                       Form: DW_FORM_flag (1-byte)
##                                              ^---                   Form: DW_FORM_sdata (SLEB128) 0x1234
##                                                   ^-------          Form: DW_FORM_strp (4-byte)
##                                                            ^---     Form: DW_FORM_udata (ULEB128) 0x1234
##                                                                ^--- Form: DW_FORM_ref_addr (4-byte)
# DWARF32-BE-CONTENT-NEXT:   0040: 56781212 34123456 78123456 789ABCDE
##                                 ----
##                                     ^-                              Form: DW_FORM_ref1 (1-byte)
##                                       ^----                         Form: DW_FORM_ref2 (2-byte)
##                                            ^--------                Form: DW_FORM_ref4 (4-byte)
##                                                     ^-------------- Form: DW_FORM_ref8 (8-byte)
# DWARF32-BE-CONTENT-NEXT:   0050: F0B42408 65666768 00000012 34021234
##                                 --
##                                   ^---                              Form: DW_FORM_ref_udata (ULEB128) 0x1234
##                                       ^-                            Form: DW_FORM_indirect (ULEB128) DW_FORM_string
##                                          ^----------                "efgh\0"
##                                                     ^--------       Form: DW_FORM_sec_offset (4-byte)
##                                                              ^-     Form: DW_FORM_exprloc size (ULEB128) 0x02
##                                                                ^-^- Form: DW_FORM_exprloc body (2-byte)
# DWARF32-BE-CONTENT-NEXT:   0060: B424B424 12345678 12345678 12345678
##                                 ^---                                Form: DW_FORM_strx (ULEB128)
##                                     ^---                            Form: DW_FORM_addrx (ULEB128)
##                                          ^-------                   Form: DW_FORM_ref_sup4 (4-byte)
##                                                   ^-------          Form: DW_FORM_strp_sup (4-byte)
##                                                            ^------- Form: DW_FORM_line_strp (4-byte)
# DWARF32-BE-CONTENT-NEXT:   0070: 12345678 9ABCDEF0 B424B424 12345678
##                                 ^----------------                   Form: DW_FORM_ref_sig8 (8-byte)
##                                                   ^---              Form: DW_FORM_loclistx (ULEB128)
##                                                       ^---          Form: DW_FORM_rnglistx (ULEB128)
##                                                            ^------- Form: DW_FORM_ref_sup8 (8-byte)
# DWARF32-BE-CONTENT-NEXT:   0080: 9ABCDEF0 12123412 34567812 12341234
##                                 --------
##                                          ^-                         Form: DW_FORM_strx1 (1-byte)
##                                            ^---                     Form: DW_FORM_strx2 (2-byte)
##                                                ^--------            Form: DW_FORM_strx4 (4-byte)
##                                                         ^-          Form: DW_FORM_addrx1 (1-byte)
##                                                            ^---     Form: DW_FORM_addrx2 (1-byte)
##                                                                ^--- Form: DW_FORM_addrx4 (4-byte)
# DWARF32-BE-CONTENT-NEXT:   0090: 56780000 12340005 01040000 12340000
##                                 ----
##                                     ^--------                       unit_length (4-byte)
##                                              ^---                   version (2-byte)
##                                                   ^-                unit_type (1-byte)
##                                                     ^-              address_size (1-byte)
##                                                       ^--------     debug_abbrev_offset (4-byte)
##                                                                ^-   abbrev code (ULEB128) 0x00
##                                                                  ^- unit_length (4-byte)
# DWARF32-BE-CONTENT-NEXT:   00A0: 00567800 04000056 78040112 34567800
##                                 ------
##                                       ^----                         version (2-byte)
##                                            ^--------                debug_abbrev_offset (4-byte)
##                                                     ^-              address_size (1-byte)
##                                                       ^-            abbrev code (ULEB128) 0x01
##                                                         ^--------   Form: DW_FORM_addr
##                                                                  ^- Form: DW_FORM_block2 size (2-byte)
# DWARF32-BE-CONTENT-NEXT:   00B0: 021234
##                                 --
##                                   ^-^-                              Form: DW_FORM_block2 body (2-byte)
# DWARF32-BE-CONTENT-NEXT: )

## b) Generate the .debug_info section from raw section content.

# RUN: yaml2obj --docnum=2 %s -o %t2.o
# RUN: llvm-readobj --sections --section-data %t2.o | \
# RUN:   FileCheck -DINDEX=1 -DNAME=1 -DOFFSET=0x40 -DSIZE=3 -DADDRALIGN=0 %s --check-prefixes=SHDR,ARBITRARY-CONTENT

# ARBITRARY-CONTENT-NEXT: SectionData (
# ARBITRARY-CONTENT-NEXT:   0000: 112233
# ARBITRARY-CONTENT-NEXT: )

--- !ELF
FileHeader:
  Class: ELFCLASS64
  Data:  ELFDATA2LSB
  Type:  ET_EXEC
Sections:
  - Name:    .debug_info
    Type:    SHT_PROGBITS
    Content: "112233"

## c) Generate the .debug_info section when the "Size" is specified.

# RUN: yaml2obj --docnum=3 %s -o %t3.o
# RUN: llvm-readobj --sections --section-data %t3.o | \
# RUN:   FileCheck -DINDEX=1 -DNAME=1 -DOFFSET=0x40 -DSIZE=16 -DADDRALIGN=0 %s --check-prefixes=SHDR,SIZE

# SIZE-NEXT: SectionData (
# SIZE-NEXT:   0000: 00000000 00000000 00000000 00000000
# SIZE-NEXT: )

--- !ELF
FileHeader:
  Class: ELFCLASS64
  Data:  ELFDATA2LSB
  Type:  ET_EXEC
Sections:
  - Name: .debug_info
    Type: SHT_PROGBITS
    Size: 0x10

## d) Test that yaml2obj emits an error message when both the "Size" and the
## "debug_info" entry are specified at the same time.

# RUN: not yaml2obj --docnum=4 %s 2>&1 | FileCheck %s --check-prefix=AMBIGUOUS-CONTENT

# AMBIGUOUS-CONTENT: yaml2obj: error: cannot specify section '.debug_info' contents in the 'DWARF' entry and the 'Content' or 'Size' in the 'Sections' entry at the same time

--- !ELF
FileHeader:
  Class: ELFCLASS64
  Data:  ELFDATA2LSB
  Type:  ET_EXEC
Sections:
  - Name: .debug_info
    Type: SHT_PROGBITS
    Size: 0x10
DWARF:
  debug_abbrev:
    - Table:
        - Code:       1
          Tag:        DW_TAG_compile_unit
          Children:   DW_CHILDREN_no
  debug_info:
    - Length:     0x1234
      Version:    5
      UnitType:   DW_UT_type
      AbbrOffset: 0x1234
      Entries:    []

## e) Test that yaml2obj emits an error message when both the "Content" and the
## "debug_info" entry are specified at the same time.

# RUN: not yaml2obj --docnum=5 %s 2>&1 | FileCheck %s --check-prefix=AMBIGUOUS-CONTENT

--- !ELF
FileHeader:
  Class: ELFCLASS64
  Data:  ELFDATA2LSB
  Type:  ET_EXEC
Sections:
  - Name: .debug_info
    Type: SHT_PROGBITS
    Content: "00"
DWARF:
  debug_abbrev:
    - Table:
        - Code:       1
          Tag:        DW_TAG_compile_unit
          Children:   DW_CHILDREN_no
  debug_info:
    - Length:     0x1234
      Version:    5
      UnitType:   DW_UT_type
      AbbrOffset: 0x1234
      Entries:    []

## f) Test that all the properties can be overridden by the section header when
## the "debug_info" entry doesn't exist.

# RUN: yaml2obj --docnum=6 %s -o %t6.o
# RUN: llvm-readelf --sections %t6.o | FileCheck %s --check-prefix=OVERRIDDEN

#      OVERRIDDEN: [Nr] Name        Type   Address          Off    Size   ES Flg Lk Inf Al
#      OVERRIDDEN: [ 1] .debug_info STRTAB 0000000000002020 000050 00000d 01   A  2   1  2
# OVERRIDDEN-NEXT: [ 2] .sec        STRTAB 0000000000000000 00005d 000000 00      0   0  0

--- !ELF
FileHeader:
  Class: ELFCLASS64
  Data:  ELFDATA2LSB
  Type:  ET_EXEC
Sections:
  - Name:         .debug_info
    Type:         SHT_STRTAB  ## SHT_PROGBITS by default.
    Flags:        [SHF_ALLOC] ## 0 by default.
    Link:         .sec        ## 0 by default.
    EntSize:      1           ## 0 by default.
    Info:         1           ## 0 by default.
    AddressAlign: 2           ## 0 by default.
    Address:      0x2020      ## 0x00 by default.
    Offset:       0x50        ## 0x40 for the first section.
    Size:         0x0d        ## Set the "Size" so that we can reuse the check tag "OVERRIDDEN".
  - Name:         .sec        ## Linked by .debug_info.
    Type:         SHT_STRTAB

## g) Test that all the properties can be overridden by the section header when
## the "debug_info" entry exists.

# RUN: yaml2obj --docnum=7 %s -o %t7.o
# RUN: llvm-readelf --sections %t7.o | FileCheck %s --check-prefix=OVERRIDDEN

--- !ELF
FileHeader:
  Class: ELFCLASS64
  Data:  ELFDATA2LSB
  Type:  ET_EXEC
Sections:
  - Name:         .debug_info
    Type:         SHT_STRTAB  ## SHT_PROGBITS by default.
    Flags:        [SHF_ALLOC] ## 0 by default.
    Link:         .sec        ## 0 by default.
    EntSize:      1           ## 0 by default.
    Info:         1           ## 0 by default.
    AddressAlign: 2           ## 0 by default.
    Address:      0x2020      ## 0x00 by default.
    Offset:       0x50        ## 0x40 for the first section.
  - Name:         .sec        ## Linked by .debug_info.
    Type:         SHT_STRTAB
DWARF:
  debug_abbrev:
    - Table:
        - Code:       1
          Tag:        DW_TAG_compile_unit
          Children:   DW_CHILDREN_no
  debug_info:
    - Length:     0x1234
      Version:    5
      UnitType:   DW_UT_type
      AbbrOffset: 0x1234
      Entries:
        - AbbrCode: 0
          Values:   []

## h) Test that yaml2obj doesn't crash when the 'Entries' of a compilation unit is empty.

# RUN: yaml2obj --docnum=8 %s -o %t8.o
# RUN: llvm-readelf --hex-dump=.debug_info %t8.o | \
# RUN:   FileCheck %s --check-prefix=EMPTY-ENTRIES --match-full-lines

#       EMPTY-ENTRIES: Hex dump of section '.debug_info':
#  EMPTY-ENTRIES-NEXT: 0x00000000 34120000 05000204 34120000 4.......4...
# EMPTY-ENTRIES-EMPTY:
##                                ^- 'Entries' is empty

--- !ELF
FileHeader:
  Class: ELFCLASS32
  Data:  ELFDATA2LSB
  Type:  ET_EXEC
DWARF:
  debug_info:
    - Length:     0x1234
      Version:    5
      UnitType:   DW_UT_type
      AbbrOffset: 0x1234
      Entries:    []

## h) Test that yaml2obj emits values in the DIE according to the abbreviation whose
## index is equal to the value in 'AbbrevCode'.

# RUN: yaml2obj --docnum=9 %s -o %t9.o
# RUN: llvm-readelf --hex-dump=.debug_info %t9.o | \
# RUN:   FileCheck %s --check-prefix=FORM --match-full-lines

#       FORM: Hex dump of section '.debug_info':
#  FORM-NEXT: 0x00000000 34120000 05000204 34120000 02341221 4.......4....4.!
##                       ^-------                            unit_length (4-byte)
##                                                  ^-       abbreviation code (ULEB128)
##                                                    ^---   Form: DW_FORM_data2 (2-byte)
##                                                        ^- Form: DW_FORM_data4 (4-byte)
#  FORM-NEXT: 0x00000010 43658701 21436587 341200            Ce..!Ce.4..
##                       ------
##                             ^-                            abbreviation code (ULEB128)
##                                ^-------                   Form: DW_FORM_data4 (4-byte)
##                                         ^---              Form: DW_FORM_data2 (2-byte)
##                                             ^-            abbreviation code (ULEB128)
# FORM-EMPTY:

--- !ELF
FileHeader:
  Class: ELFCLASS32
  Data:  ELFDATA2LSB
  Type:  ET_EXEC
DWARF:
  debug_abbrev:
    - Table:
        - Tag:        DW_TAG_compile_unit
          Children:   DW_CHILDREN_yes
          Attributes:
            - Attribute: DW_AT_low_pc
              Form:      DW_FORM_data4
            - Attribute: DW_AT_high_pc
              Form:      DW_FORM_data2
        - Tag:        DW_TAG_subprogram
          Children:   DW_CHILDREN_no
          Attributes:
            - Attribute: DW_AT_low_pc
              Form:      DW_FORM_data2
            - Attribute: DW_AT_high_pc
              Form:      DW_FORM_data4
  debug_info:
    - Length:     0x1234
      Version:    5
      UnitType:   DW_UT_type
      AbbrOffset: 0x1234
      Entries:
        ## Test that yaml2obj emits values when the abbrev code is specified.
        - AbbrCode: 2
          Values:
            - Value: 0x1234
            - Value: 0x87654321
        ## Test that yaml2obj emits values when the abbrev code is specified to
        ## be lower than the first abbrev.
        - AbbrCode: 1
          Values:
            - Value: 0x87654321
            - Value: 0x1234
        ## Test that yaml2obj ignores the contents of entries with abbrev code 0.
        - AbbrCode: 0
          Values:
            - Value: 0x1234

## i) Test that yaml2obj reports an error when 'debug_info' has values in its
## entries but 'debug_abbrev' doesn't have enough attributes for them.

# RUN: not yaml2obj --docnum=10 %s -o %t10.o 2>&1 | \
# RUN:   FileCheck %s --check-prefixes=ERROR

# ERROR: yaml2obj: error: abbrev code must be less than or equal to the number of entries in abbreviation table

--- !ELF
FileHeader:
  Class: ELFCLASS64
  Data:  ELFDATA2LSB
  Type:  ET_EXEC
DWARF:
  debug_abbrev:
    - Table: []
  debug_info:
    - Length:     0x1234
      Version:    5
      UnitType:   DW_UT_type
      AbbrOffset: 0x1234
      Entries:
        - AbbrCode: 1
          Values:
            - Value: 0x1234

## j) Test that yaml2obj emits the correct DWARF64 unit headers.

## DWARFv5 unit header.

# RUN: yaml2obj --docnum=11 %s -o %t11.o
# RUN: llvm-readelf --hex-dump=.debug_info %t11.o | \
# RUN:   FileCheck %s --check-prefix=DWARFV5-HEADER

#      DWARFV5-HEADER: Hex dump of section '.debug_info':
# DWARFV5-HEADER-NEXT: 0x00000000 ffffffff 0c000000 00000000 05000208 ................
##                                ^-------------------------          unit_length (12-byte)
##                                                           ^---     version (2-byte)
##                                                               ^-   unit_type (1-byte)
##                                                                 ^- address_size (1-byte)
# DWARFV5-HEADER-NEXT: 0x00000010 34120000 00000000                   4.......
##                                ^----------------                   debug_abbrev_offset (8-byte)

--- !ELF
FileHeader:
  Class: ELFCLASS64
  Data:  ELFDATA2LSB
  Type:  ET_EXEC
DWARF:
  debug_info:
    - Format:     DWARF64
      Length:     0x0c
      Version:    5
      UnitType:   DW_UT_type
      AbbrOffset: 0x1234
      Entries:    []

## DWARFv4 unit header.

# RUN: yaml2obj --docnum=12 %s -o %t12.o
# RUN: llvm-readelf --hex-dump=.debug_info %t12.o | \
# RUN:   FileCheck %s --check-prefix=DWARFV4-HEADER

#      DWARFV4-HEADER: Hex dump of section '.debug_info':
# DWARFV4-HEADER-NEXT: 0x00000000 ffffffff 0c000000 00000000 04003412 ..............4.
##                                ^-------------------------          unit_length (12-byte)
##                                                           ^---     version (2-byte)
##                                                               ^--- debug_abbrev_offset (8-byte)
# DWARFV4-HEADER-NEXT: 0x00000010 00000000 000008                     .......
##                                -------------
##                                             ^-                     address_size (1-byte)

--- !ELF
FileHeader:
  Class: ELFCLASS64
  Data:  ELFDATA2LSB
  Type:  ET_EXEC
DWARF:
  debug_info:
    - Format:     DWARF64
      Length:     0x0c
      Version:    4
      AbbrOffset: 0x1234
      Entries:    []

## k) Test that yaml2obj is able to emit a correct length for compilation units.

# RUN: yaml2obj --docnum=13 %s -o %t13.o
# RUN: llvm-readelf --hex-dump=.debug_info %t13.o | \
# RUN:   FileCheck %s --check-prefix=INFER-LENGTH

#      INFER-LENGTH: Hex dump of section '.debug_info':
# INFER-LENGTH-NEXT: 0x00000000 37000000 04000000 00000801 00000000 7...............
##                              ^-------                            unit_length (0x37)
##                                       ^---                       version (2-byte)
##                                           ^--------              debug_abbrev_offset (4-byte)
##                                                    ^-            address_size (1-byte)
##                                                      ^-          abbrev code (ULEB128) 0x01
##                                                         ^------- Form: DW_FORM_strp (4-byte)
# INFER-LENGTH-NEXT: 0x00000010 0c001600 00000000 00001e00 00002011 .............. .
##                              ^---                                Form: DW_FORM_data2 (2-byte)
##                                  ^--------                       Form: DW_FORM_strp (4-byte)
##                                           ^--------              Form: DW_FORM_sec_offset (4-byte)
##                                                    ^--------     Form: DW_FORM_strp (4-byte)
##                                                             ^--- Form: DW_FORM_addr (8-byte)
# INFER-LENGTH-NEXT: 0x00000020 00000000 00003300 00000220 11000000 ......3.... ....
##                              -------------
##                                           ^--------              Form: DW_FORM_data4 (4-byte)
##                                                    ^-            abbrev code (ULEB128) 0x02
##                                                      ^---------- Form: DW_FORM_addr (8-byte)
# INFER-LENGTH-NEXT: 0x00000030 00000006 00000038 000000            .......8...
##                              ------
##                                    ^--------                     Form: DW_FORM_data4 (4-byte)
##                                             ^--------            Form: DW_FORM_strp (4-byte)

## The handwritten DIEs should look like:

## 0x0000000b: DW_TAG_compile_unit [1] *
##               DW_AT_producer [DW_FORM_strp]        ( .debug_str[0x00000000] = "clang version 10.0.0 ")
##               DW_AT_language [DW_FORM_data2]       (DW_LANG_C99)
##               DW_AT_name [DW_FORM_strp]            ( .debug_str[0x00000016] = "hello.c")
##               DW_AT_stmt_list [DW_FORM_sec_offset] (0x00000000)
##               DW_AT_comp_dir [DW_FORM_strp]        ( .debug_str[0x0000001e] = "/home/v/x/llvm/playground")
##               DW_AT_low_pc [DW_FORM_addr]          (0x0000000000001120)
##               DW_AT_high_pc [DW_FORM_data4]        (0x00000033)
## 
## 0x0000002a:   DW_TAG_subprogram [2]  
##                 DW_AT_low_pc [DW_FORM_addr]        (0x0000000000001120)
##                 DW_AT_high_pc [DW_FORM_data4]      (0x00000006)
##                 DW_AT_name [DW_FORM_strp]          ( .debug_str[0x00000038] = "main")

--- !ELF
FileHeader:
  Class: ELFCLASS64
  Data:  ELFDATA2LSB
  Type:  ET_EXEC
DWARF:
  debug_str:
    - "clang version 10.0.0 "
    - "hello.c"
    - "/home/v/x/llvm/playground"
    - "main"
  debug_abbrev:
    - Table:
        - Code:     1
          Tag:      DW_TAG_compile_unit
          Children: DW_CHILDREN_yes
          Attributes:
            - Attribute: DW_AT_producer
              Form:      DW_FORM_strp
            - Attribute: DW_AT_language
              Form:      DW_FORM_data2
            - Attribute: DW_AT_name
              Form:      DW_FORM_strp
            - Attribute: DW_AT_stmt_list
              Form:      DW_FORM_sec_offset
            - Attribute: DW_AT_comp_dir
              Form:      DW_FORM_strp
            - Attribute: DW_AT_low_pc
              Form:      DW_FORM_addr
            - Attribute: DW_AT_high_pc
              Form:      DW_FORM_data4
        - Code: 2
          Tag:  DW_TAG_subprogram
          Children: DW_CHILDREN_no
          Attributes:
            - Attribute: DW_AT_low_pc
              Form:      DW_FORM_addr
            - Attribute: DW_AT_high_pc
              Form:      DW_FORM_data4
            - Attribute: DW_AT_name
              Form:      DW_FORM_strp
  debug_info:
    - Version:    4
      AbbrOffset: 0x00
      Entries:
        - AbbrCode: 1
          Values:
            - Value: 0x00   ## DW_AT_producer [DW_FORM_strp]
            - Value: 0x0c   ## DW_LANG_C99, DW_AT_language [DW_FORM_data2]
            - Value: 0x16   ## DW_AT_name [DW_FORM_strp]
            - Value: 0x00   ## DW_AT_stmt_list [DW_FORM_sec_offset]
            - Value: 0x1e   ## DW_AT_comp_dir [DW_FORM_strp]
            - Value: 0x1120 ## DW_AT_low_pc [DW_FORM_addr]
            - Value: 0x33   ## DW_AT_high_pc [DW_FORM_data4]
        - AbbrCode: 2
          Values:
            - Value: 0x1120 ## DW_AT_low_pc [DW_FORM_addr]
            - Value: 0x06   ## DW_AT_high_pc [DW_FORM_data4]
            - Value: 0x38   ## DW_AT_name [DW_FORM_strp]

## l) Test that if we don't specify the 'Values' key for an entry, yaml2obj will only emit the abbrev_code.

# RUN: yaml2obj --docnum=14 %s -o %t14.o
# RUN: llvm-readelf --hex-dump=.debug_info %t14.o | \
# RUN:   FileCheck %s --check-prefix=NO-VALUES

#      NO-VALUES: Hex dump of section '.debug_info':
# NO-VALUES-NEXT: 0x00000000 0a000000 04000000 00000801 0002     ..............
##                           ^-------                            unit_length (4-byte)
##                                    ^---                       version (2-byte)
##                                        ^--------              debug_abbrev_offset (4-byte)
##                                                 ^-            address_size (1-byte)
##                                                   ^-          abbrev_code (ULEB128) 0x01
##                                                      ^-       abbrev_code (ULEB128) 0x00
##                                                        ^-     abbrev_code (ULEB128) 0x02

--- !ELF
FileHeader:
  Class: ELFCLASS64
  Data:  ELFDATA2LSB
  Type:  ET_EXEC
DWARF:
  debug_info:
    - Version:    4
      AbbrOffset: 0x00
      Entries:
        - AbbrCode: 1
        - AbbrCode: 0
        - AbbrCode: 2

## m) Test that yaml2obj is able to infer the address size from the object file.

# RUN: yaml2obj --docnum=15 -DBITS=64 %s -o %t15.64-bit.o
# RUN: llvm-readelf --hex-dump=.debug_info %t15.64-bit.o | \
# RUN:   FileCheck %s --check-prefix=ADDRSIZE -DADDRSIZE=08

#      ADDRSIZE: Hex dump of section '.debug_info':
# ADDRSIZE-NEXT: 0x00000000 07000000 04000000 0000[[ADDRSIZE]]            ...........

# RUN: yaml2obj --docnum=15 -DBITS=32 %s -o %t15.32-bit.o
# RUN: llvm-readelf --hex-dump=.debug_info %t15.32-bit.o | \
# RUN:   FileCheck %s --check-prefix=ADDRSIZE -DADDRSIZE=04

--- !ELF
FileHeader:
  Class: ELFCLASS[[BITS]]
  Data:  ELFDATA2LSB
  Type:  ET_EXEC
DWARF:
  debug_info:
    - Version:    4
      AbbrOffset: 0x00

## n) Test that yaml2obj emits an error message when a compilation unit has values but there is no associated abbrev table.

## RUN: not yaml2obj --docnum=16 %s 2>&1 | FileCheck %s --check-prefix=NO-ABBREV

# NO-ABBREV: yaml2obj: error: cannot find abbrev table whose ID is 0 for compilation unit with index 0

--- !ELF
FileHeader:
  Class:   ELFCLASS64
  Data:    ELFDATA2LSB
  Type:    ET_EXEC
  Machine: EM_X86_64
DWARF:
  debug_info:
    - Version:    4
      AbbrOffset: 0x00
      Entries:
        - AbbrCode: 1
          Values:
            - Value: 0x1234

## o) Test that yaml2obj is able to generate compilation units according to the
## associated abbrev table that is referenced by the 'AbbrevTableID' and infer
## the value of the debug_abbrev_offset field.

# RUN: yaml2obj --docnum=17 %s -o %t17.o
# RUN: llvm-readelf --hex-dump=.debug_info %t17.o | FileCheck %s --check-prefix=MULTI-TABLES

#      MULTI-TABLES: Hex dump of section '.debug_info':
# MULTI-TABLES-NEXT: 0x00000000 0c000000 04000800 00000801 34120000 ............4...
##                              ^-------                            unit_length (4-byte)
##                                       ^---                       version (2-byte)
##                                           ^--------              debug_abbrev_offset (4-byte)
##                                                    ^-            address_size (1-byte)
##                                                      ^-          abbrev_code (ULEB128) 0x01
##                                                         ^------- Form: DW_FORM_data4 (4-byte) 0x1234
# MULTI-TABLES-NEXT: 0x00000010 0c000000 04000800 00000801 21430000 ............!C..
##                              ^-------                            unit_length (4-byte)
##                                       ^---                       version (2-byte)
##                                           ^--------              debug_abbrev_offset (4-byte)
##                                                    ^-            address_size (1-byte)
##                                                      ^-          abbrev_code (ULEB128) 0x01
##                                                         ^------- Form: DW_FORM_data4 (4-byte) 0x4321
# MULTI-TABLES-NEXT: 0x00000020 10000000 04000000 00000801 78560000 ............xV..
##                              ^-------                            unit_length (4-byte)
##                                       ^---                       version (2-byte)
##                                           ^--------              debug_abbrev_offset (4-byte)
##                                                    ^-            address_size (1-byte)
##                                                      ^-          abbrev_code (ULEB128) 0x01
##                                                         ^------- Form: DW_FORM_addr (8-byte) 0x5678
# MULTI-TABLES-NEXT: 0x00000030 00000000 0b000000 04001000 00000801 ................
##                              --------
##                                       ^-------                   unit_length (4-byte)
##                                                ^---              version (2-byte)
##                                                    ^--------     debug_abbrev_offset (4-byte)
##                                                             ^-   address_size (1-byte)
##                                                               ^- abbrev_code (ULEB128) 0x01
# MULTI-TABLES-NEXT: 0x00000040 e58e02                              ...
##                              ^-----                              Form: DW_FORM_udata (ULEB128) 0x8765

--- !ELF
FileHeader:
  Class:   ELFCLASS64
  Data:    ELFDATA2LSB
  Type:    ET_EXEC
DWARF:
  debug_abbrev:
    - Table:
        - Code:     1
          Tag:      DW_TAG_compile_unit
          Children: DW_CHILDREN_no
          Attributes:
            - Attribute: DW_AT_low_pc
              Form:      DW_FORM_addr
    - ID: 2
      Table:
        - Code:     1
          Tag:      DW_TAG_compile_unit
          Children: DW_CHILDREN_no
          Attributes:
            - Attribute: DW_AT_low_pc
              Form:      DW_FORM_data4
    - ID: 1
      Table:
        - Code:     1
          Tag:      DW_TAG_compile_unit
          Children: DW_CHILDREN_no
          Attributes:
            - Attribute: DW_AT_low_pc
              Form:      DW_FORM_udata
  debug_info:
    - Version:       4
      AbbrevTableID: 2
      Entries:
        - AbbrCode: 1
          Values:
            - Value: 0x1234
    - Version:       4
      AbbrevTableID: 2
      Entries:
        - AbbrCode: 1
          Values:
            - Value: 0x4321
    - Version:       4
      AbbrevTableID: 0
      Entries:
        - AbbrCode: 1
          Values:
            - Value: 0x5678
    - Version:       4
      AbbrevTableID: 1
      Entries:
        - AbbrCode: 1
          Values:
            - Value: 0x8765

## p) Test that when the debug_abbrev_offset field isn't specified and there is no associated
## abbrev table, yaml2obj will assign 0 to the debug_abbrev_offset field.

# RUN: yaml2obj --docnum=18 %s -o %t18.o
# RUN: llvm-readelf --hex-dump=.debug_info %t18.o | FileCheck %s --check-prefix=ZERO-OFFSET

#      ZERO-OFFSET: Hex dump of section '.debug_info':
# ZERO-OFFSET-NEXT: 0x00000000 07000000 04000000 000008            ...........
##                             ^-------                            unit_length (4-byte)
##                                      ^---                       version (2-byte)
##                                          ^--------              debug_abbrev_offset (4-byte)
##                                                   ^-            address_size (1-byte)

--- !ELF
FileHeader:
  Class:   ELFCLASS64
  Data:    ELFDATA2LSB
  Type:    ET_EXEC
DWARF:
  debug_info:
    - Version:       4
      AbbrevTableID: [[ABBREVID=<none>]]

## q) Test that when we assign an invalid 'AbbrevTableID' that doesn't point to an abbrev table,
## yaml2obj will assign 0 to the debug_abbrev_offset field.

# RUN: yaml2obj --docnum=18 -DABBREVID=2 %s -o %t18.o
# RUN: llvm-readelf --hex-dump=.debug_info %t18.o | FileCheck %s --check-prefix=ZERO-OFFSET