<div dir="ltr">Would it make sense to push the value retrieval down into DWARFFormValue to separate getting the value from a DIE from getting the value into some particular type - they seem pretty orthogonal & it's odd that DWARFDie handles the type handling side of that rather than an attribute/form abstraction.<br><br>Perhaps it'd be a bit abusive, but we could even overload op[](dwarf::Attribute) on DWARFDie for easy map-like attribute lookup. Maybe 'find' would be a better name, though.<br><br>I'm OK omitting the 'attribute' part of the name entirely if everyone's OK with overloading in this context & if the callsites tend to be pretty self documenting. (mostly if you're searching for a particular attribute you've probably got the attribute name in a literal at the callsite anyway, right?)<br><br>So code like this, perhaps:<br><br>  x = Die.find(DW_AT_name).asString();<br><br>or perhaps:<br><br>  x = asString(Die.find(DW_AT_name));<br><br>(so that find/findAttr/[] whatever we call it can continue to return Optional<DWARFFormValue> which asString can pass along as NOne if it's passed None (or passed a non-string value), and otherwise decompose into a string, etc)<br><br><br></div><br><div class="gmail_quote"><div dir="ltr">On Wed, Jan 11, 2017 at 10:19 AM Greg Clayton <<a href="mailto:clayborg@gmail.com">clayborg@gmail.com</a>> wrote:<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" class="gmail_msg"><div class="gmail_msg"><blockquote type="cite" class="gmail_msg"><div class="gmail_msg">On Jan 11, 2017, at 10:01 AM, David Blaikie <<a href="mailto:dblaikie@gmail.com" class="gmail_msg" target="_blank">dblaikie@gmail.com</a>> wrote:</div><br class="m_-3945023613651099127Apple-interchange-newline gmail_msg"><div class="gmail_msg"><div dir="ltr" class="gmail_msg"><br class="gmail_msg"><br class="gmail_msg"><div class="gmail_quote gmail_msg"><div dir="ltr" class="gmail_msg">On Wed, Jan 11, 2017 at 9:53 AM Greg Clayton via Phabricator <<a href="mailto:reviews@reviews.llvm.org" class="gmail_msg" target="_blank">reviews@reviews.llvm.org</a>> wrote:<br class="gmail_msg"></div><blockquote class="gmail_quote gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">clayborg added a comment.<br class="gmail_msg">
<br class="gmail_msg">
I will leave the tests using getValueOr() for now as I would like it to fail nicely so we can get a complete snapshot of what is failing instead of crashing on any failure and not knowing how many others tests would fail.</blockquote><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">Fair enough - another tradeoff to be aware of there is that by collapsing the value-or-no-value states with getValueOr (or similarly with the previous code) it makes the failures harder to understand in some ways - if the EXPECT fails and the value is 0, is it because the value wasn't present, or because the value was present but was 0?<br class="gmail_msg"><br class="gmail_msg">All good - mostly I mentioned it because the lines seemed to be egtting a bit long/verbose and figured it might also make the tests easier to follow by removing some clutter.</div></div></div></div></blockquote><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><br class="gmail_msg"></div></div></div><div style="word-wrap:break-word" class="gmail_msg"><div class="gmail_msg"><div class="gmail_msg">The length of the DWARFDie getAttributeValueAs functions, which were ported from DWARFDebugInfoEntry, was a patch I was thinking about. Does anyone have an objection to shortening all of the DWARFDie::getAttributeValueAsXXX() calls to have shorter names?</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">I was thinking:</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><div class="gmail_msg">From the current:</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">  Optional<DWARFFormValue> getAttributeValue(dwarf::Attribute Attr) const;</div><div class="gmail_msg">  const char *getAttributeValueAsString(dwarf::Attribute Attr, const char *FailValue) const;</div><div class="gmail_msg">  Optional<uint64_t> getAttributeValueAsAddress(dwarf::Attribute Attr) const;</div><div class="gmail_msg">  Optional<int64_t> getAttributeValueAsSignedConstant(dwarf::Attribute Attr) const;</div><div class="gmail_msg">  Optional<uint64_t> getAttributeValueAsUnsignedConstant(dwarf::Attribute Attr) const;</div><div class="gmail_msg">  Optional<uint64_t> getAttributeValueAsReference(dwarf::Attribute Attr) const;</div><div class="gmail_msg">  Optional<uint64_t> getAttributeValueAsSectionOffset(dwarf::Attribute Attr) const;</div><div class="gmail_msg">  DWARFDie getAttributeValueAsReferencedDie(dwarf::Attribute Attr) const;</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">It would be nice to change “getAttributeValue” to “getAttr” and remove the “Constant” from UnsignedConstant” and SignedConstant”:</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">The shorter versions would look like:</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">  Optional<DWARFFormValue> getAttr(dwarf::Attribute Attr) const;</div><div class="gmail_msg">  const char *getAttrAsString(dwarf::Attribute Attr, const char *FailValue) const;</div><div class="gmail_msg">  Optional<uint64_t> getAttrAsAddress(dwarf::Attribute Attr) const;</div><div class="gmail_msg">  Optional<int64_t> getAttrAsSigned(dwarf::Attribute Attr) const;</div><div class="gmail_msg">  Optional<uint64_t> getAttrAsUnsigned(dwarf::Attribute Attr) const;</div><div class="gmail_msg">  Optional<uint64_t> getAttrAsReference(dwarf::Attribute Attr) const;</div><div class="gmail_msg">  Optional<uint64_t> getAttrAsSectionOffset(dwarf::Attribute Attr) const;</div><div class="gmail_msg">  DWARFDie getAttrAsDie(dwarf::Attribute Attr) const;</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">This would help a lot of the DWARF code out. Any thoughts or objections?</div><div class="gmail_msg"><br class="gmail_msg"></div></div></div></div><div style="word-wrap:break-word" class="gmail_msg"><div class="gmail_msg"><div class="gmail_msg"><blockquote type="cite" class="gmail_msg"><div dir="ltr" class="gmail_msg"><div class="gmail_quote gmail_msg"></div></div></blockquote></div><blockquote type="cite" class="gmail_msg"><div class="gmail_msg"><div dir="ltr" class="gmail_msg"><div class="gmail_quote gmail_msg"><div class="gmail_msg"> </div><blockquote class="gmail_quote gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> I will read up on EXPECT_* and make a separate change for switching arg order if needed.<br class="gmail_msg"></blockquote><div class="gmail_msg"><br class="gmail_msg">Cool cool - thanks! The order of arguments catches me up every time.<br class="gmail_msg"> </div><blockquote class="gmail_quote gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br class="gmail_msg">
<br class="gmail_msg">
<a href="https://reviews.llvm.org/D28569" rel="noreferrer" class="gmail_msg" target="_blank">https://reviews.llvm.org/D28569</a><br class="gmail_msg">
<br class="gmail_msg">
<br class="gmail_msg">
<br class="gmail_msg">
</blockquote></div></div>
</div></blockquote></div></div></blockquote></div>