<div dir="ltr">Chris - maybe you can take a look at this.<br><br><div class="gmail_quote"><div dir="ltr">On Tue, Feb 28, 2017 at 8:12 AM David Blaikie <<a href="mailto:dblaikie@gmail.com">dblaikie@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 dir="ltr" class="gmail_msg"><div class="gmail_quote gmail_msg"><div dir="ltr" class="gmail_msg">On Fri, Jan 13, 2017 at 1:19 PM Greg Clayton via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org" class="gmail_msg" target="_blank">llvm-commits@lists.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">Author: gclayton<br class="gmail_msg">
Date: Fri Jan 13 15:08:18 2017<br class="gmail_msg">
New Revision: 291959<br class="gmail_msg">
<br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=291959&view=rev" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project?rev=291959&view=rev</a><br class="gmail_msg">
Log:<br class="gmail_msg">
Cleanup how DWARFDie attributes are accessed and decoded.<br class="gmail_msg">
<br class="gmail_msg">
Removed all DWARFDie::getAttributeValueAs*() calls.<br class="gmail_msg">
Renamed:<br class="gmail_msg">
Optional<DWARFFormValue> DWARFDie::getAttributeValue(dwarf::Attribute);<br class="gmail_msg">
To:<br class="gmail_msg">
Optional<DWARFFormValue> DWARFDie::find(dwarf::Attribute);<br class="gmail_msg">
Added:<br class="gmail_msg">
Optional<DWARFFormValue> DWARFDie::findRecursively(dwarf::Attribute);<br class="gmail_msg">
<br class="gmail_msg">
All decoding of Optional<DWARFFormValue> values are now done using the dwarf::to*() functions from DWARFFormValue.h:<br class="gmail_msg">
<br class="gmail_msg">
Old code:<br class="gmail_msg">
<br class="gmail_msg">
auto DeclLine = DWARFDie.getAttributeValueAsSignedConstant(DW_AT_decl_line).getValueOr(0);<br class="gmail_msg">
<br class="gmail_msg">
New code:<br class="gmail_msg">
<br class="gmail_msg">
auto DeclLine = toUnsigned(DWARFDie.find(DW_AT_decl_line), 0);<br class="gmail_msg">
<br class="gmail_msg">
This composition helps us since we can now easily do:<br class="gmail_msg">
<br class="gmail_msg">
auto DeclLine = toUnsigned(DWARFDie.findRecursively(DW_AT_decl_line), 0);<br class="gmail_msg">
<br class="gmail_msg">
This allows us to easily find attribute values in the current DIE only (the first new code above) or in any DW_AT_abstract_origin or DW_AT_specification Dies using the line above. Note that the code line length is shorter and more concise.<br class="gmail_msg">
<br class="gmail_msg">
Differential Revision: <a href="https://reviews.llvm.org/D28581" rel="noreferrer" class="gmail_msg" target="_blank">https://reviews.llvm.org/D28581</a><br class="gmail_msg">
<br class="gmail_msg">
<br class="gmail_msg">
Modified:<br class="gmail_msg">
llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFDie.h<br class="gmail_msg">
llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFFormValue.h<br class="gmail_msg">
llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp<br class="gmail_msg">
llvm/trunk/lib/DebugInfo/DWARF/DWARFDie.cpp<br class="gmail_msg">
llvm/trunk/lib/DebugInfo/DWARF/DWARFTypeUnit.cpp<br class="gmail_msg">
llvm/trunk/lib/DebugInfo/DWARF/DWARFUnit.cpp<br class="gmail_msg">
llvm/trunk/tools/dsymutil/DwarfLinker.cpp<br class="gmail_msg">
llvm/trunk/tools/obj2yaml/dwarf2yaml.cpp<br class="gmail_msg">
llvm/trunk/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp<br class="gmail_msg">
<br class="gmail_msg">
Modified: llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFDie.h<br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFDie.h?rev=291959&r1=291958&r2=291959&view=diff" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFDie.h?rev=291959&r1=291958&r2=291959&view=diff</a><br class="gmail_msg">
==============================================================================<br class="gmail_msg">
--- llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFDie.h (original)<br class="gmail_msg">
+++ llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFDie.h Fri Jan 13 15:08:18 2017<br class="gmail_msg">
@@ -124,76 +124,17 @@ public:<br class="gmail_msg">
/// \param Attr the attribute to extract.<br class="gmail_msg">
/// \returns an optional DWARFFormValue that will have the form value if the<br class="gmail_msg">
/// attribute was successfully extracted.<br class="gmail_msg">
- Optional<DWARFFormValue> getAttributeValue(dwarf::Attribute Attr) const;<br class="gmail_msg">
-<br class="gmail_msg">
- /// Extract the specified attribute from this DIE as a C string.<br class="gmail_msg">
- ///<br class="gmail_msg">
- /// Extract an attribute value from this DIE only. This call doesn't look<br class="gmail_msg">
- /// for the attribute value in any DW_AT_specification or<br class="gmail_msg">
- /// DW_AT_abstract_origin referenced DIEs.<br class="gmail_msg">
- ///<br class="gmail_msg">
- /// \param Attr the attribute to extract.<br class="gmail_msg">
- /// \param FailValue the value to return if this DIE doesn't have this<br class="gmail_msg">
- /// attribute.<br class="gmail_msg">
- /// \returns the NULL terminated C string value owned by the DWARF section<br class="gmail_msg">
- /// that contains the string or FailValue if the attribute doesn't exist or<br class="gmail_msg">
- /// if the attribute's form isn't a form that describes an string.<br class="gmail_msg">
- const char *getAttributeValueAsString(dwarf::Attribute Attr,<br class="gmail_msg">
- const char *FailValue) const;<br class="gmail_msg">
-<br class="gmail_msg">
- /// Extract the specified attribute from this DIE as an address.<br class="gmail_msg">
- ///<br class="gmail_msg">
- /// Extract an attribute value from this DIE only. This call doesn't look<br class="gmail_msg">
- /// for the attribute value in any DW_AT_specification or<br class="gmail_msg">
- /// DW_AT_abstract_origin referenced DIEs.<br class="gmail_msg">
- ///<br class="gmail_msg">
- /// \param Attr the attribute to extract.<br class="gmail_msg">
- /// \returns an optional value for the attribute.<br class="gmail_msg">
- Optional<uint64_t> getAttributeValueAsAddress(dwarf::Attribute Attr) const;<br class="gmail_msg">
-<br class="gmail_msg">
- /// Extract the specified attribute from this DIE as a signed integer.<br class="gmail_msg">
- ///<br class="gmail_msg">
- /// Extract an attribute value from this DIE only. This call doesn't look<br class="gmail_msg">
- /// for the attribute value in any DW_AT_specification or<br class="gmail_msg">
- /// DW_AT_abstract_origin referenced DIEs.<br class="gmail_msg">
- ///<br class="gmail_msg">
- /// \param Attr the attribute to extract.<br class="gmail_msg">
- /// \returns an optional value for the attribute.<br class="gmail_msg">
- Optional<int64_t><br class="gmail_msg">
- getAttributeValueAsSignedConstant(dwarf::Attribute Attr) const;<br class="gmail_msg">
-<br class="gmail_msg">
- /// Extract the specified attribute from this DIE as an unsigned integer.<br class="gmail_msg">
- ///<br class="gmail_msg">
- /// Extract an attribute value from this DIE only. This call doesn't look<br class="gmail_msg">
- /// for the attribute value in any DW_AT_specification or<br class="gmail_msg">
- /// DW_AT_abstract_origin referenced DIEs.<br class="gmail_msg">
- ///<br class="gmail_msg">
- /// \param Attr the attribute to extract.<br class="gmail_msg">
- /// \returns an optional value for the attribute.<br class="gmail_msg">
- Optional<uint64_t><br class="gmail_msg">
- getAttributeValueAsUnsignedConstant(dwarf::Attribute Attr) const;<br class="gmail_msg">
+ Optional<DWARFFormValue> find(dwarf::Attribute Attr) const;<br class="gmail_msg">
<br class="gmail_msg">
- /// Extract the specified attribute from this DIE as absolute DIE Offset.<br class="gmail_msg">
- ///<br class="gmail_msg">
- /// Extract an attribute value from this DIE only. This call doesn't look<br class="gmail_msg">
- /// for the attribute value in any DW_AT_specification or<br class="gmail_msg">
- /// DW_AT_abstract_origin referenced DIEs.<br class="gmail_msg">
- ///<br class="gmail_msg">
- /// \param Attr the attribute to extract.<br class="gmail_msg">
- /// \returns an optional value for the attribute.<br class="gmail_msg">
- Optional<uint64_t> getAttributeValueAsReference(dwarf::Attribute Attr) const;<br class="gmail_msg">
<br class="gmail_msg">
- /// Extract the specified attribute from this DIE as absolute section offset.<br class="gmail_msg">
- ///<br class="gmail_msg">
- /// Extract an attribute value from this DIE only. This call doesn't look<br class="gmail_msg">
- /// for the attribute value in any DW_AT_specification or<br class="gmail_msg">
- /// DW_AT_abstract_origin referenced DIEs.<br class="gmail_msg">
+ /// Extract an attribute value from this DIE and recurse into any<br class="gmail_msg">
+ /// DW_AT_specification or DW_AT_abstract_origin referenced DIEs.<br class="gmail_msg">
///<br class="gmail_msg">
/// \param Attr the attribute to extract.<br class="gmail_msg">
- /// \returns an optional value for the attribute.<br class="gmail_msg">
- Optional<uint64_t><br class="gmail_msg">
- getAttributeValueAsSectionOffset(dwarf::Attribute Attr) const;<br class="gmail_msg">
-<br class="gmail_msg">
+ /// \returns an optional DWARFFormValue that will have the form value if the<br class="gmail_msg">
+ /// attribute was successfully extracted.<br class="gmail_msg">
+ Optional<DWARFFormValue> findRecursively(dwarf::Attribute Attr) const;<br class="gmail_msg">
+<br class="gmail_msg">
/// Extract the specified attribute from this DIE as the referenced DIE.<br class="gmail_msg">
///<br class="gmail_msg">
/// Regardless of the reference type, return the correct DWARFDie instance if<br class="gmail_msg">
<br class="gmail_msg">
Modified: llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFFormValue.h<br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFFormValue.h?rev=291959&r1=291958&r2=291959&view=diff" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFFormValue.h?rev=291959&r1=291958&r2=291959&view=diff</a><br class="gmail_msg">
==============================================================================<br class="gmail_msg">
--- llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFFormValue.h (original)<br class="gmail_msg">
+++ llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFFormValue.h Fri Jan 13 15:08:18 2017<br class="gmail_msg">
@@ -10,6 +10,7 @@<br class="gmail_msg">
#ifndef LLVM_DEBUGINFO_DWARFFORMVALUE_H<br class="gmail_msg">
#define LLVM_DEBUGINFO_DWARFFORMVALUE_H<br class="gmail_msg">
<br class="gmail_msg">
+#include "llvm/ADT/ArrayRef.h"<br class="gmail_msg">
#include "llvm/ADT/Optional.h"<br class="gmail_msg">
#include "llvm/Support/DataExtractor.h"<br class="gmail_msg">
#include "llvm/Support/Dwarf.h"<br class="gmail_msg">
@@ -60,6 +61,10 @@ public:<br class="gmail_msg">
void setUValue(uint64_t V) { Value.uval = V; }<br class="gmail_msg">
void setSValue(int64_t V) { Value.sval = V; }<br class="gmail_msg">
void setPValue(const char *V) { Value.cstr = V; }<br class="gmail_msg">
+ void setBlockValue(const ArrayRef<uint8_t> &Data) {<br class="gmail_msg">
+ Value.data = Data.data();<br class="gmail_msg">
+ setUValue(Data.size());<br class="gmail_msg">
+ }<br class="gmail_msg">
bool isFormClass(FormClass FC) const;<br class="gmail_msg">
const DWARFUnit *getUnit() const { return U; }<br class="gmail_msg">
void dump(raw_ostream &OS) const;<br class="gmail_msg">
@@ -164,6 +169,153 @@ private:<br class="gmail_msg">
void dumpString(raw_ostream &OS) const;<br class="gmail_msg">
};<br class="gmail_msg">
<br class="gmail_msg">
+namespace dwarf {<br class="gmail_msg">
+ /// Take an optional DWARFFormValue and try to extract a string value from it.<br class="gmail_msg">
+ ///<br class="gmail_msg">
+ /// \param V and optional DWARFFormValue to attempt to extract the value from.<br class="gmail_msg">
+ /// \returns an optional value that contains a value if the form value<br class="gmail_msg">
+ /// was valid and was a string.<br class="gmail_msg">
+ inline Optional<const char*> toString(const Optional<DWARFFormValue>& V) {<br class="gmail_msg">
+ if (V)<br class="gmail_msg">
+ return V->getAsCString();<br class="gmail_msg">
+ return None;<br class="gmail_msg">
+ }<br class="gmail_msg">
+<br class="gmail_msg">
+ /// Take an optional DWARFFormValue and extract a string value from it.<br class="gmail_msg">
+ ///<br class="gmail_msg">
+ /// \param V and optional DWARFFormValue to attempt to extract the value from.<br class="gmail_msg">
+ /// \param Default the default value to return in case of failure.<br class="gmail_msg">
+ /// \returns the string value or Default if the V doesn't have a value or the<br class="gmail_msg">
+ /// form value's encoding wasn't a string.<br class="gmail_msg">
+ inline const char*<br class="gmail_msg">
+ toString(const Optional<DWARFFormValue>& V, const char *Default) {<br class="gmail_msg">
+ return toString(V).getValueOr(Default);<br class="gmail_msg">
+ }<br class="gmail_msg">
+<br class="gmail_msg">
+ /// Take an optional DWARFFormValue and try to extract an unsigned constant.<br class="gmail_msg">
+ ///<br class="gmail_msg">
+ /// \param V and optional DWARFFormValue to attempt to extract the value from.<br class="gmail_msg">
+ /// \returns an optional value that contains a value if the form value<br class="gmail_msg">
+ /// was valid and has a unsigned constant form.<br class="gmail_msg">
+ inline Optional<uint64_t> toUnsigned(const Optional<DWARFFormValue>& V) {<br class="gmail_msg">
+ if (V)<br class="gmail_msg">
+ return V->getAsUnsignedConstant();<br class="gmail_msg">
+ return None;<br class="gmail_msg">
+ }<br class="gmail_msg">
+<br class="gmail_msg">
+ /// Take an optional DWARFFormValue and extract a unsigned constant.<br class="gmail_msg">
+ ///<br class="gmail_msg">
+ /// \param V and optional DWARFFormValue to attempt to extract the value from.<br class="gmail_msg">
+ /// \param Default the default value to return in case of failure.<br class="gmail_msg">
+ /// \returns the extracted unsigned value or Default if the V doesn't have a<br class="gmail_msg">
+ /// value or the form value's encoding wasn't an unsigned constant form.<br class="gmail_msg">
+ inline uint64_t<br class="gmail_msg">
+ toUnsigned(const Optional<DWARFFormValue>& V, uint64_t Default) {<br class="gmail_msg">
+ return toUnsigned(V).getValueOr(Default);<br class="gmail_msg">
+ }<br class="gmail_msg">
+<br class="gmail_msg">
+ /// Take an optional DWARFFormValue and try to extract an reference.<br class="gmail_msg">
+ ///<br class="gmail_msg">
+ /// \param V and optional DWARFFormValue to attempt to extract the value from.<br class="gmail_msg">
+ /// \returns an optional value that contains a value if the form value<br class="gmail_msg">
+ /// was valid and has a reference form.<br class="gmail_msg">
+ inline Optional<uint64_t> toReference(const Optional<DWARFFormValue>& V) {<br class="gmail_msg">
+ if (V)<br class="gmail_msg">
+ return V->getAsReference();<br class="gmail_msg">
+ return None;<br class="gmail_msg">
+ }<br class="gmail_msg">
+<br class="gmail_msg">
+ /// Take an optional DWARFFormValue and extract a reference.<br class="gmail_msg">
+ ///<br class="gmail_msg">
+ /// \param V and optional DWARFFormValue to attempt to extract the value from.<br class="gmail_msg">
+ /// \param Default the default value to return in case of failure.<br class="gmail_msg">
+ /// \returns the extracted reference value or Default if the V doesn't have a<br class="gmail_msg">
+ /// value or the form value's encoding wasn't a reference form.<br class="gmail_msg">
+ inline uint64_t<br class="gmail_msg">
+ toReference(const Optional<DWARFFormValue>& V, uint64_t Default) {<br class="gmail_msg">
+ return toReference(V).getValueOr(Default);<br class="gmail_msg">
+ }<br class="gmail_msg">
+<br class="gmail_msg">
+ /// Take an optional DWARFFormValue and try to extract an signed constant.<br class="gmail_msg">
+ ///<br class="gmail_msg">
+ /// \param V and optional DWARFFormValue to attempt to extract the value from.<br class="gmail_msg">
+ /// \returns an optional value that contains a value if the form value<br class="gmail_msg">
+ /// was valid and has a signed constant form.<br class="gmail_msg">
+ inline Optional<int64_t> toSigned(const Optional<DWARFFormValue>& V) {<br class="gmail_msg">
+ if (V)<br class="gmail_msg">
+ return V->getAsSignedConstant();<br class="gmail_msg">
+ return None;<br class="gmail_msg">
+ }<br class="gmail_msg">
+<br class="gmail_msg">
+ /// Take an optional DWARFFormValue and extract a signed integer.<br class="gmail_msg">
+ ///<br class="gmail_msg">
+ /// \param V and optional DWARFFormValue to attempt to extract the value from.<br class="gmail_msg">
+ /// \param Default the default value to return in case of failure.<br class="gmail_msg">
+ /// \returns the extracted signed integer value or Default if the V doesn't<br class="gmail_msg">
+ /// have a value or the form value's encoding wasn't a signed integer form.<br class="gmail_msg">
+ inline int64_t<br class="gmail_msg">
+ toSigned(const Optional<DWARFFormValue>& V, int64_t Default) {<br class="gmail_msg">
+ return toSigned(V).getValueOr(Default);<br class="gmail_msg">
+ }<br class="gmail_msg">
+<br class="gmail_msg">
+ /// Take an optional DWARFFormValue and try to extract an address.<br class="gmail_msg">
+ ///<br class="gmail_msg">
+ /// \param V and optional DWARFFormValue to attempt to extract the value from.<br class="gmail_msg">
+ /// \returns an optional value that contains a value if the form value<br class="gmail_msg">
+ /// was valid and has a address form.<br class="gmail_msg">
+ inline Optional<uint64_t> toAddress(const Optional<DWARFFormValue>& V) {<br class="gmail_msg">
+ if (V)<br class="gmail_msg">
+ return V->getAsAddress();<br class="gmail_msg">
+ return None;<br class="gmail_msg">
+ }<br class="gmail_msg">
+<br class="gmail_msg">
+ /// Take an optional DWARFFormValue and extract a address.<br class="gmail_msg">
+ ///<br class="gmail_msg">
+ /// \param V and optional DWARFFormValue to attempt to extract the value from.<br class="gmail_msg">
+ /// \param Default the default value to return in case of failure.<br class="gmail_msg">
+ /// \returns the extracted address value or Default if the V doesn't have a<br class="gmail_msg">
+ /// value or the form value's encoding wasn't an address form.<br class="gmail_msg">
+ inline uint64_t<br class="gmail_msg">
+ toAddress(const Optional<DWARFFormValue>& V, uint64_t Default) {<br class="gmail_msg">
+ return toAddress(V).getValueOr(Default);<br class="gmail_msg">
+ }<br class="gmail_msg">
+<br class="gmail_msg">
+ /// Take an optional DWARFFormValue and try to extract an section offset.<br class="gmail_msg">
+ ///<br class="gmail_msg">
+ /// \param V and optional DWARFFormValue to attempt to extract the value from.<br class="gmail_msg">
+ /// \returns an optional value that contains a value if the form value<br class="gmail_msg">
+ /// was valid and has a section offset form.<br class="gmail_msg">
+ inline Optional<uint64_t> toSectionOffset(const Optional<DWARFFormValue>& V) {<br class="gmail_msg">
+ if (V)<br class="gmail_msg">
+ return V->getAsSectionOffset();<br class="gmail_msg">
+ return None;<br class="gmail_msg">
+ }<br class="gmail_msg">
+<br class="gmail_msg">
+ /// Take an optional DWARFFormValue and extract a section offset.<br class="gmail_msg">
+ ///<br class="gmail_msg">
+ /// \param V and optional DWARFFormValue to attempt to extract the value from.<br class="gmail_msg">
+ /// \param Default the default value to return in case of failure.<br class="gmail_msg">
+ /// \returns the extracted section offset value or Default if the V doesn't<br class="gmail_msg">
+ /// have a value or the form value's encoding wasn't a section offset form.<br class="gmail_msg">
+ inline uint64_t<br class="gmail_msg">
+ toSectionOffset(const Optional<DWARFFormValue>& V, uint64_t Default) {<br class="gmail_msg">
+ return toSectionOffset(V).getValueOr(Default);<br class="gmail_msg">
+ }<br class="gmail_msg">
+<br class="gmail_msg">
+ /// Take an optional DWARFFormValue and try to extract block data.<br class="gmail_msg">
+ ///<br class="gmail_msg">
+ /// \param V and optional DWARFFormValue to attempt to extract the value from.<br class="gmail_msg">
+ /// \returns an optional value that contains a value if the form value<br class="gmail_msg">
+ /// was valid and has a block form.<br class="gmail_msg">
+ inline Optional<ArrayRef<uint8_t>><br class="gmail_msg">
+ toBlock(const Optional<DWARFFormValue>& V) {<br class="gmail_msg">
+ if (V)<br class="gmail_msg">
+ return V->getAsBlock();<br class="gmail_msg">
+ return None;<br class="gmail_msg">
+ }<br class="gmail_msg">
+<br class="gmail_msg">
+} // end namespace dwarf<br class="gmail_msg">
+<br class="gmail_msg">
}<br class="gmail_msg">
<br class="gmail_msg">
#endif<br class="gmail_msg">
<br class="gmail_msg">
Modified: llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp<br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp?rev=291959&r1=291958&r2=291959&view=diff" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp?rev=291959&r1=291958&r2=291959&view=diff</a><br class="gmail_msg">
==============================================================================<br class="gmail_msg">
--- llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp (original)<br class="gmail_msg">
+++ llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp Fri Jan 13 15:08:18 2017<br class="gmail_msg">
@@ -128,8 +128,7 @@ void DWARFContext::dump(raw_ostream &OS,<br class="gmail_msg">
auto CUDIE = CU->getUnitDIE();<br class="gmail_msg">
if (!CUDIE)<br class="gmail_msg">
continue;<br class="gmail_msg">
- if (auto StmtOffset =<br class="gmail_msg">
- CUDIE.getAttributeValueAsSectionOffset(DW_AT_stmt_list)) {<br class="gmail_msg">
+ if (auto StmtOffset = toSectionOffset(CUDIE.find(DW_AT_stmt_list))) {<br class="gmail_msg">
DataExtractor lineData(getLineSection().Data, isLittleEndian(),<br class="gmail_msg">
savedAddressByteSize);<br class="gmail_msg">
DWARFDebugLine::LineTable LineTable;<br class="gmail_msg">
@@ -387,7 +386,7 @@ DWARFContext::getLineTableForUnit(DWARFU<br class="gmail_msg">
if (!UnitDIE)<br class="gmail_msg">
return nullptr;<br class="gmail_msg">
<br class="gmail_msg">
- auto Offset = UnitDIE.getAttributeValueAsSectionOffset(DW_AT_stmt_list);<br class="gmail_msg">
+ auto Offset = toSectionOffset(UnitDIE.find(DW_AT_stmt_list));<br class="gmail_msg">
if (!Offset)<br class="gmail_msg">
return nullptr; // No line table for this compile unit.<br class="gmail_msg">
<br class="gmail_msg">
<br class="gmail_msg">
Modified: llvm/trunk/lib/DebugInfo/DWARF/DWARFDie.cpp<br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFDie.cpp?rev=291959&r1=291958&r2=291959&view=diff" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFDie.cpp?rev=291959&r1=291958&r2=291959&view=diff</a><br class="gmail_msg">
==============================================================================<br class="gmail_msg">
--- llvm/trunk/lib/DebugInfo/DWARF/DWARFDie.cpp (original)<br class="gmail_msg">
+++ llvm/trunk/lib/DebugInfo/DWARF/DWARFDie.cpp Fri Jan 13 15:08:18 2017<br class="gmail_msg">
@@ -134,7 +134,7 @@ bool DWARFDie::isSubroutineDIE() const {<br class="gmail_msg">
}<br class="gmail_msg">
<br class="gmail_msg">
Optional<DWARFFormValue><br class="gmail_msg">
-DWARFDie::getAttributeValue(dwarf::Attribute Attr) const {<br class="gmail_msg">
+DWARFDie::find(dwarf::Attribute Attr) const {<br class="gmail_msg">
if (!isValid())<br class="gmail_msg">
return None;<br class="gmail_msg">
auto AbbrevDecl = getAbbreviationDeclarationPtr();<br class="gmail_msg">
@@ -143,54 +143,24 @@ DWARFDie::getAttributeValue(dwarf::Attri<br class="gmail_msg">
return None;<br class="gmail_msg">
}<br class="gmail_msg">
<br class="gmail_msg">
-const char *DWARFDie::getAttributeValueAsString(dwarf::Attribute Attr,<br class="gmail_msg">
- const char *FailValue) const {<br class="gmail_msg">
- auto FormValue = getAttributeValue(Attr);<br class="gmail_msg">
- if (!FormValue)<br class="gmail_msg">
- return FailValue;<br class="gmail_msg">
- Optional<const char *> Result = FormValue->getAsCString();<br class="gmail_msg">
- return Result.hasValue() ? Result.getValue() : FailValue;<br class="gmail_msg">
-}<br class="gmail_msg">
-<br class="gmail_msg">
-Optional<uint64_t><br class="gmail_msg">
-DWARFDie::getAttributeValueAsAddress(dwarf::Attribute Attr) const {<br class="gmail_msg">
- if (auto FormValue = getAttributeValue(Attr))<br class="gmail_msg">
- return FormValue->getAsAddress();<br class="gmail_msg">
- return None;<br class="gmail_msg">
-}<br class="gmail_msg">
-<br class="gmail_msg">
-Optional<int64_t><br class="gmail_msg">
-DWARFDie::getAttributeValueAsSignedConstant(dwarf::Attribute Attr) const {<br class="gmail_msg">
- if (auto FormValue = getAttributeValue(Attr))<br class="gmail_msg">
- return FormValue->getAsSignedConstant();<br class="gmail_msg">
- return None;<br class="gmail_msg">
-}<br class="gmail_msg">
-<br class="gmail_msg">
-Optional<uint64_t><br class="gmail_msg">
-DWARFDie::getAttributeValueAsUnsignedConstant(dwarf::Attribute Attr) const {<br class="gmail_msg">
- if (auto FormValue = getAttributeValue(Attr))<br class="gmail_msg">
- return FormValue->getAsUnsignedConstant();<br class="gmail_msg">
- return None;<br class="gmail_msg">
-}<br class="gmail_msg">
-<br class="gmail_msg">
-Optional<uint64_t><br class="gmail_msg">
-DWARFDie::getAttributeValueAsReference(dwarf::Attribute Attr) const {<br class="gmail_msg">
- if (auto FormValue = getAttributeValue(Attr))<br class="gmail_msg">
- return FormValue->getAsReference();<br class="gmail_msg">
- return None;<br class="gmail_msg">
-}<br class="gmail_msg">
-<br class="gmail_msg">
-Optional<uint64_t><br class="gmail_msg">
-DWARFDie::getAttributeValueAsSectionOffset(dwarf::Attribute Attr) const {<br class="gmail_msg">
- if (auto FormValue = getAttributeValue(Attr))<br class="gmail_msg">
- return FormValue->getAsSectionOffset();<br class="gmail_msg">
+Optional<DWARFFormValue><br class="gmail_msg">
+DWARFDie::findRecursively(dwarf::Attribute Attr) const {<br class="gmail_msg">
+ if (!isValid())<br class="gmail_msg">
+ return None;<br class="gmail_msg">
+ if (auto Value = find(Attr))<br class="gmail_msg">
+ return Value;<br class="gmail_msg">
+ if (auto Die = getAttributeValueAsReferencedDie(DW_AT_abstract_origin))<br class="gmail_msg">
+ if (auto Value = Die.find(Attr))<br class="gmail_msg">
+ return Value;<br class="gmail_msg">
+ if (auto Die = getAttributeValueAsReferencedDie(DW_AT_specification))<br class="gmail_msg">
+ if (auto Value = Die.find(Attr))<br class="gmail_msg">
+ return Value;<br class="gmail_msg">
return None;<br class="gmail_msg">
}<br class="gmail_msg">
<br class="gmail_msg">
-<br class="gmail_msg">
DWARFDie<br class="gmail_msg">
DWARFDie::getAttributeValueAsReferencedDie(dwarf::Attribute Attr) const {<br class="gmail_msg">
- auto SpecRef = getAttributeValueAsReference(Attr);<br class="gmail_msg">
+ auto SpecRef = toReference(find(Attr));<br class="gmail_msg">
if (SpecRef) {<br class="gmail_msg">
auto SpecUnit = U->getUnitSection().getUnitForOffset(*SpecRef);<br class="gmail_msg">
if (SpecUnit)<br class="gmail_msg">
@@ -201,14 +171,14 @@ DWARFDie::getAttributeValueAsReferencedD<br class="gmail_msg">
<br class="gmail_msg">
Optional<uint64_t><br class="gmail_msg">
DWARFDie::getRangesBaseAttribute() const {<br class="gmail_msg">
- auto Result = getAttributeValueAsSectionOffset(DW_AT_rnglists_base);<br class="gmail_msg">
+ auto Result = toSectionOffset(find(DW_AT_rnglists_base));<br class="gmail_msg">
if (Result)<br class="gmail_msg">
return Result;<br class="gmail_msg">
- return getAttributeValueAsSectionOffset(DW_AT_GNU_ranges_base);<br class="gmail_msg">
+ return toSectionOffset(find(DW_AT_GNU_ranges_base));<br class="gmail_msg">
}<br class="gmail_msg">
<br class="gmail_msg">
Optional<uint64_t> DWARFDie::getHighPC(uint64_t LowPC) const {<br class="gmail_msg">
- if (auto FormValue = getAttributeValue(DW_AT_high_pc)) {<br class="gmail_msg">
+ if (auto FormValue = find(DW_AT_high_pc)) {<br class="gmail_msg">
if (auto Address = FormValue->getAsAddress()) {<br class="gmail_msg">
// High PC is an address.<br class="gmail_msg">
return Address;<br class="gmail_msg">
@@ -222,7 +192,7 @@ Optional<uint64_t> DWARFDie::getHighPC(u<br class="gmail_msg">
}<br class="gmail_msg">
<br class="gmail_msg">
bool DWARFDie::getLowAndHighPC(uint64_t &LowPC, uint64_t &HighPC) const {<br class="gmail_msg">
- auto LowPcAddr = getAttributeValueAsAddress(DW_AT_low_pc);<br class="gmail_msg">
+ auto LowPcAddr = toAddress(find(DW_AT_low_pc));<br class="gmail_msg">
if (!LowPcAddr)<br class="gmail_msg">
return false;<br class="gmail_msg">
if (auto HighPcAddr = getHighPC(*LowPcAddr)) {<br class="gmail_msg">
@@ -243,7 +213,7 @@ DWARFDie::getAddressRanges() const {<br class="gmail_msg">
return DWARFAddressRangesVector(1, std::make_pair(LowPC, HighPC));<br class="gmail_msg">
}<br class="gmail_msg">
// Multiple ranges from .debug_ranges section.<br class="gmail_msg">
- auto RangesOffset = getAttributeValueAsSectionOffset(DW_AT_ranges);<br class="gmail_msg">
+ auto RangesOffset = toSectionOffset(find(DW_AT_ranges));<br class="gmail_msg">
if (RangesOffset) {<br class="gmail_msg">
DWARFDebugRangeList RangeList;<br class="gmail_msg">
if (U->extractRangeList(*RangesOffset, RangeList))<br class="gmail_msg">
@@ -284,33 +254,25 @@ const char *<br class="gmail_msg">
DWARFDie::getName(DINameKind Kind) const {<br class="gmail_msg">
if (!isValid() || Kind == DINameKind::None)<br class="gmail_msg">
return nullptr;<br class="gmail_msg">
- const char *name = nullptr;<br class="gmail_msg">
// Try to get mangled name only if it was asked for.<br class="gmail_msg">
if (Kind == DINameKind::LinkageName) {<br class="gmail_msg">
- if ((name = getAttributeValueAsString(DW_AT_MIPS_linkage_name, nullptr)))<br class="gmail_msg">
- return name;<br class="gmail_msg">
- if ((name = getAttributeValueAsString(DW_AT_linkage_name, nullptr)))<br class="gmail_msg">
- return name;<br class="gmail_msg">
- }<br class="gmail_msg">
- if ((name = getAttributeValueAsString(DW_AT_name, nullptr)))<br class="gmail_msg">
- return name;<br class="gmail_msg">
- // Try to get name from specification DIE.<br class="gmail_msg">
- DWARFDie SpecDie = getAttributeValueAsReferencedDie(DW_AT_specification);<br class="gmail_msg">
- if (SpecDie && (name = SpecDie.getName(Kind)))<br class="gmail_msg">
- return name;<br class="gmail_msg">
- // Try to get name from abstract origin DIE.<br class="gmail_msg">
- DWARFDie AbsDie = getAttributeValueAsReferencedDie(DW_AT_abstract_origin);<br class="gmail_msg">
- if (AbsDie && (name = AbsDie.getName(Kind)))<br class="gmail_msg">
- return name;<br class="gmail_msg">
+ if (auto Name = dwarf::toString(findRecursively(DW_AT_MIPS_linkage_name),<br class="gmail_msg">
+ nullptr))<br class="gmail_msg">
+ return Name;<br class="gmail_msg">
+ if (auto Name = dwarf::toString(findRecursively(DW_AT_linkage_name),<br class="gmail_msg">
+ nullptr))<br class="gmail_msg">
+ return Name;<br class="gmail_msg">
+ }<br class="gmail_msg">
+ if (auto Name = dwarf::toString(findRecursively(DW_AT_name), nullptr))<br class="gmail_msg">
+ return Name;<br class="gmail_msg">
return nullptr;<br class="gmail_msg">
}<br class="gmail_msg">
<br class="gmail_msg">
void DWARFDie::getCallerFrame(uint32_t &CallFile, uint32_t &CallLine,<br class="gmail_msg">
uint32_t &CallColumn) const {<br class="gmail_msg">
- CallFile = getAttributeValueAsUnsignedConstant(DW_AT_call_file).getValueOr(0);<br class="gmail_msg">
- CallLine = getAttributeValueAsUnsignedConstant(DW_AT_call_line).getValueOr(0);<br class="gmail_msg">
- CallColumn =<br class="gmail_msg">
- getAttributeValueAsUnsignedConstant(DW_AT_call_column).getValueOr(0);<br class="gmail_msg">
+ CallFile = toUnsigned(find(DW_AT_call_file), 0);<br class="gmail_msg">
+ CallLine = toUnsigned(find(DW_AT_call_line), 0);<br class="gmail_msg">
+ CallColumn = toUnsigned(find(DW_AT_call_column), 0);<br class="gmail_msg">
}<br class="gmail_msg">
<br class="gmail_msg">
void DWARFDie::dump(raw_ostream &OS, unsigned RecurseDepth,<br class="gmail_msg">
<br class="gmail_msg">
Modified: llvm/trunk/lib/DebugInfo/DWARF/DWARFTypeUnit.cpp<br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFTypeUnit.cpp?rev=291959&r1=291958&r2=291959&view=diff" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFTypeUnit.cpp?rev=291959&r1=291958&r2=291959&view=diff</a><br class="gmail_msg">
==============================================================================<br class="gmail_msg">
--- llvm/trunk/lib/DebugInfo/DWARF/DWARFTypeUnit.cpp (original)<br class="gmail_msg">
+++ llvm/trunk/lib/DebugInfo/DWARF/DWARFTypeUnit.cpp Fri Jan 13 15:08:18 2017<br class="gmail_msg">
@@ -26,7 +26,7 @@ bool DWARFTypeUnit::extractImpl(DataExtr<br class="gmail_msg">
<br class="gmail_msg">
void DWARFTypeUnit::dump(raw_ostream &OS, bool SummarizeTypes) {<br class="gmail_msg">
DWARFDie TD = getDIEForOffset(TypeOffset + getOffset());<br class="gmail_msg">
- const char *Name = TD.getAttributeValueAsString(llvm::dwarf::DW_AT_name, "");<br class="gmail_msg">
+ const char *Name = TD.getName(DINameKind::ShortName);<br class="gmail_msg">
<br class="gmail_msg">
if (SummarizeTypes) {<br class="gmail_msg">
OS << "name = '" << Name << "'"<br class="gmail_msg">
<br class="gmail_msg">
Modified: llvm/trunk/lib/DebugInfo/DWARF/DWARFUnit.cpp<br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFUnit.cpp?rev=291959&r1=291958&r2=291959&view=diff" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFUnit.cpp?rev=291959&r1=291958&r2=291959&view=diff</a><br class="gmail_msg">
==============================================================================<br class="gmail_msg">
--- llvm/trunk/lib/DebugInfo/DWARF/DWARFUnit.cpp (original)<br class="gmail_msg">
+++ llvm/trunk/lib/DebugInfo/DWARF/DWARFUnit.cpp Fri Jan 13 15:08:18 2017<br class="gmail_msg">
@@ -13,6 +13,7 @@<br class="gmail_msg">
#include "llvm/DebugInfo/DWARF/DWARFAbbreviationDeclaration.h"<br class="gmail_msg">
#include "llvm/DebugInfo/DWARF/DWARFContext.h"<br class="gmail_msg">
#include "llvm/DebugInfo/DWARF/DWARFDebugAbbrev.h"<br class="gmail_msg">
+#include "llvm/DebugInfo/DWARF/DWARFFormValue.h"<br class="gmail_msg">
#include "llvm/DebugInfo/DWARF/DWARFUnit.h"<br class="gmail_msg">
#include "llvm/Object/ObjectFile.h"<br class="gmail_msg">
#include "llvm/Support/Casting.h"<br class="gmail_msg">
@@ -151,11 +152,11 @@ void DWARFUnit::clear() {<br class="gmail_msg">
}<br class="gmail_msg">
<br class="gmail_msg">
const char *DWARFUnit::getCompilationDir() {<br class="gmail_msg">
- return getUnitDIE().getAttributeValueAsString(DW_AT_comp_dir, nullptr);<br class="gmail_msg">
+ return toString(getUnitDIE().find(DW_AT_comp_dir), nullptr);<br class="gmail_msg">
}<br class="gmail_msg">
<br class="gmail_msg">
Optional<uint64_t> DWARFUnit::getDWOId() {<br class="gmail_msg">
- return getUnitDIE().getAttributeValueAsUnsignedConstant(DW_AT_GNU_dwo_id);<br class="gmail_msg">
+ return toUnsigned(getUnitDIE().find(DW_AT_GNU_dwo_id));<br class="gmail_msg">
}<br class="gmail_msg">
<br class="gmail_msg">
void DWARFUnit::extractDIEsToVector(<br class="gmail_msg">
@@ -225,17 +226,13 @@ size_t DWARFUnit::extractDIEsIfNeeded(bo<br class="gmail_msg">
// If CU DIE was just parsed, copy several attribute values from it.<br class="gmail_msg">
if (!HasCUDie) {<br class="gmail_msg">
DWARFDie UnitDie = getUnitDIE();<br class="gmail_msg">
- auto BaseAddr = UnitDie.getAttributeValueAsAddress(DW_AT_low_pc);<br class="gmail_msg">
+ auto BaseAddr = toAddress(UnitDie.find(DW_AT_low_pc));<br class="gmail_msg">
if (!BaseAddr)<br class="gmail_msg">
- BaseAddr = UnitDie.getAttributeValueAsAddress(DW_AT_entry_pc);<br class="gmail_msg">
+ BaseAddr = toAddress(UnitDie.find(DW_AT_entry_pc));<br class="gmail_msg">
if (BaseAddr)<br class="gmail_msg">
setBaseAddress(*BaseAddr);<br class="gmail_msg">
- AddrOffsetSectionBase =<br class="gmail_msg">
- UnitDie.getAttributeValueAsSectionOffset(DW_AT_GNU_addr_base)<br class="gmail_msg">
- .getValueOr(0);<br class="gmail_msg">
- RangeSectionBase =<br class="gmail_msg">
- UnitDie.getAttributeValueAsSectionOffset(DW_AT_rnglists_base)<br class="gmail_msg">
- .getValueOr(0);<br class="gmail_msg">
+ AddrOffsetSectionBase = toSectionOffset(UnitDie.find(DW_AT_GNU_addr_base), 0);<br class="gmail_msg">
+ RangeSectionBase = toSectionOffset(UnitDie.find(DW_AT_rnglists_base), 0);<br class="gmail_msg">
// Don't fall back to DW_AT_GNU_ranges_base: it should be ignored for<br class="gmail_msg">
// skeleton CU DIE, so that DWARF users not aware of it are not broken.<br class="gmail_msg">
}<br class="gmail_msg">
@@ -266,17 +263,16 @@ bool DWARFUnit::parseDWO() {<br class="gmail_msg">
DWARFDie UnitDie = getUnitDIE();<br class="gmail_msg">
if (!UnitDie)<br class="gmail_msg">
return false;<br class="gmail_msg">
- const char *DWOFileName =<br class="gmail_msg">
- UnitDie.getAttributeValueAsString(DW_AT_GNU_dwo_name, nullptr);<br class="gmail_msg">
+ auto DWOFileName = toString(UnitDie.find(DW_AT_GNU_dwo_name));<br class="gmail_msg">
if (!DWOFileName)<br class="gmail_msg">
return false;<br class="gmail_msg">
- const char *CompilationDir =<br class="gmail_msg">
- UnitDie.getAttributeValueAsString(DW_AT_comp_dir, nullptr);<br class="gmail_msg">
+ auto CompilationDir = toString(UnitDie.find(DW_AT_comp_dir));<br class="gmail_msg">
SmallString<16> AbsolutePath;<br class="gmail_msg">
- if (sys::path::is_relative(DWOFileName) && CompilationDir != nullptr) {<br class="gmail_msg">
- sys::path::append(AbsolutePath, CompilationDir);<br class="gmail_msg">
+ if (sys::path::is_relative(*DWOFileName) && CompilationDir &&<br class="gmail_msg">
+ *CompilationDir) {<br class="gmail_msg">
+ sys::path::append(AbsolutePath, *CompilationDir);<br class="gmail_msg">
}<br class="gmail_msg">
- sys::path::append(AbsolutePath, DWOFileName);<br class="gmail_msg">
+ sys::path::append(AbsolutePath, *DWOFileName);<br class="gmail_msg">
DWO = llvm::make_unique<DWOHolder>(AbsolutePath);<br class="gmail_msg">
DWARFUnit *DWOCU = DWO->getUnit();<br class="gmail_msg">
// Verify that compile unit in .dwo file is valid.<br class="gmail_msg">
<br class="gmail_msg">
Modified: llvm/trunk/tools/dsymutil/DwarfLinker.cpp<br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/dsymutil/DwarfLinker.cpp?rev=291959&r1=291958&r2=291959&view=diff" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/dsymutil/DwarfLinker.cpp?rev=291959&r1=291958&r2=291959&view=diff</a><br class="gmail_msg">
==============================================================================<br class="gmail_msg">
--- llvm/trunk/tools/dsymutil/DwarfLinker.cpp (original)<br class="gmail_msg">
+++ llvm/trunk/tools/dsymutil/DwarfLinker.cpp Fri Jan 13 15:08:18 2017<br class="gmail_msg">
@@ -205,14 +205,12 @@ public:<br class="gmail_msg">
Info.resize(OrigUnit.getNumDIEs());<br class="gmail_msg">
<br class="gmail_msg">
auto CUDie = OrigUnit.getUnitDIE(false);<br class="gmail_msg">
- unsigned Lang =<br class="gmail_msg">
- CUDie.getAttributeValueAsUnsignedConstant(dwarf::DW_AT_language)<br class="gmail_msg">
- .getValueOr(0);<br class="gmail_msg">
- HasODR = CanUseODR && (Lang == dwarf::DW_LANG_C_plus_plus ||<br class="gmail_msg">
- Lang == dwarf::DW_LANG_C_plus_plus_03 ||<br class="gmail_msg">
- Lang == dwarf::DW_LANG_C_plus_plus_11 ||<br class="gmail_msg">
- Lang == dwarf::DW_LANG_C_plus_plus_14 ||<br class="gmail_msg">
- Lang == dwarf::DW_LANG_ObjC_plus_plus);<br class="gmail_msg">
+ if (auto Lang = dwarf::toUnsigned(CUDie.find(dwarf::DW_AT_language)))<br class="gmail_msg">
+ HasODR = CanUseODR && (*Lang == dwarf::DW_LANG_C_plus_plus ||<br class="gmail_msg">
+ *Lang == dwarf::DW_LANG_C_plus_plus_03 ||<br class="gmail_msg">
+ *Lang == dwarf::DW_LANG_C_plus_plus_11 ||<br class="gmail_msg">
+ *Lang == dwarf::DW_LANG_C_plus_plus_14 ||<br class="gmail_msg">
+ *Lang == dwarf::DW_LANG_ObjC_plus_plus);<br class="gmail_msg">
}<br class="gmail_msg">
<br class="gmail_msg">
DWARFUnit &getOrigUnit() const { return OrigUnit; }<br class="gmail_msg">
@@ -843,8 +841,7 @@ void DwarfStreamer::emitLocationsForUnit<br class="gmail_msg">
DWARFUnit &OrigUnit = Unit.getOrigUnit();<br class="gmail_msg">
auto OrigUnitDie = OrigUnit.getUnitDIE(false);<br class="gmail_msg">
int64_t UnitPcOffset = 0;<br class="gmail_msg">
- auto OrigLowPc = OrigUnitDie.getAttributeValueAsAddress(dwarf::DW_AT_low_pc);<br class="gmail_msg">
- if (OrigLowPc)<br class="gmail_msg">
+ if (auto OrigLowPc = dwarf::toAddress(OrigUnitDie.find(dwarf::DW_AT_low_pc)))<br class="gmail_msg">
UnitPcOffset = int64_t(*OrigLowPc) - Unit.getLowPc();<br class="gmail_msg">
<br class="gmail_msg">
for (const auto &Attr : Attributes) {<br class="gmail_msg">
@@ -1558,8 +1555,7 @@ PointerIntPair<DeclContext *, 1> DeclCon<br class="gmail_msg">
// Do not unique anything inside CU local functions.<br class="gmail_msg">
if ((Context.getTag() == dwarf::DW_TAG_namespace ||<br class="gmail_msg">
Context.getTag() == dwarf::DW_TAG_compile_unit) &&<br class="gmail_msg">
- !DIE.getAttributeValueAsUnsignedConstant(dwarf::DW_AT_external)<br class="gmail_msg">
- .getValueOr(0))<br class="gmail_msg">
+ !dwarf::toUnsigned(DIE.find(dwarf::DW_AT_external), 0))<br class="gmail_msg">
return PointerIntPair<DeclContext *, 1>(nullptr);<br class="gmail_msg">
LLVM_FALLTHROUGH;<br class="gmail_msg">
case dwarf::DW_TAG_member:<br class="gmail_msg">
@@ -1573,8 +1569,7 @@ PointerIntPair<DeclContext *, 1> DeclCon<br class="gmail_msg">
// created on demand. For example implicitely defined constructors<br class="gmail_msg">
// are ambiguous because of the way we identify contexts, and they<br class="gmail_msg">
// won't be generated everytime everywhere.<br class="gmail_msg">
- if (DIE.getAttributeValueAsUnsignedConstant(dwarf::DW_AT_artificial)<br class="gmail_msg">
- .getValueOr(0))<br class="gmail_msg">
+ if (dwarf::toUnsigned(DIE.find(dwarf::DW_AT_artificial), 0))<br class="gmail_msg">
return PointerIntPair<DeclContext *, 1>(nullptr);<br class="gmail_msg">
break;<br class="gmail_msg">
}<br class="gmail_msg">
@@ -1614,12 +1609,9 @@ PointerIntPair<DeclContext *, 1> DeclCon<br class="gmail_msg">
// namespaces, use these additional data points to make the process<br class="gmail_msg">
// safer. This is disabled for clang modules, because forward<br class="gmail_msg">
// declarations of module-defined types do not have a file and line.<br class="gmail_msg">
- ByteSize = DIE.getAttributeValueAsUnsignedConstant(dwarf::DW_AT_byte_size)<br class="gmail_msg">
- .getValueOr(UINT64_MAX);<br class="gmail_msg">
+ ByteSize = dwarf::toUnsigned(DIE.find(dwarf::DW_AT_byte_size), UINT64_MAX);<br class="gmail_msg">
if (Tag != dwarf::DW_TAG_namespace || !Name) {<br class="gmail_msg">
- if (unsigned FileNum =<br class="gmail_msg">
- DIE.getAttributeValueAsUnsignedConstant(dwarf::DW_AT_decl_file)<br class="gmail_msg">
- .getValueOr(0)) {<br class="gmail_msg">
+ if (unsigned FileNum = dwarf::toUnsigned(DIE.find(dwarf::DW_AT_decl_file), 0)) {<br class="gmail_msg">
if (const auto *LT = U.getOrigUnit().getContext().getLineTableForUnit(<br class="gmail_msg">
&U.getOrigUnit())) {<br class="gmail_msg">
// FIXME: dsymutil-classic compatibility. I'd rather not<br class="gmail_msg">
@@ -1632,9 +1624,7 @@ PointerIntPair<DeclContext *, 1> DeclCon<br class="gmail_msg">
// instead of "" would allow more uniquing, but for now, do<br class="gmail_msg">
// it this way to match dsymutil-classic.<br class="gmail_msg">
if (LT->hasFileAtIndex(FileNum)) {<br class="gmail_msg">
- Line =<br class="gmail_msg">
- DIE.getAttributeValueAsUnsignedConstant(dwarf::DW_AT_decl_line)<br class="gmail_msg">
- .getValueOr(0);<br class="gmail_msg">
+ Line = dwarf::toUnsigned(DIE.find(dwarf::DW_AT_decl_line), 0);<br class="gmail_msg">
// Cache the resolved paths, because calling realpath is expansive.<br class="gmail_msg">
StringRef ResolvedPath = U.getResolvedPath(FileNum);<br class="gmail_msg">
if (!ResolvedPath.empty()) {<br class="gmail_msg">
@@ -1782,8 +1772,7 @@ static bool analyzeContextInfo(const DWA<br class="gmail_msg">
//<br class="gmail_msg">
// We treat non-C++ modules like namespaces for this reason.<br class="gmail_msg">
if (DIE.getTag() == dwarf::DW_TAG_module && ParentIdx == 0 &&<br class="gmail_msg">
- DIE.getAttributeValueAsString(dwarf::DW_AT_name,<br class="gmail_msg">
- "") != CU.getClangModuleName()) {<br class="gmail_msg">
+ dwarf::toString(DIE.find(dwarf::DW_AT_name), "") != CU.getClangModuleName()) {<br class="gmail_msg">
InImportedModule = true;<br class="gmail_msg">
}<br class="gmail_msg">
<br class="gmail_msg">
@@ -1811,8 +1800,7 @@ static bool analyzeContextInfo(const DWA<br class="gmail_msg">
// forward declarations.<br class="gmail_msg">
Info.Prune &=<br class="gmail_msg">
(DIE.getTag() == dwarf::DW_TAG_module) ||<br class="gmail_msg">
- DIE.getAttributeValueAsUnsignedConstant(dwarf::DW_AT_declaration)<br class="gmail_msg">
- .getValueOr(0);<br class="gmail_msg">
+ dwarf::toUnsigned(DIE.find(dwarf::DW_AT_declaration), 0);<br class="gmail_msg">
<br class="gmail_msg">
// Don't prune it if there is no definition for the DIE.<br class="gmail_msg">
Info.Prune &= Info.Ctxt && Info.Ctxt->getCanonicalDIEOffset();<br class="gmail_msg">
@@ -2129,7 +2117,7 @@ unsigned DwarfLinker::shouldKeepSubprogr<br class="gmail_msg">
std::tie(LowPcOffset, LowPcEndOffset) =<br class="gmail_msg">
getAttributeOffsets(Abbrev, *LowPcIdx, Offset, OrigUnit);<br class="gmail_msg">
<br class="gmail_msg">
- auto LowPc = DIE.getAttributeValueAsAddress(dwarf::DW_AT_low_pc);<br class="gmail_msg">
+ auto LowPc = dwarf::toAddress(DIE.find(dwarf::DW_AT_low_pc));<br class="gmail_msg">
assert(LowPc.hasValue() && "low_pc attribute is not an address.");<br class="gmail_msg">
if (!LowPc ||<br class="gmail_msg">
!RelocMgr.hasValidRelocation(LowPcOffset, LowPcEndOffset, MyInfo))<br class="gmail_msg">
@@ -2746,14 +2734,11 @@ DIE *DwarfLinker::DIECloner::cloneDIE(<br class="gmail_msg">
// file might be start address of another function which got moved<br class="gmail_msg">
// independantly by the linker). The computation of the actual<br class="gmail_msg">
// high_pc value is done in cloneAddressAttribute().<br class="gmail_msg">
- AttrInfo.OrigHighPc =<br class="gmail_msg">
- InputDIE.getAttributeValueAsAddress(dwarf::DW_AT_high_pc).getValueOr(0);<br class="gmail_msg">
+ AttrInfo.OrigHighPc = dwarf::toAddress(InputDIE.find(dwarf::DW_AT_high_pc), 0);<br class="gmail_msg">
// Also store the low_pc. It might get relocated in an<br class="gmail_msg">
// inline_subprogram that happens at the beginning of its<br class="gmail_msg">
// inlining function.<br class="gmail_msg">
- AttrInfo.OrigLowPc =<br class="gmail_msg">
- InputDIE.getAttributeValueAsAddress(dwarf::DW_AT_low_pc)<br class="gmail_msg">
- .getValueOr(UINT64_MAX);<br class="gmail_msg">
+ AttrInfo.OrigLowPc = dwarf::toAddress(InputDIE.find(dwarf::DW_AT_low_pc), UINT64_MAX);<br class="gmail_msg">
}<br class="gmail_msg">
<br class="gmail_msg">
// Reset the Offset to 0 as we will be working on the local copy of<br class="gmail_msg">
@@ -2872,9 +2857,7 @@ void DwarfLinker::patchRangesForUnit(con<br class="gmail_msg">
auto InvalidRange = FunctionRanges.end(), CurrRange = InvalidRange;<br class="gmail_msg">
DWARFUnit &OrigUnit = Unit.getOrigUnit();<br class="gmail_msg">
auto OrigUnitDie = OrigUnit.getUnitDIE(false);<br class="gmail_msg">
- uint64_t OrigLowPc =<br class="gmail_msg">
- OrigUnitDie.getAttributeValueAsAddress(dwarf::DW_AT_low_pc)<br class="gmail_msg">
- .getValueOr(-1ULL);<br class="gmail_msg">
+ uint64_t OrigLowPc = dwarf::toAddress(OrigUnitDie.find(dwarf::DW_AT_low_pc), -1ULL);<br class="gmail_msg">
// Ranges addresses are based on the unit's low_pc. Compute the<br class="gmail_msg">
// offset we need to apply to adapt to the new unit's low_pc.<br class="gmail_msg">
int64_t UnitPcOffset = 0;<br class="gmail_msg">
@@ -2969,7 +2952,7 @@ static void patchStmtList(DIE &Die, DIEI<br class="gmail_msg">
void DwarfLinker::patchLineTableForUnit(CompileUnit &Unit,<br class="gmail_msg">
DWARFContext &OrigDwarf) {<br class="gmail_msg">
DWARFDie CUDie = Unit.getOrigUnit().getUnitDIE();<br class="gmail_msg">
- auto StmtList = CUDie.getAttributeValueAsSectionOffset(dwarf::DW_AT_stmt_list);<br class="gmail_msg">
+ auto StmtList = dwarf::toSectionOffset(CUDie.find(dwarf::DW_AT_stmt_list));<br class="gmail_msg">
if (!StmtList)<br class="gmail_msg">
return;<br class="gmail_msg">
<br class="gmail_msg">
@@ -3201,10 +3184,10 @@ void DwarfLinker::DIECloner::copyAbbrev(<br class="gmail_msg">
<br class="gmail_msg">
static uint64_t getDwoId(const DWARFDie &CUDie,<br class="gmail_msg">
const DWARFUnit &Unit) {<br class="gmail_msg">
- auto DwoId = CUDie.getAttributeValueAsUnsignedConstant(dwarf::DW_AT_dwo_id);<br class="gmail_msg">
+ auto DwoId = dwarf::toUnsigned(CUDie.find(dwarf::DW_AT_dwo_id));<br class="gmail_msg">
if (DwoId)<br class="gmail_msg">
return *DwoId;<br class="gmail_msg">
- DwoId = CUDie.getAttributeValueAsUnsignedConstant(dwarf::DW_AT_GNU_dwo_id);<br class="gmail_msg">
+ DwoId = dwarf::toUnsigned(CUDie.find(dwarf::DW_AT_GNU_dwo_id));<br class="gmail_msg">
if (DwoId)<br class="gmail_msg">
return *DwoId;<br class="gmail_msg">
return 0;<br class="gmail_msg">
@@ -3213,21 +3196,17 @@ static uint64_t getDwoId(const DWARFDie<br class="gmail_msg">
bool DwarfLinker::registerModuleReference(<br class="gmail_msg">
const DWARFDie &CUDie, const DWARFUnit &Unit,<br class="gmail_msg">
DebugMap &ModuleMap, unsigned Indent) {<br class="gmail_msg">
- std::string PCMfile =<br class="gmail_msg">
- CUDie.getAttributeValueAsString(dwarf::DW_AT_dwo_name, "");<br class="gmail_msg">
+ std::string PCMfile = dwarf::toString(CUDie.find(dwarf::DW_AT_dwo_name), "");<br class="gmail_msg">
if (PCMfile.empty())<br class="gmail_msg">
- PCMfile =<br class="gmail_msg">
- CUDie.getAttributeValueAsString(dwarf::DW_AT_GNU_dwo_name, "");<br class="gmail_msg">
+ PCMfile = dwarf::toString(CUDie.find(dwarf::DW_AT_GNU_dwo_name), "");<br class="gmail_msg">
if (PCMfile.empty())<br class="gmail_msg">
return false;<br class="gmail_msg">
<br class="gmail_msg">
// Clang module DWARF skeleton CUs abuse this for the path to the module.<br class="gmail_msg">
- std::string PCMpath =<br class="gmail_msg">
- CUDie.getAttributeValueAsString(dwarf::DW_AT_comp_dir, "");<br class="gmail_msg">
+ std::string PCMpath = dwarf::toString(CUDie.find(dwarf::DW_AT_comp_dir), "");<br class="gmail_msg">
uint64_t DwoId = getDwoId(CUDie, Unit);<br class="gmail_msg">
<br class="gmail_msg">
- std::string Name =<br class="gmail_msg">
- CUDie.getAttributeValueAsString(dwarf::DW_AT_name, "");<br class="gmail_msg">
+ std::string Name = dwarf::toString(CUDie.find(dwarf::DW_AT_name), "");<br class="gmail_msg">
if (Name.empty()) {<br class="gmail_msg">
reportWarning("Anonymous module skeleton CU for " + PCMfile);<br class="gmail_msg">
return true;<br class="gmail_msg">
<br class="gmail_msg">
Modified: llvm/trunk/tools/obj2yaml/dwarf2yaml.cpp<br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/obj2yaml/dwarf2yaml.cpp?rev=291959&r1=291958&r2=291959&view=diff" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/obj2yaml/dwarf2yaml.cpp?rev=291959&r1=291958&r2=291959&view=diff</a><br class="gmail_msg">
==============================================================================<br class="gmail_msg">
--- llvm/trunk/tools/obj2yaml/dwarf2yaml.cpp (original)<br class="gmail_msg">
+++ llvm/trunk/tools/obj2yaml/dwarf2yaml.cpp Fri Jan 13 15:08:18 2017<br class="gmail_msg">
@@ -126,7 +126,7 @@ void dumpDebugInfo(DWARFContextInMemory<br class="gmail_msg">
DWARFYAML::FormValue NewValue;<br class="gmail_msg">
NewValue.Value = 0xDEADBEEFDEADBEEF;<br class="gmail_msg">
DWARFDie DIEWrapper(CU.get(), &DIE);<br class="gmail_msg">
- auto FormValue = DIEWrapper.getAttributeValue(AttrSpec.Attr);<br class="gmail_msg">
+ auto FormValue = DIEWrapper.find(AttrSpec.Attr);<br class="gmail_msg">
if (!FormValue)<br class="gmail_msg">
return;<br class="gmail_msg">
auto Form = FormValue.getValue().getForm();<br class="gmail_msg">
@@ -228,7 +228,7 @@ void dumpDebugLines(DWARFContextInMemory<br class="gmail_msg">
if (!CUDIE)<br class="gmail_msg">
continue;<br class="gmail_msg">
if (auto StmtOffset =<br class="gmail_msg">
- CUDIE.getAttributeValueAsSectionOffset(dwarf::DW_AT_stmt_list)) {<br class="gmail_msg">
+ dwarf::toSectionOffset(CUDIE.find(dwarf::DW_AT_stmt_list))) {<br class="gmail_msg">
DWARFYAML::LineTable DebugLines;<br class="gmail_msg">
DataExtractor LineData(DCtx.getLineSection().Data, DCtx.isLittleEndian(),<br class="gmail_msg">
CU->getAddressByteSize());<br class="gmail_msg">
<br class="gmail_msg">
Modified: llvm/trunk/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp<br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp?rev=291959&r1=291958&r2=291959&view=diff" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp?rev=291959&r1=291958&r2=291959&view=diff</a><br class="gmail_msg">
==============================================================================<br class="gmail_msg">
--- llvm/trunk/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp (original)<br class="gmail_msg">
+++ llvm/trunk/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp Fri Jan 13 15:08:18 2017<br class="gmail_msg">
@@ -228,8 +228,7 @@ void TestAllForms() {<br class="gmail_msg">
//----------------------------------------------------------------------<br class="gmail_msg">
// Test address forms<br class="gmail_msg">
//----------------------------------------------------------------------<br class="gmail_msg">
- EXPECT_EQ(DieDG.getAttributeValueAsAddress(Attr_DW_FORM_addr).getValueOr(0),<br class="gmail_msg">
- AddrValue);<br class="gmail_msg">
+ EXPECT_EQ(AddrValue, toAddress(DieDG.find(Attr_DW_FORM_addr), 0));<br class="gmail_msg">
<br class="gmail_msg">
//----------------------------------------------------------------------<br class="gmail_msg">
// Test block forms<br class="gmail_msg">
@@ -238,7 +237,7 @@ void TestAllForms() {<br class="gmail_msg">
ArrayRef<uint8_t> ExtractedBlockData;<br class="gmail_msg">
Optional<ArrayRef<uint8_t>> BlockDataOpt;<br class="gmail_msg">
<br class="gmail_msg">
- FormValue = DieDG.getAttributeValue(Attr_DW_FORM_block);<br class="gmail_msg">
+ FormValue = DieDG.find(Attr_DW_FORM_block);<br class="gmail_msg">
EXPECT_TRUE((bool)FormValue);<br class="gmail_msg">
BlockDataOpt = FormValue->getAsBlock();<br class="gmail_msg">
EXPECT_TRUE(BlockDataOpt.hasValue());<br class="gmail_msg">
@@ -246,7 +245,7 @@ void TestAllForms() {<br class="gmail_msg">
EXPECT_EQ(ExtractedBlockData.size(), BlockSize);<br class="gmail_msg">
EXPECT_TRUE(memcmp(ExtractedBlockData.data(), BlockData, BlockSize) == 0);<br class="gmail_msg">
<br class="gmail_msg">
- FormValue = DieDG.getAttributeValue(Attr_DW_FORM_block1);<br class="gmail_msg">
+ FormValue = DieDG.find(Attr_DW_FORM_block1);<br class="gmail_msg">
EXPECT_TRUE((bool)FormValue);<br class="gmail_msg">
BlockDataOpt = FormValue->getAsBlock();<br class="gmail_msg">
EXPECT_TRUE(BlockDataOpt.hasValue());<br class="gmail_msg">
@@ -254,7 +253,7 @@ void TestAllForms() {<br class="gmail_msg">
EXPECT_EQ(ExtractedBlockData.size(), BlockSize);<br class="gmail_msg">
EXPECT_TRUE(memcmp(ExtractedBlockData.data(), BlockData, BlockSize) == 0);<br class="gmail_msg">
<br class="gmail_msg">
- FormValue = DieDG.getAttributeValue(Attr_DW_FORM_block2);<br class="gmail_msg">
+ FormValue = DieDG.find(Attr_DW_FORM_block2);<br class="gmail_msg">
EXPECT_TRUE((bool)FormValue);<br class="gmail_msg">
BlockDataOpt = FormValue->getAsBlock();<br class="gmail_msg">
EXPECT_TRUE(BlockDataOpt.hasValue());<br class="gmail_msg">
@@ -262,7 +261,7 @@ void TestAllForms() {<br class="gmail_msg">
EXPECT_EQ(ExtractedBlockData.size(), BlockSize);<br class="gmail_msg">
EXPECT_TRUE(memcmp(ExtractedBlockData.data(), BlockData, BlockSize) == 0);<br class="gmail_msg">
<br class="gmail_msg">
- FormValue = DieDG.getAttributeValue(Attr_DW_FORM_block4);<br class="gmail_msg">
+ FormValue = DieDG.find(Attr_DW_FORM_block4);<br class="gmail_msg">
EXPECT_TRUE((bool)FormValue);<br class="gmail_msg">
BlockDataOpt = FormValue->getAsBlock();<br class="gmail_msg">
EXPECT_TRUE(BlockDataOpt.hasValue());<br class="gmail_msg">
@@ -273,100 +272,64 @@ void TestAllForms() {<br class="gmail_msg">
//----------------------------------------------------------------------<br class="gmail_msg">
// Test data forms<br class="gmail_msg">
//----------------------------------------------------------------------<br class="gmail_msg">
- EXPECT_EQ(DieDG.getAttributeValueAsUnsignedConstant(Attr_DW_FORM_data1)<br class="gmail_msg">
- .getValueOr(0),<br class="gmail_msg">
- Data1);<br class="gmail_msg">
- EXPECT_EQ(DieDG.getAttributeValueAsUnsignedConstant(Attr_DW_FORM_data2)<br class="gmail_msg">
- .getValueOr(0),<br class="gmail_msg">
- Data2);<br class="gmail_msg">
- EXPECT_EQ(DieDG.getAttributeValueAsUnsignedConstant(Attr_DW_FORM_data4)<br class="gmail_msg">
- .getValueOr(0),<br class="gmail_msg">
- Data4);<br class="gmail_msg">
- EXPECT_EQ(DieDG.getAttributeValueAsUnsignedConstant(Attr_DW_FORM_data8)<br class="gmail_msg">
- .getValueOr(0),<br class="gmail_msg">
- Data8);<br class="gmail_msg">
+ EXPECT_EQ(Data1, toUnsigned(DieDG.find(Attr_DW_FORM_data1), 0));<br class="gmail_msg">
+ EXPECT_EQ(Data2, toUnsigned(DieDG.find(Attr_DW_FORM_data2), 0));<br class="gmail_msg">
+ EXPECT_EQ(Data4, toUnsigned(DieDG.find(Attr_DW_FORM_data4), 0));<br class="gmail_msg">
+ EXPECT_EQ(Data8, toUnsigned(DieDG.find(Attr_DW_FORM_data8), 0));<br class="gmail_msg">
<br class="gmail_msg">
//----------------------------------------------------------------------<br class="gmail_msg">
// Test string forms<br class="gmail_msg">
//----------------------------------------------------------------------<br class="gmail_msg">
- const char *ExtractedStringValue =<br class="gmail_msg">
- DieDG.getAttributeValueAsString(Attr_DW_FORM_string, nullptr);<br class="gmail_msg">
- EXPECT_TRUE(ExtractedStringValue != nullptr);<br class="gmail_msg">
- EXPECT_TRUE(strcmp(StringValue, ExtractedStringValue) == 0);<br class="gmail_msg">
-<br class="gmail_msg">
- const char *ExtractedStrpValue =<br class="gmail_msg">
- DieDG.getAttributeValueAsString(Attr_DW_FORM_strp, nullptr);<br class="gmail_msg">
- EXPECT_TRUE(ExtractedStrpValue != nullptr);<br class="gmail_msg">
- EXPECT_TRUE(strcmp(StrpValue, ExtractedStrpValue) == 0);<br class="gmail_msg">
+ auto ExtractedStringValue = toString(DieDG.find(Attr_DW_FORM_string));<br class="gmail_msg">
+ EXPECT_TRUE((bool)ExtractedStringValue);<br class="gmail_msg">
+ EXPECT_TRUE(strcmp(StringValue, *ExtractedStringValue) == 0);<br class="gmail_msg">
+<br class="gmail_msg">
+ auto ExtractedStrpValue = toString(DieDG.find(Attr_DW_FORM_strp));<br class="gmail_msg">
+ EXPECT_TRUE((bool)ExtractedStrpValue);<br class="gmail_msg">
+ EXPECT_TRUE(strcmp(StrpValue, *ExtractedStrpValue) == 0);<br class="gmail_msg">
<br class="gmail_msg">
//----------------------------------------------------------------------<br class="gmail_msg">
// Test reference forms<br class="gmail_msg">
//----------------------------------------------------------------------<br class="gmail_msg">
- EXPECT_EQ(<br class="gmail_msg">
- DieDG.getAttributeValueAsReference(Attr_DW_FORM_ref_addr).getValueOr(0),<br class="gmail_msg">
- RefAddr);<br class="gmail_msg">
- EXPECT_EQ(DieDG.getAttributeValueAsReference(Attr_DW_FORM_ref1).getValueOr(0),<br class="gmail_msg">
- Data1);<br class="gmail_msg">
- EXPECT_EQ(DieDG.getAttributeValueAsReference(Attr_DW_FORM_ref2).getValueOr(0),<br class="gmail_msg">
- Data2);<br class="gmail_msg">
- EXPECT_EQ(DieDG.getAttributeValueAsReference(Attr_DW_FORM_ref4).getValueOr(0),<br class="gmail_msg">
- Data4);<br class="gmail_msg">
- EXPECT_EQ(DieDG.getAttributeValueAsReference(Attr_DW_FORM_ref8).getValueOr(0),<br class="gmail_msg">
- Data8);<br class="gmail_msg">
- EXPECT_EQ(<br class="gmail_msg">
- DieDG.getAttributeValueAsReference(Attr_DW_FORM_ref_sig8).getValueOr(0),<br class="gmail_msg">
- Data8_2);<br class="gmail_msg">
- EXPECT_EQ(<br class="gmail_msg">
- DieDG.getAttributeValueAsReference(Attr_DW_FORM_ref_udata).getValueOr(0),<br class="gmail_msg">
- UData[0]);<br class="gmail_msg">
+ EXPECT_EQ(RefAddr, toReference(DieDG.find(Attr_DW_FORM_ref_addr), 0));<br class="gmail_msg">
+ EXPECT_EQ(Data1, toReference(DieDG.find(Attr_DW_FORM_ref1), 0));<br class="gmail_msg">
+ EXPECT_EQ(Data2, toReference(DieDG.find(Attr_DW_FORM_ref2), 0));<br class="gmail_msg">
+ EXPECT_EQ(Data4, toReference(DieDG.find(Attr_DW_FORM_ref4), 0));<br class="gmail_msg">
+ EXPECT_EQ(Data8, toReference(DieDG.find(Attr_DW_FORM_ref8), 0));<br class="gmail_msg">
+ EXPECT_EQ(Data8_2, toReference(DieDG.find(Attr_DW_FORM_ref_sig8), 0));<br class="gmail_msg">
+ EXPECT_EQ(UData[0], toReference(DieDG.find(Attr_DW_FORM_ref_udata), 0));<br class="gmail_msg">
<br class="gmail_msg">
//----------------------------------------------------------------------<br class="gmail_msg">
// Test flag forms<br class="gmail_msg">
//----------------------------------------------------------------------<br class="gmail_msg">
- EXPECT_EQ(DieDG.getAttributeValueAsUnsignedConstant(Attr_DW_FORM_flag_true)<br class="gmail_msg">
- .getValueOr(0),<br class="gmail_msg">
- 1ULL);<br class="gmail_msg">
- EXPECT_EQ(DieDG.getAttributeValueAsUnsignedConstant(Attr_DW_FORM_flag_false)<br class="gmail_msg">
- .getValueOr(1),<br class="gmail_msg">
- 0ULL);<br class="gmail_msg">
- EXPECT_EQ(DieDG.getAttributeValueAsUnsignedConstant(Attr_DW_FORM_flag_present)<br class="gmail_msg">
- .getValueOr(0ULL),<br class="gmail_msg">
- 1ULL);<br class="gmail_msg">
+ EXPECT_EQ(1ULL, toUnsigned(DieDG.find(Attr_DW_FORM_flag_true), 0));<br class="gmail_msg">
+ EXPECT_EQ(0ULL, toUnsigned(DieDG.find(Attr_DW_FORM_flag_false), 1));<br class="gmail_msg">
+ EXPECT_EQ(1ULL, toUnsigned(DieDG.find(Attr_DW_FORM_flag_present), 0));<br class="gmail_msg">
<br class="gmail_msg">
//----------------------------------------------------------------------<br class="gmail_msg">
// Test SLEB128 based forms<br class="gmail_msg">
//----------------------------------------------------------------------<br class="gmail_msg">
- EXPECT_EQ(<br class="gmail_msg">
- DieDG.getAttributeValueAsSignedConstant(Attr_DW_FORM_sdata).getValueOr(0),<br class="gmail_msg">
- SData);<br class="gmail_msg">
+ EXPECT_EQ(SData, toSigned(DieDG.find(Attr_DW_FORM_sdata), 0));<br class="gmail_msg">
if (Version >= 5)<br class="gmail_msg">
- EXPECT_EQ(<br class="gmail_msg">
- DieDG.getAttributeValueAsSignedConstant(Attr_DW_FORM_implicit_const)<br class="gmail_msg">
- .getValueOr(0),<br class="gmail_msg">
- ICSData);<br class="gmail_msg">
+ EXPECT_EQ(ICSData, toSigned(DieDG.find(Attr_DW_FORM_implicit_const), 0));<br class="gmail_msg">
<br class="gmail_msg">
//----------------------------------------------------------------------<br class="gmail_msg">
// Test ULEB128 based forms<br class="gmail_msg">
//----------------------------------------------------------------------<br class="gmail_msg">
- EXPECT_EQ(DieDG.getAttributeValueAsUnsignedConstant(Attr_DW_FORM_udata)<br class="gmail_msg">
- .getValueOr(0),<br class="gmail_msg">
- UData[0]);<br class="gmail_msg">
+ EXPECT_EQ(UData[0], toUnsigned(DieDG.find(Attr_DW_FORM_udata), 0));<br class="gmail_msg">
<br class="gmail_msg">
//----------------------------------------------------------------------<br class="gmail_msg">
// Test DWARF32/DWARF64 forms<br class="gmail_msg">
//----------------------------------------------------------------------<br class="gmail_msg">
- EXPECT_EQ(DieDG.getAttributeValueAsReference(Attr_DW_FORM_GNU_ref_alt)<br class="gmail_msg">
- .getValueOr(0),<br class="gmail_msg">
- Dwarf32Values[0]);<br class="gmail_msg">
- EXPECT_EQ(DieDG.getAttributeValueAsSectionOffset(Attr_DW_FORM_sec_offset)<br class="gmail_msg">
- .getValueOr(0),<br class="gmail_msg">
- Dwarf32Values[1]);<br class="gmail_msg">
+ EXPECT_EQ(Dwarf32Values[0],<br class="gmail_msg">
+ toReference(DieDG.find(Attr_DW_FORM_GNU_ref_alt), 0));<br class="gmail_msg">
+ EXPECT_EQ(Dwarf32Values[1],<br class="gmail_msg">
+ toSectionOffset(DieDG.find(Attr_DW_FORM_sec_offset), 0));<br class="gmail_msg">
<br class="gmail_msg">
//----------------------------------------------------------------------<br class="gmail_msg">
// Add an address at the end to make sure we can decode this value<br class="gmail_msg">
//----------------------------------------------------------------------<br class="gmail_msg">
- EXPECT_EQ(DieDG.getAttributeValueAsAddress(Attr_Last).getValueOr(0),<br class="gmail_msg">
- AddrValue);<br class="gmail_msg">
+ EXPECT_EQ(AddrValue, toAddress(DieDG.find(Attr_Last), 0));<br class="gmail_msg">
}<br class="gmail_msg">
<br class="gmail_msg">
TEST(DWARFDebugInfo, TestDWARF32Version2Addr4AllForms) {<br class="gmail_msg">
@@ -669,123 +632,107 @@ template <uint16_t Version, class AddrTy<br class="gmail_msg">
auto CU1TypeDieDG = Unit1DieDG.getFirstChild();<br class="gmail_msg">
EXPECT_TRUE(CU1TypeDieDG.isValid());<br class="gmail_msg">
EXPECT_EQ(CU1TypeDieDG.getTag(), DW_TAG_base_type);<br class="gmail_msg">
- EXPECT_EQ(CU1TypeDieDG.getAttributeValueAsUnsignedConstant(DW_AT_encoding)<br class="gmail_msg">
- .getValueOr(0),<br class="gmail_msg">
- DW_ATE_signed);<br class="gmail_msg">
+ EXPECT_EQ(DW_ATE_signed, toUnsigned(CU1TypeDieDG.find(DW_AT_encoding), 0));<br class="gmail_msg">
<br class="gmail_msg">
// Verify the first child of the compile unit 2 DIE is our float base type.<br class="gmail_msg">
auto CU2TypeDieDG = Unit2DieDG.getFirstChild();<br class="gmail_msg">
EXPECT_TRUE(CU2TypeDieDG.isValid());<br class="gmail_msg">
EXPECT_EQ(CU2TypeDieDG.getTag(), DW_TAG_base_type);<br class="gmail_msg">
- EXPECT_EQ(CU2TypeDieDG.getAttributeValueAsUnsignedConstant(DW_AT_encoding)<br class="gmail_msg">
- .getValueOr(0),<br class="gmail_msg">
- DW_ATE_float);<br class="gmail_msg">
+ EXPECT_EQ(DW_ATE_float, toUnsigned(CU2TypeDieDG.find(DW_AT_encoding), 0));<br class="gmail_msg">
<br class="gmail_msg">
// Verify the sibling of the base type DIE is our Ref1 DIE and that its<br class="gmail_msg">
// DW_AT_type points to our base type DIE.<br class="gmail_msg">
auto CU1Ref1DieDG = CU1TypeDieDG.getSibling();<br class="gmail_msg">
EXPECT_TRUE(CU1Ref1DieDG.isValid());<br class="gmail_msg">
EXPECT_EQ(CU1Ref1DieDG.getTag(), DW_TAG_variable);<br class="gmail_msg">
- EXPECT_EQ(<br class="gmail_msg">
- CU1Ref1DieDG.getAttributeValueAsReference(DW_AT_type).getValueOr(-1ULL),<br class="gmail_msg">
- CU1TypeDieDG.getOffset());<br class="gmail_msg">
+ EXPECT_EQ(CU1TypeDieDG.getOffset(),<br class="gmail_msg">
+ toReference(CU1Ref1DieDG.find(DW_AT_type), -1ULL));<br class="gmail_msg">
// Verify the sibling is our Ref2 DIE and that its DW_AT_type points to our<br class="gmail_msg">
// base type DIE in CU1.<br class="gmail_msg">
auto CU1Ref2DieDG = CU1Ref1DieDG.getSibling();<br class="gmail_msg">
EXPECT_TRUE(CU1Ref2DieDG.isValid());<br class="gmail_msg">
EXPECT_EQ(CU1Ref2DieDG.getTag(), DW_TAG_variable);<br class="gmail_msg">
- EXPECT_EQ(<br class="gmail_msg">
- CU1Ref2DieDG.getAttributeValueAsReference(DW_AT_type).getValueOr(-1ULL),<br class="gmail_msg">
- CU1TypeDieDG.getOffset());<br class="gmail_msg">
+ EXPECT_EQ(CU1TypeDieDG.getOffset(),<br class="gmail_msg">
+ toReference(CU1Ref2DieDG.find(DW_AT_type), -1ULL));<br class="gmail_msg">
<br class="gmail_msg">
// Verify the sibling is our Ref4 DIE and that its DW_AT_type points to our<br class="gmail_msg">
// base type DIE in CU1.<br class="gmail_msg">
auto CU1Ref4DieDG = CU1Ref2DieDG.getSibling();<br class="gmail_msg">
EXPECT_TRUE(CU1Ref4DieDG.isValid());<br class="gmail_msg">
EXPECT_EQ(CU1Ref4DieDG.getTag(), DW_TAG_variable);<br class="gmail_msg">
- EXPECT_EQ(<br class="gmail_msg">
- CU1Ref4DieDG.getAttributeValueAsReference(DW_AT_type).getValueOr(-1ULL),<br class="gmail_msg">
- CU1TypeDieDG.getOffset());<br class="gmail_msg">
+ EXPECT_EQ(CU1TypeDieDG.getOffset(),<br class="gmail_msg">
+ toReference(CU1Ref4DieDG.find(DW_AT_type), -1ULL));<br class="gmail_msg">
<br class="gmail_msg">
// Verify the sibling is our Ref8 DIE and that its DW_AT_type points to our<br class="gmail_msg">
// base type DIE in CU1.<br class="gmail_msg">
auto CU1Ref8DieDG = CU1Ref4DieDG.getSibling();<br class="gmail_msg">
EXPECT_TRUE(CU1Ref8DieDG.isValid());<br class="gmail_msg">
EXPECT_EQ(CU1Ref8DieDG.getTag(), DW_TAG_variable);<br class="gmail_msg">
- EXPECT_EQ(<br class="gmail_msg">
- CU1Ref8DieDG.getAttributeValueAsReference(DW_AT_type).getValueOr(-1ULL),<br class="gmail_msg">
- CU1TypeDieDG.getOffset());<br class="gmail_msg">
+ EXPECT_EQ(CU1TypeDieDG.getOffset(),<br class="gmail_msg">
+ toReference(CU1Ref8DieDG.find(DW_AT_type), -1ULL));<br class="gmail_msg">
<br class="gmail_msg">
// Verify the sibling is our RefAddr DIE and that its DW_AT_type points to our<br class="gmail_msg">
// base type DIE in CU1.<br class="gmail_msg">
auto CU1RefAddrDieDG = CU1Ref8DieDG.getSibling();<br class="gmail_msg">
EXPECT_TRUE(CU1RefAddrDieDG.isValid());<br class="gmail_msg">
EXPECT_EQ(CU1RefAddrDieDG.getTag(), DW_TAG_variable);<br class="gmail_msg">
- EXPECT_EQ(CU1RefAddrDieDG.getAttributeValueAsReference(DW_AT_type)<br class="gmail_msg">
- .getValueOr(-1ULL),<br class="gmail_msg">
- CU1TypeDieDG.getOffset());<br class="gmail_msg">
+ EXPECT_EQ(CU1TypeDieDG.getOffset(),<br class="gmail_msg">
+ toReference(CU1RefAddrDieDG.find(DW_AT_type), -1ULL));<br class="gmail_msg">
<br class="gmail_msg">
// Verify the sibling of the Ref4 DIE is our RefAddr DIE and that its<br class="gmail_msg">
// DW_AT_type points to our base type DIE.<br class="gmail_msg">
auto CU1ToCU2RefAddrDieDG = CU1RefAddrDieDG.getSibling();<br class="gmail_msg">
EXPECT_TRUE(CU1ToCU2RefAddrDieDG.isValid());<br class="gmail_msg">
EXPECT_EQ(CU1ToCU2RefAddrDieDG.getTag(), DW_TAG_variable);<br class="gmail_msg">
- EXPECT_EQ(CU1ToCU2RefAddrDieDG.getAttributeValueAsReference(DW_AT_type)<br class="gmail_msg">
- .getValueOr(-1ULL),<br class="gmail_msg">
- CU2TypeDieDG.getOffset());<br class="gmail_msg">
+ EXPECT_EQ(CU2TypeDieDG.getOffset(),<br class="gmail_msg">
+ toReference(CU1ToCU2RefAddrDieDG.find(DW_AT_type), -1ULL));<br class="gmail_msg">
<br class="gmail_msg">
// Verify the sibling of the base type DIE is our Ref1 DIE and that its<br class="gmail_msg">
// DW_AT_type points to our base type DIE.<br class="gmail_msg">
auto CU2Ref1DieDG = CU2TypeDieDG.getSibling();<br class="gmail_msg">
EXPECT_TRUE(CU2Ref1DieDG.isValid());<br class="gmail_msg">
EXPECT_EQ(CU2Ref1DieDG.getTag(), DW_TAG_variable);<br class="gmail_msg">
- EXPECT_EQ(<br class="gmail_msg">
- CU2Ref1DieDG.getAttributeValueAsReference(DW_AT_type).getValueOr(-1ULL),<br class="gmail_msg">
- CU2TypeDieDG.getOffset());<br class="gmail_msg">
+ EXPECT_EQ(CU2TypeDieDG.getOffset(),<br class="gmail_msg">
+ toReference(CU2Ref1DieDG.find(DW_AT_type), -1ULL));<br class="gmail_msg">
// Verify the sibling is our Ref2 DIE and that its DW_AT_type points to our<br class="gmail_msg">
// base type DIE in CU2.<br class="gmail_msg">
auto CU2Ref2DieDG = CU2Ref1DieDG.getSibling();<br class="gmail_msg">
EXPECT_TRUE(CU2Ref2DieDG.isValid());<br class="gmail_msg">
EXPECT_EQ(CU2Ref2DieDG.getTag(), DW_TAG_variable);<br class="gmail_msg">
- EXPECT_EQ(<br class="gmail_msg">
- CU2Ref2DieDG.getAttributeValueAsReference(DW_AT_type).getValueOr(-1ULL),<br class="gmail_msg">
- CU2TypeDieDG.getOffset());<br class="gmail_msg">
+ EXPECT_EQ(CU2TypeDieDG.getOffset(),<br class="gmail_msg">
+ toReference(CU2Ref2DieDG.find(DW_AT_type), -1ULL));<br class="gmail_msg">
<br class="gmail_msg">
// Verify the sibling is our Ref4 DIE and that its DW_AT_type points to our<br class="gmail_msg">
// base type DIE in CU2.<br class="gmail_msg">
auto CU2Ref4DieDG = CU2Ref2DieDG.getSibling();<br class="gmail_msg">
EXPECT_TRUE(CU2Ref4DieDG.isValid());<br class="gmail_msg">
EXPECT_EQ(CU2Ref4DieDG.getTag(), DW_TAG_variable);<br class="gmail_msg">
- EXPECT_EQ(<br class="gmail_msg">
- CU2Ref4DieDG.getAttributeValueAsReference(DW_AT_type).getValueOr(-1ULL),<br class="gmail_msg">
- CU2TypeDieDG.getOffset());<br class="gmail_msg">
+ EXPECT_EQ(CU2TypeDieDG.getOffset(),<br class="gmail_msg">
+ toReference(CU2Ref4DieDG.find(DW_AT_type), -1ULL));<br class="gmail_msg">
<br class="gmail_msg">
// Verify the sibling is our Ref8 DIE and that its DW_AT_type points to our<br class="gmail_msg">
// base type DIE in CU2.<br class="gmail_msg">
auto CU2Ref8DieDG = CU2Ref4DieDG.getSibling();<br class="gmail_msg">
EXPECT_TRUE(CU2Ref8DieDG.isValid());<br class="gmail_msg">
EXPECT_EQ(CU2Ref8DieDG.getTag(), DW_TAG_variable);<br class="gmail_msg">
- EXPECT_EQ(<br class="gmail_msg">
- CU2Ref8DieDG.getAttributeValueAsReference(DW_AT_type).getValueOr(-1ULL),<br class="gmail_msg">
- CU2TypeDieDG.getOffset());<br class="gmail_msg">
+ EXPECT_EQ(CU2TypeDieDG.getOffset(),<br class="gmail_msg">
+ toReference(CU2Ref8DieDG.find(DW_AT_type), -1ULL));<br class="gmail_msg">
<br class="gmail_msg">
// Verify the sibling is our RefAddr DIE and that its DW_AT_type points to our<br class="gmail_msg">
// base type DIE in CU2.<br class="gmail_msg">
auto CU2RefAddrDieDG = CU2Ref8DieDG.getSibling();<br class="gmail_msg">
EXPECT_TRUE(CU2RefAddrDieDG.isValid());<br class="gmail_msg">
EXPECT_EQ(CU2RefAddrDieDG.getTag(), DW_TAG_variable);<br class="gmail_msg">
- EXPECT_EQ(CU2RefAddrDieDG.getAttributeValueAsReference(DW_AT_type)<br class="gmail_msg">
- .getValueOr(-1ULL),<br class="gmail_msg">
- CU2TypeDieDG.getOffset());<br class="gmail_msg">
+ EXPECT_EQ(CU2TypeDieDG.getOffset(),<br class="gmail_msg">
+ toReference(CU2RefAddrDieDG.find(DW_AT_type), -1ULL));<br class="gmail_msg">
<br class="gmail_msg">
// Verify the sibling of the Ref4 DIE is our RefAddr DIE and that its<br class="gmail_msg">
// DW_AT_type points to our base type DIE.<br class="gmail_msg">
auto CU2ToCU1RefAddrDieDG = CU2RefAddrDieDG.getSibling();<br class="gmail_msg">
EXPECT_TRUE(CU2ToCU1RefAddrDieDG.isValid());<br class="gmail_msg">
EXPECT_EQ(CU2ToCU1RefAddrDieDG.getTag(), DW_TAG_variable);<br class="gmail_msg">
- EXPECT_EQ(CU2ToCU1RefAddrDieDG.getAttributeValueAsReference(DW_AT_type)<br class="gmail_msg">
- .getValueOr(-1ULL),<br class="gmail_msg">
- CU1TypeDieDG.getOffset());<br class="gmail_msg">
+ EXPECT_EQ(CU1TypeDieDG.getOffset(),<br class="gmail_msg">
+ toReference(CU2ToCU1RefAddrDieDG.find(DW_AT_type), -1ULL));<br class="gmail_msg">
}<br class="gmail_msg">
<br class="gmail_msg">
TEST(DWARFDebugInfo, TestDWARF32Version2Addr4References) {<br class="gmail_msg">
@@ -892,14 +839,14 @@ template <uint16_t Version, class AddrTy<br class="gmail_msg">
auto SubprogramDieNoPC = DieDG.getFirstChild();<br class="gmail_msg">
EXPECT_TRUE(SubprogramDieNoPC.isValid());<br class="gmail_msg">
EXPECT_EQ(SubprogramDieNoPC.getTag(), DW_TAG_subprogram);<br class="gmail_msg">
- OptU64 = SubprogramDieNoPC.getAttributeValueAsAddress(DW_AT_low_pc);<br class="gmail_msg">
+ OptU64 = toAddress(SubprogramDieNoPC.find(DW_AT_low_pc));<br class="gmail_msg">
EXPECT_FALSE((bool)OptU64);<br class="gmail_msg">
- OptU64 = SubprogramDieNoPC.getAttributeValueAsAddress(DW_AT_high_pc);<br class="gmail_msg">
+ OptU64 = toAddress(SubprogramDieNoPC.find(DW_AT_high_pc));<br class="gmail_msg">
EXPECT_FALSE((bool)OptU64);<br class="gmail_msg">
EXPECT_FALSE(SubprogramDieNoPC.getLowAndHighPC(LowPC, HighPC));<br class="gmail_msg">
- OptU64 = SubprogramDieNoPC.getAttributeValueAsAddress(DW_AT_high_pc);<br class="gmail_msg">
+ OptU64 = toAddress(SubprogramDieNoPC.find(DW_AT_high_pc));<br class="gmail_msg">
EXPECT_FALSE((bool)OptU64);<br class="gmail_msg">
- OptU64 = SubprogramDieNoPC.getAttributeValueAsUnsignedConstant(DW_AT_high_pc);<br class="gmail_msg">
+ OptU64 = toUnsigned(SubprogramDieNoPC.find(DW_AT_high_pc));<br class="gmail_msg">
EXPECT_FALSE((bool)OptU64);<br class="gmail_msg">
OptU64 = SubprogramDieNoPC.getHighPC(ActualLowPC);<br class="gmail_msg">
EXPECT_FALSE((bool)OptU64);<br class="gmail_msg">
@@ -912,12 +859,12 @@ template <uint16_t Version, class AddrTy<br class="gmail_msg">
auto SubprogramDieLowPC = SubprogramDieNoPC.getSibling();<br class="gmail_msg">
EXPECT_TRUE(SubprogramDieLowPC.isValid());<br class="gmail_msg">
EXPECT_EQ(SubprogramDieLowPC.getTag(), DW_TAG_subprogram);<br class="gmail_msg">
- OptU64 = SubprogramDieLowPC.getAttributeValueAsAddress(DW_AT_low_pc);<br class="gmail_msg">
+ OptU64 = toAddress(SubprogramDieLowPC.find(DW_AT_low_pc));<br class="gmail_msg">
EXPECT_TRUE((bool)OptU64);<br class="gmail_msg">
EXPECT_EQ(OptU64.getValue(), ActualLowPC);<br class="gmail_msg">
- OptU64 = SubprogramDieLowPC.getAttributeValueAsAddress(DW_AT_high_pc);<br class="gmail_msg">
+ OptU64 = toAddress(SubprogramDieLowPC.find(DW_AT_high_pc));<br class="gmail_msg">
EXPECT_FALSE((bool)OptU64);<br class="gmail_msg">
- OptU64 = SubprogramDieLowPC.getAttributeValueAsUnsignedConstant(DW_AT_high_pc);<br class="gmail_msg">
+ OptU64 = toUnsigned(SubprogramDieLowPC.find(DW_AT_high_pc));<br class="gmail_msg">
EXPECT_FALSE((bool)OptU64);<br class="gmail_msg">
OptU64 = SubprogramDieLowPC.getHighPC(ActualLowPC);<br class="gmail_msg">
EXPECT_FALSE((bool)OptU64);<br class="gmail_msg">
@@ -930,12 +877,12 @@ template <uint16_t Version, class AddrTy<br class="gmail_msg">
auto SubprogramDieLowHighPC = SubprogramDieLowPC.getSibling();<br class="gmail_msg">
EXPECT_TRUE(SubprogramDieLowHighPC.isValid());<br class="gmail_msg">
EXPECT_EQ(SubprogramDieLowHighPC.getTag(), DW_TAG_subprogram);<br class="gmail_msg">
- OptU64 = SubprogramDieLowHighPC.getAttributeValueAsAddress(DW_AT_low_pc);<br class="gmail_msg">
+ OptU64 = toAddress(SubprogramDieLowHighPC.find(DW_AT_low_pc));<br class="gmail_msg">
EXPECT_TRUE((bool)OptU64);<br class="gmail_msg">
EXPECT_EQ(OptU64.getValue(), ActualLowPC);<br class="gmail_msg">
// Get the high PC as an address. This should succeed if the high PC was<br class="gmail_msg">
// encoded as an address and fail if the high PC was encoded as an offset.<br class="gmail_msg">
- OptU64 = SubprogramDieLowHighPC.getAttributeValueAsAddress(DW_AT_high_pc);<br class="gmail_msg">
+ OptU64 = toAddress(SubprogramDieLowHighPC.find(DW_AT_high_pc));<br class="gmail_msg">
if (SupportsHighPCAsOffset) {<br class="gmail_msg">
EXPECT_FALSE((bool)OptU64);<br class="gmail_msg">
} else {<br class="gmail_msg">
@@ -944,8 +891,7 @@ template <uint16_t Version, class AddrTy<br class="gmail_msg">
}<br class="gmail_msg">
// Get the high PC as an unsigned constant. This should succeed if the high PC<br class="gmail_msg">
// was encoded as an offset and fail if the high PC was encoded as an address.<br class="gmail_msg">
- OptU64 = SubprogramDieLowHighPC.getAttributeValueAsUnsignedConstant(<br class="gmail_msg">
- DW_AT_high_pc);<br class="gmail_msg">
+ OptU64 = toUnsigned(SubprogramDieLowHighPC.find(DW_AT_high_pc));<br class="gmail_msg">
if (SupportsHighPCAsOffset) {<br class="gmail_msg">
EXPECT_TRUE((bool)OptU64);<br class="gmail_msg">
EXPECT_EQ(OptU64.getValue(), ActualHighPCOffset);<br class="gmail_msg">
@@ -1318,4 +1264,216 @@ TEST(DWARFDebugInfo, TestAttributeIterat<br class="gmail_msg">
EXPECT_EQ(E, ++I);<br class="gmail_msg">
}<br class="gmail_msg">
<br class="gmail_msg">
+TEST(DWARFDebugInfo, TestFindRecurse) {<br class="gmail_msg">
+ uint16_t Version = 4;<br class="gmail_msg">
+<br class="gmail_msg">
+ const uint8_t AddrSize = sizeof(void *);<br class="gmail_msg">
+ initLLVMIfNeeded();<br class="gmail_msg">
+ Triple Triple = getHostTripleForAddrSize(AddrSize);<br class="gmail_msg">
+ auto ExpectedDG = dwarfgen::Generator::create(Triple, Version);<br class="gmail_msg">
+ if (HandleExpectedError(ExpectedDG))<br class="gmail_msg">
+ return;<br class="gmail_msg">
+ dwarfgen::Generator *DG = ExpectedDG.get().get();<br class="gmail_msg">
+ dwarfgen::CompileUnit &CU = DG->addCompileUnit();<br class="gmail_msg">
+<br class="gmail_msg">
+ StringRef SpecDieName("spec");<br class="gmail_msg">
+ StringRef AbsDieName("abs");<br class="gmail_msg">
+ // Scope to allow us to re-use the same DIE names<br class="gmail_msg">
+ {<br class="gmail_msg">
+ // Create a compile unit DIE that has an abbreviation that says it has<br class="gmail_msg">
+ // children, but doesn't have any actual attributes. This helps us test<br class="gmail_msg">
+ // a DIE that has only one child: a NULL DIE.<br class="gmail_msg"></blockquote><div class="gmail_msg"><br class="gmail_msg"></div></div></div><div dir="ltr" class="gmail_msg"><div class="gmail_quote gmail_msg"><div class="gmail_msg">This comment ^ seems to be out of date. Could you update it & make sure whatever it was suggesting needed coverage still has coverage?</div></div></div><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">
+ auto CUDie = CU.getUnitDIE();<br class="gmail_msg">
+ auto FuncSpecDie = CUDie.addChild(DW_TAG_subprogram);<br class="gmail_msg">
+ auto FuncDie = CUDie.addChild(DW_TAG_subprogram);<br class="gmail_msg">
+ auto VarAbsDie = CUDie.addChild(DW_TAG_variable);<br class="gmail_msg">
+ auto VarDie = CUDie.addChild(DW_TAG_variable);<br class="gmail_msg">
+ FuncSpecDie.addAttribute(DW_AT_name, DW_FORM_strp, SpecDieName);<br class="gmail_msg">
+ FuncDie.addAttribute(DW_AT_specification, DW_FORM_ref4, FuncSpecDie);<br class="gmail_msg">
+ VarAbsDie.addAttribute(DW_AT_name, DW_FORM_strp, AbsDieName);<br class="gmail_msg">
+ VarDie.addAttribute(DW_AT_abstract_origin, DW_FORM_ref4, VarAbsDie);<br class="gmail_msg">
+ }<br class="gmail_msg">
+<br class="gmail_msg">
+ MemoryBufferRef FileBuffer(DG->generate(), "dwarf");<br class="gmail_msg">
+ auto Obj = object::ObjectFile::createObjectFile(FileBuffer);<br class="gmail_msg">
+ EXPECT_TRUE((bool)Obj);<br class="gmail_msg">
+ DWARFContextInMemory DwarfContext(*Obj.get());<br class="gmail_msg">
+<br class="gmail_msg">
+ // Verify the number of compile units is correct.<br class="gmail_msg">
+ uint32_t NumCUs = DwarfContext.getNumCompileUnits();<br class="gmail_msg">
+ EXPECT_EQ(NumCUs, 1u);<br class="gmail_msg">
+ DWARFCompileUnit *U = DwarfContext.getCompileUnitAtIndex(0);<br class="gmail_msg">
+<br class="gmail_msg">
+ // Get the compile unit DIE is valid.<br class="gmail_msg">
+ auto CUDie = U->getUnitDIE(false);<br class="gmail_msg">
+ EXPECT_TRUE(CUDie.isValid());<br class="gmail_msg">
+<br class="gmail_msg">
+ auto FuncSpecDie = CUDie.getFirstChild();<br class="gmail_msg">
+ auto FuncDie = FuncSpecDie.getSibling();<br class="gmail_msg">
+ auto VarAbsDie = FuncDie.getSibling();<br class="gmail_msg">
+ auto VarDie = VarAbsDie.getSibling();<br class="gmail_msg">
+<br class="gmail_msg">
+ // Make sure we can't extract the name from the specification die when using<br class="gmail_msg">
+ // DWARFDie::find() since it won't check the DW_AT_specification DIE.<br class="gmail_msg">
+ EXPECT_FALSE(FuncDie.find(DW_AT_name).hasValue());<br class="gmail_msg">
+<br class="gmail_msg">
+ // Make sure we can extract the name from the specification die when using<br class="gmail_msg">
+ // DWARFDie::findRecursively() since it should recurse through the<br class="gmail_msg">
+ // DW_AT_specification DIE.<br class="gmail_msg">
+ auto NameOpt = FuncDie.findRecursively(DW_AT_name);<br class="gmail_msg">
+ EXPECT_TRUE(NameOpt.hasValue());<br class="gmail_msg">
+ // Test the dwarf::toString() helper function.<br class="gmail_msg">
+ auto StringOpt = toString(NameOpt);<br class="gmail_msg">
+ EXPECT_TRUE(StringOpt.hasValue());<br class="gmail_msg">
+ EXPECT_EQ(SpecDieName, StringOpt.getValueOr(nullptr));<br class="gmail_msg">
+ // Test the dwarf::toString() helper function with a default value specified.<br class="gmail_msg">
+ EXPECT_EQ(SpecDieName, toString(NameOpt, nullptr));<br class="gmail_msg">
+<br class="gmail_msg">
+ // Make sure we can't extract the name from the abstract origin die when using<br class="gmail_msg">
+ // DWARFDie::find() since it won't check the DW_AT_abstract_origin DIE.<br class="gmail_msg">
+ EXPECT_FALSE(VarDie.find(DW_AT_name).hasValue());<br class="gmail_msg">
+<br class="gmail_msg">
+ // Make sure we can extract the name from the abstract origin die when using<br class="gmail_msg">
+ // DWARFDie::findRecursively() since it should recurse through the<br class="gmail_msg">
+ // DW_AT_abstract_origin DIE.<br class="gmail_msg">
+ NameOpt = VarDie.findRecursively(DW_AT_name);<br class="gmail_msg">
+ EXPECT_TRUE(NameOpt.hasValue());<br class="gmail_msg">
+ // Test the dwarf::toString() helper function.<br class="gmail_msg">
+ StringOpt = toString(NameOpt);<br class="gmail_msg">
+ EXPECT_TRUE(StringOpt.hasValue());<br class="gmail_msg">
+ EXPECT_EQ(AbsDieName, StringOpt.getValueOr(nullptr));<br class="gmail_msg">
+ // Test the dwarf::toString() helper function with a default value specified.<br class="gmail_msg">
+ EXPECT_EQ(AbsDieName, toString(NameOpt, nullptr));<br class="gmail_msg">
+}<br class="gmail_msg">
+<br class="gmail_msg">
+TEST(DWARFDebugInfo, TestDwarfToFunctions) {<br class="gmail_msg">
+ // Test all of the dwarf::toXXX functions that take a<br class="gmail_msg">
+ // Optional<DWARFFormValue> and extract the values from it.<br class="gmail_msg">
+ DWARFFormValue FormVal;<br class="gmail_msg">
+ uint64_t InvalidU64 = 0xBADBADBADBADBADB;<br class="gmail_msg">
+ int64_t InvalidS64 = 0xBADBADBADBADBADB;<br class="gmail_msg">
+ // First test that we don't get valid values back when using an optional with<br class="gmail_msg">
+ // no value.<br class="gmail_msg">
+ Optional<DWARFFormValue> FormValOpt;<br class="gmail_msg">
+ EXPECT_FALSE(toString(FormValOpt).hasValue());<br class="gmail_msg">
+ EXPECT_FALSE(toUnsigned(FormValOpt).hasValue());<br class="gmail_msg">
+ EXPECT_FALSE(toReference(FormValOpt).hasValue());<br class="gmail_msg">
+ EXPECT_FALSE(toSigned(FormValOpt).hasValue());<br class="gmail_msg">
+ EXPECT_FALSE(toAddress(FormValOpt).hasValue());<br class="gmail_msg">
+ EXPECT_FALSE(toSectionOffset(FormValOpt).hasValue());<br class="gmail_msg">
+ EXPECT_FALSE(toBlock(FormValOpt).hasValue());<br class="gmail_msg">
+ EXPECT_EQ(nullptr, toString(FormValOpt, nullptr));<br class="gmail_msg">
+ EXPECT_EQ(InvalidU64, toUnsigned(FormValOpt, InvalidU64));<br class="gmail_msg">
+ EXPECT_EQ(InvalidU64, toReference(FormValOpt, InvalidU64));<br class="gmail_msg">
+ EXPECT_EQ(InvalidU64, toAddress(FormValOpt, InvalidU64));<br class="gmail_msg">
+ EXPECT_EQ(InvalidU64, toSectionOffset(FormValOpt, InvalidU64));<br class="gmail_msg">
+ EXPECT_EQ(InvalidS64, toSigned(FormValOpt, InvalidS64));<br class="gmail_msg">
+<br class="gmail_msg">
+<br class="gmail_msg">
+ // Test successful and unsuccessful address decoding.<br class="gmail_msg">
+ uint64_t Address = 0x100000000ULL;<br class="gmail_msg">
+ FormVal.setForm(DW_FORM_addr);<br class="gmail_msg">
+ FormVal.setUValue(Address);<br class="gmail_msg">
+ FormValOpt = FormVal;<br class="gmail_msg">
+<br class="gmail_msg">
+ EXPECT_FALSE(toString(FormValOpt).hasValue());<br class="gmail_msg">
+ EXPECT_FALSE(toUnsigned(FormValOpt).hasValue());<br class="gmail_msg">
+ EXPECT_FALSE(toReference(FormValOpt).hasValue());<br class="gmail_msg">
+ EXPECT_FALSE(toSigned(FormValOpt).hasValue());<br class="gmail_msg">
+ EXPECT_TRUE(toAddress(FormValOpt).hasValue());<br class="gmail_msg">
+ EXPECT_FALSE(toSectionOffset(FormValOpt).hasValue());<br class="gmail_msg">
+ EXPECT_FALSE(toBlock(FormValOpt).hasValue());<br class="gmail_msg">
+ EXPECT_EQ(nullptr, toString(FormValOpt, nullptr));<br class="gmail_msg">
+ EXPECT_EQ(InvalidU64, toUnsigned(FormValOpt, InvalidU64));<br class="gmail_msg">
+ EXPECT_EQ(InvalidU64, toReference(FormValOpt, InvalidU64));<br class="gmail_msg">
+ EXPECT_EQ(Address, toAddress(FormValOpt, InvalidU64));<br class="gmail_msg">
+ EXPECT_EQ(InvalidU64, toSectionOffset(FormValOpt, InvalidU64));<br class="gmail_msg">
+ EXPECT_EQ(InvalidS64, toSigned(FormValOpt, InvalidU64));<br class="gmail_msg">
+<br class="gmail_msg">
+ // Test successful and unsuccessful unsigned constant decoding.<br class="gmail_msg">
+ uint64_t UData8 = 0x1020304050607080ULL;<br class="gmail_msg">
+ FormVal.setForm(DW_FORM_udata);<br class="gmail_msg">
+ FormVal.setUValue(UData8);<br class="gmail_msg">
+ FormValOpt = FormVal;<br class="gmail_msg">
+<br class="gmail_msg">
+ EXPECT_FALSE(toString(FormValOpt).hasValue());<br class="gmail_msg">
+ EXPECT_TRUE(toUnsigned(FormValOpt).hasValue());<br class="gmail_msg">
+ EXPECT_FALSE(toReference(FormValOpt).hasValue());<br class="gmail_msg">
+ EXPECT_TRUE(toSigned(FormValOpt).hasValue());<br class="gmail_msg">
+ EXPECT_FALSE(toAddress(FormValOpt).hasValue());<br class="gmail_msg">
+ EXPECT_FALSE(toSectionOffset(FormValOpt).hasValue());<br class="gmail_msg">
+ EXPECT_FALSE(toBlock(FormValOpt).hasValue());<br class="gmail_msg">
+ EXPECT_EQ(nullptr, toString(FormValOpt, nullptr));<br class="gmail_msg">
+ EXPECT_EQ(UData8, toUnsigned(FormValOpt, InvalidU64));<br class="gmail_msg">
+ EXPECT_EQ(InvalidU64, toReference(FormValOpt, InvalidU64));<br class="gmail_msg">
+ EXPECT_EQ(InvalidU64, toAddress(FormValOpt, InvalidU64));<br class="gmail_msg">
+ EXPECT_EQ(InvalidU64, toSectionOffset(FormValOpt, InvalidU64));<br class="gmail_msg">
+ EXPECT_EQ((int64_t)UData8, toSigned(FormValOpt, InvalidU64));<br class="gmail_msg">
+<br class="gmail_msg">
+ // Test successful and unsuccessful reference decoding.<br class="gmail_msg">
+ uint32_t RefData = 0x11223344U;<br class="gmail_msg">
+ FormVal.setForm(DW_FORM_ref_addr);<br class="gmail_msg">
+ FormVal.setUValue(RefData);<br class="gmail_msg">
+ FormValOpt = FormVal;<br class="gmail_msg">
+<br class="gmail_msg">
+ EXPECT_FALSE(toString(FormValOpt).hasValue());<br class="gmail_msg">
+ EXPECT_FALSE(toUnsigned(FormValOpt).hasValue());<br class="gmail_msg">
+ EXPECT_TRUE(toReference(FormValOpt).hasValue());<br class="gmail_msg">
+ EXPECT_FALSE(toSigned(FormValOpt).hasValue());<br class="gmail_msg">
+ EXPECT_FALSE(toAddress(FormValOpt).hasValue());<br class="gmail_msg">
+ EXPECT_FALSE(toSectionOffset(FormValOpt).hasValue());<br class="gmail_msg">
+ EXPECT_FALSE(toBlock(FormValOpt).hasValue());<br class="gmail_msg">
+ EXPECT_EQ(nullptr, toString(FormValOpt, nullptr));<br class="gmail_msg">
+ EXPECT_EQ(InvalidU64, toUnsigned(FormValOpt, InvalidU64));<br class="gmail_msg">
+ EXPECT_EQ(RefData, toReference(FormValOpt, InvalidU64));<br class="gmail_msg">
+ EXPECT_EQ(InvalidU64, toAddress(FormValOpt, InvalidU64));<br class="gmail_msg">
+ EXPECT_EQ(InvalidU64, toSectionOffset(FormValOpt, InvalidU64));<br class="gmail_msg">
+ EXPECT_EQ(InvalidS64, toSigned(FormValOpt, InvalidU64));<br class="gmail_msg">
+<br class="gmail_msg">
+ // Test successful and unsuccessful signed constant decoding.<br class="gmail_msg">
+ int64_t SData8 = 0x1020304050607080ULL;<br class="gmail_msg">
+ FormVal.setForm(DW_FORM_udata);<br class="gmail_msg">
+ FormVal.setSValue(SData8);<br class="gmail_msg">
+ FormValOpt = FormVal;<br class="gmail_msg">
+<br class="gmail_msg">
+ EXPECT_FALSE(toString(FormValOpt).hasValue());<br class="gmail_msg">
+ EXPECT_TRUE(toUnsigned(FormValOpt).hasValue());<br class="gmail_msg">
+ EXPECT_FALSE(toReference(FormValOpt).hasValue());<br class="gmail_msg">
+ EXPECT_TRUE(toSigned(FormValOpt).hasValue());<br class="gmail_msg">
+ EXPECT_FALSE(toAddress(FormValOpt).hasValue());<br class="gmail_msg">
+ EXPECT_FALSE(toSectionOffset(FormValOpt).hasValue());<br class="gmail_msg">
+ EXPECT_FALSE(toBlock(FormValOpt).hasValue());<br class="gmail_msg">
+ EXPECT_EQ(nullptr, toString(FormValOpt, nullptr));<br class="gmail_msg">
+ EXPECT_EQ((uint64_t)SData8, toUnsigned(FormValOpt, InvalidU64));<br class="gmail_msg">
+ EXPECT_EQ(InvalidU64, toReference(FormValOpt, InvalidU64));<br class="gmail_msg">
+ EXPECT_EQ(InvalidU64, toAddress(FormValOpt, InvalidU64));<br class="gmail_msg">
+ EXPECT_EQ(InvalidU64, toSectionOffset(FormValOpt, InvalidU64));<br class="gmail_msg">
+ EXPECT_EQ(SData8, toSigned(FormValOpt, InvalidU64));<br class="gmail_msg">
+<br class="gmail_msg">
+ // Test successful and unsuccessful block decoding.<br class="gmail_msg">
+ uint8_t Data[] = { 2, 3, 4 };<br class="gmail_msg">
+ ArrayRef<uint8_t> Array(Data);<br class="gmail_msg">
+ FormVal.setForm(DW_FORM_block1);<br class="gmail_msg">
+ FormVal.setBlockValue(Array);<br class="gmail_msg">
+ FormValOpt = FormVal;<br class="gmail_msg">
+<br class="gmail_msg">
+ EXPECT_FALSE(toString(FormValOpt).hasValue());<br class="gmail_msg">
+ EXPECT_FALSE(toUnsigned(FormValOpt).hasValue());<br class="gmail_msg">
+ EXPECT_FALSE(toReference(FormValOpt).hasValue());<br class="gmail_msg">
+ EXPECT_FALSE(toSigned(FormValOpt).hasValue());<br class="gmail_msg">
+ EXPECT_FALSE(toAddress(FormValOpt).hasValue());<br class="gmail_msg">
+ EXPECT_FALSE(toSectionOffset(FormValOpt).hasValue());<br class="gmail_msg">
+ auto BlockOpt = toBlock(FormValOpt);<br class="gmail_msg">
+ EXPECT_TRUE(BlockOpt.hasValue());<br class="gmail_msg">
+ EXPECT_EQ(*BlockOpt, Array);<br class="gmail_msg">
+ EXPECT_EQ(nullptr, toString(FormValOpt, nullptr));<br class="gmail_msg">
+ EXPECT_EQ(InvalidU64, toUnsigned(FormValOpt, InvalidU64));<br class="gmail_msg">
+ EXPECT_EQ(InvalidU64, toReference(FormValOpt, InvalidU64));<br class="gmail_msg">
+ EXPECT_EQ(InvalidU64, toAddress(FormValOpt, InvalidU64));<br class="gmail_msg">
+ EXPECT_EQ(InvalidU64, toSectionOffset(FormValOpt, InvalidU64));<br class="gmail_msg">
+ EXPECT_EQ(InvalidS64, toSigned(FormValOpt, InvalidU64));<br class="gmail_msg">
+<br class="gmail_msg">
+ // Test<br class="gmail_msg">
+}<br class="gmail_msg">
+<br class="gmail_msg">
} // end anonymous namespace<br class="gmail_msg">
<br class="gmail_msg">
<br class="gmail_msg">
_______________________________________________<br class="gmail_msg">
llvm-commits mailing list<br class="gmail_msg">
<a href="mailto:llvm-commits@lists.llvm.org" class="gmail_msg" target="_blank">llvm-commits@lists.llvm.org</a><br class="gmail_msg">
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" class="gmail_msg" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br class="gmail_msg">
</blockquote></div></div></blockquote></div></div>