diff --git a/llvm/lib/ObjectYAML/DWARFVisitor.cpp b/llvm/lib/ObjectYAML/DWARFVisitor.cpp index f478a1b84397..a2dd37b5fe32 100644 --- a/llvm/lib/ObjectYAML/DWARFVisitor.cpp +++ b/llvm/lib/ObjectYAML/DWARFVisitor.cpp @@ -1,190 +1,196 @@ //===--- DWARFVisitor.cpp ---------------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // //===----------------------------------------------------------------------===// #include "DWARFVisitor.h" #include "llvm/BinaryFormat/Dwarf.h" #include "llvm/ObjectYAML/DWARFYAML.h" #include "llvm/Support/Errc.h" #include "llvm/Support/Error.h" using namespace llvm; template void DWARFYAML::VisitorImpl::onVariableSizeValue(uint64_t U, unsigned Size) { switch (Size) { case 8: onValue((uint64_t)U); break; case 4: onValue((uint32_t)U); break; case 2: onValue((uint16_t)U); break; case 1: onValue((uint8_t)U); break; default: llvm_unreachable("Invalid integer write size."); } } static unsigned getOffsetSize(const DWARFYAML::Unit &Unit) { return Unit.Format == dwarf::DWARF64 ? 8 : 4; } static unsigned getRefSize(const DWARFYAML::Unit &Unit) { if (Unit.Version == 2) return Unit.AddrSize; return getOffsetSize(Unit); } template Error DWARFYAML::VisitorImpl::traverseDebugInfo() { for (auto &Unit : DebugInfo.CompileUnits) { onStartCompileUnit(Unit); if (Unit.Entries.empty()) continue; for (auto &Entry : Unit.Entries) { onStartDIE(Unit, Entry); uint32_t AbbrCode = Entry.AbbrCode; if (AbbrCode == 0 || Entry.Values.empty()) continue; if (AbbrCode > DebugInfo.AbbrevDecls.size()) return createStringError( errc::invalid_argument, "abbrev code must be less than or equal to the number of " "entries in abbreviation table"); const DWARFYAML::Abbrev &Abbrev = DebugInfo.AbbrevDecls[AbbrCode - 1]; auto FormVal = Entry.Values.begin(); auto AbbrForm = Abbrev.Attributes.begin(); for (; FormVal != Entry.Values.end() && AbbrForm != Abbrev.Attributes.end(); ++FormVal, ++AbbrForm) { onForm(*AbbrForm, *FormVal); dwarf::Form Form = AbbrForm->Form; bool Indirect; do { Indirect = false; switch (Form) { case dwarf::DW_FORM_addr: onVariableSizeValue(FormVal->Value, Unit.AddrSize); break; case dwarf::DW_FORM_ref_addr: onVariableSizeValue(FormVal->Value, getRefSize(Unit)); break; case dwarf::DW_FORM_exprloc: case dwarf::DW_FORM_block: onValue((uint64_t)FormVal->BlockData.size(), true); onValue( MemoryBufferRef(StringRef((const char *)&FormVal->BlockData[0], FormVal->BlockData.size()), "")); break; case dwarf::DW_FORM_block1: { auto writeSize = FormVal->BlockData.size(); onValue((uint8_t)writeSize); onValue( MemoryBufferRef(StringRef((const char *)&FormVal->BlockData[0], FormVal->BlockData.size()), "")); break; } case dwarf::DW_FORM_block2: { auto writeSize = FormVal->BlockData.size(); onValue((uint16_t)writeSize); onValue( MemoryBufferRef(StringRef((const char *)&FormVal->BlockData[0], FormVal->BlockData.size()), "")); break; } case dwarf::DW_FORM_block4: { auto writeSize = FormVal->BlockData.size(); onValue((uint32_t)writeSize); onValue( MemoryBufferRef(StringRef((const char *)&FormVal->BlockData[0], FormVal->BlockData.size()), "")); break; } + case dwarf::DW_FORM_strx: + case dwarf::DW_FORM_addrx: + case dwarf::DW_FORM_rnglistx: + case dwarf::DW_FORM_loclistx: + onValue((uint64_t)FormVal->Value, /*LEB=*/true); + break; case dwarf::DW_FORM_data1: case dwarf::DW_FORM_ref1: case dwarf::DW_FORM_flag: case dwarf::DW_FORM_strx1: case dwarf::DW_FORM_addrx1: onValue((uint8_t)FormVal->Value); break; case dwarf::DW_FORM_data2: case dwarf::DW_FORM_ref2: case dwarf::DW_FORM_strx2: case dwarf::DW_FORM_addrx2: onValue((uint16_t)FormVal->Value); break; case dwarf::DW_FORM_data4: case dwarf::DW_FORM_ref4: case dwarf::DW_FORM_ref_sup4: case dwarf::DW_FORM_strx4: case dwarf::DW_FORM_addrx4: onValue((uint32_t)FormVal->Value); break; case dwarf::DW_FORM_data8: case dwarf::DW_FORM_ref8: case dwarf::DW_FORM_ref_sup8: onValue((uint64_t)FormVal->Value); break; case dwarf::DW_FORM_sdata: onValue((int64_t)FormVal->Value, true); break; case dwarf::DW_FORM_udata: case dwarf::DW_FORM_ref_udata: onValue((uint64_t)FormVal->Value, true); break; case dwarf::DW_FORM_string: onValue(FormVal->CStr); break; case dwarf::DW_FORM_indirect: onValue((uint64_t)FormVal->Value, true); Indirect = true; Form = static_cast((uint64_t)FormVal->Value); ++FormVal; break; case dwarf::DW_FORM_strp: case dwarf::DW_FORM_sec_offset: case dwarf::DW_FORM_GNU_ref_alt: case dwarf::DW_FORM_GNU_strp_alt: case dwarf::DW_FORM_line_strp: case dwarf::DW_FORM_strp_sup: onVariableSizeValue(FormVal->Value, getOffsetSize(Unit)); break; case dwarf::DW_FORM_ref_sig8: onValue((uint64_t)FormVal->Value); break; case dwarf::DW_FORM_GNU_addr_index: case dwarf::DW_FORM_GNU_str_index: onValue((uint64_t)FormVal->Value, true); break; default: break; } } while (Indirect); } onEndDIE(Unit, Entry); } onEndCompileUnit(Unit); } return Error::success(); } // Explicitly instantiate the two template expansions. template class DWARFYAML::VisitorImpl; template class DWARFYAML::VisitorImpl; diff --git a/llvm/test/tools/yaml2obj/ELF/DWARF/debug-info.yaml b/llvm/test/tools/yaml2obj/ELF/DWARF/debug-info.yaml index 896a9b472887..177de3ee816e 100644 --- a/llvm/test/tools/yaml2obj/ELF/DWARF/debug-info.yaml +++ b/llvm/test/tools/yaml2obj/ELF/DWARF/debug-info.yaml @@ -1,725 +1,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=171 -DADDRALIGN=1 %s --check-prefixes=SHDR,DWARF32-LE-CONTENT +# 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: 78563412 78563412 78563412 F0DEBC9A -## ^------- Form: DW_FORM_ref_sup4 (4-byte) -## ^------- Form: DW_FORM_strp_sup (4-byte) -## ^------- Form: DW_FORM_line_strp (4-byte) -## ^------- Form: DW_FORM_ref_sig8 (8-byte) -# DWARF32-LE-CONTENT-NEXT: 0070: 78563412 F0DEBC9A 78563412 12341278 +# 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_ref_sup8 (8-byte) -## ^- Form: DW_FORM_strx1 (1-byte) -## ^--- Form: DW_FORM_strx2 (2-byte) -## ^- Form: DW_FORM_strx4 (4-byte) -# DWARF32-LE-CONTENT-NEXT: 0080: 56341212 34127856 34123412 00000500 +## ^- 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 ## ------ -## ^- Form: DW_FORM_addrx1 (1-byte) -## ^--- From: DW_FORM_addrx2 (2-byte) -## ^-------- Form: DW_FORM_addrx4 (4-byte) -## ^-------- unit_length (4-byte) -## ^--- version (2-byte) -# DWARF32-LE-CONTENT-NEXT: 0090: 01043412 00000078 56000004 00785600 -## ^- unit_type (1-byte) DW_UT_compile -## ^- address_size (4-byte) -## ^-------- debug_abbrev_offset (4-byte) -## ^-------- unit_length (4-byte) -## ^--- version (2-byte) -## ^- abbreviation code (ULEB128) -## ^----- debug_abbrev_offset (4-byte) -# DWARF32-LE-CONTENT-NEXT: 00A0: 00040178 56341202 001234 +## ^---- 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 ## -- -## ^- address_size (1-byte) -## ^- abbreviation code (ULEB128) 0x01 -## ^-------- Form: DW_FORM_addr (4-byte) -## ^---- Form: DW_FORM_block2 size (2-byte) -## ^-^- Form: DW_FORM_block2 body (2-byte) +## ^-^- 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 (unimplemented) - - Value: 0x1234 ## DW_FORM_addrx (unimplemented) + - 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 (unimplemented) - - Value: 0x1234 ## DW_FORM_rnglistx (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=171 -DADDRALIGN=1 %s --check-prefixes=SHDR,DWARF32-BE-CONTENT +# 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: 12345678 12345678 12345678 12345678 -## ^------- Form: DW_FORM_ref_sup4 (4-byte) -## ^------- Form: DW_FORM_strp_sup (4-byte) -## ^------- Form: DW_FORM_line_strp (4-byte) -## ^------- Form: DW_FORM_ref_sig8 (8-byte) -# DWARF32-BE-CONTENT-NEXT: 0070: 9ABCDEF0 12345678 9ABCDEF0 12123412 +# 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_ref_sup8 (8-byte) -## ^- Form: DW_FORM_strx1 (1-byte) -## ^--- Form: DW_FORM_strx2 (2-byte) -## ^- Form: DW_FORM_strx4 (4-byte) -# DWARF32-BE-CONTENT-NEXT: 0080: 34567812 12341234 56780000 12340005 +## ^- 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 ## ------ -## ^- Form: DW_FORM_addrx1 (1-byte) -## ^--- From: DW_FORM_addrx2 (2-byte) -## ^-------- Form: DW_FORM_addrx4 (4-byte) -## ^-------- unit_length (4-byte) -## ^--- version (2-byte) -# DWARF32-BE-CONTENT-NEXT: 0090: 01040000 12340000 00567800 04000056 -## ^- unit_type (1-byte) DW_UT_compile -## ^- address_size (4-byte) -## ^-------- debug_abbrev_offset (4-byte) -## ^-------- unit_length (4-byte) -## ^--- version (2-byte) -## ^- abbreviation code (ULEB128) -## ^----- debug_abbrev_offset (4-byte) -# DWARF32-BE-CONTENT-NEXT: 00A0: 78040112 34567800 021234 +## ^---- 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 ## -- -## ^- address_size (1-byte) -## ^- abbreviation code (ULEB128) 0x01 -## ^-------- Form: DW_FORM_addr (4-byte) -## ^---- Form: DW_FORM_block2 size (2-byte) -## ^-^- Form: DW_FORM_block2 body (2-byte) +## ^-^- 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: []