debug-info.yaml 34.4 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
## 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
  Machine: EM_X86_64
DWARF:
  debug_abbrev:
    - 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
      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
  Machine: EM_X86_64
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
  Machine: EM_X86_64
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
  Machine: EM_X86_64
Sections:
  - Name: .debug_info
    Type: SHT_PROGBITS
    Size: 0x10
DWARF:
  debug_abbrev:
    - Code:       1
      Tag:        DW_TAG_compile_unit
      Children:   DW_CHILDREN_no
      Attributes: []
  debug_info:
    - Length:     0x1234
      Version:    5
      UnitType:   DW_UT_type
      AbbrOffset: 0x1234
      AddrSize:   4
      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
  Machine: EM_X86_64
Sections:
  - Name: .debug_info
    Type: SHT_PROGBITS
    Content: "00"
DWARF:
  debug_abbrev:
    - Code:       1
      Tag:        DW_TAG_compile_unit
      Children:   DW_CHILDREN_no
      Attributes: []
  debug_info:
    - Length:     0x1234
      Version:    5
      UnitType:   DW_UT_type
      AbbrOffset: 0x1234
      AddrSize:   4
      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
  Machine: EM_X86_64
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
  Machine: EM_X86_64
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:
    - Code:       1
      Tag:        DW_TAG_compile_unit
      Children:   DW_CHILDREN_no
      Attributes: []
  debug_info:
    - Length:     0x1234
      Version:    5
      UnitType:   DW_UT_type
      AbbrOffset: 0x1234
      AddrSize:   4
      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:   ELFCLASS64
  Data:    ELFDATA2LSB
  Type:    ET_EXEC
  Machine: EM_X86_64
DWARF:
  debug_info:
    - Length:     0x1234
      Version:    5
      UnitType:   DW_UT_type
      AbbrOffset: 0x1234
      AddrSize:   4
      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:   ELFCLASS64
  Data:    ELFDATA2LSB
  Type:    ET_EXEC
  Machine: EM_X86_64
DWARF:
  debug_abbrev:
    - 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
      AddrSize:   4
      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
  Machine: EM_X86_64
DWARF:
  debug_info:
    - Length:     0x1234
      Version:    5
      UnitType:   DW_UT_type
      AbbrOffset: 0x1234
      AddrSize:   4
      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
  Machine: EM_X86_64
DWARF:
  debug_info:
    - Format:     DWARF64
      Length:     0x0c
      Version:    5
      UnitType:   DW_UT_type
      AbbrOffset: 0x1234
      AddrSize:   8
      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
  Machine: EM_X86_64
DWARF:
  debug_info:
    - Format:     DWARF64
      Length:     0x0c
      Version:    4
      AbbrOffset: 0x1234
      AddrSize:   8
      Entries:    []