<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Nov 12, 2014 at 4:06 PM, Frédéric 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"><div style="word-wrap:break-word"><br><div><div><div class="h5"><blockquote type="cite"><div>On Nov 12, 2014, at 3:59 PM, David Blaikie <<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>> wrote:</div><br><div><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></div></div></div></div></blockquote><div><br></div></div></div><div>OK, I’ll fix that up.</div><span class=""><br><blockquote type="cite"><div><div dir="ltr"><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>
+ /// 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></div></div></div></div></blockquote><div><br></div></span><div>With this patch, the extractValue fails, ie. it returns false. </div></div></div></blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><div>I prefer that over the assertion, </div></div></div></blockquote><div><br>Why do you prefer that over an assertion? I assume that encoding isn't valid in the accelerator table - is the table self-describing (does it include the form code in the data read from the file? So it could, in theory (if mangled/fuzzed/etc) include a relocatable form?)? In that case I get where you're coming from, we shouldn't crash/assert on the bytes read from the file no matter how absurd they are.<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><div>but then disallowed is misleading. I should maybe reword that as "will result in an extraction failure”.</div><div><br></div><div>Fred</div><div><div class="h5"><br><blockquote type="cite"><div><div dir="ltr"><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>
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" target="_blank">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>
</div></blockquote></div></div></div><br></div></blockquote></div><br></div></div>