[PATCH] D35643: [DWARF] Added check that verifies that no abbreviation declaration has more than one attribute with the same name.

Spyridoula Gravani via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 19 19:08:07 PDT 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL308579: [DWARF] Added check that verifies that no abbreviation declaration has moreā€¦ (authored by sgravani).

Changed prior to commit:
  https://reviews.llvm.org/D35643?vs=107427&id=107437#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D35643

Files:
  llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFVerifier.h
  llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp
  llvm/trunk/lib/DebugInfo/DWARF/DWARFVerifier.cpp
  llvm/trunk/test/tools/llvm-dwarfdump/X86/verify_debug_info.s


Index: llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp
===================================================================
--- llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp
+++ llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp
@@ -418,6 +418,7 @@
 bool DWARFContext::verify(raw_ostream &OS, DIDumpType DumpType) {
   bool Success = true;
   DWARFVerifier verifier(OS, *this);
+  Success &= verifier.handleDebugAbbrev();
   if (DumpType == DIDT_All || DumpType == DIDT_Info) {
     if (!verifier.handleDebugInfo())
       Success = false;
Index: llvm/trunk/lib/DebugInfo/DWARF/DWARFVerifier.cpp
===================================================================
--- llvm/trunk/lib/DebugInfo/DWARF/DWARFVerifier.cpp
+++ llvm/trunk/lib/DebugInfo/DWARF/DWARFVerifier.cpp
@@ -102,6 +102,37 @@
   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 NumErrors = 0;
+  const DWARFDebugAbbrev *Abbrev = DCtx.getDebugAbbrev();
+  if (Abbrev) {
+    const DWARFAbbreviationDeclarationSet *AbbrDecls =
+        Abbrev->getAbbreviationDeclarationSet(0);
+    for (auto AbbrDecl : *AbbrDecls) {
+      SmallDenseSet<uint16_t> AttributeSet;
+      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";
+          ++NumErrors;
+        }
+      }
+    }
+  }
+  return NumErrors == 0;
+}
+
 bool DWARFVerifier::handleDebugInfo() {
   OS << "Verifying .debug_info Unit Header Chain...\n";
 
Index: llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFVerifier.h
===================================================================
--- llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFVerifier.h
+++ llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFVerifier.h
@@ -114,6 +114,13 @@
 public:
   DWARFVerifier(raw_ostream &S, DWARFContext &D)
       : OS(S), DCtx(D) {}
+  /// Verify the information in the .debug_abbrev section.
+  ///
+  /// Currently, we check that no Abbreviation Declaration has more than one
+  /// attributes with the same name.
+  ///
+  /// \returns true if the .debug_abbrev verifies 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: llvm/trunk/test/tools/llvm-dwarfdump/X86/verify_debug_info.s
===================================================================
--- llvm/trunk/test/tools/llvm-dwarfdump/X86/verify_debug_info.s
+++ llvm/trunk/test/tools/llvm-dwarfdump/X86/verify_debug_info.s
@@ -2,7 +2,9 @@
 # RUN: | not llvm-dwarfdump -verify - \
 # RUN: | FileCheck %s
 
-# CHECK: Verifying .debug_info Unit Header Chain...
+# 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-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)")
@@ -80,7 +82,7 @@
 	.byte	1                       ## DW_CHILDREN_yes
 	.byte	17                      ## DW_AT_low_pc
 	.byte	1                       ## DW_FORM_addr
-	.byte	18                      ## DW_AT_high_pc
+	.byte	17                      ## DW_AT_low_pc -- Error: Die at offset 0x0000002b contains multiple DW_AT_low_pc attributes.
 	.byte	6                       ## DW_FORM_data4
 	.byte	64                      ## DW_AT_frame_base
 	.byte	24                      ## DW_FORM_exprloc


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D35643.107437.patch
Type: text/x-patch
Size: 4074 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170720/4cf928b2/attachment.bin>


More information about the llvm-commits mailing list