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