LLVM 23.0.0git
llvm::gsym::GsymReader Class Referenceabstract

GsymReader is used to read GSYM data from a file or buffer. More...

#include "llvm/DebugInfo/GSYM/GsymReader.h"

Inheritance diagram for llvm::gsym::GsymReader:
[legend]

Public Member Functions

LLVM_ABI GsymReader (GsymReader &&RHS)=default
virtual ~GsymReader ()=default
bool isLittleEndian () const
virtual uint16_t getVersion () const =0
 Get the GSYM version for this reader.
virtual uint64_t getBaseAddress () const =0
 Get the base address of this GSYM file.
virtual uint64_t getNumAddresses () const =0
 Get the number of addresses in this GSYM file.
virtual uint8_t getAddressOffsetSize () const =0
 Get the address offset byte size for this GSYM file.
virtual uint8_t getAddressInfoOffsetSize () const =0
 Get the address info offset byte size for this GSYM file.
virtual uint8_t getStringOffsetSize () const =0
 Get the string offset byte size for this GSYM file.
LLVM_ABI llvm::Expected< FunctionInfogetFunctionInfo (uint64_t Addr) const
 Get the full function info for an address.
LLVM_ABI llvm::Expected< FunctionInfogetFunctionInfoAtIndex (uint64_t AddrIdx) const
 Get the full function info given an address index.
LLVM_ABI llvm::Expected< LookupResultlookup (uint64_t Addr, std::optional< GsymDataExtractor > *MergedFuncsData=nullptr) const
 Lookup an address in the a GSYM.
LLVM_ABI llvm::Expected< std::vector< LookupResult > > lookupAll (uint64_t Addr) const
 Lookup all merged functions for a given address.
StringRef getString (gsym_strp_t Offset) const
 Get a string from the string table.
std::optional< FileEntrygetFile (uint32_t Index) const
 Get the a file entry for the suppplied file index.
virtual void dump (raw_ostream &OS)=0
 Dump the entire Gsym data contained in this object.
LLVM_ABI void dump (raw_ostream &OS, const FunctionInfo &FI, uint32_t Indent=0)
 Dump a FunctionInfo object.
LLVM_ABI void dump (raw_ostream &OS, const MergedFunctionsInfo &MFI)
 Dump a MergedFunctionsInfo object.
LLVM_ABI void dump (raw_ostream &OS, const CallSiteInfo &CSI)
 Dump a CallSiteInfo object.
LLVM_ABI void dump (raw_ostream &OS, const CallSiteInfoCollection &CSIC, uint32_t Indent=0)
 Dump a CallSiteInfoCollection object.
LLVM_ABI void dump (raw_ostream &OS, const LineTable &LT, uint32_t Indent=0)
 Dump a LineTable object.
LLVM_ABI void dump (raw_ostream &OS, const InlineInfo &II, uint32_t Indent=0)
 Dump a InlineInfo object.
LLVM_ABI void dump (raw_ostream &OS, std::optional< FileEntry > FE)
 Dump a FileEntry object.
LLVM_ABI std::optional< uint64_tgetAddress (size_t Index) const
 Gets an address from the address table.

Static Public Member Functions

static LLVM_ABI llvm::Expected< std::unique_ptr< GsymReader > > openFile (StringRef Path)
 Construct a GsymReader from a file on disk.
static LLVM_ABI llvm::Expected< std::unique_ptr< GsymReader > > copyBuffer (StringRef Bytes)
 Construct a GsymReader from a buffer.

Protected Member Functions

 GsymReader (std::unique_ptr< MemoryBuffer > Buffer, llvm::endianness Endian)
LLVM_ABI std::optional< GlobalDatagetGlobalData (GlobalInfoType Type) const
 Get the GlobalData entry for a section type.
LLVM_ABI llvm::Expected< StringRefgetRequiredGlobalDataBytes (GlobalInfoType Type) const
 Get the raw bytes for a required GlobalData section as a StringRef.
LLVM_ABI std::optional< StringRefgetOptionalGlobalDataBytes (GlobalInfoType Type) const
 Get the raw bytes for an optional GlobalData section as a StringRef.
LLVM_ABI llvm::Error parse ()
 Parse the GSYM data from the memory buffer.
virtual llvm::Error parseHeaderAndGlobalDataEntries ()=0
 Parse the version-specific header and populate GlobalDataSections.
template<class HeaderT>
llvm::Error parseHeader (const HeaderT *&OutHdr, std::unique_ptr< HeaderT > &OutSwappedHdr)
 Parse and validate the header from the beginning of the memory buffer.
llvm::Error parseGlobalDataEntries (uint64_t Offset)
 Parse GlobalData entries starting at Offset into GlobalDataSections.
llvm::Error parseAddrOffsets (StringRef Bytes)
 Parse address offsets section bytes into AddrOffsets.
llvm::Error setAddrInfoOffsetsData (StringRef Bytes)
 Set address info offsets section bytes into AddrInfoOffsetsData.
llvm::Error setStringTableData (StringRef Bytes)
 Set string table section bytes into StrTab.
llvm::Error setFileTableData (StringRef Bytes)
 Set file table section bytes into FileEntryData.
template<class T>
ArrayRef< TgetAddrOffsets () const
 Get an appropriate address info offsets array.
template<class T>
std::optional< uint64_taddressForIndex (size_t Index) const
 Get an appropriate address from the address table.
template<class T>
std::optional< uint64_tgetAddressOffsetIndex (const uint64_t AddrOffset) const
 Lookup an address offset in the AddrOffsets table.
LLVM_ABI Expected< uint64_tgetAddressIndex (const uint64_t Addr) const
 Given an address, find the address index.
LLVM_ABI std::optional< uint64_tgetAddressInfoOffset (size_t Index) const
 Given an address index, get the offset for the FunctionInfo.
LLVM_ABI llvm::Expected< GsymDataExtractorgetFunctionInfoDataForAddress (uint64_t Addr, uint64_t &FuncStartAddr) const
 Given an address, find the correct function info data and function address.
LLVM_ABI llvm::Expected< GsymDataExtractorgetFunctionInfoDataAtIndex (uint64_t AddrIdx, uint64_t &FuncStartAddr) const
 Get the function data and address given an address index.

Static Protected Member Functions

static LLVM_ABI llvm::Expected< std::unique_ptr< GsymReader > > create (std::unique_ptr< MemoryBuffer > &MemBuffer)
 Create a GSYM from a memory buffer.

Protected Attributes

std::unique_ptr< MemoryBufferMemBuffer
llvm::endianness Endian
std::map< GlobalInfoType, GlobalDataGlobalDataSections
 Parsed GlobalData entries, keyed by type.
ArrayRef< uint8_tAddrOffsets
std::vector< uint8_tSwappedAddrOffsets
GsymDataExtractor AddrInfoOffsetsData
GsymDataExtractor FileEntryData
StringTable StrTab

Detailed Description

GsymReader is used to read GSYM data from a file or buffer.

This class is optimized for very quick lookups when the endianness matches the host system. The header and the address table are designed to be mmap'ed as read only into memory and used without any parsing needed. If the endianness doesn't match, we swap the byte order of the address table into a separate buffer for efficient binary search. All the other data are parsed on demand with the correct endianness.

GsymReader objects must use one of the static functions to create an instance: GsymReader::openFile(...) and GsymReader::copyBuffer(...).

Definition at line 48 of file GsymReader.h.

Constructor & Destructor Documentation

◆ GsymReader() [1/2]

GsymReader::GsymReader ( std::unique_ptr< MemoryBuffer > Buffer,
llvm::endianness Endian )
protected

Definition at line 27 of file GsymReader.cpp.

References AddrInfoOffsetsData, Endian, FileEntryData, MemBuffer, and llvm::move().

Referenced by GsymReader().

◆ GsymReader() [2/2]

LLVM_ABI llvm::gsym::GsymReader::GsymReader ( GsymReader && RHS)
default

References GsymReader(), LLVM_ABI, and RHS.

◆ ~GsymReader()

virtual llvm::gsym::GsymReader::~GsymReader ( )
virtualdefault

Member Function Documentation

◆ addressForIndex()

template<class T>
std::optional< uint64_t > llvm::gsym::GsymReader::addressForIndex ( size_t Index) const
inlineprotected

Get an appropriate address from the address table.

The address table in the GSYM file is stored as array of 1, 2, 4 or 8 byte address offsets from the The gsym::Header::BaseAddress. The table is stored internally as a array of bytes that are in the correct endianness. In order to extract an address from the address table we must access the address offset using the correct size and then add it to the BaseAddress in the header.

Parameters
IndexAn index into the AddrOffsets array.
Returns
An virtual address that matches the original object file for the address as the specified index, or std::nullopt if Index is out of bounds.

Definition at line 422 of file GsymReader.h.

References getAddrOffsets(), getBaseAddress(), and llvm::ArrayRef< T >::size().

Referenced by getAddress().

◆ copyBuffer()

llvm::Expected< std::unique_ptr< GsymReader > > GsymReader::copyBuffer ( StringRef Bytes)
static

Construct a GsymReader from a buffer.

Parameters
BytesA set of bytes that will be copied and owned by the returned object on success.
Returns
An expected GsymReader that contains the object or an error object that indicates reason for failing to read the GSYM.

Definition at line 78 of file GsymReader.cpp.

References create(), llvm::MemoryBuffer::getMemBufferCopy(), and MemBuffer.

◆ create()

llvm::Expected< std::unique_ptr< GsymReader > > GsymReader::create ( std::unique_ptr< MemoryBuffer > & MemBuffer)
staticprotected

Create a GSYM from a memory buffer.

Called by both openFile() and copyBuffer(), this function does all of the work of parsing the GSYM file and returning an error.

Parameters
MemBufferA memory buffer that will transfer ownership into the GsymReader.
Returns
An expected GsymReader that contains the object or an error object that indicates reason for failing to read the GSYM.

Definition at line 84 of file GsymReader.cpp.

References checkMagicAndDetectVersionEndian(), llvm::createStringError(), Endian, llvm::gsym::Header::getVersion(), llvm::gsym::HeaderV2::getVersion(), MemBuffer, llvm::Expected< T >::takeError(), and llvm::Version.

Referenced by copyBuffer(), and openFile().

◆ dump() [1/8]

virtual void llvm::gsym::GsymReader::dump ( raw_ostream & OS)
pure virtual

Dump the entire Gsym data contained in this object.

Parameters
OSThe output stream to dump to.

Implemented in llvm::gsym::GsymReaderV1, and llvm::gsym::GsymReaderV2.

References II, and LLVM_ABI.

Referenced by dump(), dump(), dump(), dump(), and dump().

◆ dump() [2/8]

void GsymReader::dump ( raw_ostream & OS,
const CallSiteInfo & CSI )

Dump a CallSiteInfo object.

This function will output the details of a CallSiteInfo object in a human-readable format.

Parameters
OSThe output stream to dump to.
CSIThe CallSiteInfo object to dump.

Definition at line 522 of file GsymReader.cpp.

References llvm::gsym::CallSiteInfo::ExternalCall, getString(), HEX16, llvm::gsym::CallSiteInfo::InternalCall, llvm::gsym::CallSiteInfo::MatchRegex, llvm::gsym::CallSiteInfo::None, and llvm::gsym::CallSiteInfo::ReturnOffset.

◆ dump() [3/8]

void GsymReader::dump ( raw_ostream & OS,
const CallSiteInfoCollection & CSIC,
uint32_t Indent = 0 )

Dump a CallSiteInfoCollection object.

This function will iterate over a collection of CallSiteInfo objects and dump each one.

Parameters
OSThe output stream to dump to.
CSICThe CallSiteInfoCollection object to dump.
IndentThe indentation as number of spaces. Used when dumping as an item from within MergedFunctionsInfo.

Definition at line 554 of file GsymReader.cpp.

References llvm::gsym::CallSiteInfoCollection::CallSites, dump(), and llvm::raw_ostream::indent().

◆ dump() [4/8]

void GsymReader::dump ( raw_ostream & OS,
const FunctionInfo & FI,
uint32_t Indent = 0 )

Dump a FunctionInfo object.

This function will convert any string table indexes and file indexes into human readable format.

Parameters
OSThe output stream to dump to.
FIThe object to dump.
IndentThe indentation as number of spaces. Used when dumping as an item within MergedFunctionsInfo.

Definition at line 497 of file GsymReader.cpp.

References assert(), llvm::gsym::FunctionInfo::CallSites, dump(), getString(), llvm::raw_ostream::indent(), llvm::gsym::FunctionInfo::Inline, llvm::gsym::FunctionInfo::MergedFunctions, llvm::gsym::FunctionInfo::Name, llvm::gsym::FunctionInfo::OptLineTable, and llvm::gsym::FunctionInfo::Range.

◆ dump() [5/8]

void GsymReader::dump ( raw_ostream & OS,
const InlineInfo & II,
uint32_t Indent = 0 )

Dump a InlineInfo object.

This function will convert any string table indexes and file indexes into human readable format.

Parameters
OSThe output stream to dump to.
IIThe object to dump.
IndentThe indentation as number of spaces. Used for recurive dumping.

Definition at line 578 of file GsymReader.cpp.

References dump(), getFile(), getString(), II, and llvm::raw_ostream::indent().

◆ dump() [6/8]

void GsymReader::dump ( raw_ostream & OS,
const LineTable & LT,
uint32_t Indent = 0 )

Dump a LineTable object.

This function will convert any string table indexes and file indexes into human readable format.

Parameters
OSThe output stream to dump to.
LTThe object to dump.
IndentThe indentation as number of spaces. Used when dumping as an item from within MergedFunctionsInfo.

Definition at line 566 of file GsymReader.cpp.

References dump(), getFile(), HEX64, and llvm::raw_ostream::indent().

◆ dump() [7/8]

void GsymReader::dump ( raw_ostream & OS,
const MergedFunctionsInfo & MFI )

Dump a MergedFunctionsInfo object.

This function will dump a MergedFunctionsInfo object - basically by dumping the contained FunctionInfo objects with indentation.

Parameters
OSThe output stream to dump to.
MFIThe object to dump.

Definition at line 515 of file GsymReader.cpp.

References dump(), and llvm::gsym::MergedFunctionsInfo::MergedFunctions.

◆ dump() [8/8]

void GsymReader::dump ( raw_ostream & OS,
std::optional< FileEntry > FE )

Dump a FileEntry object.

This function will convert any string table indexes into human readable format.

Parameters
OSThe output stream to dump to.
FEThe object to dump.

Definition at line 596 of file GsymReader.cpp.

References llvm::sampleprof::Base, llvm::StringRef::empty(), and getString().

◆ getAddress()

std::optional< uint64_t > GsymReader::getAddress ( size_t Index) const

Gets an address from the address table.

Addresses are stored as offsets frrom the gsym::Header::BaseAddress.

Parameters
IndexA index into the address table.
Returns
A resolved virtual address for adddress in the address table or std::nullopt if Index is out of bounds.

Definition at line 311 of file GsymReader.cpp.

References addressForIndex(), getAddressOffsetSize(), and llvm_unreachable.

Referenced by llvm::gsym::GsymReaderV1::dump(), llvm::gsym::GsymReaderV2::dump(), and getFunctionInfoDataAtIndex().

◆ getAddressIndex()

Expected< uint64_t > GsymReader::getAddressIndex ( const uint64_t Addr) const
protected

Given an address, find the address index.

Binary search the address table and find the matching address index.

Parameters
AddrA virtual address that matches the original object file to lookup.
Returns
An index into the address table. This index can be used to extract the FunctionInfo data's offset from the AddrInfoOffsets array. Returns an error if the address isn't in the GSYM with details of why.

Definition at line 338 of file GsymReader.cpp.

References llvm::createStringError(), getAddressOffsetIndex(), getAddressOffsetSize(), and getBaseAddress().

Referenced by getFunctionInfoDataForAddress().

◆ getAddressInfoOffset()

std::optional< uint64_t > GsymReader::getAddressInfoOffset ( size_t Index) const
protected

Given an address index, get the offset for the FunctionInfo.

Looking up an address is done by finding the corresponding address index for the address. This index is then used to get the offset of the FunctionInfo data that we will decode using this function.

Parameters
IndexAn index into the address table.
Returns
An optional GSYM data offset for the offset of the FunctionInfo that needs to be decoded.

Definition at line 323 of file GsymReader.cpp.

References AddrInfoOffsetsData, llvm::gsym::FunctionInfo, getAddressInfoOffsetSize(), getNumAddresses(), getVersion(), llvm::gsym::Header::getVersion(), GlobalDataSections, and llvm::Offset.

Referenced by llvm::gsym::GsymReaderV1::dump(), llvm::gsym::GsymReaderV2::dump(), and getFunctionInfoDataAtIndex().

◆ getAddressInfoOffsetSize()

virtual uint8_t llvm::gsym::GsymReader::getAddressInfoOffsetSize ( ) const
pure virtual

Get the address info offset byte size for this GSYM file.

Implemented in llvm::gsym::GsymReaderV1, and llvm::gsym::GsymReaderV2.

Referenced by getAddressInfoOffset(), and parse().

◆ getAddressOffsetIndex()

template<class T>
std::optional< uint64_t > llvm::gsym::GsymReader::getAddressOffsetIndex ( const uint64_t AddrOffset) const
inlineprotected

Lookup an address offset in the AddrOffsets table.

Given an address offset, look it up using a binary search of the AddrOffsets table.

Parameters
AddrOffsetAn address offset, that has already been computed by subtracting the gsym::Header::BaseAddress.
Returns
The matching address offset index. This index will be used to extract the FunctionInfo data's offset from the AddrInfoOffsets array.

Definition at line 440 of file GsymReader.h.

References llvm::ArrayRef< T >::begin(), llvm::ArrayRef< T >::end(), and getAddrOffsets().

Referenced by getAddressIndex().

◆ getAddressOffsetSize()

virtual uint8_t llvm::gsym::GsymReader::getAddressOffsetSize ( ) const
pure virtual

Get the address offset byte size for this GSYM file.

Implemented in llvm::gsym::GsymReaderV1, and llvm::gsym::GsymReaderV2.

Referenced by getAddress(), getAddressIndex(), parse(), and parseAddrOffsets().

◆ getAddrOffsets()

template<class T>
ArrayRef< T > llvm::gsym::GsymReader::getAddrOffsets ( ) const
inlineprotected

Get an appropriate address info offsets array.

The address table in the GSYM file is stored as array of 1, 2, 4 or 8 byte offsets from the The gsym::Header::BaseAddress. The table is stored internally as a array of bytes that are in the correct endianness. When we access this table we must get an array that matches those sizes. This templatized helper function is used when accessing address offsets in the AddrOffsets member variable.

Returns
An ArrayRef of an appropriate address offset size.

Definition at line 404 of file GsymReader.h.

References AddrOffsets, and T.

Referenced by addressForIndex(), and getAddressOffsetIndex().

◆ getBaseAddress()

virtual uint64_t llvm::gsym::GsymReader::getBaseAddress ( ) const
pure virtual

Get the base address of this GSYM file.

Implemented in llvm::gsym::GsymReaderV1, and llvm::gsym::GsymReaderV2.

Referenced by addressForIndex(), and getAddressIndex().

◆ getFile()

std::optional< FileEntry > llvm::gsym::GsymReader::getFile ( uint32_t Index) const
inline

Get the a file entry for the suppplied file index.

Used to convert any file indexes in the FunctionInfo data back into files. This function can be used for iteration, but is more commonly used for random access when doing lookups.

Parameters
IndexAn index into the file table.
Returns
An optional FileInfo that will be valid if the file index is valid, or std::nullopt if the file index is out of bounds,

Definition at line 184 of file GsymReader.h.

References llvm::gsym::FileEntry::Base, llvm::gsym::FileEntry::Dir, FileEntryData, llvm::gsym::FileEntry::getEncodedSize(), and llvm::Offset.

Referenced by dump(), dump(), llvm::gsym::GsymReaderV1::dump(), llvm::gsym::GsymReaderV2::dump(), llvm::gsym::FunctionInfo::lookup(), and lookup().

◆ getFunctionInfo()

llvm::Expected< FunctionInfo > GsymReader::getFunctionInfo ( uint64_t Addr) const

Get the full function info for an address.

This should be called when a client will store a copy of the complete FunctionInfo for a given address. For one off lookups, use the lookup() function below.

Symbolication server processes might want to parse the entire function info for a given address and cache it if the process stays around to service many symbolication addresses, like for parsing profiling information.

Parameters
AddrA virtual address from the orignal object file to lookup.
Returns
An expected FunctionInfo that contains the function info object or an error object that indicates reason for failing to lookup the address.

Definition at line 434 of file GsymReader.cpp.

References llvm::gsym::FunctionInfo::decode(), and getFunctionInfoDataForAddress().

◆ getFunctionInfoAtIndex()

llvm::Expected< FunctionInfo > GsymReader::getFunctionInfoAtIndex ( uint64_t AddrIdx) const

Get the full function info given an address index.

Parameters
AddrIdxA address index for an address in the address table.
Returns
An expected FunctionInfo that contains the function info object or an error object that indicates reason for failing get the function info object.

Definition at line 443 of file GsymReader.cpp.

References llvm::gsym::FunctionInfo::decode(), and getFunctionInfoDataAtIndex().

Referenced by llvm::gsym::GsymReaderV1::dump(), and llvm::gsym::GsymReaderV2::dump().

◆ getFunctionInfoDataAtIndex()

llvm::Expected< GsymDataExtractor > GsymReader::getFunctionInfoDataAtIndex ( uint64_t AddrIdx,
uint64_t & FuncStartAddr ) const
protected

Get the function data and address given an address index.

Parameters
AddrIdxA address index from the address table.
Returns
An expected FunctionInfo that contains the function info object or an error object that indicates reason for failing to lookup the address.

Definition at line 412 of file GsymReader.cpp.

References assert(), llvm::big, llvm::createStringError(), llvm::Data, llvm::StringRef::empty(), Endian, getAddress(), getAddressInfoOffset(), getStringOffsetSize(), isLittleEndian(), llvm::little, and MemBuffer.

Referenced by getFunctionInfoAtIndex(), and getFunctionInfoDataForAddress().

◆ getFunctionInfoDataForAddress()

llvm::Expected< GsymDataExtractor > GsymReader::getFunctionInfoDataForAddress ( uint64_t Addr,
uint64_t & FuncStartAddr ) const
protected

Given an address, find the correct function info data and function address.

Binary search the address table and find the matching address info and make sure that the function info contains the address. GSYM allows functions to overlap, and the most debug info is contained in the first entries due to the sorting when GSYM files are created. We can have multiple function info that start at the same address only if their address range doesn't match. So find the first entry that matches Addr and iterate forward until we find one that contains the address.

Parameters
[in]AddrA virtual address that matches the original object file to lookup.
[out]FuncStartAddrA virtual address that is the base address of the function that is used for decoding the FunctionInfo.
Returns
An valid data extractor on success, or an error if we fail to find the address in a function info or corrrectly decode the data

Definition at line 369 of file GsymReader.cpp.

References contains(), llvm::createStringError(), getAddressIndex(), getFunctionInfoDataAtIndex(), getNumAddresses(), llvm::Offset, and llvm::Expected< T >::takeError().

Referenced by getFunctionInfo(), and lookup().

◆ getGlobalData()

std::optional< GlobalData > GsymReader::getGlobalData ( GlobalInfoType Type) const
protected

Get the GlobalData entry for a section type.

Parameters
TypeThe section type to retrieve.
Returns
The GlobalData entry, or std::nullopt if the section is not present.

Definition at line 277 of file GsymReader.cpp.

References GlobalDataSections.

Referenced by llvm::gsym::GsymReaderV1::dump(), and getOptionalGlobalDataBytes().

◆ getNumAddresses()

virtual uint64_t llvm::gsym::GsymReader::getNumAddresses ( ) const
pure virtual

Get the number of addresses in this GSYM file.

Implemented in llvm::gsym::GsymReaderV1, and llvm::gsym::GsymReaderV2.

Referenced by getAddressInfoOffset(), getFunctionInfoDataForAddress(), parse(), and parseAddrOffsets().

◆ getOptionalGlobalDataBytes()

std::optional< StringRef > GsymReader::getOptionalGlobalDataBytes ( GlobalInfoType Type) const
protected

Get the raw bytes for an optional GlobalData section as a StringRef.

Parameters
TypeThe section type to retrieve.
Returns
The section data, or std::nullopt if the section is not present or any bytes are not present in the file.

Definition at line 301 of file GsymReader.cpp.

References getGlobalData(), MemBuffer, llvm::StringRef::size(), and llvm::StringRef::substr().

Referenced by llvm::gsym::GsymReaderV1::dump(), and llvm::gsym::GsymReaderV2::dump().

◆ getRequiredGlobalDataBytes()

llvm::Expected< StringRef > GsymReader::getRequiredGlobalDataBytes ( GlobalInfoType Type) const
protected

Get the raw bytes for a required GlobalData section as a StringRef.

Parameters
TypeThe section type to retrieve.
Returns
The section data, or an error if the section is not present or any bytes are not present in the file.

Definition at line 285 of file GsymReader.cpp.

Referenced by parse().

◆ getString()

StringRef llvm::gsym::GsymReader::getString ( gsym_strp_t Offset) const
inline

Get a string from the string table.

Parameters
OffsetThe string table offset for the string to retrieve.
Returns
The string from the strin table.

Definition at line 173 of file GsymReader.h.

References llvm::Offset, and StrTab.

Referenced by dump(), dump(), dump(), dump(), llvm::gsym::FunctionInfo::lookup(), and lookup().

◆ getStringOffsetSize()

virtual uint8_t llvm::gsym::GsymReader::getStringOffsetSize ( ) const
pure virtual

Get the string offset byte size for this GSYM file.

Implemented in llvm::gsym::GsymReaderV1, and llvm::gsym::GsymReaderV2.

References LLVM_ABI.

Referenced by getFunctionInfoDataAtIndex(), and setFileTableData().

◆ getVersion()

virtual uint16_t llvm::gsym::GsymReader::getVersion ( ) const
pure virtual

Get the GSYM version for this reader.

Implemented in llvm::gsym::GsymReaderV1, and llvm::gsym::GsymReaderV2.

Referenced by getAddressInfoOffset(), and parseGlobalDataEntries().

◆ isLittleEndian()

◆ lookup()

llvm::Expected< LookupResult > GsymReader::lookup ( uint64_t Addr,
std::optional< GsymDataExtractor > * MergedFuncsData = nullptr ) const

Lookup an address in the a GSYM.

Lookup just the information needed for a specific address Addr. This function is faster that calling getFunctionInfo() as it will only return information that pertains to Addr and allows the parsing to skip any extra information encoded for other addresses. For example the line table parsing can stop when a matching LineEntry has been fouhnd, and the InlineInfo can stop parsing early once a match has been found and also skip information that doesn't match. This avoids memory allocations and is much faster for lookups.

Parameters
AddrA virtual address from the orignal object file to lookup.
MergedFuncsDataA pointer to an optional GsymDataExtractor that, if non-null, will be set to the raw data of the MergedFunctionInfo, if present.
Returns
An expected LookupResult that contains only the information needed for the current address, or an error object that indicates reason for failing to lookup the address.

Definition at line 451 of file GsymReader.cpp.

References getFunctionInfoDataForAddress(), and llvm::gsym::FunctionInfo::lookup().

Referenced by lookupAll().

◆ lookupAll()

llvm::Expected< std::vector< LookupResult > > GsymReader::lookupAll ( uint64_t Addr) const

Lookup all merged functions for a given address.

This function performs a lookup for the specified address and then retrieves additional LookupResults from any merged functions associated with the primary LookupResult.

Parameters
AddrThe address to lookup.
Returns
A vector of LookupResult objects, where the first element is the primary result, followed by results for any merged functions

Definition at line 463 of file GsymReader.cpp.

References llvm::gsym::MergedFunctionsInfo::getFuncsDataExtractors(), llvm::gsym::FunctionInfo::lookup(), lookup(), and Results.

◆ openFile()

llvm::Expected< std::unique_ptr< GsymReader > > GsymReader::openFile ( StringRef Path)
static

Construct a GsymReader from a file on disk.

Parameters
PathThe file path the GSYM file to read.
Returns
An expected GsymReader that contains the object or an error object that indicates reason for failing to read the GSYM.

Definition at line 67 of file GsymReader.cpp.

References create(), llvm::errorCodeToError(), Filename, llvm::ErrorOr< T >::get(), llvm::ErrorOr< T >::getError(), and llvm::MemoryBuffer::getFileOrSTDIN().

Referenced by llvm::symbolize::LLVMSymbolizer::getOrCreateModuleInfo(), and llvm::gsym::DwarfTransformer::verify().

◆ parse()

◆ parseAddrOffsets()

llvm::Error GsymReader::parseAddrOffsets ( StringRef Bytes)
protected

Parse address offsets section bytes into AddrOffsets.

Parameters
BytesThe raw section bytes.
Returns
Error on failure.

Definition at line 201 of file GsymReader.cpp.

References AddrOffsets, llvm::createStringError(), Endian, getAddressOffsetSize(), getNumAddresses(), llvm::native, and llvm::StringRef::size().

Referenced by parse().

◆ parseGlobalDataEntries()

llvm::Error GsymReader::parseGlobalDataEntries ( uint64_t Offset)
protected

Parse GlobalData entries starting at Offset into GlobalDataSections.

This should only be called by any GSYM version >= 2. If called by V1, an error will be returned.

Parameters
OffsetThe byte offset where GlobalData entries begin.
Returns
Error on failure.

Definition at line 166 of file GsymReader.cpp.

References llvm::createStringError(), llvm::Data, llvm::gsym::GlobalData::decode(), llvm::gsym::EndOfList, llvm::gsym::GlobalData::FileOffset, llvm::gsym::GlobalData::FileSize, getVersion(), llvm::gsym::HeaderV2::getVersion(), GlobalDataSections, isLittleEndian(), MemBuffer, llvm::Offset, llvm::StringRef::size(), llvm::Error::success(), and llvm::gsym::GlobalData::Type.

Referenced by llvm::gsym::GsymReaderV2::parseHeaderAndGlobalDataEntries().

◆ parseHeader()

template<class HeaderT>
llvm::Error llvm::gsym::GsymReader::parseHeader ( const HeaderT *& OutHdr,
std::unique_ptr< HeaderT > & OutSwappedHdr )
inlineprotected

Parse and validate the header from the beginning of the memory buffer.

Parameters
OutHdrOutput pointer to the parsed header.
OutSwappedHdrStorage for byte-swapped header if needed.
Returns
Error on failure.

Definition at line 336 of file GsymReader.h.

References llvm::createStringError(), llvm::Data, llvm::StringRef::data(), Endian, isLittleEndian(), MemBuffer, llvm::native, llvm::StringRef::size(), and llvm::Error::success().

Referenced by llvm::gsym::GsymReaderV1::parseHeaderAndGlobalDataEntries(), and llvm::gsym::GsymReaderV2::parseHeaderAndGlobalDataEntries().

◆ parseHeaderAndGlobalDataEntries()

virtual llvm::Error llvm::gsym::GsymReader::parseHeaderAndGlobalDataEntries ( )
protectedpure virtual

Parse the version-specific header and populate GlobalDataSections.

Returns
Error on failure.

Implemented in llvm::gsym::GsymReaderV1, and llvm::gsym::GsymReaderV2.

Referenced by parse().

◆ setAddrInfoOffsetsData()

llvm::Error GsymReader::setAddrInfoOffsetsData ( StringRef Bytes)
protected

Set address info offsets section bytes into AddrInfoOffsetsData.

Parameters
BytesThe raw section bytes.
Returns
Error on failure.

Definition at line 252 of file GsymReader.cpp.

References AddrInfoOffsetsData, isLittleEndian(), and llvm::Error::success().

Referenced by parse().

◆ setFileTableData()

llvm::Error GsymReader::setFileTableData ( StringRef Bytes)
protected

Set file table section bytes into FileEntryData.

Parameters
BytesThe raw section bytes.
Returns
Error on failure.

Definition at line 262 of file GsymReader.cpp.

References llvm::createStringError(), llvm::Data, FileEntryData, llvm::gsym::FileEntry::getEncodedSize(), getStringOffsetSize(), isLittleEndian(), llvm::Offset, and llvm::StringRef::size().

Referenced by parse().

◆ setStringTableData()

llvm::Error GsymReader::setStringTableData ( StringRef Bytes)
protected

Set string table section bytes into StrTab.

Parameters
BytesThe raw section bytes.
Returns
Error on failure.

Definition at line 257 of file GsymReader.cpp.

References StrTab, and llvm::Error::success().

Referenced by parse().

Member Data Documentation

◆ AddrInfoOffsetsData

GsymDataExtractor llvm::gsym::GsymReader::AddrInfoOffsetsData
protected

◆ AddrOffsets

ArrayRef<uint8_t> llvm::gsym::GsymReader::AddrOffsets
protected

Definition at line 55 of file GsymReader.h.

Referenced by getAddrOffsets(), and parseAddrOffsets().

◆ Endian

◆ FileEntryData

GsymDataExtractor llvm::gsym::GsymReader::FileEntryData
protected

Definition at line 58 of file GsymReader.h.

Referenced by getFile(), GsymReader(), and setFileTableData().

◆ GlobalDataSections

std::map<GlobalInfoType, GlobalData> llvm::gsym::GsymReader::GlobalDataSections
protected

◆ MemBuffer

◆ StrTab

StringTable llvm::gsym::GsymReader::StrTab
protected

◆ SwappedAddrOffsets

std::vector<uint8_t> llvm::gsym::GsymReader::SwappedAddrOffsets
protected

Definition at line 56 of file GsymReader.h.

Referenced by llvm::gsym::GsymReaderV1::dump(), and llvm::gsym::GsymReaderV1::dump().


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