[llvm] d261a1c - [DWARFYAML][debug_abbrev] Make the abbreviation code optional.
Xing GUO via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 17 21:58:55 PDT 2020
Author: Xing GUO
Date: 2020-06-18T13:02:54+08:00
New Revision: d261a1c0e0e5962ec1a42841692b47aca655e3a0
URL: https://github.com/llvm/llvm-project/commit/d261a1c0e0e5962ec1a42841692b47aca655e3a0
DIFF: https://github.com/llvm/llvm-project/commit/d261a1c0e0e5962ec1a42841692b47aca655e3a0.diff
LOG: [DWARFYAML][debug_abbrev] Make the abbreviation code optional.
This patch helps make the `Code` optional in abbreviations table.
Reviewed By: jhenderson
Differential Revision: https://reviews.llvm.org/D81826
Added:
Modified:
llvm/include/llvm/ObjectYAML/DWARFYAML.h
llvm/lib/ObjectYAML/DWARFEmitter.cpp
llvm/lib/ObjectYAML/DWARFYAML.cpp
llvm/test/ObjectYAML/MachO/DWARF-BigEndian.yaml
llvm/test/ObjectYAML/MachO/DWARF-LittleEndian.yaml
llvm/test/ObjectYAML/MachO/DWARF-debug_abbrev.yaml
llvm/test/ObjectYAML/MachO/DWARF5-abbrevValues.yaml
llvm/test/tools/yaml2obj/ELF/DWARF/debug-abbrev.yaml
Removed:
################################################################################
diff --git a/llvm/include/llvm/ObjectYAML/DWARFYAML.h b/llvm/include/llvm/ObjectYAML/DWARFYAML.h
index efa28d422431..f6dc4e07dc1a 100644
--- a/llvm/include/llvm/ObjectYAML/DWARFYAML.h
+++ b/llvm/include/llvm/ObjectYAML/DWARFYAML.h
@@ -52,7 +52,7 @@ struct AttributeAbbrev {
};
struct Abbrev {
- llvm::yaml::Hex32 Code;
+ Optional<yaml::Hex64> Code;
llvm::dwarf::Tag Tag;
llvm::dwarf::Constants Children;
std::vector<AttributeAbbrev> Attributes;
diff --git a/llvm/lib/ObjectYAML/DWARFEmitter.cpp b/llvm/lib/ObjectYAML/DWARFEmitter.cpp
index ab14a30dcc09..6c60f0423c00 100644
--- a/llvm/lib/ObjectYAML/DWARFEmitter.cpp
+++ b/llvm/lib/ObjectYAML/DWARFEmitter.cpp
@@ -94,8 +94,10 @@ Error DWARFYAML::emitDebugStr(raw_ostream &OS, const DWARFYAML::Data &DI) {
}
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
index d87a45c85275..3043463ba8f8 100644
--- a/llvm/lib/ObjectYAML/DWARFYAML.cpp
+++ b/llvm/lib/ObjectYAML/DWARFYAML.cpp
@@ -62,7 +62,7 @@ void MappingTraits<DWARFYAML::Data>::mapping(IO &IO, DWARFYAML::Data &DWARF) {
void MappingTraits<DWARFYAML::Abbrev>::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
index c6a45cd36eab..67bcf1dbd4fe 100644
--- a/llvm/test/ObjectYAML/MachO/DWARF-BigEndian.yaml
+++ b/llvm/test/ObjectYAML/MachO/DWARF-BigEndian.yaml
@@ -386,7 +386,7 @@ DWARF:
#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 @@ DWARF:
#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 @@ DWARF:
#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 @@ DWARF:
#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 @@ DWARF:
#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 @@ DWARF:
#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 @@ DWARF:
#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
index 1e136e67be13..47ca338e5887 100644
--- a/llvm/test/ObjectYAML/MachO/DWARF-LittleEndian.yaml
+++ b/llvm/test/ObjectYAML/MachO/DWARF-LittleEndian.yaml
@@ -375,7 +375,7 @@ DWARF:
#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 @@ DWARF:
#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 @@ DWARF:
#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 @@ DWARF:
#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 @@ DWARF:
#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 @@ DWARF:
#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 @@ DWARF:
#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
index 8301aa69172a..bcdce34600a1 100644
--- a/llvm/test/ObjectYAML/MachO/DWARF-debug_abbrev.yaml
+++ b/llvm/test/ObjectYAML/MachO/DWARF-debug_abbrev.yaml
@@ -349,7 +349,7 @@ DWARF:
#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 @@ DWARF:
#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 @@ DWARF:
#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 @@ DWARF:
#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 @@ DWARF:
#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
index 817830d35420..c4563fe2e9c2 100644
--- a/llvm/test/ObjectYAML/MachO/DWARF5-abbrevValues.yaml
+++ b/llvm/test/ObjectYAML/MachO/DWARF5-abbrevValues.yaml
@@ -286,7 +286,7 @@ DWARF:
#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
index f809fec46495..eba30652dc2d 100644
--- a/llvm/test/tools/yaml2obj/ELF/DWARF/debug-abbrev.yaml
+++ b/llvm/test/tools/yaml2obj/ELF/DWARF/debug-abbrev.yaml
@@ -239,3 +239,47 @@ DWARF:
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
+## ^- abbreviation code ULEB128
+## ^- abbreviation code (ULEB128) 0x04
+## ^- abbreviation code (ULEB128) 0x04
+##
+# CODE-NEXT: 0x00000010 2e000000 052e0000 00062e00 0000
+## ^- abbreviation code ULEB128
+## ^- abbreviation code ULEB128
+
+--- !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: []
More information about the llvm-commits
mailing list