26GsymReader::GsymReader(std::unique_ptr<MemoryBuffer> Buffer)
29GsymReader::GsymReader(
GsymReader &&RHS) =
default;
52 "invalid memory buffer");
56 return std::move(Err);
66 if (FileData.readObject(Hdr))
68 "not enough data for a GSYM header");
73 Endian = HostByteOrder;
79 Swap.reset(
new SwappedData);
91 Swap->Hdr = ExpectedHdr.get();
93 return ExpectedHdr.takeError();
110 FileData.readArray(AddrOffsets,
113 "failed to read address table");
116 if (FileData.padToAlignment(4) ||
119 "failed to read address info offsets table");
123 if (FileData.readInteger(NumFiles) || FileData.readArray(Files, NumFiles))
125 "failed to read file table");
131 "failed to read string table");
146 "failed to read address table");
150 reinterpret_cast<uint16_t *
>(Swap->AddrOffsets.data()),
153 "failed to read address table");
157 reinterpret_cast<uint32_t *
>(Swap->AddrOffsets.data()),
160 "failed to read address table");
164 reinterpret_cast<uint64_t *
>(Swap->AddrOffsets.data()),
167 "failed to read address table");
178 "failed to read address table");
182 Swap->Files.resize(NumFiles);
183 if (
Data.getU32(&
Offset, &Swap->Files[0].Dir, NumFiles*2))
187 "failed to read file table");
194 "failed to read string table");
210 case 1:
return addressForIndex<uint8_t>(
Index);
211 case 2:
return addressForIndex<uint16_t>(
Index);
212 case 4:
return addressForIndex<uint32_t>(
Index);
213 case 8:
return addressForIndex<uint64_t>(
Index);
219 const auto NumAddrInfoOffsets = AddrInfoOffsets.
size();
220 if (
Index < NumAddrInfoOffsets)
221 return AddrInfoOffsets[
Index];
229 std::optional<uint64_t> AddrOffsetIndex;
232 AddrOffsetIndex = getAddressOffsetIndex<uint8_t>(AddrOffset);
235 AddrOffsetIndex = getAddressOffsetIndex<uint16_t>(AddrOffset);
238 AddrOffsetIndex = getAddressOffsetIndex<uint32_t>(AddrOffset);
241 AddrOffsetIndex = getAddressOffsetIndex<uint64_t>(AddrOffset);
245 "unsupported address offset size %u",
249 return *AddrOffsetIndex;
252 "address 0x%" PRIx64
" is not in GSYM",
Addr);
260 if (!ExpectedAddrIdx)
262 const uint64_t FirstAddrIdx = *ExpectedAddrIdx;
266 std::optional<uint64_t> FirstFuncStartAddr;
268 for (
uint64_t AddrIdx = FirstAddrIdx; AddrIdx < NumAddresses; ++AddrIdx) {
277 if (FirstFuncStartAddr.has_value()) {
278 if (*FirstFuncStartAddr != FuncStartAddr)
281 FirstFuncStartAddr = FuncStartAddr;
296 "address 0x%" PRIx64
" is not in GSYM",
Addr);
304 "invalid address index %" PRIu64, AddrIdx);
305 const uint32_t AddrInfoOffset = AddrInfoOffsets[AddrIdx];
307 "Endian must be either big or little");
308 StringRef Bytes = MemBuffer->getBuffer().substr(AddrInfoOffset);
311 "invalid address info offset 0x%" PRIx32,
313 std::optional<uint64_t> OptFuncStartAddr =
getAddress(AddrIdx);
314 if (!OptFuncStartAddr)
316 "failed to extract address[%" PRIu64
"]", AddrIdx);
317 FuncStartAddr = *OptFuncStartAddr;
326 return ExpectedData.takeError();
335 return ExpectedData.takeError();
343 return ExpectedData.takeError();
351 OS <<
"Address Table:\n";
352 OS <<
"INDEX OFFSET";
355 case 1:
OS <<
"8 ";
break;
356 case 2:
OS <<
"16";
break;
357 case 4:
OS <<
"32";
break;
358 case 8:
OS <<
"64";
break;
359 default:
OS <<
"??";
break;
361 OS <<
" (ADDRESS)\n";
362 OS <<
"====== =============================== \n";
366 case 1: OS << HEX8(getAddrOffsets<uint8_t>()[
I]);
break;
367 case 2: OS << HEX16(getAddrOffsets<uint16_t>()[
I]);
break;
368 case 4: OS << HEX32(getAddrOffsets<uint32_t>()[
I]);
break;
369 case 8: OS << HEX32(getAddrOffsets<uint64_t>()[
I]);
break;
375 OS <<
"\nAddress Info Offsets:\n";
376 OS <<
"INDEX Offset\n";
377 OS <<
"====== ==========\n";
382 OS <<
"INDEX DIRECTORY BASENAME PATH\n";
383 OS <<
"====== ========== ========== ==============================\n";
390 OS <<
"\n" << StrTab <<
"\n";
393 OS <<
"FunctionInfo @ " <<
HEX32(AddrInfoOffsets[
I]) <<
": ";
411 assert(Indent == 0 &&
"MergedFunctionsInfo should only exist at top level");
418 OS <<
"++ Merged FunctionInfos[" << inx <<
"]:\n";
425 OS <<
"LineTable:\n";
428 OS <<
" " <<
HEX64(LE.Addr) <<
' ';
431 OS <<
':' << LE.Line <<
'\n';
437 OS <<
"InlineInfo:\n";
441 if (
II.CallFile != 0) {
443 OS <<
" called from ";
445 OS <<
':' <<
II.CallLine;
449 for (
const auto &ChildII:
II.Children)
450 dump(
OS, ChildII, Indent + 2);
456 if (FE->Dir == 0 && FE->Base == 0)
462 if (Dir.contains(
'\\') && !Dir.contains(
'/'))
473 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.
Function information in GSYM files encodes information for one contiguous address range.
std::optional< InlineInfo > Inline
std::optional< MergedFunctionsInfo > MergedFunctions
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