<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jun 25, 2015 at 2:42 PM, Duncan P. N. Exon Smith <span dir="ltr"><<a href="mailto:dexonsmith@apple.com" target="_blank">dexonsmith@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: dexonsmith<br>
Date: Thu Jun 25 16:42:46 2015<br>
New Revision: 240701<br>
<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject-3Frev-3D240701-26view-3Drev&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=GvaJZGV39qAMAgYHKR1u-zsjkKmCt3nwsSLAHLRTBho&s=DinfE_5a30PpPNswFLk4WG08RbV4AWiJvG2iOuOQJXY&e=" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=240701&view=rev</a><br>
Log:<br>
dsymutil: Split out patchStmtList(), NFC<br>
<br>
Split out code to patch up the `DW_AT_stmt_list` for the cloned DIE, and<br>
reorganize it so that it doesn't depend on `DIE::values_begin()` and<br>
`DIE::values_end()` (which I'm trying to kill off).<br>
<br>
David Blaikie and I talked about adding a range-algorithm version of<br>
`std::find_if()`, but the assertion *still* required getting at the end<br>
iterator.  IMO, a separate helper function with an early return is<br>
easier to reason about here.<br></blockquote><div><br>I don't much mind an I == x.values().end(), but this does get into the more interesting range-based algorithm design... find_if could return a trimmed range (move the beginning of the range up to the first found item) and you just test if it it's !empty(r). But then we have to wonder if different names are needed for those algorithms... blah. blah. I haven't followed the standards committee enough to know where the range proposals are going there.<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
A follow-up commit that removes `DIE::setValue()` and mutates the<br>
`DIEValue` directly is coming shortly.<br>
<br>
Modified:<br>
    llvm/trunk/tools/dsymutil/DwarfLinker.cpp<br>
<br>
Modified: llvm/trunk/tools/dsymutil/DwarfLinker.cpp<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_llvm_trunk_tools_dsymutil_DwarfLinker.cpp-3Frev-3D240701-26r1-3D240700-26r2-3D240701-26view-3Ddiff&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=GvaJZGV39qAMAgYHKR1u-zsjkKmCt3nwsSLAHLRTBho&s=b8TYtgT2zHxZOewXDY_Old7csRvUN867LtEq-J20MnI&e=" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/dsymutil/DwarfLinker.cpp?rev=240701&r1=240700&r2=240701&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/tools/dsymutil/DwarfLinker.cpp (original)<br>
+++ llvm/trunk/tools/dsymutil/DwarfLinker.cpp Thu Jun 25 16:42:46 2015<br>
@@ -2364,6 +2364,17 @@ static void insertLineSequence(std::vect<br>
   Seq.clear();<br>
 }<br>
<br>
+static void patchStmtList(DIE &Die, DIEInteger Offset) {<br>
+  for (auto &V : Die.values())<br>
+    if (V.getAttribute() == dwarf::DW_AT_stmt_list) {<br>
+      Die.setValue(&V - Die.values_begin(),<br>
+                   DIEValue(V.getAttribute(), V.getForm(), Offset));<br>
+      return;<br>
+    }<br>
+<br>
+  llvm_unreachable("Didn't find DW_AT_stmt_list in cloned DIE!");<br>
+}<br>
+<br>
 /// \brief Extract the line table for \p Unit from \p OrigDwarf, and<br>
 /// recreate a relocated version of these for the address ranges that<br>
 /// are present in the binary.<br>
@@ -2376,18 +2387,8 @@ void DwarfLinker::patchLineTableForUnit(<br>
     return;<br>
<br>
   // Update the cloned DW_AT_stmt_list with the correct debug_line offset.<br>
-  if (auto *OutputDIE = Unit.getOutputUnitDIE()) {<br>
-    auto Stmt =<br>
-        std::find_if(OutputDIE->values_begin(), OutputDIE->values_end(),<br>
-                     [](const DIEValue &Value) {<br>
-                       return Value.getAttribute() == dwarf::DW_AT_stmt_list;<br>
-                     });<br>
-    assert(Stmt != OutputDIE->values_end() &&<br>
-           "Didn't find DW_AT_stmt_list in cloned DIE!");<br>
-    OutputDIE->setValue(Stmt - OutputDIE->values_begin(),<br>
-                        DIEValue(Stmt->getAttribute(), Stmt->getForm(),<br>
-                                 DIEInteger(Streamer->getLineSectionSize())));<br>
-  }<br>
+  if (auto *OutputDIE = Unit.getOutputUnitDIE())<br>
+    patchStmtList(*OutputDIE, DIEInteger(Streamer->getLineSectionSize()));<br>
<br>
   // Parse the original line info for the unit.<br>
   DWARFDebugLine::LineTable LineTable;<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div></div>