[PATCH] D151933: [DebugInfo] Return an error from DWARFUnitHeader::applyIndexEntry

Alex Langford via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 1 13:52:35 PDT 2023


bulbazord created this revision.
bulbazord added reviewers: aprantl, JDevlieghere, jhenderson, dblaikie, fdeazeve, rastogishubham.
Herald added subscribers: arphaman, hiraditya.
Herald added a project: All.
bulbazord requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

I'm in the process of converting LLDB to use LLVM's DWARFUnitHeader
instead of its own implementation. One big difference between the two is
that LLDB actually provides an error when applying an index entry to a
DWARFHeaderUnit in a DWO context. LLVM's implementation would be more
useful if it did the same.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151933

Files:
  llvm/include/llvm/DebugInfo/DWARF/DWARFUnit.h
  llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp


Index: llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp
===================================================================
--- llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp
+++ llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp
@@ -95,8 +95,12 @@
         if (!IndexEntry)
           IndexEntry = Index.getFromOffset(Header.getOffset());
       }
-      if (IndexEntry && !Header.applyIndexEntry(IndexEntry))
-        return nullptr;
+      if (IndexEntry) {
+        if (Error Err = Header.applyIndexEntry(IndexEntry)) {
+          Context.getWarningHandler()(std::move(Err));
+          return nullptr;
+        }
+      }
       std::unique_ptr<DWARFUnit> U;
       if (Header.isTypeUnit())
         U = std::make_unique<DWARFTypeUnit>(Context, InfoSection, Header, DA,
@@ -345,21 +349,33 @@
   return true;
 }
 
-bool DWARFUnitHeader::applyIndexEntry(const DWARFUnitIndex::Entry *Entry) {
+Error DWARFUnitHeader::applyIndexEntry(const DWARFUnitIndex::Entry *Entry) {
   assert(Entry);
   assert(!IndexEntry);
-  IndexEntry = Entry;
   if (AbbrOffset)
-    return false;
-  auto *UnitContrib = IndexEntry->getContribution();
+    return createStringError(
+        errc::invalid_argument,
+        "DWARF package unit at offset 0x%8.8" PRIx64
+        " has a non-zero abbreviation offset prior to applying an index entry",
+        Offset);
+
+  auto *UnitContrib = Entry->getContribution();
   if (!UnitContrib ||
       UnitContrib->getLength() != (getLength() + getUnitLengthFieldByteSize()))
-    return false;
-  auto *AbbrEntry = IndexEntry->getContribution(DW_SECT_ABBREV);
+    return createStringError(errc::invalid_argument,
+                             "DWARF package unit at offset 0x%8.8" PRIx64
+                             " has an inconsistent unit index",
+                             Offset);
+
+  auto *AbbrEntry = Entry->getContribution(DW_SECT_ABBREV);
   if (!AbbrEntry)
-    return false;
+    return createStringError(errc::invalid_argument,
+                             "DWARF package unit at offset 0x%8.8" PRIx64
+                             " is missing an abbreviation column",
+                             Offset);
   AbbrOffset = AbbrEntry->getOffset();
-  return true;
+  IndexEntry = Entry;
+  return Error::success();
 }
 
 Error DWARFUnit::extractRangeList(uint64_t RangeListOffset,
Index: llvm/include/llvm/DebugInfo/DWARF/DWARFUnit.h
===================================================================
--- llvm/include/llvm/DebugInfo/DWARF/DWARFUnit.h
+++ llvm/include/llvm/DebugInfo/DWARF/DWARFUnit.h
@@ -80,7 +80,7 @@
                uint64_t *offset_ptr, DWARFSectionKind SectionKind);
   // For units in DWARF Package File, remember the index entry and update
   // the abbreviation offset read by extract().
-  bool applyIndexEntry(const DWARFUnitIndex::Entry *Entry);
+  Error applyIndexEntry(const DWARFUnitIndex::Entry *Entry);
   uint64_t getOffset() const { return Offset; }
   const dwarf::FormParams &getFormParams() const { return FormParams; }
   uint16_t getVersion() const { return FormParams.Version; }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D151933.527601.patch
Type: text/x-patch
Size: 3039 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230601/f0c2da6a/attachment.bin>


More information about the llvm-commits mailing list