26GsymReader::GsymReader(std::unique_ptr<MemoryBuffer> Buffer) :
30 GsymReader::GsymReader(
GsymReader &&RHS) =
default;
53 "invalid memory buffer");
57 return std::move(Err);
68 if (FileData.readObject(Hdr))
70 "not enough data for a GSYM header");
75 Endian = HostByteOrder;
80 Swap.reset(
new SwappedData);
92 Swap->Hdr = ExpectedHdr.get();
94 return ExpectedHdr.takeError();
111 FileData.readArray(AddrOffsets,
114 "failed to read address table");
117 if (FileData.padToAlignment(4) ||
120 "failed to read address info offsets table");
124 if (FileData.readInteger(NumFiles) || FileData.readArray(Files, NumFiles))
126 "failed to read file table");
132 "failed to read string table");
147 "failed to read address table");
151 reinterpret_cast<uint16_t *
>(Swap->AddrOffsets.data()),
154 "failed to read address table");
158 reinterpret_cast<uint32_t *
>(Swap->AddrOffsets.data()),
161 "failed to read address table");
165 reinterpret_cast<uint64_t *
>(Swap->AddrOffsets.data()),
168 "failed to read address table");
179 "failed to read address table");
183 Swap->Files.resize(NumFiles);
184 if (
Data.getU32(&
Offset, &Swap->Files[0].Dir, NumFiles*2))
188 "failed to read file table");
195 "failed to read string table");
211 case 1:
return addressForIndex<uint8_t>(
Index);
212 case 2:
return addressForIndex<uint16_t>(
Index);
213 case 4:
return addressForIndex<uint32_t>(
Index);
214 case 8:
return addressForIndex<uint64_t>(
Index);
220 const auto NumAddrInfoOffsets = AddrInfoOffsets.
size();
221 if (
Index < NumAddrInfoOffsets)
222 return AddrInfoOffsets[
Index];
230 std::optional<uint64_t> AddrOffsetIndex;
233 AddrOffsetIndex = getAddressOffsetIndex<uint8_t>(AddrOffset);
236 AddrOffsetIndex = getAddressOffsetIndex<uint16_t>(AddrOffset);
239 AddrOffsetIndex = getAddressOffsetIndex<uint32_t>(AddrOffset);
242 AddrOffsetIndex = getAddressOffsetIndex<uint64_t>(AddrOffset);
246 "unsupported address offset size %u",
250 return *AddrOffsetIndex;
253 "address 0x%" PRIx64
" is not in GSYM",
Addr);
262 assert(*AddressIndex < AddrInfoOffsets.
size());
263 auto AddrInfoOffset = AddrInfoOffsets[*AddressIndex];
265 if (std::optional<uint64_t> OptAddr =
getAddress(*AddressIndex)) {
268 if (ExpectedFI->Range.contains(
Addr) || ExpectedFI->Range.size() == 0)
271 "address 0x%" PRIx64
" is not in GSYM",
Addr);
275 "failed to extract address[%" PRIu64
"]",
284 assert(*AddressIndex < AddrInfoOffsets.
size());
285 auto AddrInfoOffset = AddrInfoOffsets[*AddressIndex];
287 if (std::optional<uint64_t> OptAddr =
getAddress(*AddressIndex))
290 "failed to extract address[%" PRIu64
"]",
299 OS <<
"Address Table:\n";
300 OS <<
"INDEX OFFSET";
303 case 1:
OS <<
"8 ";
break;
304 case 2:
OS <<
"16";
break;
305 case 4:
OS <<
"32";
break;
306 case 8:
OS <<
"64";
break;
307 default:
OS <<
"??";
break;
309 OS <<
" (ADDRESS)\n";
310 OS <<
"====== =============================== \n";
314 case 1: OS << HEX8(getAddrOffsets<uint8_t>()[
I]);
break;
315 case 2: OS << HEX16(getAddrOffsets<uint16_t>()[
I]);
break;
316 case 4: OS << HEX32(getAddrOffsets<uint32_t>()[
I]);
break;
317 case 8: OS << HEX32(getAddrOffsets<uint64_t>()[
I]);
break;
323 OS <<
"\nAddress Info Offsets:\n";
324 OS <<
"INDEX Offset\n";
325 OS <<
"====== ==========\n";
330 OS <<
"INDEX DIRECTORY BASENAME PATH\n";
331 OS <<
"====== ========== ========== ==============================\n";
338 OS <<
"\n" << StrTab <<
"\n";
341 OS <<
"FunctionInfo @ " <<
HEX32(AddrInfoOffsets[
I]) <<
": ";
358 OS <<
"LineTable:\n";
360 OS <<
" " <<
HEX64(LE.Addr) <<
' ';
363 OS <<
':' << LE.Line <<
'\n';
369 OS <<
"InlineInfo:\n";
375 OS <<
" called from ";
381 for (
const auto &ChildII: II.
Children)
382 dump(
OS, ChildII, Indent + 2);
388 if (FE->Dir == 0 && FE->Base == 0)
394 if (Dir.contains(
'\\') && !Dir.contains(
'/'))
405 OS <<
"<invalid-file>";
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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.
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.
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.
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 endianness system_endianness()
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
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< InlineInfo > Children
uint32_t CallFile
1 based file index in the file table.
uint32_t CallLine
Source line number.
uint32_t Name
String table offset in the string table.