diff --git a/llvm/include/llvm/ObjectYAML/DWARFYAML.h b/llvm/include/llvm/ObjectYAML/DWARFYAML.h --- a/llvm/include/llvm/ObjectYAML/DWARFYAML.h +++ b/llvm/include/llvm/ObjectYAML/DWARFYAML.h @@ -52,7 +52,7 @@ }; struct Abbrev { - llvm::yaml::Hex32 Code; + Optional Code; llvm::dwarf::Tag Tag; llvm::dwarf::Constants Children; std::vector Attributes; diff --git a/llvm/lib/ObjectYAML/DWARFEmitter.cpp b/llvm/lib/ObjectYAML/DWARFEmitter.cpp --- a/llvm/lib/ObjectYAML/DWARFEmitter.cpp +++ b/llvm/lib/ObjectYAML/DWARFEmitter.cpp @@ -89,8 +89,11 @@ } Error DWARFYAML::emitDebugAbbrev(raw_ostream &OS, const DWARFYAML::Data &DI) { + uint64_t AbbrevCode = 0; for (auto AbbrevDecl : DI.AbbrevDecls) { - encodeULEB128(AbbrevDecl.Code, OS); + AbbrevCode = + AbbrevDecl.Code ? (uint64_t) * (AbbrevDecl.Code) : AbbrevCode + 1; + encodeULEB128(AbbrevCode, OS); encodeULEB128(AbbrevDecl.Tag, OS); OS.write(AbbrevDecl.Children); for (auto Attr : AbbrevDecl.Attributes) { diff --git a/llvm/lib/ObjectYAML/DWARFYAML.cpp b/llvm/lib/ObjectYAML/DWARFYAML.cpp --- a/llvm/lib/ObjectYAML/DWARFYAML.cpp +++ b/llvm/lib/ObjectYAML/DWARFYAML.cpp @@ -59,7 +59,7 @@ void MappingTraits::mapping(IO &IO, DWARFYAML::Abbrev &Abbrev) { - IO.mapRequired("Code", Abbrev.Code); + IO.mapOptional("Code", Abbrev.Code); IO.mapRequired("Tag", Abbrev.Tag); IO.mapRequired("Children", Abbrev.Children); IO.mapRequired("Attributes", Abbrev.Attributes); diff --git a/llvm/test/tools/yaml2obj/ELF/DWARF/debug-abbrev.yaml b/llvm/test/tools/yaml2obj/ELF/DWARF/debug-abbrev.yaml --- a/llvm/test/tools/yaml2obj/ELF/DWARF/debug-abbrev.yaml +++ b/llvm/test/tools/yaml2obj/ELF/DWARF/debug-abbrev.yaml @@ -245,3 +245,43 @@ Tag: DW_TAG_compile_unit Children: DW_CHILDREN_no Attributes: [] + +## h) Test that yaml2obj automatically generates abbreviation codes for us. + +# RUN: yaml2obj --docnum=8 %s -o %t8.o +# RUN: llvm-readelf --hex-dump=.debug_abbrev %t8.o | FileCheck %s --check-prefix=CODE + +# CODE: 0x00000000 01110000 00022e00 0000042e 00000005 +## | | | | +## | | | +- abbreviation code (ULEB128) 0x05 +## | | +- abbreviation code (ULEB128) 0x04 +## | +- abbreviation code (ULEB128) 0x02 +## +- abbreviation code (ULEB128) 0x01 +# CODE-NEXT: 0x00000010 2e000000 062e0000 00 +## | +## +- abbreviation code (ULEB128) 0x06 + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_EXEC + Machine: EM_X86_64 +DWARF: + debug_abbrev: + - Tag: DW_TAG_compile_unit + Children: DW_CHILDREN_no + Attributes: [] + - Tag: DW_TAG_subprogram + Children: DW_CHILDREN_no + Attributes: [] + - Code: 4 + Tag: DW_TAG_subprogram + Children: DW_CHILDREN_no + Attributes: [] + - Tag: DW_TAG_subprogram + Children: DW_CHILDREN_no + Attributes: [] + - Tag: DW_TAG_subprogram + Children: DW_CHILDREN_no + Attributes: []