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>>
87 "invalid memory buffer");
90 if (!VersionEndianOrErr)
95 std::unique_ptr<GsymReader> GR;
105 "unsupported GSYM version %u",
Version);
107 if (
auto Err = GR->parse())
108 return std::move(Err);
109 return std::move(GR);
124 std::errc::invalid_argument,
"missing required section type %s (%u)",
130 "AddrOffsets section size mismatch");
135 "AddrInfoOffsets section size mismatch");
169 "GlobalData section not supported in GSYM V1");
177 return GDOrErr.takeError();
185 "GlobalData section type %u has zero size",
190 std::errc::invalid_argument,
191 "GlobalData section type %u extends beyond "
192 "buffer (offset=%" PRIu64
", size=%" PRIu64
", bufsize=%" PRIu64
")",
198 "GlobalData array not terminated by EndOfList");
204 const size_t TotalBytes = NumAddrs * AddrOffSize;
205 if (Bytes.
size() < TotalBytes)
207 "failed to read address table");
220 switch (AddrOffSize) {
224 "failed to read address table");
231 "failed to read address table");
238 "failed to read address table");
245 "failed to read address table");
271 "FileTable section too small for %u files",
294 std::errc::invalid_argument,
295 "missing bytes for %s, GSYM file might be truncated", TypeName);
297 "missing required section type %s", TypeName);
300std::optional<StringRef>
306 if (GD->FileSize == 0 || GD->FileOffset + GD->FileSize > Buf.
size())
308 return Buf.
substr(GD->FileOffset, GD->FileSize);
335 return AddrInfoOffset;
340 if (Addr >= BaseAddr) {
341 const uint64_t AddrOffset = Addr - BaseAddr;
342 std::optional<uint64_t> AddrOffsetIndex;
358 "unsupported address offset size %u",
362 return *AddrOffsetIndex;
365 "address 0x%" PRIx64
" is not in GSYM", Addr);
372 if (!ExpectedAddrIdx)
374 const uint64_t FirstAddrIdx = *ExpectedAddrIdx;
378 std::optional<uint64_t> FirstFuncStartAddr;
380 for (
uint64_t AddrIdx = FirstAddrIdx; AddrIdx < NumAddresses; ++AddrIdx) {
389 if (FirstFuncStartAddr.has_value()) {
390 if (*FirstFuncStartAddr != FuncStartAddr)
393 FirstFuncStartAddr = FuncStartAddr;
408 "address 0x%" PRIx64
" is not in GSYM", Addr);
415 if (AddrInfoOffset == std::nullopt)
417 "invalid address index %" PRIu64, AddrIdx);
419 "Endian must be either big or little");
423 "invalid address info offset 0x%" PRIx64,
425 std::optional<uint64_t> OptFuncStartAddr =
getAddress(AddrIdx);
426 if (!OptFuncStartAddr)
428 "failed to extract address[%" PRIu64
"]", AddrIdx);
429 FuncStartAddr = *OptFuncStartAddr;
439 return ExpectedData.takeError();
448 return ExpectedData.takeError();
453 std::optional<GsymDataExtractor> *MergedFunctionsData)
const {
457 MergedFunctionsData);
459 return ExpectedData.takeError();
464 std::vector<LookupResult>
Results;
465 std::optional<GsymDataExtractor> MergedFunctionsData;
468 auto MainResult =
lookup(Addr, &MergedFunctionsData);
470 return MainResult.takeError();
473 Results.push_back(std::move(*MainResult));
476 if (MergedFunctionsData) {
478 auto ExpectedMergedFuncExtractors =
480 if (!ExpectedMergedFuncExtractors)
481 return ExpectedMergedFuncExtractors.takeError();
486 MainResult->FuncRange.start(), Addr)) {
487 Results.push_back(std::move(*FI));
489 return FI.takeError();
510 assert(Indent == 0 &&
"MergedFunctionsInfo should only exist at top level");
517 OS <<
"++ Merged FunctionInfos[" << inx <<
"]:\n";
526 auto addFlag = [&](
const char *Flag) {
536 addFlag(
"InternalCall");
539 addFlag(
"ExternalCall");
541 OS <<
" Flags[" << Flags <<
"]";
544 OS <<
" MatchRegex[";
557 OS <<
"CallSites (by relative return offset):\n";
568 OS <<
"LineTable:\n";
569 for (
auto &LE : LT) {
571 OS <<
" " <<
HEX64(LE.Addr) <<
' ';
574 OS <<
':' << LE.Line <<
'\n';
580 OS <<
"InlineInfo:\n";
584 if (
II.CallFile != 0) {
586 OS <<
" called from ";
588 OS <<
':' <<
II.CallLine;
592 for (
const auto &ChildII :
II.Children)
593 dump(OS, ChildII, Indent + 2);
599 if (FE->Dir == 0 && FE->Base == 0)
605 if (Dir.contains(
'\\') && !Dir.contains(
'/'))
616 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.
ArrayRef - 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 "-".
StringRef - 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
empty - Check if the string is empty.
constexpr size_t size() const
size - Get the string size.
constexpr const char * data() const
data - 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