<div dir="ltr">I don't quite follow - why would there be two levels of abstract origin? (X -abstract_origin-> Y -abstract_origin-> Z) rather than having X refer to Z as its abstract_origin directly?<br><br><div class="gmail_quote"><div dir="ltr">On Thu, Nov 16, 2017 at 4:01 PM Greg Clayton via Phabricator <<a href="mailto:reviews@reviews.llvm.org">reviews@reviews.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">clayborg created this revision.<br>
Herald added a subscriber: JDevlieghere.<br>
<br>
The previous implementation would only look 1 DW_AT_specification or DW_AT_abstract_origin deep. This means DWARFDie::getName() would fail in certain cases. I ran into such a case while creating a tool that used the LLVM DWARF parser to generate a symbolication format so I have seen this in the wild.<br>
<br>
<br>
Repository:<br>
  rL LLVM<br>
<br>
<a href="https://reviews.llvm.org/D40156" rel="noreferrer" target="_blank">https://reviews.llvm.org/D40156</a><br>
<br>
Files:<br>
  lib/DebugInfo/DWARF/DWARFDie.cpp<br>
  unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp<br>
<br>
<br>
Index: unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp<br>
===================================================================<br>
--- unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp<br>
+++ unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp<br>
@@ -1287,12 +1287,16 @@<br>
     auto CUDie = CU.getUnitDIE();<br>
     auto FuncSpecDie = CUDie.addChild(DW_TAG_subprogram);<br>
     auto FuncAbsDie = CUDie.addChild(DW_TAG_subprogram);<br>
+    // Put the linkage name in a second abstract origin DIE to ensure we<br>
+    // recurse through more than just one DIE when looking for attributes.<br>
+    auto FuncAbsDie2 = CUDie.addChild(DW_TAG_subprogram);<br>
     auto FuncDie = CUDie.addChild(DW_TAG_subprogram);<br>
     auto VarAbsDie = CUDie.addChild(DW_TAG_variable);<br>
     auto VarDie = CUDie.addChild(DW_TAG_variable);<br>
     FuncSpecDie.addAttribute(DW_AT_name, DW_FORM_strp, SpecDieName);<br>
-    FuncAbsDie.addAttribute(DW_AT_linkage_name, DW_FORM_strp, SpecLinkageName);<br>
+    FuncAbsDie2.addAttribute(DW_AT_linkage_name, DW_FORM_strp, SpecLinkageName);<br>
     FuncAbsDie.addAttribute(DW_AT_specification, DW_FORM_ref4, FuncSpecDie);<br>
+    FuncAbsDie.addAttribute(DW_AT_abstract_origin, DW_FORM_ref4, FuncAbsDie2);<br>
     FuncDie.addAttribute(DW_AT_abstract_origin, DW_FORM_ref4, FuncAbsDie);<br>
     VarAbsDie.addAttribute(DW_AT_name, DW_FORM_strp, AbsDieName);<br>
     VarDie.addAttribute(DW_AT_abstract_origin, DW_FORM_ref4, VarAbsDie);<br>
@@ -1314,7 +1318,8 @@<br>
<br>
   auto FuncSpecDie = CUDie.getFirstChild();<br>
   auto FuncAbsDie = FuncSpecDie.getSibling();<br>
-  auto FuncDie = FuncAbsDie.getSibling();<br>
+  auto FuncAbsDie2 = FuncAbsDie.getSibling();<br>
+  auto FuncDie = FuncAbsDie2.getSibling();<br>
   auto VarAbsDie = FuncDie.getSibling();<br>
   auto VarDie = VarAbsDie.getSibling();<br>
<br>
Index: lib/DebugInfo/DWARF/DWARFDie.cpp<br>
===================================================================<br>
--- lib/DebugInfo/DWARF/DWARFDie.cpp<br>
+++ lib/DebugInfo/DWARF/DWARFDie.cpp<br>
@@ -298,17 +298,16 @@<br>
 DWARFDie::findRecursively(ArrayRef<dwarf::Attribute> Attrs) const {<br>
   if (!isValid())<br>
     return None;<br>
-  auto Die = *this;<br>
-  if (auto Value = Die.find(Attrs))<br>
+  if (auto Value = find(Attrs))<br>
     return Value;<br>
-  if (auto D = Die.getAttributeValueAsReferencedDie(DW_AT_abstract_origin))<br>
-    Die = D;<br>
-  if (auto Value = Die.find(Attrs))<br>
-    return Value;<br>
-  if (auto D = Die.getAttributeValueAsReferencedDie(DW_AT_specification))<br>
-    Die = D;<br>
-  if (auto Value = Die.find(Attrs))<br>
-    return Value;<br>
+  if (auto Die = getAttributeValueAsReferencedDie(DW_AT_abstract_origin)) {<br>
+    if (auto Value = Die.findRecursively(Attrs))<br>
+      return Value;<br>
+  }<br>
+  if (auto Die = getAttributeValueAsReferencedDie(DW_AT_specification)) {<br>
+    if (auto Value = Die.findRecursively(Attrs))<br>
+      return Value;<br>
+  }<br>
   return None;<br>
 }<br>
<br>
<br>
<br>
</blockquote></div></div>