25GsymReader::GsymReader(std::unique_ptr<MemoryBuffer> Buffer)
28GsymReader::GsymReader(
GsymReader &&RHS) =
default;
51 "invalid memory buffer");
55 return std::move(Err);
65 if (FileData.readObject(Hdr))
67 "not enough data for a GSYM header");
72 Endian = HostByteOrder;
78 Swap.reset(
new SwappedData);
90 Swap->Hdr = ExpectedHdr.get();
92 return ExpectedHdr.takeError();
109 FileData.readArray(AddrOffsets,
112 "failed to read address table");
115 if (FileData.padToAlignment(4) ||
118 "failed to read address info offsets table");
122 if (FileData.readInteger(NumFiles) || FileData.readArray(Files, NumFiles))
124 "failed to read file table");
130 "failed to read string table");
145 "failed to read address table");
149 reinterpret_cast<uint16_t *
>(Swap->AddrOffsets.data()),
152 "failed to read address table");
156 reinterpret_cast<uint32_t *
>(Swap->AddrOffsets.data()),
159 "failed to read address table");
163 reinterpret_cast<uint64_t *
>(Swap->AddrOffsets.data()),
166 "failed to read address table");
177 "failed to read address table");
181 Swap->Files.resize(NumFiles);
182 if (
Data.getU32(&
Offset, &Swap->Files[0].Dir, NumFiles*2))
186 "failed to read file table");
193 "failed to read string table");
209 case 1:
return addressForIndex<uint8_t>(Index);
210 case 2:
return addressForIndex<uint16_t>(Index);
211 case 4:
return addressForIndex<uint32_t>(Index);
212 case 8:
return addressForIndex<uint64_t>(Index);
218 const auto NumAddrInfoOffsets = AddrInfoOffsets.
size();
219 if (Index < NumAddrInfoOffsets)
220 return AddrInfoOffsets[Index];
228 std::optional<uint64_t> AddrOffsetIndex;
231 AddrOffsetIndex = getAddressOffsetIndex<uint8_t>(AddrOffset);
234 AddrOffsetIndex = getAddressOffsetIndex<uint16_t>(AddrOffset);
237 AddrOffsetIndex = getAddressOffsetIndex<uint32_t>(AddrOffset);
240 AddrOffsetIndex = getAddressOffsetIndex<uint64_t>(AddrOffset);
244 "unsupported address offset size %u",
248 return *AddrOffsetIndex;
251 "address 0x%" PRIx64
" is not in GSYM",
Addr);
259 if (!ExpectedAddrIdx)
261 const uint64_t FirstAddrIdx = *ExpectedAddrIdx;
265 std::optional<uint64_t> FirstFuncStartAddr;
267 for (
uint64_t AddrIdx = FirstAddrIdx; AddrIdx < NumAddresses; ++AddrIdx) {
276 if (FirstFuncStartAddr.has_value()) {
277 if (*FirstFuncStartAddr != FuncStartAddr)
280 FirstFuncStartAddr = FuncStartAddr;
295 "address 0x%" PRIx64
" is not in GSYM",
Addr);
303 "invalid address index %" PRIu64, AddrIdx);
304 const uint32_t AddrInfoOffset = AddrInfoOffsets[AddrIdx];
306 "Endian must be either big or little");
307 StringRef Bytes = MemBuffer->getBuffer().substr(AddrInfoOffset);
310 "invalid address info offset 0x%" PRIx32,
312 std::optional<uint64_t> OptFuncStartAddr =
getAddress(AddrIdx);
313 if (!OptFuncStartAddr)
315 "failed to extract address[%" PRIu64
"]", AddrIdx);
316 FuncStartAddr = *OptFuncStartAddr;
325 return ExpectedData.takeError();
334 return ExpectedData.takeError();
342 return ExpectedData.takeError();
350 OS <<
"Address Table:\n";
351 OS <<
"INDEX OFFSET";
354 case 1:
OS <<
"8 ";
break;
355 case 2:
OS <<
"16";
break;
356 case 4:
OS <<
"32";
break;
357 case 8:
OS <<
"64";
break;
358 default:
OS <<
"??";
break;
360 OS <<
" (ADDRESS)\n";
361 OS <<
"====== =============================== \n";
365 case 1: OS << HEX8(getAddrOffsets<uint8_t>()[
I]);
break;
366 case 2: OS << HEX16(getAddrOffsets<uint16_t>()[
I]);
break;
367 case 4: OS << HEX32(getAddrOffsets<uint32_t>()[
I]);
break;
368 case 8: OS << HEX32(getAddrOffsets<uint64_t>()[
I]);
break;
374 OS <<
"\nAddress Info Offsets:\n";
375 OS <<
"INDEX Offset\n";
376 OS <<
"====== ==========\n";
381 OS <<
"INDEX DIRECTORY BASENAME PATH\n";
382 OS <<
"====== ========== ========== ==============================\n";
389 OS <<
"\n" << StrTab <<
"\n";
392 OS <<
"FunctionInfo @ " <<
HEX32(AddrInfoOffsets[
I]) <<
": ";
413 assert(Indent == 0 &&
"MergedFunctionsInfo should only exist at top level");
420 OS <<
"++ Merged FunctionInfos[" << inx <<
"]:\n";
429 auto addFlag = [&](
const char *Flag) {
439 addFlag(
"InternalCall");
442 addFlag(
"ExternalCall");
444 OS <<
" Flags[" << Flags <<
"]";
447 OS <<
" MatchRegex[";
460 OS <<
"CallSites (by relative return offset):\n";
471 OS <<
"LineTable:\n";
474 OS <<
" " <<
HEX64(LE.Addr) <<
' ';
477 OS <<
':' << LE.Line <<
'\n';
483 OS <<
"InlineInfo:\n";
487 if (
II.CallFile != 0) {
489 OS <<
" called from ";
491 OS <<
':' <<
II.CallLine;
495 for (
const auto &ChildII:
II.Children)
496 dump(
OS, ChildII, Indent + 2);
502 if (FE->Dir == 0 && FE->Base == 0)
508 if (Dir.contains(
'\\') && !Dir.contains(
'/'))
519 OS <<
"<invalid-file>";
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
uint64_t IntrinsicInst * II
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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),...
size_t size() const
size - Get the array size.
Provides read only access to a subclass of BinaryStream.
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 bool empty() const
empty - Check if the string is empty.
GsymReader is used to read GSYM data from a file or buffer.
std::optional< FileEntry > getFile(uint32_t Index) const
Get the a file entry for the suppplied file index.
void dump(raw_ostream &OS)
Dump the entire Gsym data contained in this object.
uint32_t getNumAddresses() const
Get the number of addresses in this Gsym file.
static llvm::Expected< GsymReader > openFile(StringRef Path)
Construct a GsymReader from a file on disk.
std::optional< uint64_t > getAddress(size_t Index) const
Gets an address from the address table.
std::optional< uint64_t > getAddressInfoOffset(size_t Index) const
Given an address index, get the offset for the FunctionInfo.
StringRef getString(uint32_t Offset) const
Get a string from the string table.
llvm::Expected< FunctionInfo > getFunctionInfo(uint64_t Addr) const
Get the full function info for an address.
const Header & getHeader() const
Access the GSYM header.
llvm::Expected< llvm::DataExtractor > getFunctionInfoDataAtIndex(uint64_t AddrIdx, uint64_t &FuncStartAddr) const
Get the function data and address given an address index.
Expected< uint64_t > getAddressIndex(const uint64_t Addr) const
Given an address, find the address index.
llvm::Expected< LookupResult > lookup(uint64_t Addr) const
Lookup an address in the a GSYM.
static llvm::Expected< GsymReader > copyBuffer(StringRef Bytes)
Construct a GsymReader from a buffer.
static llvm::Expected< llvm::gsym::GsymReader > create(std::unique_ptr< MemoryBuffer > &MemBuffer)
Create a GSYM from a memory buffer.
llvm::Expected< FunctionInfo > getFunctionInfoAtIndex(uint64_t AddrIdx) const
Get the full function info given an address index.
llvm::Expected< llvm::DataExtractor > getFunctionInfoDataForAddress(uint64_t Addr, uint64_t &FuncStartAddr) const
Given an address, find the correct function info data and function address.
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.
constexpr uint32_t GSYM_MAGIC
constexpr uint32_t GSYM_CIGAM
constexpr bool IsBigEndianHost
This is an optimization pass for GlobalISel generic memory operations.
void logAllUnhandledErrors(Error E, raw_ostream &OS, Twine ErrorBanner={})
Log all errors (if any) in E to OS.
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
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
std::vector< uint32_t > MatchRegex
Offsets into the string table for function names regex patterns.
uint64_t ReturnOffset
The return offset of the call site - relative to the function start.
Function information in GSYM files encodes information for one contiguous address range.
std::optional< InlineInfo > Inline
std::optional< MergedFunctionsInfo > MergedFunctions
std::optional< CallSiteInfoCollection > CallSites
static llvm::Expected< LookupResult > lookup(DataExtractor &Data, const GsymReader &GR, uint64_t FuncAddr, uint64_t Addr)
Lookup an address within a FunctionInfo object's data stream.
uint32_t Name
String table offset in the string table.
std::optional< LineTable > OptLineTable
static llvm::Expected< FunctionInfo > decode(DataExtractor &Data, uint64_t BaseAddr)
Decode an object from a binary data stream.
Inline information stores the name of the inline function along with an array of address ranges.
std::vector< FunctionInfo > MergedFunctions