[PATCH] D81826: [DWARFYAML][debug_abbrev] Make the abbreviation code optional.

Xing GUO via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 15 01:36:13 PDT 2020


Higuoxing created this revision.
Higuoxing added reviewers: jhenderson, grimar, MaskRay.
Herald added subscribers: llvm-commits, hiraditya, emaste.
Herald added a reviewer: espindola.
Herald added a project: LLVM.
Higuoxing added a parent revision: D81820: [ObjectYAML][ELF] Add support for emitting the .debug_abbrev section..

This patch helps make the `Code` optional in abbreviations table.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D81826

Files:
  llvm/include/llvm/ObjectYAML/DWARFYAML.h
  llvm/lib/ObjectYAML/DWARFEmitter.cpp
  llvm/lib/ObjectYAML/DWARFYAML.cpp
  llvm/test/tools/yaml2obj/ELF/DWARF/debug-abbrev.yaml


Index: llvm/test/tools/yaml2obj/ELF/DWARF/debug-abbrev.yaml
===================================================================
--- llvm/test/tools/yaml2obj/ELF/DWARF/debug-abbrev.yaml
+++ 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: []
Index: llvm/lib/ObjectYAML/DWARFYAML.cpp
===================================================================
--- llvm/lib/ObjectYAML/DWARFYAML.cpp
+++ llvm/lib/ObjectYAML/DWARFYAML.cpp
@@ -59,7 +59,7 @@
 
 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);
Index: llvm/lib/ObjectYAML/DWARFEmitter.cpp
===================================================================
--- llvm/lib/ObjectYAML/DWARFEmitter.cpp
+++ 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) {
Index: llvm/include/llvm/ObjectYAML/DWARFYAML.h
===================================================================
--- llvm/include/llvm/ObjectYAML/DWARFYAML.h
+++ llvm/include/llvm/ObjectYAML/DWARFYAML.h
@@ -52,7 +52,7 @@
 };
 
 struct Abbrev {
-  llvm::yaml::Hex32 Code;
+  Optional<llvm::yaml::Hex64> Code;
   llvm::dwarf::Tag Tag;
   llvm::dwarf::Constants Children;
   std::vector<AttributeAbbrev> Attributes;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D81826.270678.patch
Type: text/x-patch
Size: 3408 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200615/b4a52801/attachment.bin>


More information about the llvm-commits mailing list