diff --git a/llvm/lib/ObjectYAML/DWARFVisitor.cpp b/llvm/lib/ObjectYAML/DWARFVisitor.cpp --- a/llvm/lib/ObjectYAML/DWARFVisitor.cpp +++ b/llvm/lib/ObjectYAML/DWARFVisitor.cpp @@ -48,13 +48,16 @@ onStartCompileUnit(Unit); if (Unit.Entries.size() == 0) continue; - auto FirstAbbrevCode = Unit.Entries[0].AbbrCode; for (auto &Entry : Unit.Entries) { onStartDIE(Unit, Entry); - if (Entry.AbbrCode == 0u) + uint32_t AbbrCode = Entry.AbbrCode; + if (AbbrCode == 0 || Entry.Values.size() == 0) continue; - auto &Abbrev = DebugInfo.AbbrevDecls[Entry.AbbrCode - FirstAbbrevCode]; + + // TODO: Add error handling and test this error. + assert(AbbrCode <= DebugInfo.AbbrevDecls.size()); + auto &Abbrev = DebugInfo.AbbrevDecls[AbbrCode - 1]; auto FormVal = Entry.Values.begin(); auto AbbrForm = Abbrev.Attributes.begin(); for (; diff --git a/llvm/test/tools/yaml2obj/ELF/DWARF/debug-info.yaml b/llvm/test/tools/yaml2obj/ELF/DWARF/debug-info.yaml --- a/llvm/test/tools/yaml2obj/ELF/DWARF/debug-info.yaml +++ b/llvm/test/tools/yaml2obj/ELF/DWARF/debug-info.yaml @@ -540,3 +540,86 @@ 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=8 %s -o %t8.o +# RUN: llvm-readelf --hex-dump=.debug_info %t8.o | FileCheck %s --check-prefix=FORM + +# FORM: Hex dump of section '.debug_info': +# FORM-NEXT: 0x00000000 34120000 05000204 34120000 00023412 +## ^------- unit_length (4-byte) +## ^- abbreviation code (ULEB128) +## ^- abbreviation code (ULEB128) +## ^--- Form: DW_FORM_data2 (2-byte) +# FORM-NEXT: 0x00000010 21436587 01214365 87341234 12000005 +## ^------- Form: DW_FORM_data4 (4-byte) +## ^- abbreviation code (ULEB128) +## ^-------- Form: DW_FORM_data4 (4-byte) +## ^--- Form: DW_FORM_data2 (2-byte) +## ^-------- unit_length (4-byte) +# FORM-NEXT: 0x00000020 00020434 12000002 34127856 3412 +## ^- abbreviation code (ULEB128) +## ^--- Form: DW_FORM_data2 (2-byte) +## ^-------- Form: DW_FORM_data4 (4-byte) + +--- !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: + TotalLength: 0x1234 + Version: 5 + UnitType: DW_UT_type + AbbrOffset: 0x1234 + AddrSize: 4 + Entries: + ## Test that yaml2obj ignores entries whose abbreviation code is 0. + - AbbrCode: 0 + Values: + - Value: 0x1234 + ## Test that yaml2obj emits values using the abbreviation whose index is 2 + ## according to the 'AbbrCode'. + - AbbrCode: 2 + Values: + - Value: 0x1234 + - Value: 0x87654321 + ## Test that yaml2obj emits values using the abbreviation whose index is 1 + ## according to the 'AbbrCode'. + - AbbrCode: 1 + Values: + - Value: 0x87654321 + - Value: 0x1234 + - Length: + TotalLength: 0x1234 + Version: 5 + UnitType: DW_UT_type + AbbrOffset: 0x1234 + AddrSize: 4 + Entries: + ## Test that yaml2obj uses the same abbreviation table to generate values + ## across different compilation units. + - AbbrCode: 2 + Values: + - Value: 0x1234 + - Value: 0x12345678