LLVM 24.0.0git
GsymReader.h
Go to the documentation of this file.
1//===- GsymReader.h ---------------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_DEBUGINFO_GSYM_GSYMREADER_H
10#define LLVM_DEBUGINFO_GSYM_GSYMREADER_H
11
12#include "llvm/ADT/ArrayRef.h"
21#include "llvm/Support/Endian.h"
24#include <inttypes.h>
25#include <map>
26#include <memory>
27#include <stdint.h>
28#include <vector>
29
30namespace llvm {
31class MemoryBuffer;
32class raw_ostream;
33
34namespace gsym {
35
36/// GsymReader is used to read GSYM data from a file or buffer.
37///
38/// This class is optimized for very quick lookups when the endianness matches
39/// the host system. The header and the address table are designed to be mmap'ed
40/// as read only into memory and used without any parsing needed. If the
41/// endianness doesn't match, we swap the byte order of the address table into a
42/// separate buffer for efficient binary search. All the other data are parsed
43/// on demand with the correct endianness.
44///
45/// GsymReader objects must use one of the static functions to create an
46/// instance: GsymReader::openFile(...) and GsymReader::copyBuffer(...).
47
49protected:
50 std::unique_ptr<MemoryBuffer> MemBuffer;
52 /// Parsed GlobalData entries, keyed by type. Populated by
53 /// parseHeaderAndGlobalDataEntries().
54 std::map<GlobalInfoType, GlobalData> GlobalDataSections;
56 std::vector<uint8_t> SwappedAddrOffsets;
60
61 LLVM_ABI GsymReader(std::unique_ptr<MemoryBuffer> Buffer,
63
64public:
66 virtual ~GsymReader() = default;
67
69
70 /// Get the GSYM version for this reader.
71 virtual uint16_t getVersion() const = 0;
72
73 /// Get the base address of this GSYM file.
74 virtual uint64_t getBaseAddress() const = 0;
75
76 /// Get the number of addresses in this GSYM file.
77 virtual uint64_t getNumAddresses() const = 0;
78
79 /// Get the address offset byte size for this GSYM file.
80 virtual uint8_t getAddressOffsetSize() const = 0;
81
82 /// Get the address info offset byte size for this GSYM file.
83 virtual uint8_t getAddressInfoOffsetSize() const = 0;
84
85 /// Get the string offset byte size for this GSYM file.
86 virtual uint8_t getStringOffsetSize() const = 0;
87
88 /// Get the raw UUID bytes for this GSYM file, or an empty ref if none.
89 /// In v1 the UUID lives in the header; in v2 it is an optional data section.
90 virtual StringRef getUUID() const = 0;
91
92 /// Construct a GsymReader from a file on disk.
93 ///
94 /// \param Path The file path the GSYM file to read.
95 /// \returns An expected GsymReader that contains the object or an error
96 /// object that indicates reason for failing to read the GSYM.
98 openFile(StringRef Path);
99
100 /// Construct a GsymReader from a buffer.
101 ///
102 /// \param Bytes A set of bytes that will be copied and owned by the
103 /// returned object on success.
104 /// \returns An expected GsymReader that contains the object or an error
105 /// object that indicates reason for failing to read the GSYM.
107 copyBuffer(StringRef Bytes);
108
109 /// Get the full function info for an address.
110 ///
111 /// This should be called when a client will store a copy of the complete
112 /// FunctionInfo for a given address. For one off lookups, use the lookup()
113 /// function below.
114 ///
115 /// Symbolication server processes might want to parse the entire function
116 /// info for a given address and cache it if the process stays around to
117 /// service many symbolication addresses, like for parsing profiling
118 /// information.
119 ///
120 /// \param Addr A virtual address from the orignal object file to lookup.
121 ///
122 /// \returns An expected FunctionInfo that contains the function info object
123 /// or an error object that indicates reason for failing to lookup the
124 /// address.
126
127 /// Get the full function info given an address index.
128 ///
129 /// \param AddrIdx A address index for an address in the address table.
130 ///
131 /// \returns An expected FunctionInfo that contains the function info object
132 /// or an error object that indicates reason for failing get the function
133 /// info object.
135 getFunctionInfoAtIndex(uint64_t AddrIdx) const;
136
137 /// Lookup an address in the a GSYM.
138 ///
139 /// Lookup just the information needed for a specific address \a Addr. This
140 /// function is faster that calling getFunctionInfo() as it will only return
141 /// information that pertains to \a Addr and allows the parsing to skip any
142 /// extra information encoded for other addresses. For example the line table
143 /// parsing can stop when a matching LineEntry has been fouhnd, and the
144 /// InlineInfo can stop parsing early once a match has been found and also
145 /// skip information that doesn't match. This avoids memory allocations and
146 /// is much faster for lookups.
147 ///
148 /// \param Addr A virtual address from the orignal object file to lookup.
149 ///
150 /// \param MergedFuncsData A pointer to an optional GsymDataExtractor that, if
151 /// non-null, will be set to the raw data of the MergedFunctionInfo, if
152 /// present.
153 ///
154 /// \returns An expected LookupResult that contains only the information
155 /// needed for the current address, or an error object that indicates reason
156 /// for failing to lookup the address.
158 lookup(uint64_t Addr,
159 std::optional<GsymDataExtractor> *MergedFuncsData = nullptr) const;
160
161 /// Lookup all merged functions for a given address.
162 ///
163 /// This function performs a lookup for the specified address and then
164 /// retrieves additional LookupResults from any merged functions associated
165 /// with the primary LookupResult.
166 ///
167 /// \param Addr The address to lookup.
168 ///
169 /// \returns A vector of LookupResult objects, where the first element is the
170 /// primary result, followed by results for any merged functions
172 lookupAll(uint64_t Addr) const;
173
174 /// Get a string from the string table.
175 ///
176 /// \param Offset The string table offset for the string to retrieve.
177 /// \returns The string from the strin table.
179
180 /// Get the a file entry for the suppplied file index.
181 ///
182 /// Used to convert any file indexes in the FunctionInfo data back into
183 /// files. This function can be used for iteration, but is more commonly used
184 /// for random access when doing lookups.
185 ///
186 /// \param Index An index into the file table.
187 /// \returns An optional FileInfo that will be valid if the file index is
188 /// valid, or std::nullopt if the file index is out of bounds,
189 std::optional<FileEntry> getFile(uint32_t Index) const {
190 uint64_t EntrySize =
191 FileEntry::getEncodedSize(FileEntryData.getStringOffsetSize());
192 uint64_t Offset = Index * EntrySize;
193 if (!FileEntryData.isValidOffsetForDataOfSize(Offset, EntrySize))
194 return std::nullopt;
195 FileEntry FE;
196 FE.Dir = FileEntryData.getStringOffset(&Offset);
197 FE.Base = FileEntryData.getStringOffset(&Offset);
198 return FE;
199 }
200
201 /// Dump the entire Gsym data contained in this object.
202 ///
203 /// \param OS The output stream to dump to.
204 virtual void dump(raw_ostream &OS) = 0;
205
207
208 /// Dump statistics about the GSYM data contained in this object.
209 ///
210 /// \param OS The output stream to dump to.
211 ///
212 /// \param Format Output format: Text, JSON (dense), or PrettyJSON.
213 ///
214 /// \param GSYMPath Optional file path, used only as a display label in the
215 /// output (empty for in-memory GSYM data).
218 StringRef GSYMPath = "");
219
220 /// Dump a FunctionInfo object.
221 ///
222 /// This function will convert any string table indexes and file indexes
223 /// into human readable format.
224 ///
225 /// \param OS The output stream to dump to.
226 ///
227 /// \param FI The object to dump.
228 ///
229 /// \param Indent The indentation as number of spaces. Used when dumping as an
230 /// item within MergedFunctionsInfo.
231 LLVM_ABI void dump(raw_ostream &OS, const FunctionInfo &FI,
232 uint32_t Indent = 0);
233
234 /// Dump a MergedFunctionsInfo object.
235 ///
236 /// This function will dump a MergedFunctionsInfo object - basically by
237 /// dumping the contained FunctionInfo objects with indentation.
238 ///
239 /// \param OS The output stream to dump to.
240 ///
241 /// \param MFI The object to dump.
242 LLVM_ABI void dump(raw_ostream &OS, const MergedFunctionsInfo &MFI);
243
244 /// Dump a CallSiteInfo object.
245 ///
246 /// This function will output the details of a CallSiteInfo object in a
247 /// human-readable format.
248 ///
249 /// \param OS The output stream to dump to.
250 ///
251 /// \param CSI The CallSiteInfo object to dump.
252 LLVM_ABI void dump(raw_ostream &OS, const CallSiteInfo &CSI);
253
254 /// Dump a CallSiteInfoCollection object.
255 ///
256 /// This function will iterate over a collection of CallSiteInfo objects and
257 /// dump each one.
258 ///
259 /// \param OS The output stream to dump to.
260 ///
261 /// \param CSIC The CallSiteInfoCollection object to dump.
262 ///
263 /// \param Indent The indentation as number of spaces. Used when dumping as an
264 /// item from within MergedFunctionsInfo.
265 LLVM_ABI void dump(raw_ostream &OS, const CallSiteInfoCollection &CSIC,
266 uint32_t Indent = 0);
267
268 /// Dump a LineTable object.
269 ///
270 /// This function will convert any string table indexes and file indexes
271 /// into human readable format.
272 ///
273 ///
274 /// \param OS The output stream to dump to.
275 ///
276 /// \param LT The object to dump.
277 ///
278 /// \param Indent The indentation as number of spaces. Used when dumping as an
279 /// item from within MergedFunctionsInfo.
280 LLVM_ABI void dump(raw_ostream &OS, const LineTable &LT, uint32_t Indent = 0);
281
282 /// Dump a InlineInfo object.
283 ///
284 /// This function will convert any string table indexes and file indexes
285 /// into human readable format.
286 ///
287 /// \param OS The output stream to dump to.
288 ///
289 /// \param II The object to dump.
290 ///
291 /// \param Indent The indentation as number of spaces. Used for recurive
292 /// dumping.
293 LLVM_ABI void dump(raw_ostream &OS, const InlineInfo &II,
294 uint32_t Indent = 0);
295
296 /// Dump a FileEntry object.
297 ///
298 /// This function will convert any string table indexes into human readable
299 /// format.
300 ///
301 /// \param OS The output stream to dump to.
302 ///
303 /// \param FE The object to dump.
304 LLVM_ABI void dump(raw_ostream &OS, std::optional<FileEntry> FE);
305
306 /// Gets an address from the address table.
307 ///
308 /// Addresses are stored as offsets frrom the gsym::Header::BaseAddress.
309 ///
310 /// \param Index A index into the address table.
311 /// \returns A resolved virtual address for adddress in the address table
312 /// or std::nullopt if Index is out of bounds.
313 LLVM_ABI std::optional<uint64_t> getAddress(size_t Index) const;
314
315protected:
316 /// Get the GlobalData entry for a section type.
317 ///
318 /// \param Type The section type to retrieve.
319 /// \returns The GlobalData entry, or std::nullopt if the section is not
320 /// present.
321 LLVM_ABI std::optional<GlobalData> getGlobalData(GlobalInfoType Type) const;
322
323 /// Get the raw bytes for a required GlobalData section as a StringRef.
324 ///
325 /// \param Type The section type to retrieve.
326 /// \returns The section data, or an error if the section is not present or
327 /// any bytes are not present in the file.
330
331 /// Get the raw bytes for an optional GlobalData section as a StringRef.
332 ///
333 /// \param Type The section type to retrieve.
334 /// \returns The section data, or std::nullopt if the section is not present
335 /// or any bytes are not present in the file.
336 LLVM_ABI std::optional<StringRef>
338
339 /// Parse the GSYM data from the memory buffer.
340 ///
341 /// \returns Error on failure.
343
344 /// Parse the version-specific header and populate GlobalDataSections.
345 ///
346 /// \returns Error on failure.
348
349 /// Parse and validate the header from the beginning of the memory buffer.
350 ///
351 /// \param OutHdr Output pointer to the parsed header.
352 /// \param OutSwappedHdr Storage for byte-swapped header if needed.
353 /// \returns Error on failure.
354 template <class HeaderT>
355 llvm::Error parseHeader(const HeaderT *&OutHdr,
356 std::unique_ptr<HeaderT> &OutSwappedHdr) {
357 const StringRef Buf = MemBuffer->getBuffer();
358 if (Buf.size() < HeaderT::getEncodedSize())
359 return createStringError(std::errc::invalid_argument,
360 "not enough data for a GSYM header");
362 // Non-swap case. Mmap the header.
363 OutHdr = reinterpret_cast<const HeaderT *>(Buf.data());
364 } else {
365 // Swap case. Decode with a GsymDataExtractor with the correct endianness.
367 OutSwappedHdr = std::make_unique<HeaderT>();
368 auto ExpectedHdr = HeaderT::decode(Data);
369 if (!ExpectedHdr)
370 return ExpectedHdr.takeError();
371 *OutSwappedHdr = *ExpectedHdr;
372 OutHdr = OutSwappedHdr.get();
373 }
374 if (Error Err = OutHdr->checkForError())
375 return Err;
376 return Error::success();
377 }
378
379 /// Parse GlobalData entries starting at \p Offset into GlobalDataSections.
380 ///
381 /// This should only be called by any GSYM version >= 2. If called by V1, an
382 /// error will be returned.
383 ///
384 /// \param Offset The byte offset where GlobalData entries begin.
385 /// \returns Error on failure.
387
388 /// Parse address offsets section bytes into AddrOffsets.
389 ///
390 /// \param Bytes The raw section bytes.
391 /// \returns Error on failure.
393
394 /// Set address info offsets section bytes into AddrInfoOffsetsData.
395 ///
396 /// \param Bytes The raw section bytes.
397 /// \returns Error on failure.
399
400 /// Set string table section bytes into StrTab.
401 ///
402 /// \param Bytes The raw section bytes.
403 /// \returns Error on failure.
405
406 /// Set file table section bytes into FileEntryData.
407 ///
408 /// \param Bytes The raw section bytes.
409 /// \returns Error on failure.
411
412 /// Get an appropriate address info offsets array.
413 ///
414 /// The address table in the GSYM file is stored as array of 1, 2, 4 or 8
415 /// byte offsets from the The gsym::Header::BaseAddress. The table is stored
416 /// internally as a array of bytes that are in the correct endianness. When
417 /// we access this table we must get an array that matches those sizes. This
418 /// templatized helper function is used when accessing address offsets in the
419 /// AddrOffsets member variable.
420 ///
421 /// \returns An ArrayRef of an appropriate address offset size.
422 template <class T> ArrayRef<T>
424 return ArrayRef<T>(reinterpret_cast<const T *>(AddrOffsets.data()),
425 AddrOffsets.size()/sizeof(T));
426 }
427
428 /// Get an appropriate address from the address table.
429 ///
430 /// The address table in the GSYM file is stored as array of 1, 2, 4 or 8
431 /// byte address offsets from the The gsym::Header::BaseAddress. The table is
432 /// stored internally as a array of bytes that are in the correct endianness.
433 /// In order to extract an address from the address table we must access the
434 /// address offset using the correct size and then add it to the BaseAddress
435 /// in the header.
436 ///
437 /// \param Index An index into the AddrOffsets array.
438 /// \returns An virtual address that matches the original object file for the
439 /// address as the specified index, or std::nullopt if Index is out of bounds.
440 template <class T>
441 std::optional<uint64_t> addressForIndex(size_t Index) const {
443 if (Index < AIO.size())
444 return AIO[Index] + getBaseAddress();
445 return std::nullopt;
446 }
447
448 /// Lookup an address offset in the AddrOffsets table.
449 ///
450 /// Given an address offset, look it up using a binary search of the
451 /// AddrOffsets table.
452 ///
453 /// \param AddrOffset An address offset, that has already been computed by
454 /// subtracting the gsym::Header::BaseAddress.
455 /// \returns The matching address offset index. This index will be used to
456 /// extract the FunctionInfo data's offset from the AddrInfoOffsets array.
457 template <class T>
458 std::optional<uint64_t>
459 getAddressOffsetIndex(const uint64_t AddrOffset) const {
461 const auto Begin = AIO.begin();
462 const auto End = AIO.end();
463 auto Iter = std::lower_bound(Begin, End, AddrOffset);
464 // Watch for addresses that fall between the gsym::Header::BaseAddress and
465 // the first address offset.
466 if (Iter == Begin && AddrOffset < *Begin)
467 return std::nullopt;
468 if (Iter == End || AddrOffset < *Iter)
469 --Iter;
470
471 // GSYM files have sorted function infos with the most information (line
472 // table and/or inline info) first in the array of function infos, so
473 // always backup as much as possible as long as the address offset is the
474 // same as the previous entry.
475 while (Iter != Begin) {
476 auto Prev = Iter - 1;
477 if (*Prev == *Iter)
478 Iter = Prev;
479 else
480 break;
481 }
482
483 return std::distance(Begin, Iter);
484 }
485
486 /// Create a GSYM from a memory buffer.
487 ///
488 /// Called by both openFile() and copyBuffer(), this function does all of the
489 /// work of parsing the GSYM file and returning an error.
490 ///
491 /// \param MemBuffer A memory buffer that will transfer ownership into the
492 /// GsymReader.
493 /// \returns An expected GsymReader that contains the object or an error
494 /// object that indicates reason for failing to read the GSYM.
496 create(std::unique_ptr<MemoryBuffer> &MemBuffer);
497
498 /// Given an address, find the address index.
499 ///
500 /// Binary search the address table and find the matching address index.
501 ///
502 /// \param Addr A virtual address that matches the original object file
503 /// to lookup.
504 /// \returns An index into the address table. This index can be used to
505 /// extract the FunctionInfo data's offset from the AddrInfoOffsets array.
506 /// Returns an error if the address isn't in the GSYM with details of why.
508
509 /// Given an address index, get the offset for the FunctionInfo.
510 ///
511 /// Looking up an address is done by finding the corresponding address
512 /// index for the address. This index is then used to get the offset of the
513 /// FunctionInfo data that we will decode using this function.
514 ///
515 /// \param Index An index into the address table.
516 /// \returns An optional GSYM data offset for the offset of the FunctionInfo
517 /// that needs to be decoded.
518 LLVM_ABI std::optional<uint64_t> getAddressInfoOffset(size_t Index) const;
519
520 /// Given an address, find the correct function info data and function
521 /// address.
522 ///
523 /// Binary search the address table and find the matching address info
524 /// and make sure that the function info contains the address. GSYM allows
525 /// functions to overlap, and the most debug info is contained in the first
526 /// entries due to the sorting when GSYM files are created. We can have
527 /// multiple function info that start at the same address only if their
528 /// address range doesn't match. So find the first entry that matches \a Addr
529 /// and iterate forward until we find one that contains the address.
530 ///
531 /// \param[in] Addr A virtual address that matches the original object file
532 /// to lookup.
533 ///
534 /// \param[out] FuncStartAddr A virtual address that is the base address of
535 /// the function that is used for decoding the FunctionInfo.
536 ///
537 /// \returns An valid data extractor on success, or an error if we fail to
538 /// find the address in a function info or corrrectly decode the data
540 getFunctionInfoDataForAddress(uint64_t Addr, uint64_t &FuncStartAddr) const;
541
542 /// Get the function data and address given an address index.
543 ///
544 /// \param AddrIdx A address index from the address table.
545 ///
546 /// \returns An expected FunctionInfo that contains the function info object
547 /// or an error object that indicates reason for failing to lookup the
548 /// address.
550 getFunctionInfoDataAtIndex(uint64_t AddrIdx, uint64_t &FuncStartAddr) const;
551};
552
553} // namespace gsym
554} // namespace llvm
555
556#endif // LLVM_DEBUGINFO_GSYM_GSYMREADER_H
#define LLVM_ABI
Definition Compiler.h:215
Provides ErrorOr<T> smart pointer.
#define T
uint64_t IntrinsicInst * II
Value * RHS
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
iterator end() const
Definition ArrayRef.h:130
size_t size() const
Get the array size.
Definition ArrayRef.h:141
iterator begin() const
Definition ArrayRef.h:129
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
static ErrorSuccess success()
Create a success value.
Definition Error.h:336
Tagged union holding either a T or a Error.
Definition Error.h:485
This interface provides simple read-only access to a block of memory, and provides simple methods for...
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
constexpr size_t size() const
Get the string size.
Definition StringRef.h:144
constexpr const char * data() const
Get a pointer to the start of the string (which may not be null terminated).
Definition StringRef.h:138
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
A DataExtractor subclass that adds GSYM-specific string offset support.
StringRef getString(gsym_strp_t Offset) const
Get a string from the string table.
Definition GsymReader.h:178
LLVM_ABI llvm::Error setAddrInfoOffsetsData(StringRef Bytes)
Set address info offsets section bytes into AddrInfoOffsetsData.
LLVM_ABI llvm::Error parseGlobalDataEntries(uint64_t Offset)
Parse GlobalData entries starting at Offset into GlobalDataSections.
GsymDataExtractor FileEntryData
Definition GsymReader.h:58
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.
Definition GsymReader.h:189
bool isLittleEndian() const
Definition GsymReader.h:68
LLVM_ABI std::optional< GlobalData > getGlobalData(GlobalInfoType Type) const
Get the GlobalData entry for a section type.
llvm::Error parseHeader(const HeaderT *&OutHdr, std::unique_ptr< HeaderT > &OutSwappedHdr)
Parse and validate the header from the beginning of the memory buffer.
Definition GsymReader.h:355
ArrayRef< uint8_t > AddrOffsets
Definition GsymReader.h:55
LLVM_ABI llvm::Error setFileTableData(StringRef Bytes)
Set file table section bytes into FileEntryData.
GsymDataExtractor AddrInfoOffsetsData
Definition GsymReader.h:57
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.
ArrayRef< T > getAddrOffsets() const
Get an appropriate address info offsets array.
Definition GsymReader.h:423
LLVM_ABI GsymReader(std::unique_ptr< MemoryBuffer > Buffer, llvm::endianness Endian)
virtual uint16_t getVersion() const =0
Get the GSYM version for this reader.
LLVM_ABI 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 void dumpStatistics(raw_ostream &OS, StatisticsFormat Format=StatisticsFormat::Text, StringRef GSYMPath="")
Dump statistics about the GSYM data contained in this object.
LLVM_ABI llvm::Expected< FunctionInfo > getFunctionInfo(uint64_t Addr) const
Get the full function info for an address.
GsymReader(GsymReader &&RHS)=default
std::optional< uint64_t > addressForIndex(size_t Index) const
Get an appropriate address from the address table.
Definition GsymReader.h:441
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
Definition GsymReader.h:56
LLVM_ABI 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.
virtual ~GsymReader()=default
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.
Definition GsymReader.h:54
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
Definition GsymReader.h:50
virtual void dump(raw_ostream &OS)=0
Dump the entire Gsym data contained in this object.
virtual StringRef getUUID() const =0
Get the raw UUID bytes for this GSYM file, or an empty ref if none.
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::endianness Endian
Definition GsymReader.h:51
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.
Definition GsymReader.h:459
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.
Definition LineTable.h:119
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
uint64_t gsym_strp_t
The type of string offset used in the code.
Definition GsymTypes.h:21
GlobalInfoType
GlobalInfoType allows GSYM files to encode global information within a GSYM file in a way that is ext...
Definition GlobalData.h:26
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:578
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Definition Error.h:1321
endianness
Definition bit.h:71
Files in GSYM are contained in FileEntry structs where we split the directory and basename into two d...
Definition FileEntry.h:25
static constexpr uint64_t getEncodedSize(uint8_t StringOffsetSize)
Returns the on-disk encoded size of a FileEntry for the given string offset size.
Definition FileEntry.h:38
gsym_strp_t Dir
Offsets in the string table.
Definition FileEntry.h:29
Function information in GSYM files encodes information for one contiguous address range.
Inline information stores the name of the inline function along with an array of address ranges.
Definition InlineInfo.h:61
String tables in GSYM files are required to start with an empty string at offset zero.
Definition StringTable.h:22