[PATCH] D40199: llvm-dwarfdump --verify is incorrectly saying all DW_AT_location attributes with locations lists are invalid.

Greg Clayton via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 17 14:39:43 PST 2017


clayborg created this revision.
Herald added a subscriber: JDevlieghere.

Run "llvm-dwarfdump --verify" on any DWARF file that is optimized and contains at least one tag with a DW_AT_location with a location list offset as a DW_AT_form_dataXXX and errors will be emitted all over the place making it unusable.


Repository:
  rL LLVM

https://reviews.llvm.org/D40199

Files:
  lib/DebugInfo/DWARF/DWARFVerifier.cpp


Index: lib/DebugInfo/DWARF/DWARFVerifier.cpp
===================================================================
--- lib/DebugInfo/DWARF/DWARFVerifier.cpp
+++ lib/DebugInfo/DWARF/DWARFVerifier.cpp
@@ -411,21 +411,35 @@
     break;
   case DW_AT_location: {
     Optional<ArrayRef<uint8_t>> Expr = AttrValue.Value.getAsBlock();
-    if (!Expr) {
-      ReportError("DIE has invalid DW_AT_location encoding:");
-      break;
+    auto VerifyLocation = [&](const void *data, size_t len) {
+      DWARFUnit *U = Die.getDwarfUnit();
+      DataExtractor Data(StringRef(reinterpret_cast<const char *>(data), len),
+                         DCtx.isLittleEndian(), 0);
+      DWARFExpression Expression(Data, U->getVersion(),
+                                 U->getAddressByteSize());
+      bool Error = llvm::any_of(Expression, [](DWARFExpression::Operation &Op) {
+        return Op.isError();
+      });
+      if (Error)
+        ReportError("DIE contains invalid DWARF expression:");
+    };
+    if (Expr) {
+      // Inlined location
+      VerifyLocation(Expr->data(), Expr->size());
+    } else {
+      // Location list
+      if (auto LocOffset = AttrValue.Value.getAsUnsignedConstant()) {
+        auto DebugLoc = DCtx.getDebugLoc();
+        if (DebugLoc) {
+          auto LocList = DebugLoc->getLocationListAtOffset(*LocOffset);
+          if (LocList) {
+            for (const auto &Entry: LocList->Entries) {
+              VerifyLocation(Entry.Loc.data(), Entry.Loc.size());
+            }
+          }
+        }
+      }
     }
-
-    DWARFUnit *U = Die.getDwarfUnit();
-    DataExtractor Data(
-        StringRef(reinterpret_cast<const char *>(Expr->data()), Expr->size()),
-        DCtx.isLittleEndian(), 0);
-    DWARFExpression Expression(Data, U->getVersion(), U->getAddressByteSize());
-    bool Error = llvm::any_of(Expression, [](DWARFExpression::Operation &Op) {
-      return Op.isError();
-    });
-    if (Error)
-      ReportError("DIE contains invalid DWARF expression:");
     break;
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D40199.123425.patch
Type: text/x-patch
Size: 2021 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171117/13d55237/attachment.bin>


More information about the llvm-commits mailing list