[PATCH] D98119: Avoid infinite loop in DWARFUnit::getInlinedChainForAddress in case of unexpected DWARF information.

Alex Orlov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Mar 6 10:27:34 PST 2021


aorlov created this revision.
aorlov added reviewers: dblaikie, jhenderson, jdoerfert, MaskRay, grimar.
aorlov added a project: LLVM.
Herald added a subscriber: hiraditya.
aorlov requested review of this revision.
Herald added a subscriber: llvm-commits.

In some cases a broken or invalid debug info could cause a hang in DWARFUnit::getInlinedChainForAddress during parsing a chain of in-lined functions. This patch fixes this issue.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D98119

Files:
  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
@@ -688,15 +688,15 @@
   DWARFDie SubroutineDIE =
       (DWO ? *DWO : *this).getSubroutineForAddress(Address);
 
-  if (!SubroutineDIE)
-    return;
-
-  while (!SubroutineDIE.isSubprogramDIE()) {
+  while (SubroutineDIE) {
+    if (SubroutineDIE.isSubprogramDIE()) {
+      InlinedChain.push_back(SubroutineDIE);
+      return;
+    }
     if (SubroutineDIE.getTag() == DW_TAG_inlined_subroutine)
       InlinedChain.push_back(SubroutineDIE);
     SubroutineDIE  = SubroutineDIE.getParent();
   }
-  InlinedChain.push_back(SubroutineDIE);
 }
 
 const DWARFUnitIndex &llvm::getDWARFUnitIndex(DWARFContext &Context,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D98119.328781.patch
Type: text/x-patch
Size: 816 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210306/93322a1d/attachment.bin>


More information about the llvm-commits mailing list