[llvm] 3a48a63 - [DWARFYAML][debug_info] Use 'AbbrCode' to index the abbreviation.

Xing GUO via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 22 06:29:55 PDT 2020


Author: Xing GUO
Date: 2020-06-22T21:34:02+08:00
New Revision: 3a48a632d00ef1c98042140f402337fe13cdff52

URL: https://github.com/llvm/llvm-project/commit/3a48a632d00ef1c98042140f402337fe13cdff52
DIFF: https://github.com/llvm/llvm-project/commit/3a48a632d00ef1c98042140f402337fe13cdff52.diff

LOG: [DWARFYAML][debug_info] Use 'AbbrCode' to index the abbreviation.

Before this patch, we use `(uint32_t)AbbrCode - (uint32_t)FirstAbbrCode` to index the abbreviation. It's impossible for we to use the preceeding abbreviation of the previous one (e.g., if the previous DIE's `AbbrCode` is 2, we are unable to use the abbreviation with index 1). In this patch, we use `AbbrCode` to index the abbreviation directly.

Reviewed By: jhenderson

Differential Revision: https://reviews.llvm.org/D82173

Added: 
    

Modified: 
    llvm/lib/ObjectYAML/DWARFVisitor.cpp
    llvm/test/tools/yaml2obj/ELF/DWARF/debug-info.yaml

Removed: 
    


################################################################################
diff  --git a/llvm/lib/ObjectYAML/DWARFVisitor.cpp b/llvm/lib/ObjectYAML/DWARFVisitor.cpp
index fa443cf9e00d..99edb57153f4 100644
--- a/llvm/lib/ObjectYAML/DWARFVisitor.cpp
+++ b/llvm/lib/ObjectYAML/DWARFVisitor.cpp
@@ -10,6 +10,7 @@
 
 #include "DWARFVisitor.h"
 #include "llvm/ObjectYAML/DWARFYAML.h"
+#include "llvm/Support/ErrorHandling.h"
 
 using namespace llvm;
 
@@ -48,13 +49,19 @@ template <typename T> void DWARFYAML::VisitorImpl<T>::traverseDebugInfo() {
     onStartCompileUnit(Unit);
     if (Unit.Entries.empty())
       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.empty())
         continue;
-      auto &Abbrev = DebugInfo.AbbrevDecls[Entry.AbbrCode - FirstAbbrevCode];
+
+      if (AbbrCode > DebugInfo.AbbrevDecls.size())
+        // TODO: Handle and test this error.
+        report_fatal_error(
+            "abbrev code must be less than or equal to the number of "
+            "entries in abbreviation table");
+      const DWARFYAML::Abbrev &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
index 4811992e91e5..1061d90ae167 100644
--- a/llvm/test/tools/yaml2obj/ELF/DWARF/debug-info.yaml
+++ b/llvm/test/tools/yaml2obj/ELF/DWARF/debug-info.yaml
@@ -419,9 +419,9 @@ Sections:
 ## d) Test that yaml2obj emits an error message when both the "Size" and the
 ## "debug_info" entry are specified at the same time.
 
-# RUN: not yaml2obj --docnum=4 %s 2>&1 | FileCheck %s --check-prefix=ERROR
+# RUN: not yaml2obj --docnum=4 %s 2>&1 | FileCheck %s --check-prefix=AMBIGUOUS-CONTENT
 
-# ERROR: yaml2obj: error: cannot specify section '.debug_info' contents in the 'DWARF' entry and the 'Content' or 'Size' in the 'Sections' entry at the same time
+# AMBIGUOUS-CONTENT: yaml2obj: error: cannot specify section '.debug_info' contents in the 'DWARF' entry and the 'Content' or 'Size' in the 'Sections' entry at the same time
 
 --- !ELF
 FileHeader:
@@ -451,7 +451,7 @@ DWARF:
 ## e) Test that yaml2obj emits an error message when both the "Content" and the
 ## "debug_info" entry are specified at the same time.
 
-# RUN: not yaml2obj --docnum=5 %s 2>&1 | FileCheck %s --check-prefix=ERROR
+# RUN: not yaml2obj --docnum=5 %s 2>&1 | FileCheck %s --check-prefix=AMBIGUOUS-CONTENT
 
 --- !ELF
 FileHeader:
@@ -575,3 +575,97 @@ DWARF:
       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=9 %s -o %t9.o
+# RUN: llvm-readelf --hex-dump=.debug_info %t9.o | \
+# RUN:   FileCheck %s --check-prefix=FORM --match-full-lines
+
+#       FORM: Hex dump of section '.debug_info':
+#  FORM-NEXT: 0x00000000 34120000 05000204 34120000 02341221 4.......4....4.!
+##                       ^-------                            unit_length (4-byte)
+##                                                  ^-       abbreviation code (ULEB128)
+##                                                    ^---   Form: DW_FORM_data2 (2-byte)
+##                                                        ^- Form: DW_FORM_data4 (4-byte)
+#  FORM-NEXT: 0x00000010 43658701 21436587 341200            Ce..!Ce.4..
+##                       ------
+##                             ^-                            abbreviation code (ULEB128)
+##                                ^-------                   Form: DW_FORM_data4 (4-byte)
+##                                         ^---              Form: DW_FORM_data2 (2-byte)
+##                                             ^-            abbreviation code (ULEB128)
+# FORM-EMPTY:
+
+--- !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 emits values when the abbrev code is specified.
+        - AbbrCode: 2
+          Values:
+            - Value: 0x1234
+            - Value: 0x87654321
+        ## Test that yaml2obj emits values when the abbrev code is specified to
+        ## be lower than the first abbrev.
+        - AbbrCode: 1
+          Values:
+            - Value: 0x87654321
+            - Value: 0x1234
+        ## Test that yaml2obj ignores the contents of entries with abbrev code 0.
+        - AbbrCode: 0
+          Values:
+            - Value: 0x1234
+
+## i) Test that yaml2obj reports a fatal error when 'debug_info' has values in its
+## entries but 'debug_abbrev' doesn't have enough attributes for them.
+
+# RUN: not --crash yaml2obj --docnum=10 %s -o %t10.o 2>&1 | \
+# RUN:   FileCheck %s --check-prefixes=FATAL
+
+# FATAL: LLVM ERROR: abbrev code must be less than or equal to the number of entries in abbreviation table
+
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS64
+  Data:    ELFDATA2LSB
+  Type:    ET_EXEC
+  Machine: EM_X86_64
+DWARF:
+  debug_info:
+    - Length:
+        TotalLength: 0x1234
+      Version:    5
+      UnitType:   DW_UT_type
+      AbbrOffset: 0x1234
+      AddrSize:   4
+      Entries:
+        - AbbrCode: 1
+          Values:
+            - Value: 0x1234


        


More information about the llvm-commits mailing list