<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Nov 12, 2014, at 3:59 PM, David Blaikie <<a href="mailto:dblaikie@gmail.com" class="">dblaikie@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><br class=""><div class="gmail_extra"><br class=""><div class="gmail_quote">On Wed, Nov 12, 2014 at 3:48 PM, Frederic Riss <span dir="ltr" class=""><<a href="mailto:friss@apple.com" target="_blank" class="">friss@apple.com</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: friss<br class="">
Date: Wed Nov 12 17:48:04 2014<br class="">
New Revision: 221835<br class="">
<br class="">
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=221835&view=rev" target="_blank" class="">http://llvm.org/viewvc/llvm-project?rev=221835&view=rev</a><br class="">
Log:<br class="">
Allow DWARFFormValue::extractValue to be called with a null CU.<br class="">
<br class="">
Currently FormValues are only used for attributes of DIEs and thus<br class="">
uers always have a CU lying around when calling into the FormValue<br class="">
API.<br class="">
Accelerator tables encode their information using the same Forms<br class="">
as the attributes, thus it is natural to use DWARFFormValue to<br class="">
extract/dump them. There is no CU in that case though. Allow the<br class="">
API to be called with a null CU arguemnt by making the RelocMap<br class="">
lookup conditional on the CU pointer validity. And document this<br class="">
new behvior in the header. (Test coverage for this use of the API<br class="">
comes in the DwarfAccelTable support patch)<br class="">
<br class="">
Modified:<br class="">
    llvm/trunk/include/llvm/DebugInfo/DWARFFormValue.h<br class="">
    llvm/trunk/lib/DebugInfo/DWARFFormValue.cpp<br class="">
<br class="">
Modified: llvm/trunk/include/llvm/DebugInfo/DWARFFormValue.h<br class="">
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/DWARFFormValue.h?rev=221835&r1=221834&r2=221835&view=diff" target="_blank" class="">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/DWARFFormValue.h?rev=221835&r1=221834&r2=221835&view=diff</a><br class="">
==============================================================================<br class="">
--- llvm/trunk/include/llvm/DebugInfo/DWARFFormValue.h (original)<br class="">
+++ llvm/trunk/include/llvm/DebugInfo/DWARFFormValue.h Wed Nov 12 17:48:04 2014<br class="">
@@ -57,6 +57,13 @@ public:<br class="">
   bool isFormClass(FormClass FC) const;<br class="">
<br class="">
   void dump(raw_ostream &OS, const DWARFUnit *U) const;<br class="">
+<br class="">
+  /// \brief extracts a value in data at offset *offset_ptr.<br class="">
+  ///<br class="">
+  /// The passed DWARFUnit is allowed to be nullptr, </blockquote><div class=""><br class="">"to be null" (nullptr is just one null pointer literal - "null" is the general concept)<br class=""></div></div></div></div></div></blockquote><div><br class=""></div><div>OK, I’ll fix that up.</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">in which<br class="">
+  /// case no relocation processing will be performed and some<br class="">
+  /// kind of forms that depend on Unit information are disallowed.<br class=""></blockquote><div class=""><br class="">Disallowed is a bit vague - elegant failure? Assertion? I would probably prefer assertion failure, if that's reasonable/possible.<br class=""></div></div></div></div></div></blockquote><div><br class=""></div><div>With this patch, the extractValue fails, ie. it returns false. I prefer that over the assertion, but then disallowed is misleading. I should maybe reword that as "will result in an extraction failure”.</div><div><br class=""></div><div>Fred</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+  /// \returns wether the extraction succeeded.<br class="">
   bool extractValue(DataExtractor data, uint32_t *offset_ptr,<br class="">
                     const DWARFUnit *u);<br class="">
   bool isInlinedCStr() const {<br class="">
<br class="">
Modified: llvm/trunk/lib/DebugInfo/DWARFFormValue.cpp<br class="">
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARFFormValue.cpp?rev=221835&r1=221834&r2=221835&view=diff" target="_blank" class="">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARFFormValue.cpp?rev=221835&r1=221834&r2=221835&view=diff</a><br class="">
==============================================================================<br class="">
--- llvm/trunk/lib/DebugInfo/DWARFFormValue.cpp (original)<br class="">
+++ llvm/trunk/lib/DebugInfo/DWARFFormValue.cpp Wed Nov 12 17:48:04 2014<br class="">
@@ -139,6 +139,8 @@ bool DWARFFormValue::extractValue(DataEx<br class="">
     switch (Form) {<br class="">
     case DW_FORM_addr:<br class="">
     case DW_FORM_ref_addr: {<br class="">
+      if (!cu)<br class="">
+        return false; </blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
       uint16_t AddrSize =<br class="">
           (Form == DW_FORM_addr)<br class="">
               ? cu->getAddressByteSize()<br class="">
@@ -179,8 +181,10 @@ bool DWARFFormValue::extractValue(DataEx<br class="">
       break;<br class="">
     case DW_FORM_data4:<br class="">
     case DW_FORM_ref4: {<br class="">
-      RelocAddrMap::const_iterator AI = cu->getRelocMap()->find(*offset_ptr);<br class="">
       Value.uval = data.getU32(offset_ptr);<br class="">
+      if (!cu)<br class="">
+        break;<br class="">
+      RelocAddrMap::const_iterator AI = cu->getRelocMap()->find(*offset_ptr-4);<br class="">
       if (AI != cu->getRelocMap()->end())<br class="">
         Value.uval += AI->second.second;<br class="">
       break;<br class="">
@@ -193,13 +197,12 @@ bool DWARFFormValue::extractValue(DataEx<br class="">
       Value.sval = data.getSLEB128(offset_ptr);<br class="">
       break;<br class="">
     case DW_FORM_strp: {<br class="">
-      RelocAddrMap::const_iterator AI<br class="">
-        = cu->getRelocMap()->find(*offset_ptr);<br class="">
-      if (AI != cu->getRelocMap()->end()) {<br class="">
-        const std::pair<uint8_t, int64_t> &R = AI->second;<br class="">
-        Value.uval = data.getU32(offset_ptr) + R.second;<br class="">
-      } else<br class="">
-        Value.uval = data.getU32(offset_ptr);<br class="">
+      Value.uval = data.getU32(offset_ptr);<br class="">
+      if (!cu)<br class="">
+        break;<br class="">
+      RelocAddrMap::const_iterator AI = cu->getRelocMap()->find(*offset_ptr-4);<br class="">
+      if (AI != cu->getRelocMap()->end())<br class="">
+        Value.uval += AI->second.second;<br class="">
       break;<br class="">
     }<br class="">
     case DW_FORM_udata:<br class="">
@@ -215,13 +218,12 @@ bool DWARFFormValue::extractValue(DataEx<br class="">
       break;<br class="">
     case DW_FORM_sec_offset: {<br class="">
       // FIXME: This is 64-bit for DWARF64.<br class="">
-      RelocAddrMap::const_iterator AI<br class="">
-        = cu->getRelocMap()->find(*offset_ptr);<br class="">
-      if (AI != cu->getRelocMap()->end()) {<br class="">
-        const std::pair<uint8_t, int64_t> &R = AI->second;<br class="">
-        Value.uval = data.getU32(offset_ptr) + R.second;<br class="">
-      } else<br class="">
-        Value.uval = data.getU32(offset_ptr);<br class="">
+      Value.uval = data.getU32(offset_ptr);<br class="">
+      if (!cu)<br class="">
+        break;<br class="">
+      RelocAddrMap::const_iterator AI = cu->getRelocMap()->find(*offset_ptr-4);<br class="">
+      if (AI != cu->getRelocMap()->end())<br class="">
+        Value.uval +=  AI->second.second;<br class="">
       break;<br class="">
     }<br class="">
     case DW_FORM_flag_present:<br class="">
<br class="">
<br class="">
_______________________________________________<br class="">
llvm-commits mailing list<br class="">
<a href="mailto:llvm-commits@cs.uiuc.edu" class="">llvm-commits@cs.uiuc.edu</a><br class="">
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank" class="">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br class="">
</blockquote></div><br class=""></div></div>
</div></blockquote></div><br class=""></body></html>