LLVM 20.0.0git
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
llvm::gsym::FunctionInfo Struct Reference

Function information in GSYM files encodes information for one contiguous address range. More...

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

Public Member Functions

 FunctionInfo (uint64_t Addr=0, uint64_t Size=0, uint32_t N=0)
 
bool hasRichInfo () const
 Query if a FunctionInfo has rich debug info.
 
bool isValid () const
 Query if a FunctionInfo object is valid.
 
llvm::Expected< uint64_tencode (FileWriter &O, bool NoPadding=false) const
 Encode this object into FileWriter stream.
 
uint64_t cacheEncoding ()
 Encode this function info into the internal byte cache and return the size in bytes.
 
uint64_t startAddress () const
 
uint64_t endAddress () const
 
uint64_t size () const
 
void clear ()
 

Static Public Member Functions

static llvm::Expected< FunctionInfodecode (DataExtractor &Data, uint64_t BaseAddr)
 Decode an object from a binary data stream.
 
static llvm::Expected< LookupResultlookup (DataExtractor &Data, const GsymReader &GR, uint64_t FuncAddr, uint64_t Addr)
 Lookup an address within a FunctionInfo object's data stream.
 

Public Attributes

AddressRange Range
 
uint32_t Name
 String table offset in the string table.
 
std::optional< LineTableOptLineTable
 
std::optional< InlineInfoInline
 
std::optional< MergedFunctionsInfoMergedFunctions
 
std::optional< CallSiteInfoCollectionCallSites
 
SmallString< 32 > EncodingCache
 If we encode a FunctionInfo during segmenting so we know its size, we can cache that encoding here so we don't need to re-encode it when saving the GSYM file.
 

Detailed Description

Function information in GSYM files encodes information for one contiguous address range.

If a function has discontiguous address ranges, they will need to be encoded using multiple FunctionInfo objects.

ENCODING

The function information gets the function start address as an argument to the FunctionInfo::decode(...) function. This information is calculated from the GSYM header and an address offset from the GSYM address offsets table. The encoded FunctionInfo information must be aligned to a 4 byte boundary.

The encoded data for a FunctionInfo starts with fixed data that all function info objects have:

ENCODING NAME DESCRIPTION ========= =========== ==================================================== uint32_t Size The size in bytes of this function. uint32_t Name The string table offset of the function name.

The optional data in a FunctionInfo object follows this fixed information and consists of a stream of tuples that consist of:

ENCODING NAME DESCRIPTION ========= =========== ==================================================== uint32_t InfoType An "InfoType" enumeration that describes the type of optional data that is encoded. uint32_t InfoLength The size in bytes of the encoded data that immediately follows this length if this value is greater than zero. uint8_t[] InfoData Encoded bytes that represent the data for the "InfoType". These bytes are only present if "InfoLength" is greater than zero.

The "InfoType" is an enumeration:

enum InfoType { EndOfList = 0u, LineTableInfo = 1u, InlineInfo = 2u, MergedFunctionsInfo = 3u, CallSiteInfo = 4u };

This stream of tuples is terminated by a "InfoType" whose value is InfoType::EndOfList and a zero for "InfoLength". This signifies the end of the optional information list. This format allows us to add new optional information data to a FunctionInfo object over time and allows older clients to still parse the format and skip over any data that they don't understand or want to parse.

So the function information encoding essentially looks like:

struct { uint32_t Size; uint32_t Name; struct { uint32_t InfoType; uint32_t InfoLength; uint8_t InfoData[InfoLength]; }[N]; }

Where "N" is the number of tuples.

Definition at line 92 of file FunctionInfo.h.

Constructor & Destructor Documentation

◆ FunctionInfo()

llvm::gsym::FunctionInfo::FunctionInfo ( uint64_t  Addr = 0,
uint64_t  Size = 0,
uint32_t  N = 0 
)
inline

Definition at line 104 of file FunctionInfo.h.

Member Function Documentation

◆ cacheEncoding()

uint64_t FunctionInfo::cacheEncoding ( )

Encode this function info into the internal byte cache and return the size in bytes.

When segmenting GSYM files we need to know how big each FunctionInfo will encode into so we can generate segments of the right size. We don't want to have to encode a FunctionInfo twice, so we can cache the encoded bytes and re-use then when calling FunctionInfo::encode(...).

Returns
The size in bytes of the FunctionInfo if it were to be encoded into a byte stream.

Definition at line 119 of file FunctionInfo.cpp.

References llvm::SmallVectorImpl< T >::clear(), llvm::consumeError(), encode(), EncodingCache, isValid(), llvm::native, and llvm::SmallVectorBase< Size_T >::size().

◆ clear()

void llvm::gsym::FunctionInfo::clear ( )
inline

Definition at line 202 of file FunctionInfo.h.

References Inline, Name, OptLineTable, and Range.

◆ decode()

llvm::Expected< FunctionInfo > FunctionInfo::decode ( DataExtractor Data,
uint64_t  BaseAddr 
)
static

Decode an object from a binary data stream.

Parameters
DataThe binary stream to read the data from. This object must have the data for the object starting at offset zero. The data can contain more data than needed.
BaseAddrThe FunctionInfo's start address and will be used as the base address when decoding any contained information like the line table and the inline info.
Returns
An FunctionInfo or an error describing the issue that was encountered during decoding.

Definition at line 41 of file FunctionInfo.cpp.

References CallSites, llvm::createStringError(), llvm::Data, llvm::gsym::CallSiteInfoCollection::decode(), llvm::gsym::InlineInfo::decode(), llvm::gsym::LineTable::decode(), llvm::gsym::MergedFunctionsInfo::decode(), llvm::Done, II, Inline, IT, MergedFunctions, MI, Name, llvm::Offset, OptLineTable, and Range.

Referenced by llvm::gsym::MergedFunctionsInfo::decode(), llvm::gsym::GsymReader::getFunctionInfo(), and llvm::gsym::GsymReader::getFunctionInfoAtIndex().

◆ encode()

llvm::Expected< uint64_t > FunctionInfo::encode ( FileWriter O,
bool  NoPadding = false 
) const

Encode this object into FileWriter stream.

Parameters
OThe binary stream to write the data to at the current file position.
NoPaddingDirectly write the FunctionInfo data, without any padding By default, FunctionInfo will be 4-byte aligned by padding with 0's at the start. This is OK since the function will return the offset of actual data in the stream. However when writing FunctionInfo's as a stream, the padding will break the decoding of the data - since the offset where the FunctionInfo starts is not kept in this scenario.
Returns
An error object that indicates failure or the offset of the function info that was successfully written into the stream.

Definition at line 134 of file FunctionInfo.cpp.

References llvm::gsym::FileWriter::alignTo(), CallSites, llvm::createStringError(), llvm::SmallVectorTemplateCommon< T, typename >::data(), llvm::SmallVectorBase< Size_T >::empty(), EncodingCache, llvm::gsym::FileWriter::fixup32(), llvm::gsym::FileWriter::getByteOrder(), Inline, isValid(), llvm::Length, MergedFunctions, Name, llvm::native, OptLineTable, Range, llvm::SmallVectorBase< Size_T >::size(), size(), llvm::AddressRange::start(), llvm::gsym::FileWriter::tell(), llvm::gsym::FileWriter::writeData(), and llvm::gsym::FileWriter::writeU32().

Referenced by cacheEncoding().

◆ endAddress()

uint64_t llvm::gsym::FunctionInfo::endAddress ( ) const
inline

Definition at line 199 of file FunctionInfo.h.

References llvm::AddressRange::end(), and Range.

Referenced by convertFunctionLineTable().

◆ hasRichInfo()

bool llvm::gsym::FunctionInfo::hasRichInfo ( ) const
inline

Query if a FunctionInfo has rich debug info.

Returns
A bool that indicates if this object has something else than range and name. When converting information from a symbol table and from debug info, we might end up with multiple FunctionInfo objects for the same range and we need to be able to tell which one is the better object to use.

Definition at line 114 of file FunctionInfo.h.

References CallSites, Inline, and OptLineTable.

Referenced by llvm::gsym::GsymCreator::finalize().

◆ isValid()

bool llvm::gsym::FunctionInfo::isValid ( ) const
inline

Query if a FunctionInfo object is valid.

Address and size can be zero and there can be no line entries for a symbol so the only indication this entry is valid is if the name is not zero. This can happen when extracting information from symbol tables that do not encode symbol sizes. In that case only the address and name will be filled in.

Returns
A boolean indicating if this FunctionInfo is valid.

Definition at line 125 of file FunctionInfo.h.

References Name.

Referenced by cacheEncoding(), and encode().

◆ lookup()

llvm::Expected< LookupResult > FunctionInfo::lookup ( DataExtractor Data,
const GsymReader GR,
uint64_t  FuncAddr,
uint64_t  Addr 
)
static

Lookup an address within a FunctionInfo object's data stream.

Instead of decoding an entire FunctionInfo object when doing lookups, we can decode only the information we need from the FunctionInfo's data for the specific address. The lookup result information is returned as a LookupResult.

Parameters
DataThe binary stream to read the data from. This object must have the data for the object starting at offset zero. The data can contain more data than needed.
GRThe GSYM reader that contains the string and file table that will be used to fill in information in the returned result.
FuncAddrThe function start address decoded from the GsymReader.
AddrThe address to lookup.
Returns
An LookupResult or an error describing the issue that was encountered during decoding. An error should only be returned if the address is not contained in the FunctionInfo or if the data is corrupted.

Definition at line 238 of file FunctionInfo.cpp.

References Addr, llvm::gsym::SourceLocation::Base, llvm::AddressRange::contains(), llvm::createStringError(), llvm::Data, llvm::gsym::SourceLocation::Dir, llvm::Done, llvm::gsym::LineEntry::File, llvm::gsym::LookupResult::FuncName, llvm::gsym::LookupResult::FuncRange, llvm::gsym::GsymReader::getFile(), llvm::gsym::GsymReader::getString(), IT, llvm::gsym::LineEntry::Line, llvm::gsym::SourceLocation::Line, llvm::gsym::LookupResult::Locations, llvm::gsym::InlineInfo::lookup(), llvm::gsym::LineTable::lookup(), llvm::gsym::LookupResult::LookupAddr, llvm::gsym::SourceLocation::Name, llvm::gsym::SourceLocation::Offset, llvm::Offset, llvm::AddressRange::size(), and llvm::StringRef::size().

Referenced by llvm::gsym::GsymReader::lookup().

◆ size()

uint64_t llvm::gsym::FunctionInfo::size ( ) const
inline

Definition at line 200 of file FunctionInfo.h.

References Range, and llvm::AddressRange::size().

Referenced by encode(), and llvm::gsym::DwarfTransformer::verify().

◆ startAddress()

uint64_t llvm::gsym::FunctionInfo::startAddress ( ) const
inline

Definition at line 198 of file FunctionInfo.h.

References Range, and llvm::AddressRange::start().

Referenced by convertFunctionLineTable().

Member Data Documentation

◆ CallSites

std::optional<CallSiteInfoCollection> llvm::gsym::FunctionInfo::CallSites

◆ EncodingCache

SmallString<32> llvm::gsym::FunctionInfo::EncodingCache

If we encode a FunctionInfo during segmenting so we know its size, we can cache that encoding here so we don't need to re-encode it when saving the GSYM file.

Definition at line 102 of file FunctionInfo.h.

Referenced by cacheEncoding(), and encode().

◆ Inline

std::optional<InlineInfo> llvm::gsym::FunctionInfo::Inline

◆ MergedFunctions

std::optional<MergedFunctionsInfo> llvm::gsym::FunctionInfo::MergedFunctions

◆ Name

uint32_t llvm::gsym::FunctionInfo::Name

String table offset in the string table.

Definition at line 94 of file FunctionInfo.h.

Referenced by clear(), decode(), llvm::gsym::GsymReader::dump(), encode(), isValid(), and llvm::gsym::operator<<().

◆ OptLineTable

std::optional<LineTable> llvm::gsym::FunctionInfo::OptLineTable

◆ Range

AddressRange llvm::gsym::FunctionInfo::Range

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