]> granicus.if.org Git - llvm/commitdiff
[DWARF] Generalized verification of .debug_abbrev to be applicable to both .debug_abb...
authorSpyridoula Gravani <sgravani@apple.com>
Fri, 21 Jul 2017 00:51:32 +0000 (00:51 +0000)
committerSpyridoula Gravani <sgravani@apple.com>
Fri, 21 Jul 2017 00:51:32 +0000 (00:51 +0000)
Differential Revision: https://reviews.llvm.org/D35698

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@308703 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/DebugInfo/DWARF/DWARFVerifier.h
lib/DebugInfo/DWARF/DWARFVerifier.cpp
test/tools/llvm-dwarfdump/X86/verify_debug_abbrev.s [new file with mode: 0644]
test/tools/llvm-dwarfdump/X86/verify_debug_info.s

index a7564780cc23ed6ca0d9aadf8eed192505e39aff..56b34736764dfa92c7cb1cf81c9a2942c075c696 100644 (file)
@@ -22,6 +22,7 @@ class DWARFDie;
 class DWARFUnit;
 class DWARFAcceleratorTable;
 class DWARFDataExtractor;
+class DWARFDebugAbbrev;
 
 /// A class that verifies DWARF debug information given a DWARF Context.
 class DWARFVerifier {
@@ -34,6 +35,18 @@ class DWARFVerifier {
   uint32_t NumDebugLineErrors = 0;
   uint32_t NumAppleNamesErrors = 0;
 
+  /// Verifies the abbreviations section.
+  ///
+  /// This function currently checks that:
+  /// --No abbreviation declaration has more than one attributes with the same
+  /// name.
+  ///
+  /// \param Abbrev Pointer to the abbreviations section we are verifying
+  /// Abbrev can be a pointer to either .debug_abbrev or debug_abbrev.dwo.
+  ///
+  /// \returns The number of errors that occured during verification.
+  unsigned verifyAbbrevSection(const DWARFDebugAbbrev *Abbrev);
+
   /// Verifies the header of a unit in the .debug_info section.
   ///
   /// This function currently checks for:
@@ -114,13 +127,16 @@ class DWARFVerifier {
 public:
   DWARFVerifier(raw_ostream &S, DWARFContext &D)
       : OS(S), DCtx(D) {}
-  /// Verify the information in the .debug_abbrev section.
+  /// Verify the information in any of the following sections, if available:
+  /// .debug_abbrev, debug_abbrev.dwo
   ///
-  /// Currently, we check that no Abbreviation Declaration has more than one
-  /// attributes with the same name.
+  /// Any errors are reported to the stream that was this object was
+  /// constructed with.
   ///
-  /// \returns true if the .debug_abbrev verifies successfully, false otherwise.
+  /// \returns true if .debug_abbrev and .debug_abbrev.dwo verify successfully,
+  /// false otherwise.
   bool handleDebugAbbrev();
+
   /// Verify the information in the .debug_info section.
   ///
   /// Any errors are reported to the stream that was this object was
index d683642af02350aff2452e9502b53d4b2e4ab5f2..db38b63242286f0f9b08e4604dd1201746987dff 100644 (file)
@@ -102,17 +102,8 @@ bool DWARFVerifier::verifyUnitContents(DWARFUnit Unit) {
   return NumUnitErrors == 0;
 }
 
-bool DWARFVerifier::handleDebugAbbrev() {
-  OS << "Verifying .debug_abbrev...\n";
-
-  const DWARFObject &DObj = DCtx.getDWARFObj();
-  if (DObj.getAbbrevSection().empty()) {
-    OS << "Warning: .debug_abbrev is empty.\n";
-    return true;
-  }
-
+unsigned DWARFVerifier::verifyAbbrevSection(const DWARFDebugAbbrev *Abbrev) {
   unsigned NumErrors = 0;
-  const DWARFDebugAbbrev *Abbrev = DCtx.getDebugAbbrev();
   if (Abbrev) {
     const DWARFAbbreviationDeclarationSet *AbbrDecls =
         Abbrev->getAbbreviationDeclarationSet(0);
@@ -121,15 +112,34 @@ bool DWARFVerifier::handleDebugAbbrev() {
       for (auto Attribute : AbbrDecl.attributes()) {
         auto Result = AttributeSet.insert(Attribute.Attr);
         if (!Result.second) {
-          OS << format("Error: Abbreviation declaration with code %d ",
-                       AbbrDecl.getCode());
-          OS << "contains multiple " << AttributeString(Attribute.Attr)
-             << " attributes.\n";
+          OS << "Error: Abbreviation declaration contains multiple "
+             << AttributeString(Attribute.Attr) << " attributes.\n";
+          AbbrDecl.dump(OS);
           ++NumErrors;
         }
       }
     }
   }
+  return NumErrors;
+}
+
+bool DWARFVerifier::handleDebugAbbrev() {
+  OS << "Verifying .debug_abbrev...\n";
+
+  const DWARFObject &DObj = DCtx.getDWARFObj();
+  bool noDebugAbbrev = DObj.getAbbrevSection().empty();
+  bool noDebugAbbrevDWO = DObj.getAbbrevDWOSection().empty();
+
+  if (noDebugAbbrev && noDebugAbbrevDWO) {
+    return true;
+  }
+
+  unsigned NumErrors = 0;
+  if (!noDebugAbbrev)
+    NumErrors += verifyAbbrevSection(DCtx.getDebugAbbrev());
+
+  if (!noDebugAbbrevDWO)
+    NumErrors += verifyAbbrevSection(DCtx.getDebugAbbrevDWO());
   return NumErrors == 0;
 }
 
diff --git a/test/tools/llvm-dwarfdump/X86/verify_debug_abbrev.s b/test/tools/llvm-dwarfdump/X86/verify_debug_abbrev.s
new file mode 100644 (file)
index 0000000..e8571ee
--- /dev/null
@@ -0,0 +1,44 @@
+# RUN: llvm-mc %s -filetype obj -triple x86_64-unknown-linux-gnu -o - \
+# RUN: | not llvm-dwarfdump -verify - \
+# RUN: | FileCheck %s
+
+# CHECK: Verifying .debug_abbrev...
+# CHECK-NEXT: Error: Abbreviation declaration contains multiple DW_AT_stmt_list attributes.
+# CHECK-NEXT:[1] DW_TAG_compile_unit   DW_CHILDREN_no
+# CHECK-NEXT:  DW_AT_stmt_list DW_FORM_sec_offset
+# CHECK-NEXT:  DW_AT_GNU_dwo_name      DW_FORM_strp
+# CHECK-NEXT:  DW_AT_stmt_list DW_FORM_strp{{[[:space:]]}}
+# CHECK-NEXT: Error: Abbreviation declaration contains multiple DW_AT_producer attributes.
+# CHECK-NEXT:[1] DW_TAG_compile_unit   DW_CHILDREN_yes
+# CHECK-NEXT:  DW_AT_GNU_dwo_name      DW_FORM_GNU_str_index
+# CHECK-NEXT:  DW_AT_producer  DW_FORM_GNU_str_index
+# CHECK-NEXT:  DW_AT_producer  DW_FORM_data2
+
+
+  .section  .debug_abbrev,"",@progbits
+  .byte  1                       # Abbreviation Code
+  .byte  17                      # DW_TAG_compile_unit
+  .byte  0                       # DW_CHILDREN_no
+  .byte  16                      # DW_AT_stmt_list
+  .byte  23                      # DW_FORM_sec_offset
+  .ascii  "\260B"                # DW_AT_GNU_dwo_name
+  .byte  14                      # DW_FORM_strp
+  .byte  16                      # DW_AT_stmt_list -- Error: Abbreviation declaration contains multiple DW_AT_stmt_list attributes.
+  .byte  14                      # DW_FORM_strp
+  .byte  0                       # EOM(1)
+  .byte  0                       # EOM(2)
+  .byte  0                       # EOM(3)
+  .section  .debug_abbrev.dwo,"",@progbits
+  .byte  1                       # Abbreviation Code
+  .byte  17                      # DW_TAG_compile_unit
+  .byte  1                       # DW_CHILDREN_yes
+  .ascii  "\260B"                # DW_AT_GNU_dwo_name
+  .ascii  "\202>"                # DW_FORM_GNU_str_index
+  .byte  37                      # DW_AT_producer
+  .ascii  "\202>"                # DW_FORM_GNU_str_index
+  .byte  37                      # DW_AT_producer -- Error: Abbreviation declaration contains multiple DW_AT_producer attributes.
+  .byte  5                       # DW_FORM_data1
+  .byte  0                       # EOM(1)
+  .byte  0                       # EOM(2)
+  .byte  0                       # EOM(3)
+  
\ No newline at end of file
index 3268bb91d6f0d2c1a29e500240b66799ac25354a..426a5fad51a3f763edc409cd98b47ad4cf43650a 100644 (file)
@@ -2,10 +2,7 @@
 # RUN: | not llvm-dwarfdump -verify - \
 # RUN: | FileCheck %s
 
-# CHECK: Verifying .debug_abbrev...
-# CHECK-NEXT: Error: Abbreviation declaration with code 2 contains multiple DW_AT_low_pc attributes.
-# CHECK-NEXT: Verifying .debug_info Unit Header Chain...
-# CHECK-NEXT: error: DIE has invalid DW_AT_stmt_list encoding:{{[[:space:]]}}
+# CHECK: error: DIE has invalid DW_AT_stmt_list encoding:{{[[:space:]]}}
 # CHECK-NEXT: 0x0000000c: DW_TAG_compile_unit [1] *
 # CHECK-NEXT: DW_AT_producer [DW_FORM_strp]    ( .debug_str[0x00000000] = "clang version 5.0.0 (trunk 308185) (llvm/trunk 308186)")
 # CHECK-NEXT: DW_AT_language [DW_FORM_data2]   (DW_LANG_C99)
@@ -82,7 +79,7 @@ Lsection_abbrev:
        .byte   1                       ## DW_CHILDREN_yes
        .byte   17                      ## DW_AT_low_pc
        .byte   1                       ## DW_FORM_addr
-       .byte   17                      ## DW_AT_low_pc -- Error: Die at offset 0x0000002b contains multiple DW_AT_low_pc attributes.
+       .byte   18                      ## DW_AT_high_pc
        .byte   6                       ## DW_FORM_data4
        .byte   64                      ## DW_AT_frame_base
        .byte   24                      ## DW_FORM_exprloc