LLVM  6.0.0svn
Public Member Functions | List of all members
llvm::DataExtractor Class Reference

#include "llvm/Support/DataExtractor.h"

Inheritance diagram for llvm::DataExtractor:
Inheritance graph
[legend]

Public Member Functions

 DataExtractor (StringRef Data, bool IsLittleEndian, uint8_t AddressSize)
 Construct with a buffer that is owned by the caller. More...
 
StringRef getData () const
 Get the data pointed to by this extractor. More...
 
bool isLittleEndian () const
 Get the endianness for this extractor. More...
 
uint8_t getAddressSize () const
 Get the address size for this extractor. More...
 
void setAddressSize (uint8_t Size)
 Set the address size for this extractor. More...
 
const chargetCStr (uint32_t *offset_ptr) const
 Extract a C string from *offset_ptr. More...
 
StringRef getCStrRef (uint32_t *OffsetPtr) const
 Extract a C string from *OffsetPtr. More...
 
uint64_t getUnsigned (uint32_t *offset_ptr, uint32_t byte_size) const
 Extract an unsigned integer of size byte_size from *offset_ptr. More...
 
int64_t getSigned (uint32_t *offset_ptr, uint32_t size) const
 Extract an signed integer of size byte_size from *offset_ptr. More...
 
uint64_t getAddress (uint32_t *offset_ptr) const
 Extract an pointer from *offset_ptr. More...
 
uint8_t getU8 (uint32_t *offset_ptr) const
 Extract a uint8_t value from *offset_ptr. More...
 
uint8_t * getU8 (uint32_t *offset_ptr, uint8_t *dst, uint32_t count) const
 Extract count uint8_t values from *offset_ptr. More...
 
uint16_t getU16 (uint32_t *offset_ptr) const
 Extract a uint16_t value from *offset_ptr. More...
 
uint16_t * getU16 (uint32_t *offset_ptr, uint16_t *dst, uint32_t count) const
 Extract count uint16_t values from *offset_ptr. More...
 
uint32_t getU24 (uint32_t *offset_ptr) const
 Extract a 24-bit unsigned value from *offset_ptr and return it in a uint32_t. More...
 
uint32_t getU32 (uint32_t *offset_ptr) const
 Extract a uint32_t value from *offset_ptr. More...
 
uint32_tgetU32 (uint32_t *offset_ptr, uint32_t *dst, uint32_t count) const
 Extract count uint32_t values from *offset_ptr. More...
 
uint64_t getU64 (uint32_t *offset_ptr) const
 Extract a uint64_t value from *offset_ptr. More...
 
uint64_t * getU64 (uint32_t *offset_ptr, uint64_t *dst, uint32_t count) const
 Extract count uint64_t values from *offset_ptr. More...
 
int64_t getSLEB128 (uint32_t *offset_ptr) const
 Extract a signed LEB128 value from *offset_ptr. More...
 
uint64_t getULEB128 (uint32_t *offset_ptr) const
 Extract a unsigned LEB128 value from *offset_ptr. More...
 
bool isValidOffset (uint32_t offset) const
 Test the validity of offset. More...
 
bool isValidOffsetForDataOfSize (uint32_t offset, uint32_t length) const
 Test the availability of length bytes of data from offset. More...
 
bool isValidOffsetForAddress (uint32_t offset) const
 Test the availability of enough bytes of data for a pointer from offset. More...
 

Detailed Description

Definition at line 41 of file DataExtractor.h.

Constructor & Destructor Documentation

◆ DataExtractor()

llvm::DataExtractor::DataExtractor ( StringRef  Data,
bool  IsLittleEndian,
uint8_t  AddressSize 
)
inline

Construct with a buffer that is owned by the caller.

This constructor allows us to use data that is owned by the caller. The data must stay around as long as this object is valid.

Definition at line 51 of file DataExtractor.h.

Member Function Documentation

◆ getAddress()

uint64_t llvm::DataExtractor::getAddress ( uint32_t offset_ptr) const
inline

Extract an pointer from *offset_ptr.

Extract a single pointer from the data and update the offset pointed to by offset_ptr. The size of the extracted pointer is getAddressSize(), so the address size has to be set correctly prior to extracting any pointer values.

Parameters
[in,out]offset_ptrA pointer to an offset within the data that will be advanced by the appropriate number of bytes if the value is extracted correctly. If the offset is out of bounds or there are not enough bytes to extract this value, the offset will be left unmodified.
Returns
The extracted pointer value as a 64 integer.

Definition at line 175 of file DataExtractor.h.

References llvm::count().

Referenced by llvm::symbolize::SymbolizableObjectFile::create(), llvm::DWARFDebugFrame::parse(), and llvm::FrameEntry::parseInstructions().

◆ getAddressSize()

uint8_t llvm::DataExtractor::getAddressSize ( ) const
inline

◆ getCStr()

const char * DataExtractor::getCStr ( uint32_t offset_ptr) const

Extract a C string from *offset_ptr.

Returns a pointer to a C String from the data at the offset pointed to by offset_ptr. A variable length NULL terminated C string will be extracted and the offset_ptr will be updated with the offset of the byte that follows the NULL terminator byte.

Parameters
[in,out]offset_ptrA pointer to an offset within the data that will be advanced by the appropriate number of bytes if the value is extracted correctly. If the offset is out of bounds or there are not enough bytes to extract this value, the offset will be left unmodified.
Returns
A pointer to the C string value in the data. If the offset pointed to by offset_ptr is out of bounds, or if the offset plus the length of the C string is out of bounds, NULL will be returned.

Definition at line 128 of file DataExtractor.cpp.

References llvm::StringRef::data(), llvm::StringRef::find(), and llvm::StringRef::npos.

Referenced by llvm::DWARFAcceleratorTable::dump(), dumpDWARFv5StringOffsetsSection(), dumpStringOffsetsSection(), llvm::DWARFDebugPubTable::DWARFDebugPubTable(), llvm::DWARFFormValue::extractValue(), llvm::DWARFVerifier::handleDebugLine(), llvm::DWARFDebugFrame::parse(), llvm::DWARFDebugMacro::parse(), llvm::DWARFDebugLine::LineTable::parse(), and llvm::DWARFFormValue::skipValue().

◆ getCStrRef()

StringRef DataExtractor::getCStrRef ( uint32_t OffsetPtr) const

Extract a C string from *OffsetPtr.

Returns a StringRef for the C String from the data at the offset pointed to by OffsetPtr. A variable length NULL terminated C string will be extracted and the OffsetPtr will be updated with the offset of the byte that follows the NULL terminator byte.

Parameters
[in,out]OffsetPtrA pointer to an offset within the data that will be advanced by the appropriate number of bytes if the value is extracted correctly. If the offset is out of bounds or there are not enough bytes to extract this value, the offset will be left unmodified.
Returns
A StringRef for the C string value in the data. If the offset pointed to by OffsetPtr is out of bounds, or if the offset plus the length of the C string is out of bounds, a default-initialized StringRef will be returned.

Definition at line 138 of file DataExtractor.cpp.

References llvm::StringRef::data(), llvm::StringRef::find(), and llvm::StringRef::npos.

Referenced by parseV2DirFileTables().

◆ getData()

StringRef llvm::DataExtractor::getData ( ) const
inline

◆ getSigned()

int64_t DataExtractor::getSigned ( uint32_t offset_ptr,
uint32_t  size 
) const

Extract an signed integer of size byte_size from *offset_ptr.

Extract a single signed integer value (sign extending if required) and update the offset pointed to by offset_ptr. The size of the extracted integer is specified by the byte_size argument. byte_size should have a value greater than or equal to one and less than or equal to eight since the return value is 64 bits wide. Any byte_size values less than 1 or greater than 8 will result in nothing being extracted, and zero being returned.

Parameters
[in,out]offset_ptrA pointer to an offset within the data that will be advanced by the appropriate number of bytes if the value is extracted correctly. If the offset is out of bounds or there are not enough bytes to extract this value, the offset will be left unmodified.
[in]sizeThe size in bytes of the integer to extract.
Returns
The sign extended signed integer value that was extracted, or zero on failure.

Definition at line 114 of file DataExtractor.cpp.

References getU16(), getU32(), getU64(), getU8(), and llvm_unreachable.

◆ getSLEB128()

int64_t DataExtractor::getSLEB128 ( uint32_t offset_ptr) const

Extract a signed LEB128 value from *offset_ptr.

Extracts an signed LEB128 number from this object's data starting at the offset pointed to by offset_ptr. The offset pointed to by offset_ptr will be updated with the offset of the byte following the last extracted byte.

Parameters
[in,out]offset_ptrA pointer to an offset within the data that will be advanced by the appropriate number of bytes if the value is extracted correctly. If the offset is out of bounds or there are not enough bytes to extract this value, the offset will be left unmodified.
Returns
The extracted signed integer value.

Definition at line 169 of file DataExtractor.cpp.

References llvm::StringRef::empty(), and isValidOffset().

Referenced by llvm::DWARFExpression::Operation::extract(), llvm::DWARFAbbreviationDeclaration::extract(), llvm::DWARFFormValue::extractValue(), llvm::DWARFDebugFrame::parse(), llvm::DWARFDebugLine::LineTable::parse(), llvm::FrameEntry::parseInstructions(), and llvm::DWARFFormValue::skipValue().

◆ getU16() [1/2]

uint16_t DataExtractor::getU16 ( uint32_t offset_ptr) const

Extract a uint16_t value from *offset_ptr.

Extract a single uint16_t from the binary data at the offset pointed to by offset_ptr, and update the offset on success.

Parameters
[in,out]offset_ptrA pointer to an offset within the data that will be advanced by the appropriate number of bytes if the value is extracted correctly. If the offset is out of bounds or there are not enough bytes to extract this value, the offset will be left unmodified.
Returns
The extracted uint16_t value.

Definition at line 61 of file DataExtractor.cpp.

References llvm::StringRef::data().

Referenced by dumpDWARFv5StringOffsetsSection(), llvm::DWARFDebugPubTable::DWARFDebugPubTable(), llvm::DWARFDebugArangeSet::extract(), llvm::DWARFExpression::Operation::extract(), llvm::DWARFAcceleratorTable::extract(), llvm::DWARFUnit::extractImpl(), llvm::DWARFFormValue::extractValue(), getSigned(), getUnsigned(), llvm::DWARFVerifier::DieRangeInfo::intersects(), llvm::DWARFDebugLine::Prologue::parse(), llvm::DWARFDebugLine::LineTable::parse(), llvm::FrameEntry::parseInstructions(), llvm::DWARFDebugLoc::parseOneLocationList(), llvm::DWARFDebugLocDWO::parseOneLocationList(), readPointer(), and llvm::DWARFFormValue::skipValue().

◆ getU16() [2/2]

uint16_t * DataExtractor::getU16 ( uint32_t offset_ptr,
uint16_t *  dst,
uint32_t  count 
) const

Extract count uint16_t values from *offset_ptr.

Extract count uint16_t values from the binary data at the offset pointed to by offset_ptr, and advance the offset on success. The extracted values are copied into dst.

Parameters
[in,out]offset_ptrA pointer to an offset within the data that will be advanced by the appropriate number of bytes if the value is extracted correctly. If the offset is out of bounds or there are not enough bytes to extract this value, the offset will be left unmodified.
[out]dstA buffer to copy count uint16_t values into. dst must be large enough to hold all requested data.
[in]countThe number of uint16_t values to extract.
Returns
dst if all values were properly extracted and copied, NULL otherise.

Definition at line 65 of file DataExtractor.cpp.

References llvm::count(), and llvm::StringRef::data().

◆ getU24()

uint32_t DataExtractor::getU24 ( uint32_t offset_ptr) const

Extract a 24-bit unsigned value from *offset_ptr and return it in a uint32_t.

Extract 3 bytes from the binary data at the offset pointed to by offset_ptr, construct a uint32_t from them and update the offset on success.

Parameters
[in,out]offset_ptrA pointer to an offset within the data that will be advanced by the 3 bytes if the value is extracted correctly. If the offset is out of bounds or there are not enough bytes to extract this value, the offset will be left unmodified.
Returns
The extracted 24-bit value represented in a uint32_t.

Definition at line 71 of file DataExtractor.cpp.

References llvm::StringRef::data(), llvm::Uint24::getAsUint32(), and llvm::sys::IsLittleEndianHost.

Referenced by llvm::DWARFFormValue::extractValue().

◆ getU32() [1/2]

uint32_t DataExtractor::getU32 ( uint32_t offset_ptr) const

Extract a uint32_t value from *offset_ptr.

Extract a single uint32_t from the binary data at the offset pointed to by offset_ptr, and update the offset on success.

Parameters
[in,out]offset_ptrA pointer to an offset within the data that will be advanced by the appropriate number of bytes if the value is extracted correctly. If the offset is out of bounds or there are not enough bytes to extract this value, the offset will be left unmodified.
Returns
The extracted uint32_t value.

Definition at line 78 of file DataExtractor.cpp.

References llvm::StringRef::data().

Referenced by llvm::DWARFGdbIndex::dump(), llvm::DWARFAcceleratorTable::dump(), dumpDWARFv5StringOffsetsSection(), dumpStringOffsetsSection(), llvm::DWARFDebugPubTable::DWARFDebugPubTable(), llvm::DWARFDebugArangeSet::extract(), llvm::DWARFExpression::Operation::extract(), llvm::DWARFAcceleratorTable::extract(), llvm::DWARFTypeUnit::extractImpl(), llvm::DWARFUnit::extractImpl(), llvm::DWARFFormValue::extractValue(), getSigned(), getUnsigned(), llvm::DWARFVerifier::DieRangeInfo::intersects(), llvm::DWARFDebugFrame::parse(), llvm::DWARFUnitIndex::parse(), llvm::DWARFDebugLine::Prologue::parse(), llvm::FrameEntry::parseInstructions(), llvm::DWARFDebugLocDWO::parseOneLocationList(), readPointer(), llvm::DWARFFormValue::skipValue(), and llvm::DWARFAcceleratorTable::ValueIterator::ValueIterator().

◆ getU32() [2/2]

uint32_t * DataExtractor::getU32 ( uint32_t offset_ptr,
uint32_t dst,
uint32_t  count 
) const

Extract count uint32_t values from *offset_ptr.

Extract count uint32_t values from the binary data at the offset pointed to by offset_ptr, and advance the offset on success. The extracted values are copied into dst.

Parameters
[in,out]offset_ptrA pointer to an offset within the data that will be advanced by the appropriate number of bytes if the value is extracted correctly. If the offset is out of bounds or there are not enough bytes to extract this value, the offset will be left unmodified.
[out]dstA buffer to copy count uint32_t values into. dst must be large enough to hold all requested data.
[in]countThe number of uint32_t values to extract.
Returns
dst if all values were properly extracted and copied, NULL otherise.

Definition at line 82 of file DataExtractor.cpp.

References llvm::count(), and llvm::StringRef::data().

◆ getU64() [1/2]

uint64_t DataExtractor::getU64 ( uint32_t offset_ptr) const

Extract a uint64_t value from *offset_ptr.

Extract a single uint64_t from the binary data at the offset pointed to by offset_ptr, and update the offset on success.

Parameters
[in,out]offset_ptrA pointer to an offset within the data that will be advanced by the appropriate number of bytes if the value is extracted correctly. If the offset is out of bounds or there are not enough bytes to extract this value, the offset will be left unmodified.
Returns
The extracted uint64_t value.

Definition at line 88 of file DataExtractor.cpp.

References llvm::StringRef::data().

Referenced by llvm::DWARFGdbIndex::dump(), dumpDWARFv5StringOffsetsSection(), llvm::DWARFExpression::Operation::extract(), llvm::DWARFTypeUnit::extractImpl(), llvm::DWARFFormValue::extractValue(), getSigned(), getUnsigned(), loadELF64(), llvm::DWARFDebugFrame::parse(), llvm::DWARFUnitIndex::parse(), llvm::DWARFDebugLine::Prologue::parse(), and readPointer().

◆ getU64() [2/2]

uint64_t * DataExtractor::getU64 ( uint32_t offset_ptr,
uint64_t *  dst,
uint32_t  count 
) const

Extract count uint64_t values from *offset_ptr.

Extract count uint64_t values from the binary data at the offset pointed to by offset_ptr, and advance the offset on success. The extracted values are copied into dst.

Parameters
[in,out]offset_ptrA pointer to an offset within the data that will be advanced by the appropriate number of bytes if the value is extracted correctly. If the offset is out of bounds or there are not enough bytes to extract this value, the offset will be left unmodified.
[out]dstA buffer to copy count uint64_t values into. dst must be large enough to hold all requested data.
[in]countThe number of uint64_t values to extract.
Returns
dst if all values were properly extracted and copied, NULL otherise.

Definition at line 92 of file DataExtractor.cpp.

References llvm::count(), and llvm::StringRef::data().

◆ getU8() [1/2]

uint8_t DataExtractor::getU8 ( uint32_t offset_ptr) const

Extract a uint8_t value from *offset_ptr.

Extract a single uint8_t from the binary data at the offset pointed to by offset_ptr, and advance the offset on success.

Parameters
[in,out]offset_ptrA pointer to an offset within the data that will be advanced by the appropriate number of bytes if the value is extracted correctly. If the offset is out of bounds or there are not enough bytes to extract this value, the offset will be left unmodified.
Returns
The extracted uint8_t value.

Definition at line 50 of file DataExtractor.cpp.

References llvm::StringRef::data().

Referenced by dumpDataAux(), llvm::DWARFDebugPubTable::DWARFDebugPubTable(), llvm::DWARFDebugArangeSet::extract(), llvm::DWARFExpression::Operation::extract(), llvm::DWARFAbbreviationDeclaration::extract(), llvm::DWARFUnit::extractImpl(), llvm::DWARFFormValue::extractValue(), getSigned(), getUnsigned(), llvm::DWARFVerifier::DieRangeInfo::intersects(), loadELF64(), llvm::DWARFDebugFrame::parse(), llvm::DWARFDebugLine::Prologue::parse(), llvm::DWARFDebugLine::LineTable::parse(), llvm::FrameEntry::parseInstructions(), llvm::DWARFDebugLocDWO::parseOneLocationList(), parseV5DirFileTables(), parseV5EntryFormat(), llvm::DWARFExpression::Operation::print(), and llvm::DWARFFormValue::skipValue().

◆ getU8() [2/2]

uint8_t * DataExtractor::getU8 ( uint32_t offset_ptr,
uint8_t *  dst,
uint32_t  count 
) const

Extract count uint8_t values from *offset_ptr.

Extract count uint8_t values from the binary data at the offset pointed to by offset_ptr, and advance the offset on success. The extracted values are copied into dst.

Parameters
[in,out]offset_ptrA pointer to an offset within the data that will be advanced by the appropriate number of bytes if the value is extracted correctly. If the offset is out of bounds or there are not enough bytes to extract this value, the offset will be left unmodified.
[out]dstA buffer to copy count uint8_t values into. dst must be large enough to hold all requested data.
[in]countThe number of uint8_t values to extract.
Returns
dst if all values were properly extracted and copied, NULL otherise.

Definition at line 55 of file DataExtractor.cpp.

References llvm::count(), and llvm::StringRef::data().

◆ getULEB128()

uint64_t DataExtractor::getULEB128 ( uint32_t offset_ptr) const

Extract a unsigned LEB128 value from *offset_ptr.

Extracts an unsigned LEB128 number from this object's data starting at the offset pointed to by offset_ptr. The offset pointed to by offset_ptr will be updated with the offset of the byte following the last extracted byte.

Parameters
[in,out]offset_ptrA pointer to an offset within the data that will be advanced by the appropriate number of bytes if the value is extracted correctly. If the offset is out of bounds or there are not enough bytes to extract this value, the offset will be left unmodified.
Returns
The extracted unsigned integer value.

Definition at line 148 of file DataExtractor.cpp.

References llvm::StringRef::empty(), and isValidOffset().

Referenced by llvm::DWARFDie::dump(), llvm::DWARFExpression::Operation::extract(), llvm::DWARFAbbreviationDeclaration::extract(), llvm::DWARFDebugInfoEntry::extractFast(), llvm::DWARFFormValue::extractValue(), llvm::DWARFDebugFrame::parse(), llvm::DWARFDebugMacro::parse(), llvm::DWARFDebugLine::LineTable::parse(), llvm::FrameEntry::parseInstructions(), llvm::DWARFDebugLocDWO::parseOneLocationList(), parseV2DirFileTables(), parseV5EntryFormat(), llvm::object::MachOObjectFile::ReadULEB128s(), and llvm::DWARFFormValue::skipValue().

◆ getUnsigned()

uint64_t DataExtractor::getUnsigned ( uint32_t offset_ptr,
uint32_t  byte_size 
) const

Extract an unsigned integer of size byte_size from *offset_ptr.

Extract a single unsigned integer value and update the offset pointed to by offset_ptr. The size of the extracted integer is specified by the byte_size argument. byte_size should have a value greater than or equal to one and less than or equal to eight since the return value is 64 bits wide. Any byte_size values less than 1 or greater than 8 will result in nothing being extracted, and zero being returned.

Parameters
[in,out]offset_ptrA pointer to an offset within the data that will be advanced by the appropriate number of bytes if the value is extracted correctly. If the offset is out of bounds or there are not enough bytes to extract this value, the offset will be left unmodified.
[in]byte_sizeThe size in byte of the integer to extract.
Returns
The unsigned integer value that was extracted, or zero on failure.

Definition at line 99 of file DataExtractor.cpp.

References getU16(), getU32(), getU64(), getU8(), and llvm_unreachable.

Referenced by llvm::object::Decompressor::create(), llvm::DWARFDebugArangeSet::extract(), llvm::DWARFDataExtractor::getRelocatedValue(), llvm::DWARFDebugFrame::parse(), and llvm::DWARFDebugLine::Prologue::parse().

◆ isLittleEndian()

bool llvm::DataExtractor::isLittleEndian ( ) const
inline

Get the endianness for this extractor.

Definition at line 57 of file DataExtractor.h.

Referenced by llvm::DWARFDebugLoc::parse(), and llvm::DWARFDebugLocDWO::parse().

◆ isValidOffset()

bool llvm::DataExtractor::isValidOffset ( uint32_t  offset) const
inline

◆ isValidOffsetForAddress()

bool llvm::DataExtractor::isValidOffsetForAddress ( uint32_t  offset) const
inline

Test the availability of enough bytes of data for a pointer from offset.

The size of a pointer is getAddressSize().

Returns
true if offset is a valid offset and there are enough bytes for a pointer available at that offset, false otherwise.

Definition at line 421 of file DataExtractor.h.

Referenced by llvm::symbolize::SymbolizableObjectFile::create().

◆ isValidOffsetForDataOfSize()

bool llvm::DataExtractor::isValidOffsetForDataOfSize ( uint32_t  offset,
uint32_t  length 
) const
inline

Test the availability of length bytes of data from offset.

Returns
true if offset is a valid offset and there are length bytes available at that offset, false otherwise.

Definition at line 410 of file DataExtractor.h.

Referenced by llvm::DWARFAcceleratorTable::dump(), dumpDWARFv5StringOffsetsSection(), llvm::DWARFDebugArangeSet::extract(), getU(), getUs(), llvm::DWARFUnitIndex::parse(), llvm::DWARFDebugLoc::parseOneLocationList(), and llvm::DWARFAcceleratorTable::ValueIterator::ValueIterator().

◆ setAddressSize()

void llvm::DataExtractor::setAddressSize ( uint8_t  Size)
inline

Set the address size for this extractor.

Definition at line 61 of file DataExtractor.h.

References llvm::AMDGPU::HSAMD::Kernel::Arg::Key::Size.

Referenced by llvm::DWARFDebugFrame::parse().


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