LLVM  8.0.1
Classes | Public Member Functions | List of all members
llvm::DWARFDie Class Reference

Utility class that carries the DWARF compile/type unit and the debug info entry in an object. More...

#include "llvm/DebugInfo/DWARF/DWARFDie.h"

Classes

class  attribute_iterator
 
class  iterator
 

Public Member Functions

 DWARFDie ()=default
 
 DWARFDie (DWARFUnit *Unit, const DWARFDebugInfoEntry *D)
 
bool isValid () const
 
 operator bool () const
 
const DWARFDebugInfoEntrygetDebugInfoEntry () const
 
DWARFUnitgetDwarfUnit () const
 
const DWARFAbbreviationDeclarationgetAbbreviationDeclarationPtr () const
 Get the abbreviation declaration for this DIE. More...
 
uint32_t getOffset () const
 Get the absolute offset into the debug info or types section. More...
 
dwarf::Tag getTag () const
 
bool hasChildren () const
 
bool isNULL () const
 Returns true for a valid DIE that terminates a sibling chain. More...
 
bool isSubprogramDIE () const
 Returns true if DIE represents a subprogram (not inlined). More...
 
bool isSubroutineDIE () const
 Returns true if DIE represents a subprogram or an inlined subroutine. More...
 
DWARFDie getParent () const
 Get the parent of this DIE object. More...
 
DWARFDie getSibling () const
 Get the sibling of this DIE object. More...
 
DWARFDie getPreviousSibling () const
 Get the previous sibling of this DIE object. More...
 
DWARFDie getFirstChild () const
 Get the first child of this DIE object. More...
 
DWARFDie getLastChild () const
 Get the last child of this DIE object. More...
 
void dump (raw_ostream &OS, unsigned indent=0, DIDumpOptions DumpOpts=DIDumpOptions()) const
 Dump the DIE and all of its attributes to the supplied stream. More...
 
LLVM_DUMP_METHOD void dump () const
 Convenience zero-argument overload for debugging. More...
 
Optional< DWARFFormValuefind (dwarf::Attribute Attr) const
 Extract the specified attribute from this DIE. More...
 
Optional< DWARFFormValuefind (ArrayRef< dwarf::Attribute > Attrs) const
 Extract the first value of any attribute in Attrs from this DIE. More...
 
Optional< DWARFFormValuefindRecursively (ArrayRef< dwarf::Attribute > Attrs) const
 Extract the first value of any attribute in Attrs from this DIE and recurse into any DW_AT_specification or DW_AT_abstract_origin referenced DIEs. More...
 
DWARFDie getAttributeValueAsReferencedDie (dwarf::Attribute Attr) const
 Extract the specified attribute from this DIE as the referenced DIE. More...
 
DWARFDie getAttributeValueAsReferencedDie (const DWARFFormValue &V) const
 
Optional< uint64_t > getRangesBaseAttribute () const
 Extract the range base attribute from this DIE as absolute section offset. More...
 
Optional< uint64_t > getHighPC (uint64_t LowPC) const
 Get the DW_AT_high_pc attribute value as an address. More...
 
bool getLowAndHighPC (uint64_t &LowPC, uint64_t &HighPC, uint64_t &SectionIndex) const
 Retrieves DW_AT_low_pc and DW_AT_high_pc from CU. More...
 
Expected< DWARFAddressRangesVectorgetAddressRanges () const
 Get the address ranges for this DIE. More...
 
void collectChildrenAddressRanges (DWARFAddressRangesVector &Ranges) const
 Get all address ranges for any DW_TAG_subprogram DIEs in this DIE or any of its children. More...
 
bool addressRangeContainsAddress (const uint64_t Address) const
 
const chargetSubroutineName (DINameKind Kind) const
 If a DIE represents a subprogram (or inlined subroutine), returns its mangled name (or short name, if mangled is missing). More...
 
const chargetName (DINameKind Kind) const
 Return the DIE name resolving DW_AT_sepcification or DW_AT_abstract_origin references if necessary. More...
 
uint64_t getDeclLine () const
 Returns the declaration line (start line) for a DIE, assuming it specifies a subprogram. More...
 
void getCallerFrame (uint32_t &CallFile, uint32_t &CallLine, uint32_t &CallColumn, uint32_t &CallDiscriminator) const
 Retrieves values of DW_AT_call_file, DW_AT_call_line and DW_AT_call_column from DIE (or zeroes if they are missing). More...
 
iterator_range< attribute_iteratorattributes () const
 Get an iterator range to all attributes in the current DIE only. More...
 
iterator begin () const
 
iterator end () const
 
std::reverse_iterator< iteratorrbegin () const
 
std::reverse_iterator< iteratorrend () const
 
iterator_range< iteratorchildren () const
 

Detailed Description

Utility class that carries the DWARF compile/type unit and the debug info entry in an object.

When accessing information from a debug info entry we always need to DWARF compile/type unit in order to extract the info correctly as some information is relative to the compile/type unit. Prior to this class the DWARFUnit and the DWARFDebugInfoEntry was passed around separately and there was the possibility for error if the wrong DWARFUnit was used to extract a unit relative offset. This class helps to ensure that this doesn't happen and also simplifies the attribute extraction calls by not having to specify the DWARFUnit for each call.

Definition at line 43 of file DWARFDie.h.

Constructor & Destructor Documentation

◆ DWARFDie() [1/2]

llvm::DWARFDie::DWARFDie ( )
default

◆ DWARFDie() [2/2]

llvm::DWARFDie::DWARFDie ( DWARFUnit Unit,
const DWARFDebugInfoEntry D 
)
inline

Definition at line 49 of file DWARFDie.h.

Member Function Documentation

◆ addressRangeContainsAddress()

bool DWARFDie::addressRangeContainsAddress ( const uint64_t  Address) const

Definition at line 514 of file DWARFDie.cpp.

References llvm::consumeError().

Referenced by llvm::DWARFContext::getDIEsForAddress(), and isNULL().

◆ attributes()

iterator_range< DWARFDie::attribute_iterator > DWARFDie::attributes ( ) const

Get an iterator range to all attributes in the current DIE only.

Returns
an iterator range for the attributes of the current DIE.

Definition at line 665 of file DWARFDie.cpp.

References llvm::make_range().

Referenced by isNULL().

◆ begin()

DWARFDie::iterator llvm::DWARFDie::begin ( ) const
inline

Definition at line 375 of file DWARFDie.h.

References getFirstChild().

Referenced by children(), isNULL(), and rend().

◆ children()

iterator_range< DWARFDie::iterator > llvm::DWARFDie::children ( ) const
inline

Definition at line 383 of file DWARFDie.h.

References begin(), end(), and llvm::make_range().

Referenced by dumpArrayType(), dumpTypeName(), and isNULL().

◆ collectChildrenAddressRanges()

void DWARFDie::collectChildrenAddressRanges ( DWARFAddressRangesVector Ranges) const

Get all address ranges for any DW_TAG_subprogram DIEs in this DIE or any of its children.

Get the hi/low PC range if both attributes are available or exrtracts the non-contiguous address ranges from the DW_AT_ranges attribute for this DIE and all children.

Parameters
Rangesthe addres range vector to fill in.

Definition at line 498 of file DWARFDie.cpp.

References llvm::children(), and llvm::consumeError().

Referenced by isNULL().

◆ dump() [1/2]

void DWARFDie::dump ( raw_ostream OS,
unsigned  indent = 0,
DIDumpOptions  DumpOpts = DIDumpOptions() 
) const

◆ dump() [2/2]

LLVM_DUMP_METHOD void DWARFDie::dump ( ) const

Convenience zero-argument overload for debugging.

Definition at line 633 of file DWARFDie.cpp.

References llvm::dump(), and llvm::errs().

Referenced by isNULL().

◆ end()

DWARFDie::iterator llvm::DWARFDie::end ( ) const
inline

Definition at line 379 of file DWARFDie.h.

References getLastChild().

Referenced by children(), isNULL(), and rbegin().

◆ find() [1/2]

Optional< DWARFFormValue > DWARFDie::find ( dwarf::Attribute  Attr) const

Extract the specified attribute from this DIE.

Extract an attribute value from this DIE only. This call doesn't look for the attribute value in any DW_AT_specification or DW_AT_abstract_origin referenced DIEs.

Parameters
Attrthe attribute to extract.
Returns
an optional DWARFFormValue that will have the form value if the attribute was successfully extracted.

Definition at line 373 of file DWARFDie.cpp.

References llvm::getOffset(), and llvm::None.

Referenced by dumpArrayType(), findRecursively(), llvm::DWARFUnit::getBaseAddress(), llvm::DWARFUnit::getCompilationDir(), llvm::DWARFVerifier::handleDebugInfo(), isNULL(), and isVariableIndexable().

◆ find() [2/2]

Optional< DWARFFormValue > DWARFDie::find ( ArrayRef< dwarf::Attribute Attrs) const

Extract the first value of any attribute in Attrs from this DIE.

Extract the first attribute that matches from this DIE only. This call doesn't look for the attribute value in any DW_AT_specification or DW_AT_abstract_origin referenced DIEs. The attributes will be searched linearly in the order they are specified within Attrs.

Parameters
Attrsan array of DWARF attribute to look for.
Returns
an optional that has a valid DWARFFormValue for the first matching attribute in Attrs, or None if none of the attributes in Attrs exist in this DIE.

Definition at line 383 of file DWARFDie.cpp.

References llvm::getOffset(), and llvm::None.

◆ findRecursively()

Optional< DWARFFormValue > DWARFDie::findRecursively ( ArrayRef< dwarf::Attribute Attrs) const

Extract the first value of any attribute in Attrs from this DIE and recurse into any DW_AT_specification or DW_AT_abstract_origin referenced DIEs.

Parameters
Attrsan array of DWARF attribute to look for.
Returns
an optional that has a valid DWARFFormValue for the first matching attribute in Attrs, or None if none of the attributes in Attrs exist in this DIE or in any DW_AT_specification or DW_AT_abstract_origin DIEs.

Definition at line 397 of file DWARFDie.cpp.

References llvm::SmallSet< T, N, C >::count(), D, find(), getAttributeValueAsReferencedDie(), llvm::SmallSet< T, N, C >::insert(), isValid(), and llvm::None.

Referenced by isNULL(), and isVariableIndexable().

◆ getAbbreviationDeclarationPtr()

const DWARFAbbreviationDeclaration* llvm::DWARFDie::getAbbreviationDeclarationPtr ( ) const
inline

Get the abbreviation declaration for this DIE.

Returns
the abbreviation declaration or NULL for null tags.

Definition at line 59 of file DWARFDie.h.

References assert(), llvm::DWARFDebugInfoEntry::getAbbreviationDeclarationPtr(), and isValid().

Referenced by getTag(), isNULL(), and llvm::DWARFDie::attribute_iterator::operator++().

◆ getAddressRanges()

Expected< DWARFAddressRangesVector > DWARFDie::getAddressRanges ( ) const

Get the address ranges for this DIE.

Get the hi/low PC range if both attributes are available or exrtracts the non-contiguous address ranges from the DW_AT_ranges attribute.

Extracts the range information from this DIE only. This call doesn't look for the range in any DW_AT_specification or DW_AT_abstract_origin DIEs.

Returns
a address range vector that might be empty if no address range information is available.

Definition at line 481 of file DWARFDie.cpp.

References llvm::find(), llvm::DWARFFormValue::getAsSectionOffset(), and llvm::DWARFFormValue::getForm().

Referenced by llvm::DWARFUnit::collectAddressRanges(), dumpAttribute(), llvm::DWARFVerifier::handleDebugInfo(), isNULL(), and llvm::DWARFUnit::updateAddressDieMap().

◆ getAttributeValueAsReferencedDie() [1/2]

DWARFDie DWARFDie::getAttributeValueAsReferencedDie ( dwarf::Attribute  Attr) const

Extract the specified attribute from this DIE as the referenced DIE.

Regardless of the reference type, return the correct DWARFDie instance if the attribute exists. The returned DWARFDie object might be from another DWARFUnit, but that is all encapsulated in the new DWARFDie object.

Extract an attribute value from this DIE only. This call doesn't look for the attribute value in any DW_AT_specification or DW_AT_abstract_origin referenced DIEs.

Parameters
Attrthe attribute to extract.
Returns
a valid DWARFDie instance if the attribute exists, or an invalid DWARFDie object if it doesn't.

Definition at line 433 of file DWARFDie.cpp.

References F(), and llvm::find().

Referenced by dumpAttribute(), dumpTypeName(), findRecursively(), llvm::DWARFVerifier::handleDebugInfo(), and isNULL().

◆ getAttributeValueAsReferencedDie() [2/2]

DWARFDie DWARFDie::getAttributeValueAsReferencedDie ( const DWARFFormValue V) const

Definition at line 440 of file DWARFDie.cpp.

References llvm::dwarf::toReference().

◆ getCallerFrame()

void DWARFDie::getCallerFrame ( uint32_t CallFile,
uint32_t CallLine,
uint32_t CallColumn,
uint32_t CallDiscriminator 
) const

Retrieves values of DW_AT_call_file, DW_AT_call_line and DW_AT_call_column from DIE (or zeroes if they are missing).

This function looks for DW_AT_call attributes in this DIE only, it will not resolve the attribute values in any DW_AT_specification or DW_AT_abstract_origin DIEs.

Parameters
CallFilefilled in with non-zero if successful, zero if there is no DW_AT_call_file attribute in this DIE.
CallLinefilled in with non-zero if successful, zero if there is no DW_AT_call_line attribute in this DIE.
CallColumnfilled in with non-zero if successful, zero if there is no DW_AT_call_column attribute in this DIE.
CallDiscriminatorfilled in with non-zero if successful, zero if there is no DW_AT_GNU_discriminator attribute in this DIE.

Definition at line 552 of file DWARFDie.cpp.

References llvm::find(), and llvm::dwarf::toUnsigned().

Referenced by llvm::DWARFContext::getInliningInfoForAddress(), and isNULL().

◆ getDebugInfoEntry()

const DWARFDebugInfoEntry* llvm::DWARFDie::getDebugInfoEntry ( ) const
inline

Definition at line 53 of file DWARFDie.h.

Referenced by llvm::DWARFUnit::getDIEIndex(), and llvm::operator==().

◆ getDeclLine()

uint64_t DWARFDie::getDeclLine ( ) const

Returns the declaration line (start line) for a DIE, assuming it specifies a subprogram.

This may be fetched from specification or abstract origin for this subprogram by resolving DW_AT_sepcification or DW_AT_abstract_origin references if necessary.

Definition at line 548 of file DWARFDie.cpp.

References llvm::dwarf::toUnsigned().

Referenced by getFunctionNameAndStartLineForAddress(), llvm::DWARFContext::getInliningInfoForAddress(), and isNULL().

◆ getDwarfUnit()

DWARFUnit* llvm::DWARFDie::getDwarfUnit ( ) const
inline

◆ getFirstChild()

DWARFDie DWARFDie::getFirstChild ( ) const

Get the first child of this DIE object.

Returns
a valid DWARFDie instance if this object has children or an invalid DWARFDie instance if it doesn't.

Definition at line 653 of file DWARFDie.cpp.

References getFirstChild().

Referenced by begin(), getFirstChild(), isNULL(), and llvm::DWARFUnit::updateAddressDieMap().

◆ getHighPC()

Optional< uint64_t > DWARFDie::getHighPC ( uint64_t  LowPC) const

Get the DW_AT_high_pc attribute value as an address.

In DWARF version 4 and later the high PC can be encoded as an offset from the DW_AT_low_pc. This function takes care of extracting the value as an address or offset and adds it to the low PC if needed and returns the value as an optional in case the DIE doesn't have a DW_AT_high_pc attribute.

Parameters
LowPCthe low PC that might be needed to calculate the high PC.
Returns
an optional address value for the attribute.

Definition at line 452 of file DWARFDie.cpp.

References llvm::Address, llvm::find(), and llvm::None.

Referenced by isNULL().

◆ getLastChild()

DWARFDie DWARFDie::getLastChild ( ) const

Get the last child of this DIE object.

Returns
a valid null DWARFDie instance if this object has children or an invalid DWARFDie instance if it doesn't.

Definition at line 659 of file DWARFDie.cpp.

References getLastChild().

Referenced by end(), getLastChild(), and isNULL().

◆ getLowAndHighPC()

bool DWARFDie::getLowAndHighPC ( uint64_t &  LowPC,
uint64_t &  HighPC,
uint64_t &  SectionIndex 
) const

Retrieves DW_AT_low_pc and DW_AT_high_pc from CU.

Returns true if both attributes are present.

Definition at line 466 of file DWARFDie.cpp.

References F(), llvm::find(), and llvm::dwarf::toSectionedAddress().

Referenced by dumpAttribute(), and isNULL().

◆ getName()

const char * DWARFDie::getName ( DINameKind  Kind) const

Return the DIE name resolving DW_AT_sepcification or DW_AT_abstract_origin references if necessary.

Returns null if no name is found.

Definition at line 533 of file DWARFDie.cpp.

References llvm::LinkageName, Name, llvm::None, and llvm::dwarf::toString().

Referenced by llvm::DWARFTypeUnit::dump(), dumpAttribute(), dumpTypeName(), getNames(), and isNULL().

◆ getOffset()

uint32_t llvm::DWARFDie::getOffset ( ) const
inline

Get the absolute offset into the debug info or types section.

Returns
the DIE offset or -1U if invalid.

Definition at line 67 of file DWARFDie.h.

References assert(), llvm::DWARFDebugInfoEntry::getOffset(), and isValid().

Referenced by llvm::DWARFVerifier::handleDebugInfo(), isVariableIndexable(), and llvm::operator<().

◆ getParent()

DWARFDie DWARFDie::getParent ( ) const

Get the parent of this DIE object.

Returns
a valid DWARFDie instance if this object has a parent or an invalid DWARFDie instance if it doesn't.

Definition at line 635 of file DWARFDie.cpp.

References getParent().

Referenced by dumpParentChain(), llvm::DWARFUnit::getInlinedChainForAddress(), getParent(), and isNULL().

◆ getPreviousSibling()

DWARFDie DWARFDie::getPreviousSibling ( ) const

Get the previous sibling of this DIE object.

Returns
a valid DWARFDie instance if this object has a sibling or an invalid DWARFDie instance if it doesn't.

Definition at line 647 of file DWARFDie.cpp.

References getPreviousSibling().

Referenced by getPreviousSibling(), isNULL(), std::reverse_iterator< llvm::DWARFDie::iterator >::operator++(), llvm::DWARFDie::iterator::operator--(), and std::reverse_iterator< llvm::DWARFDie::iterator >::reverse_iterator().

◆ getRangesBaseAttribute()

Optional< uint64_t > DWARFDie::getRangesBaseAttribute ( ) const

Extract the range base attribute from this DIE as absolute section offset.

This is a utility function that checks for either the DW_AT_rnglists_base or DW_AT_GNU_ranges_base attribute.

Returns
anm optional absolute section offset value for the attribute.

Definition at line 448 of file DWARFDie.cpp.

References llvm::find(), and llvm::dwarf::toSectionOffset().

Referenced by llvm::DWARFUnit::getCompilationDir(), and isNULL().

◆ getSibling()

DWARFDie DWARFDie::getSibling ( ) const

Get the sibling of this DIE object.

Returns
a valid DWARFDie instance if this object has a sibling or an invalid DWARFDie instance if it doesn't.

Definition at line 641 of file DWARFDie.cpp.

References getSibling().

Referenced by std::reverse_iterator< llvm::DWARFDie::iterator >::base(), dump(), getSibling(), isNULL(), llvm::DWARFDie::iterator::operator++(), std::reverse_iterator< llvm::DWARFDie::iterator >::operator--(), and llvm::DWARFUnit::updateAddressDieMap().

◆ getSubroutineName()

const char * DWARFDie::getSubroutineName ( DINameKind  Kind) const

If a DIE represents a subprogram (or inlined subroutine), returns its mangled name (or short name, if mangled is missing).

This name may be fetched from specification or abstract origin for this subprogram. Returns null if no name is found.

Definition at line 527 of file DWARFDie.cpp.

References getName().

Referenced by getFunctionNameAndStartLineForAddress(), llvm::DWARFContext::getInliningInfoForAddress(), and isNULL().

◆ getTag()

dwarf::Tag llvm::DWARFDie::getTag ( ) const
inline

◆ hasChildren()

bool llvm::DWARFDie::hasChildren ( ) const
inline

Definition at line 79 of file DWARFDie.h.

References assert(), llvm::DWARFDebugInfoEntry::hasChildren(), and isValid().

◆ isNULL()

bool llvm::DWARFDie::isNULL ( ) const
inline

◆ isSubprogramDIE()

bool DWARFDie::isSubprogramDIE ( ) const

Returns true if DIE represents a subprogram (not inlined).

Definition at line 366 of file DWARFDie.cpp.

References llvm::dwarf::getTag().

Referenced by llvm::DWARFUnit::getInlinedChainForAddress(), and isNULL().

◆ isSubroutineDIE()

bool DWARFDie::isSubroutineDIE ( ) const

Returns true if DIE represents a subprogram or an inlined subroutine.

Definition at line 368 of file DWARFDie.cpp.

References llvm::dwarf::getTag().

Referenced by isNULL(), and llvm::DWARFUnit::updateAddressDieMap().

◆ isValid()

bool llvm::DWARFDie::isValid ( ) const
inline

◆ operator bool()

llvm::DWARFDie::operator bool ( ) const
inlineexplicit

Definition at line 52 of file DWARFDie.h.

References isValid().

◆ rbegin()

std::reverse_iterator< DWARFDie::iterator > llvm::DWARFDie::rbegin ( ) const
inline

Definition at line 459 of file DWARFDie.h.

References end(), and llvm::make_reverse_iterator().

Referenced by isNULL().

◆ rend()

std::reverse_iterator< DWARFDie::iterator > llvm::DWARFDie::rend ( ) const
inline

Definition at line 463 of file DWARFDie.h.

References begin(), and llvm::make_reverse_iterator().

Referenced by isNULL().


The documentation for this class was generated from the following files: