39 "data too small to be a GSYM file");
51 FileEndian = HostEndian;
59 "not a GSYM file (bad magic)");
63 return std::make_pair(Version, FileEndian);
66llvm::Expected<std::unique_ptr<GsymReader>>
74 auto &Buf = BuffOrErr.
get();
75 Buf->randomAccessIfMmap();
89 "invalid memory buffer");
92 if (!VersionEndianOrErr)
97 std::unique_ptr<GsymReader> GR;
107 "unsupported GSYM version %u",
Version);
109 if (
auto Err = GR->parse())
110 return std::move(Err);
111 return std::move(GR);
126 std::errc::invalid_argument,
"missing required section type %s (%u)",
132 "AddrOffsets section size mismatch");
137 "AddrInfoOffsets section size mismatch");
171 "GlobalData section not supported in GSYM V1");
179 return GDOrErr.takeError();
187 "GlobalData section type %u has zero size",
192 std::errc::invalid_argument,
193 "GlobalData section type %u extends beyond "
194 "buffer (offset=%" PRIu64
", size=%" PRIu64
", bufsize=%" PRIu64
")",
200 "GlobalData array not terminated by EndOfList");
206 const size_t TotalBytes = NumAddrs * AddrOffSize;
207 if (Bytes.
size() < TotalBytes)
209 "failed to read address table");
214 reinterpret_cast<const uint8_t *
>(Bytes.
data()), TotalBytes);
222 switch (AddrOffSize) {
226 "failed to read address table");
233 "failed to read address table");
240 "failed to read address table");
247 "failed to read address table");
273 "FileTable section too small for %u files",
296 std::errc::invalid_argument,
297 "missing bytes for %s, GSYM file might be truncated", TypeName);
299 "missing required section type %s", TypeName);
302std::optional<StringRef>
308 if (GD->FileSize == 0 || GD->FileOffset + GD->FileSize > Buf.
size())
310 return Buf.
substr(GD->FileOffset, GD->FileSize);
337 return AddrInfoOffset;
342 if (Addr >= BaseAddr) {
343 const uint64_t AddrOffset = Addr - BaseAddr;
344 std::optional<uint64_t> AddrOffsetIndex;
360 "unsupported address offset size %u",
364 return *AddrOffsetIndex;
367 "address 0x%" PRIx64
" is not in GSYM", Addr);
374 if (!ExpectedAddrIdx)
376 const uint64_t FirstAddrIdx = *ExpectedAddrIdx;
380 std::optional<uint64_t> FirstFuncStartAddr;
382 for (
uint64_t AddrIdx = FirstAddrIdx; AddrIdx < NumAddresses; ++AddrIdx) {
391 if (FirstFuncStartAddr.has_value()) {
392 if (*FirstFuncStartAddr != FuncStartAddr)
395 FirstFuncStartAddr = FuncStartAddr;
410 "address 0x%" PRIx64
" is not in GSYM", Addr);
417 if (AddrInfoOffset == std::nullopt)
419 "invalid address index %" PRIu64, AddrIdx);
421 "Endian must be either big or little");
425 "invalid address info offset 0x%" PRIx64,
427 std::optional<uint64_t> OptFuncStartAddr =
getAddress(AddrIdx);
428 if (!OptFuncStartAddr)
430 "failed to extract address[%" PRIu64
"]", AddrIdx);
431 FuncStartAddr = *OptFuncStartAddr;
441 return ExpectedData.takeError();
450 return ExpectedData.takeError();
455 std::optional<GsymDataExtractor> *MergedFunctionsData)
const {
459 MergedFunctionsData);
461 return ExpectedData.takeError();
466 std::vector<LookupResult>
Results;
467 std::optional<GsymDataExtractor> MergedFunctionsData;
470 auto MainResult =
lookup(Addr, &MergedFunctionsData);
472 return MainResult.takeError();
475 Results.push_back(std::move(*MainResult));
478 if (MergedFunctionsData) {
480 auto ExpectedMergedFuncExtractors =
482 if (!ExpectedMergedFuncExtractors)
483 return ExpectedMergedFuncExtractors.takeError();
488 MainResult->FuncRange.start(), Addr)) {
489 Results.push_back(std::move(*FI));
491 return FI.takeError();
512 assert(Indent == 0 &&
"MergedFunctionsInfo should only exist at top level");
519 OS <<
"++ Merged FunctionInfos[" << inx <<
"]:\n";
528 auto addFlag = [&](
const char *Flag) {
538 addFlag(
"InternalCall");
541 addFlag(
"ExternalCall");
543 OS <<
" Flags[" << Flags <<
"]";
546 OS <<
" MatchRegex[";
559 OS <<
"CallSites (by relative return offset):\n";
570 OS <<
"LineTable:\n";
571 for (
auto &LE : LT) {
573 OS <<
" " <<
HEX64(LE.Addr) <<
' ';
576 OS <<
':' << LE.Line <<
'\n';
582 OS <<
"InlineInfo:\n";
586 if (
II.CallFile != 0) {
588 OS <<
" called from ";
590 OS <<
':' <<
II.CallLine;
594 for (
const auto &ChildII :
II.Children)
595 dump(OS, ChildII, Indent + 2);
601 if (FE->Dir == 0 && FE->Base == 0)
607 if (Dir.contains(
'\\') && !Dir.contains(
'/'))
618 OS <<
"<invalid-file>";
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
Function Alias Analysis Results
static Expected< std::pair< uint16_t, llvm::endianness > > checkMagicAndDetectVersionEndian(StringRef Bytes)
Check magic bytes, determine endianness, and return the GSYM version and endianness.
uint64_t IntrinsicInst * II
static constexpr StringLiteral Filename
static bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
A class that represents an address range.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Represents either an error or a value T.
std::error_code getError() const
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
Error takeError()
Take ownership of the stored error.
static std::unique_ptr< MemoryBuffer > getMemBufferCopy(StringRef InputData, const Twine &BufferName="")
Open the specified memory range as a MemoryBuffer, copying the contents and taking ownership of it.
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFileOrSTDIN(const Twine &Filename, bool IsText=false, bool RequiresNullTerminator=true, std::optional< Align > Alignment=std::nullopt)
Open the specified file as a MemoryBuffer, or open stdin if the Filename is "-".
Represent a constant reference to a string, i.e.
constexpr StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
constexpr bool empty() const
Check if the string is empty.
constexpr size_t size() const
Get the string size.
constexpr const char * data() const
Get a pointer to the start of the string (which may not be null terminated).
The instances of the Type class are immutable: once they are created, they are never changed.
GsymReaderV1 reads GSYM V1 data from a buffer.
GsymReaderV2 reads GSYM V2 data from a buffer.
StringRef getString(gsym_strp_t Offset) const
Get a string from the string table.
llvm::Error setAddrInfoOffsetsData(StringRef Bytes)
Set address info offsets section bytes into AddrInfoOffsetsData.
llvm::Error parseGlobalDataEntries(uint64_t Offset)
Parse GlobalData entries starting at Offset into GlobalDataSections.
GsymDataExtractor FileEntryData
LLVM_ABI llvm::Expected< GsymDataExtractor > getFunctionInfoDataAtIndex(uint64_t AddrIdx, uint64_t &FuncStartAddr) const
Get the function data and address given an address index.
virtual uint8_t getStringOffsetSize() const =0
Get the string offset byte size for this GSYM file.
static LLVM_ABI llvm::Expected< std::unique_ptr< GsymReader > > copyBuffer(StringRef Bytes)
Construct a GsymReader from a buffer.
virtual llvm::Error parseHeaderAndGlobalDataEntries()=0
Parse the version-specific header and populate GlobalDataSections.
std::optional< FileEntry > getFile(uint32_t Index) const
Get the a file entry for the suppplied file index.
bool isLittleEndian() const
LLVM_ABI std::optional< GlobalData > getGlobalData(GlobalInfoType Type) const
Get the GlobalData entry for a section type.
ArrayRef< uint8_t > AddrOffsets
llvm::Error setFileTableData(StringRef Bytes)
Set file table section bytes into FileEntryData.
GsymDataExtractor AddrInfoOffsetsData
static LLVM_ABI llvm::Expected< std::unique_ptr< GsymReader > > create(std::unique_ptr< MemoryBuffer > &MemBuffer)
Create a GSYM from a memory buffer.
LLVM_ABI std::optional< uint64_t > getAddress(size_t Index) const
Gets an address from the address table.
LLVM_ABI std::optional< uint64_t > getAddressInfoOffset(size_t Index) const
Given an address index, get the offset for the FunctionInfo.
GsymReader(std::unique_ptr< MemoryBuffer > Buffer, llvm::endianness Endian)
virtual uint16_t getVersion() const =0
Get the GSYM version for this reader.
llvm::Error setStringTableData(StringRef Bytes)
Set string table section bytes into StrTab.
LLVM_ABI llvm::Expected< StringRef > getRequiredGlobalDataBytes(GlobalInfoType Type) const
Get the raw bytes for a required GlobalData section as a StringRef.
LLVM_ABI llvm::Expected< FunctionInfo > getFunctionInfo(uint64_t Addr) const
Get the full function info for an address.
std::optional< uint64_t > addressForIndex(size_t Index) const
Get an appropriate address from the address table.
LLVM_ABI llvm::Expected< LookupResult > lookup(uint64_t Addr, std::optional< GsymDataExtractor > *MergedFuncsData=nullptr) const
Lookup an address in the a GSYM.
std::vector< uint8_t > SwappedAddrOffsets
llvm::Error parseAddrOffsets(StringRef Bytes)
Parse address offsets section bytes into AddrOffsets.
LLVM_ABI llvm::Expected< GsymDataExtractor > getFunctionInfoDataForAddress(uint64_t Addr, uint64_t &FuncStartAddr) const
Given an address, find the correct function info data and function address.
LLVM_ABI Expected< uint64_t > getAddressIndex(const uint64_t Addr) const
Given an address, find the address index.
virtual uint64_t getNumAddresses() const =0
Get the number of addresses in this GSYM file.
std::map< GlobalInfoType, GlobalData > GlobalDataSections
Parsed GlobalData entries, keyed by type.
LLVM_ABI llvm::Error parse()
Parse the GSYM data from the memory buffer.
virtual uint8_t getAddressInfoOffsetSize() const =0
Get the address info offset byte size for this GSYM file.
std::unique_ptr< MemoryBuffer > MemBuffer
virtual void dump(raw_ostream &OS)=0
Dump the entire Gsym data contained in this object.
static LLVM_ABI llvm::Expected< std::unique_ptr< GsymReader > > openFile(StringRef Path)
Construct a GsymReader from a file on disk.
LLVM_ABI llvm::Expected< FunctionInfo > getFunctionInfoAtIndex(uint64_t AddrIdx) const
Get the full function info given an address index.
virtual uint8_t getAddressOffsetSize() const =0
Get the address offset byte size for this GSYM file.
LLVM_ABI llvm::Expected< std::vector< LookupResult > > lookupAll(uint64_t Addr) const
Lookup all merged functions for a given address.
virtual uint64_t getBaseAddress() const =0
Get the base address of this GSYM file.
std::optional< uint64_t > getAddressOffsetIndex(const uint64_t AddrOffset) const
Lookup an address offset in the AddrOffsets table.
LLVM_ABI std::optional< StringRef > getOptionalGlobalDataBytes(GlobalInfoType Type) const
Get the raw bytes for an optional GlobalData section as a StringRef.
LineTable class contains deserialized versions of line tables for each function's address ranges.
This class implements an extremely fast bulk output stream that can only output to a stream.
raw_ostream & indent(unsigned NumSpaces)
indent - Insert 'NumSpaces' spaces.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
LLVM_ABI StringRef getNameForGlobalInfoType(GlobalInfoType Type)
GlobalInfoType
GlobalInfoType allows GSYM files to encode global information within a GSYM file in a way that is ext...
constexpr uint32_t GSYM_MAGIC
constexpr uint32_t GSYM_CIGAM
This is an optimization pass for GlobalISel generic memory operations.
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
FunctionAddr VTableAddr uintptr_t uintptr_t Version
FunctionAddr VTableAddr uintptr_t uintptr_t Data
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
LLVM_ABI Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
Implement std::hash so that hash_code can be used in STL containers.
std::vector< CallSiteInfo > CallSites
uint64_t ReturnOffset
The return offset of the call site - relative to the function start.
std::vector< gsym_strp_t > MatchRegex
Offsets into the string table for function names regex patterns.
static constexpr uint64_t getEncodedSize(uint8_t StringOffsetSize)
Returns the on-disk encoded size of a FileEntry for the given string offset size.
Function information in GSYM files encodes information for one contiguous address range.
std::optional< InlineInfo > Inline
std::optional< MergedFunctionsInfo > MergedFunctions
static LLVM_ABI llvm::Expected< FunctionInfo > decode(GsymDataExtractor &Data, uint64_t BaseAddr)
Decode an object from a binary data stream.
std::optional< CallSiteInfoCollection > CallSites
gsym_strp_t Name
String table offset in the string table.
std::optional< LineTable > OptLineTable
static LLVM_ABI llvm::Expected< LookupResult > lookup(GsymDataExtractor &Data, const GsymReader &GR, uint64_t FuncAddr, uint64_t Addr, std::optional< GsymDataExtractor > *MergedFuncsData=nullptr)
Lookup an address within a FunctionInfo object's data stream.
GlobalData describes a section of data in a GSYM file by its type, file offset, and size.
static LLVM_ABI llvm::Expected< GlobalData > decode(GsymDataExtractor &GsymData, uint64_t &Offset)
Decode a GlobalData entry from a binary data stream.
Inline information stores the name of the inline function along with an array of address ranges.
static LLVM_ABI llvm::Expected< std::vector< GsymDataExtractor > > getFuncsDataExtractors(GsymDataExtractor &Data)
Get a vector of GsymDataExtractor objects for the functions in this MergedFunctionsInfo object.
std::vector< FunctionInfo > MergedFunctions