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,10 @@ } 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/ObjectYAML/MachO/DWARF-BigEndian.yaml b/llvm/test/ObjectYAML/MachO/DWARF-BigEndian.yaml --- a/llvm/test/ObjectYAML/MachO/DWARF-BigEndian.yaml +++ b/llvm/test/ObjectYAML/MachO/DWARF-BigEndian.yaml @@ -386,7 +386,7 @@ #CHECK: - N #CHECK: - t #CHECK: debug_abbrev: -#CHECK: - Code: 0x00000001 +#CHECK: - Code: 0x0000000000000001 #CHECK: Tag: DW_TAG_compile_unit #CHECK: Children: DW_CHILDREN_yes #CHECK: Attributes: @@ -404,7 +404,7 @@ #CHECK: Form: DW_FORM_addr #CHECK: - Attribute: DW_AT_high_pc #CHECK: Form: DW_FORM_data4 -#CHECK: - Code: 0x00000002 +#CHECK: - Code: 0x0000000000000002 #CHECK: Tag: DW_TAG_base_type #CHECK: Children: DW_CHILDREN_no #CHECK: Attributes: @@ -414,7 +414,7 @@ #CHECK: Form: DW_FORM_data1 #CHECK: - Attribute: DW_AT_byte_size #CHECK: Form: DW_FORM_data1 -#CHECK: - Code: 0x00000003 +#CHECK: - Code: 0x0000000000000003 #CHECK: Tag: DW_TAG_typedef #CHECK: Children: DW_CHILDREN_no #CHECK: Attributes: @@ -426,7 +426,7 @@ #CHECK: Form: DW_FORM_data1 #CHECK: - Attribute: DW_AT_decl_line #CHECK: Form: DW_FORM_data1 -#CHECK: - Code: 0x00000004 +#CHECK: - Code: 0x0000000000000004 #CHECK: Tag: DW_TAG_subprogram #CHECK: Children: DW_CHILDREN_yes #CHECK: Attributes: @@ -448,7 +448,7 @@ #CHECK: Form: DW_FORM_ref4 #CHECK: - Attribute: DW_AT_external #CHECK: Form: DW_FORM_flag_present -#CHECK: - Code: 0x00000005 +#CHECK: - Code: 0x0000000000000005 #CHECK: Tag: DW_TAG_formal_parameter #CHECK: Children: DW_CHILDREN_no #CHECK: Attributes: @@ -462,7 +462,7 @@ #CHECK: Form: DW_FORM_data1 #CHECK: - Attribute: DW_AT_type #CHECK: Form: DW_FORM_ref4 -#CHECK: - Code: 0x00000006 +#CHECK: - Code: 0x0000000000000006 #CHECK: Tag: DW_TAG_variable #CHECK: Children: DW_CHILDREN_no #CHECK: Attributes: @@ -476,7 +476,7 @@ #CHECK: Form: DW_FORM_data1 #CHECK: - Attribute: DW_AT_type #CHECK: Form: DW_FORM_ref4 -#CHECK: - Code: 0x00000007 +#CHECK: - Code: 0x0000000000000007 #CHECK: Tag: DW_TAG_const_type #CHECK: Children: DW_CHILDREN_no #CHECK: Attributes: diff --git a/llvm/test/ObjectYAML/MachO/DWARF-LittleEndian.yaml b/llvm/test/ObjectYAML/MachO/DWARF-LittleEndian.yaml --- a/llvm/test/ObjectYAML/MachO/DWARF-LittleEndian.yaml +++ b/llvm/test/ObjectYAML/MachO/DWARF-LittleEndian.yaml @@ -375,7 +375,7 @@ #CHECK: - N #CHECK: - t #CHECK: debug_abbrev: -#CHECK: - Code: 0x00000001 +#CHECK: - Code: 0x0000000000000001 #CHECK: Tag: DW_TAG_compile_unit #CHECK: Children: DW_CHILDREN_yes #CHECK: Attributes: @@ -393,7 +393,7 @@ #CHECK: Form: DW_FORM_addr #CHECK: - Attribute: DW_AT_high_pc #CHECK: Form: DW_FORM_data4 -#CHECK: - Code: 0x00000002 +#CHECK: - Code: 0x0000000000000002 #CHECK: Tag: DW_TAG_base_type #CHECK: Children: DW_CHILDREN_no #CHECK: Attributes: @@ -403,7 +403,7 @@ #CHECK: Form: DW_FORM_data1 #CHECK: - Attribute: DW_AT_byte_size #CHECK: Form: DW_FORM_data1 -#CHECK: - Code: 0x00000003 +#CHECK: - Code: 0x0000000000000003 #CHECK: Tag: DW_TAG_typedef #CHECK: Children: DW_CHILDREN_no #CHECK: Attributes: @@ -415,7 +415,7 @@ #CHECK: Form: DW_FORM_data1 #CHECK: - Attribute: DW_AT_decl_line #CHECK: Form: DW_FORM_data1 -#CHECK: - Code: 0x00000004 +#CHECK: - Code: 0x0000000000000004 #CHECK: Tag: DW_TAG_subprogram #CHECK: Children: DW_CHILDREN_yes #CHECK: Attributes: @@ -437,7 +437,7 @@ #CHECK: Form: DW_FORM_ref4 #CHECK: - Attribute: DW_AT_external #CHECK: Form: DW_FORM_flag_present -#CHECK: - Code: 0x00000005 +#CHECK: - Code: 0x0000000000000005 #CHECK: Tag: DW_TAG_formal_parameter #CHECK: Children: DW_CHILDREN_no #CHECK: Attributes: @@ -451,7 +451,7 @@ #CHECK: Form: DW_FORM_data1 #CHECK: - Attribute: DW_AT_type #CHECK: Form: DW_FORM_ref4 -#CHECK: - Code: 0x00000006 +#CHECK: - Code: 0x0000000000000006 #CHECK: Tag: DW_TAG_variable #CHECK: Children: DW_CHILDREN_no #CHECK: Attributes: @@ -465,7 +465,7 @@ #CHECK: Form: DW_FORM_data1 #CHECK: - Attribute: DW_AT_type #CHECK: Form: DW_FORM_ref4 -#CHECK: - Code: 0x00000007 +#CHECK: - Code: 0x0000000000000007 #CHECK: Tag: DW_TAG_const_type #CHECK: Children: DW_CHILDREN_no #CHECK: Attributes: diff --git a/llvm/test/ObjectYAML/MachO/DWARF-debug_abbrev.yaml b/llvm/test/ObjectYAML/MachO/DWARF-debug_abbrev.yaml --- a/llvm/test/ObjectYAML/MachO/DWARF-debug_abbrev.yaml +++ b/llvm/test/ObjectYAML/MachO/DWARF-debug_abbrev.yaml @@ -349,7 +349,7 @@ #CHECK: DWARF: #CHECK: debug_abbrev: -#CHECK: - Code: 0x00000001 +#CHECK: - Code: 0x0000000000000001 #CHECK: Tag: DW_TAG_compile_unit #CHECK: Children: DW_CHILDREN_yes #CHECK: Attributes: @@ -367,7 +367,7 @@ #CHECK: Form: DW_FORM_addr #CHECK: - Attribute: DW_AT_high_pc #CHECK: Form: DW_FORM_data4 -#CHECK: - Code: 0x00000002 +#CHECK: - Code: 0x0000000000000002 #CHECK: Tag: DW_TAG_subprogram #CHECK: Children: DW_CHILDREN_yes #CHECK: Attributes: @@ -389,7 +389,7 @@ #CHECK: Form: DW_FORM_ref4 #CHECK: - Attribute: DW_AT_external #CHECK: Form: DW_FORM_flag_present -#CHECK: - Code: 0x00000003 +#CHECK: - Code: 0x0000000000000003 #CHECK: Tag: DW_TAG_formal_parameter #CHECK: Children: DW_CHILDREN_no #CHECK: Attributes: @@ -403,7 +403,7 @@ #CHECK: Form: DW_FORM_data1 #CHECK: - Attribute: DW_AT_type #CHECK: Form: DW_FORM_ref4 -#CHECK: - Code: 0x00000004 +#CHECK: - Code: 0x0000000000000004 #CHECK: Tag: DW_TAG_base_type #CHECK: Children: DW_CHILDREN_no #CHECK: Attributes: @@ -413,7 +413,7 @@ #CHECK: Form: DW_FORM_data1 #CHECK: - Attribute: DW_AT_byte_size #CHECK: Form: DW_FORM_data1 -#CHECK: - Code: 0x00000005 +#CHECK: - Code: 0x0000000000000005 #CHECK: Tag: DW_TAG_pointer_type #CHECK: Children: DW_CHILDREN_no #CHECK: Attributes: diff --git a/llvm/test/ObjectYAML/MachO/DWARF5-abbrevValues.yaml b/llvm/test/ObjectYAML/MachO/DWARF5-abbrevValues.yaml --- a/llvm/test/ObjectYAML/MachO/DWARF5-abbrevValues.yaml +++ b/llvm/test/ObjectYAML/MachO/DWARF5-abbrevValues.yaml @@ -286,7 +286,7 @@ #CHECK: DWARF: #CHECK: debug_abbrev: -#CHECK: - Code: 0x00000001 +#CHECK: - Code: 0x0000000000000001 #CHECK: Tag: DW_TAG_compile_unit #CHECK: Children: DW_CHILDREN_yes #CHECK: 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 @@ -252,3 +252,49 @@ 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 00000004 +## | | | | +## | | | +- abbreviation code (ULEB128) 0x04 +## | | +- abbreviation code (ULEB128) 0x04 +## | +- abbreviation code (ULEB128) 0x02 +## +- abbreviation code (ULEB128) 0x01 +## +# CODE-NEXT: 0x00000010 2e000000 052e0000 00062e00 0000 +## | | +## | +- abbreviation code (ULEB128) 0x06 +## +- abbreviation code (ULEB128) 0x05 + +--- !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: [] + - 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: []