LLVM 23.0.0git
GsymReader.cpp
Go to the documentation of this file.
1//===- GsymReader.cpp -----------------------------------------------------===//
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
10
11#include <assert.h>
12#include <inttypes.h>
13#include <stdio.h>
14#include <stdlib.h>
15
23
24using namespace llvm;
25using namespace gsym;
26
27GsymReader::GsymReader(std::unique_ptr<MemoryBuffer> Buffer,
29 : MemBuffer(std::move(Buffer)), Endian(Endian),
31}
32
33/// Check magic bytes, determine endianness, and return the GSYM version and
34/// endianness. If magic bytes are invalid, return error.
37 if (Bytes.size() < 6)
38 return createStringError(std::errc::invalid_argument,
39 "data too small to be a GSYM file");
40 // Detect host endian
41 const auto HostEndian = llvm::endianness::native;
42 const bool IsHostLittleEndian = (HostEndian == llvm::endianness::little);
43 // Read magic bytes using host endian
44 GsymDataExtractor Data(Bytes, IsHostLittleEndian);
45 uint64_t Offset = 0;
46 uint32_t Magic = Data.getU32(&Offset);
47 llvm::endianness FileEndian;
48 // If magic bytes looks alright, the host and the file have the same
49 // endianness, vice versa.
50 if (Magic == GSYM_MAGIC) {
51 FileEndian = HostEndian;
52 } else if (Magic == GSYM_CIGAM) {
53 FileEndian =
55 // Re-create GsymDataExtractor with correct endianness to read version.
56 Data = GsymDataExtractor(Bytes, !IsHostLittleEndian);
57 } else {
58 return createStringError(std::errc::invalid_argument,
59 "not a GSYM file (bad magic)");
60 }
61 // Read version using the correct endian
62 uint16_t Version = Data.getU16(&Offset);
63 return std::make_pair(Version, FileEndian);
64}
65
66llvm::Expected<std::unique_ptr<GsymReader>>
68 // Open the input file and return an appropriate error if needed.
71 auto Err = BuffOrErr.getError();
72 if (Err)
73 return llvm::errorCodeToError(Err);
74 auto &Buf = BuffOrErr.get();
75 Buf->randomAccessIfMmap();
76 return create(Buf);
77}
78
81 auto MemBuffer = MemoryBuffer::getMemBufferCopy(Bytes, "GSYM bytes");
82 return create(MemBuffer);
83}
84
86GsymReader::create(std::unique_ptr<MemoryBuffer> &MemBuffer) {
87 if (!MemBuffer)
88 return createStringError(std::errc::invalid_argument,
89 "invalid memory buffer");
92 if (!VersionEndianOrErr)
93 return VersionEndianOrErr.takeError();
96 std::tie(Version, Endian) = *VersionEndianOrErr;
97 std::unique_ptr<GsymReader> GR;
98 switch (Version) {
99 case Header::getVersion():
100 GR.reset(new GsymReaderV1(std::move(MemBuffer), Endian));
101 break;
103 GR.reset(new GsymReaderV2(std::move(MemBuffer), Endian));
104 break;
105 default:
106 return createStringError(std::errc::invalid_argument,
107 "unsupported GSYM version %u", Version);
108 }
109 if (auto Err = GR->parse())
110 return std::move(Err);
111 return std::move(GR);
112}
113
115 // Step 1: Parse the version-specific header and populate GlobalDataSections.
116 if (auto Err = parseHeaderAndGlobalDataEntries())
117 return Err;
118
119 // Step 2: Validate that all required sections are present and consistent.
120 for (auto Type :
124 if (!GlobalDataSections.count(Type))
125 return createStringError(
126 std::errc::invalid_argument, "missing required section type %s (%u)",
128
131 return createStringError(std::errc::invalid_argument,
132 "AddrOffsets section size mismatch");
133
136 return createStringError(std::errc::invalid_argument,
137 "AddrInfoOffsets section size mismatch");
138
139 // Step 3: Parse each global data section.
142 if (!Bytes)
143 return Bytes.takeError();
144 if (auto Err = parseAddrOffsets(*Bytes))
145 return Err;
146
148 if (!Bytes)
149 return Bytes.takeError();
150 if (auto Err = setAddrInfoOffsetsData(*Bytes))
151 return Err;
152
154 if (!Bytes)
155 return Bytes.takeError();
156 if (auto Err = setStringTableData(*Bytes))
157 return Err;
158
160 if (!Bytes)
161 return Bytes.takeError();
162 if (auto Err = setFileTableData(*Bytes))
163 return Err;
164
165 return Error::success();
166}
167
170 return createStringError(std::errc::invalid_argument,
171 "GlobalData section not supported in GSYM V1");
172
173 const StringRef Buf = MemBuffer->getBuffer();
174 const uint64_t BufSize = Buf.size();
176 while (Offset + sizeof(GlobalData) <= BufSize) {
177 auto GDOrErr = GlobalData::decode(Data, Offset);
178 if (!GDOrErr)
179 return GDOrErr.takeError();
180 const GlobalData &GD = *GDOrErr;
181
183 return Error::success();
184
185 if (GD.FileSize == 0)
186 return createStringError(std::errc::invalid_argument,
187 "GlobalData section type %u has zero size",
188 static_cast<uint32_t>(GD.Type));
189
190 if (GD.FileOffset + GD.FileSize > BufSize)
191 return createStringError(
192 std::errc::invalid_argument,
193 "GlobalData section type %u extends beyond "
194 "buffer (offset=%" PRIu64 ", size=%" PRIu64 ", bufsize=%" PRIu64 ")",
195 static_cast<uint32_t>(GD.Type), GD.FileOffset, GD.FileSize, BufSize);
196
197 GlobalDataSections[GD.Type] = GD;
198 }
199 return createStringError(std::errc::invalid_argument,
200 "GlobalData array not terminated by EndOfList");
201}
202
204 const uint8_t AddrOffSize = getAddressOffsetSize();
205 const uint32_t NumAddrs = getNumAddresses();
206 const size_t TotalBytes = NumAddrs * AddrOffSize;
207 if (Bytes.size() < TotalBytes)
208 return createStringError(std::errc::invalid_argument,
209 "failed to read address table");
210
211 // Parse the non-swap case
214 reinterpret_cast<const uint8_t *>(Bytes.data()), TotalBytes);
215 return Error::success();
216 }
217
218 // Parse the swap case
220 uint64_t Offset = 0;
221 SwappedAddrOffsets.resize(TotalBytes);
222 switch (AddrOffSize) {
223 case 1:
224 if (!Data.getU8(&Offset, SwappedAddrOffsets.data(), NumAddrs))
225 return createStringError(std::errc::invalid_argument,
226 "failed to read address table");
227 break;
228 case 2:
229 if (!Data.getU16(&Offset,
230 reinterpret_cast<uint16_t *>(SwappedAddrOffsets.data()),
231 NumAddrs))
232 return createStringError(std::errc::invalid_argument,
233 "failed to read address table");
234 break;
235 case 4:
236 if (!Data.getU32(&Offset,
237 reinterpret_cast<uint32_t *>(SwappedAddrOffsets.data()),
238 NumAddrs))
239 return createStringError(std::errc::invalid_argument,
240 "failed to read address table");
241 break;
242 case 8:
243 if (!Data.getU64(&Offset,
244 reinterpret_cast<uint64_t *>(SwappedAddrOffsets.data()),
245 NumAddrs))
246 return createStringError(std::errc::invalid_argument,
247 "failed to read address table");
248 break;
249 }
251 return Error::success();
252}
253
258
260 StrTab.Data = Bytes;
262}
263
265 const uint8_t StrpSize = getStringOffsetSize();
266 GsymDataExtractor Data(Bytes, isLittleEndian(), StrpSize);
267 uint64_t Offset = 0;
268 uint32_t NumFiles = Data.getU32(&Offset);
269 uint64_t EntriesSize =
270 static_cast<uint64_t>(NumFiles) * FileEntry::getEncodedSize(StrpSize);
271 if (Bytes.size() < Offset + EntriesSize)
272 return createStringError(std::errc::invalid_argument,
273 "FileTable section too small for %u files",
274 NumFiles);
276 return Error::success();
277}
278
279std::optional<GlobalData> GsymReader::getGlobalData(GlobalInfoType Type) const {
280 auto It = GlobalDataSections.find(Type);
281 if (It == GlobalDataSections.end())
282 return std::nullopt;
283 return It->second;
284}
289 return *Data;
290 const char *TypeName = getNameForGlobalInfoType(Type).data();
291 std::optional<GlobalData> GD = getGlobalData(Type);
292 // We have a GlobalData entry but didn't get any bytes — the file may be
293 // truncated.
294 if (GD)
295 return createStringError(
296 std::errc::invalid_argument,
297 "missing bytes for %s, GSYM file might be truncated", TypeName);
298 return createStringError(std::errc::invalid_argument,
299 "missing required section type %s", TypeName);
300}
301
302std::optional<StringRef>
304 std::optional<GlobalData> GD = getGlobalData(Type);
305 if (!GD)
306 return std::nullopt;
307 StringRef Buf = MemBuffer->getBuffer();
308 if (GD->FileSize == 0 || GD->FileOffset + GD->FileSize > Buf.size())
309 return std::nullopt;
310 return Buf.substr(GD->FileOffset, GD->FileSize);
311}
312
313std::optional<uint64_t> GsymReader::getAddress(size_t Index) const {
314 switch (getAddressOffsetSize()) {
315 case 1: return addressForIndex<uint8_t>(Index);
316 case 2: return addressForIndex<uint16_t>(Index);
317 case 4: return addressForIndex<uint32_t>(Index);
318 case 8: return addressForIndex<uint64_t>(Index);
319 default:
320 llvm_unreachable("unsupported address offset size");
321 }
322 return std::nullopt;
323}
324
325std::optional<uint64_t> GsymReader::getAddressInfoOffset(size_t Index) const {
326 if (Index >= getNumAddresses())
327 return std::nullopt;
328 const uint8_t AddrInfoOffsetSize = getAddressInfoOffsetSize();
329 uint64_t Offset = Index * AddrInfoOffsetSize;
330 uint64_t AddrInfoOffset =
331 AddrInfoOffsetsData.getUnsigned(&Offset, AddrInfoOffsetSize);
332 // V1 stores absolute file offsets in AddrInfoOffsets, so no base offset is
333 // needed. V2+ stores offsets relative to the FunctionInfo section start.
335 AddrInfoOffset +=
337 return AddrInfoOffset;
338}
339
341 const uint64_t BaseAddr = getBaseAddress();
342 if (Addr >= BaseAddr) {
343 const uint64_t AddrOffset = Addr - BaseAddr;
344 std::optional<uint64_t> AddrOffsetIndex;
345 switch (getAddressOffsetSize()) {
346 case 1:
347 AddrOffsetIndex = getAddressOffsetIndex<uint8_t>(AddrOffset);
348 break;
349 case 2:
350 AddrOffsetIndex = getAddressOffsetIndex<uint16_t>(AddrOffset);
351 break;
352 case 4:
353 AddrOffsetIndex = getAddressOffsetIndex<uint32_t>(AddrOffset);
354 break;
355 case 8:
356 AddrOffsetIndex = getAddressOffsetIndex<uint64_t>(AddrOffset);
357 break;
358 default:
359 return createStringError(std::errc::invalid_argument,
360 "unsupported address offset size %u",
362 }
363 if (AddrOffsetIndex)
364 return *AddrOffsetIndex;
365 }
366 return createStringError(std::errc::invalid_argument,
367 "address 0x%" PRIx64 " is not in GSYM", Addr);
368}
369
372 uint64_t &FuncStartAddr) const {
373 Expected<uint64_t> ExpectedAddrIdx = getAddressIndex(Addr);
374 if (!ExpectedAddrIdx)
375 return ExpectedAddrIdx.takeError();
376 const uint64_t FirstAddrIdx = *ExpectedAddrIdx;
377 // The AddrIdx is the first index of the function info entries that match
378 // \a Addr. We need to iterate over all function info objects that start with
379 // the same address until we find a range that contains \a Addr.
380 std::optional<uint64_t> FirstFuncStartAddr;
381 const size_t NumAddresses = getNumAddresses();
382 for (uint64_t AddrIdx = FirstAddrIdx; AddrIdx < NumAddresses; ++AddrIdx) {
383 auto ExpextedData = getFunctionInfoDataAtIndex(AddrIdx, FuncStartAddr);
384 // If there was an error, return the error.
385 if (!ExpextedData)
386 return ExpextedData;
387
388 // Remember the first function start address if it hasn't already been set.
389 // If it is already valid, check to see if it matches the first function
390 // start address and only continue if it matches.
391 if (FirstFuncStartAddr.has_value()) {
392 if (*FirstFuncStartAddr != FuncStartAddr)
393 break; // Done with consecutive function entries with same address.
394 } else {
395 FirstFuncStartAddr = FuncStartAddr;
396 }
397 // Make sure the current function address ranges contains \a Addr.
398 // Some symbols on Darwin don't have valid sizes, so if we run into a
399 // symbol with zero size, then we have found a match for our address.
400
401 // The first thing the encoding of a FunctionInfo object is the function
402 // size.
403 uint64_t Offset = 0;
404 uint32_t FuncSize = ExpextedData->getU32(&Offset);
405 if (FuncSize == 0 ||
406 AddressRange(FuncStartAddr, FuncStartAddr + FuncSize).contains(Addr))
407 return ExpextedData;
408 }
409 return createStringError(std::errc::invalid_argument,
410 "address 0x%" PRIx64 " is not in GSYM", Addr);
411}
412
415 uint64_t &FuncStartAddr) const {
416 const std::optional<uint64_t> AddrInfoOffset = getAddressInfoOffset(AddrIdx);
417 if (AddrInfoOffset == std::nullopt)
418 return createStringError(std::errc::invalid_argument,
419 "invalid address index %" PRIu64, AddrIdx);
421 "Endian must be either big or little");
422 StringRef Bytes = MemBuffer->getBuffer().substr(*AddrInfoOffset);
423 if (Bytes.empty())
424 return createStringError(std::errc::invalid_argument,
425 "invalid address info offset 0x%" PRIx64,
426 *AddrInfoOffset);
427 std::optional<uint64_t> OptFuncStartAddr = getAddress(AddrIdx);
428 if (!OptFuncStartAddr)
429 return createStringError(std::errc::invalid_argument,
430 "failed to extract address[%" PRIu64 "]", AddrIdx);
431 FuncStartAddr = *OptFuncStartAddr;
433 return Data;
434}
435
437 uint64_t FuncStartAddr = 0;
438 if (auto ExpectedData = getFunctionInfoDataForAddress(Addr, FuncStartAddr))
439 return FunctionInfo::decode(*ExpectedData, FuncStartAddr);
440 else
441 return ExpectedData.takeError();
442}
443
446 uint64_t FuncStartAddr = 0;
447 if (auto ExpectedData = getFunctionInfoDataAtIndex(Idx, FuncStartAddr))
448 return FunctionInfo::decode(*ExpectedData, FuncStartAddr);
449 else
450 return ExpectedData.takeError();
451}
452
454 uint64_t Addr,
455 std::optional<GsymDataExtractor> *MergedFunctionsData) const {
456 uint64_t FuncStartAddr = 0;
457 if (auto ExpectedData = getFunctionInfoDataForAddress(Addr, FuncStartAddr))
458 return FunctionInfo::lookup(*ExpectedData, *this, FuncStartAddr, Addr,
459 MergedFunctionsData);
460 else
461 return ExpectedData.takeError();
462}
463
466 std::vector<LookupResult> Results;
467 std::optional<GsymDataExtractor> MergedFunctionsData;
468
469 // First perform a lookup to get the primary function info result.
470 auto MainResult = lookup(Addr, &MergedFunctionsData);
471 if (!MainResult)
472 return MainResult.takeError();
473
474 // Add the main result as the first entry.
475 Results.push_back(std::move(*MainResult));
476
477 // Now process any merged functions data that was found during the lookup.
478 if (MergedFunctionsData) {
479 // Get data extractors for each merged function.
480 auto ExpectedMergedFuncExtractors =
482 if (!ExpectedMergedFuncExtractors)
483 return ExpectedMergedFuncExtractors.takeError();
484
485 // Process each merged function data.
486 for (GsymDataExtractor &MergedData : *ExpectedMergedFuncExtractors) {
487 if (auto FI = FunctionInfo::lookup(MergedData, *this,
488 MainResult->FuncRange.start(), Addr)) {
489 Results.push_back(std::move(*FI));
490 } else {
491 return FI.takeError();
492 }
493 }
494 }
495
496 return Results;
497}
498
500 uint32_t Indent) {
501 OS.indent(Indent);
502 OS << FI.Range << " \"" << getString(FI.Name) << "\"\n";
503 if (FI.OptLineTable)
504 dump(OS, *FI.OptLineTable, Indent);
505 if (FI.Inline)
506 dump(OS, *FI.Inline, Indent);
507
508 if (FI.CallSites)
509 dump(OS, *FI.CallSites, Indent);
510
511 if (FI.MergedFunctions) {
512 assert(Indent == 0 && "MergedFunctionsInfo should only exist at top level");
513 dump(OS, *FI.MergedFunctions);
514 }
515}
516
518 for (uint32_t inx = 0; inx < MFI.MergedFunctions.size(); inx++) {
519 OS << "++ Merged FunctionInfos[" << inx << "]:\n";
520 dump(OS, MFI.MergedFunctions[inx], 4);
521 }
522}
523
525 OS << HEX16(CSI.ReturnOffset);
526
527 std::string Flags;
528 auto addFlag = [&](const char *Flag) {
529 if (!Flags.empty())
530 Flags += " | ";
531 Flags += Flag;
532 };
533
535 Flags = "None";
536 else {
538 addFlag("InternalCall");
539
541 addFlag("ExternalCall");
542 }
543 OS << " Flags[" << Flags << "]";
544
545 if (!CSI.MatchRegex.empty()) {
546 OS << " MatchRegex[";
547 for (uint32_t i = 0; i < CSI.MatchRegex.size(); ++i) {
548 if (i > 0)
549 OS << ";";
550 OS << getString(CSI.MatchRegex[i]);
551 }
552 OS << "]";
553 }
554}
555
557 uint32_t Indent) {
558 OS.indent(Indent);
559 OS << "CallSites (by relative return offset):\n";
560 for (const auto &CS : CSIC.CallSites) {
561 OS.indent(Indent);
562 OS << " ";
563 dump(OS, CS);
564 OS << "\n";
565 }
566}
567
568void GsymReader::dump(raw_ostream &OS, const LineTable &LT, uint32_t Indent) {
569 OS.indent(Indent);
570 OS << "LineTable:\n";
571 for (auto &LE : LT) {
572 OS.indent(Indent);
573 OS << " " << HEX64(LE.Addr) << ' ';
574 if (LE.File)
575 dump(OS, getFile(LE.File));
576 OS << ':' << LE.Line << '\n';
577 }
578}
579
581 if (Indent == 0)
582 OS << "InlineInfo:\n";
583 else
584 OS.indent(Indent);
585 OS << II.Ranges << ' ' << getString(II.Name);
586 if (II.CallFile != 0) {
587 if (auto File = getFile(II.CallFile)) {
588 OS << " called from ";
589 dump(OS, File);
590 OS << ':' << II.CallLine;
591 }
592 }
593 OS << '\n';
594 for (const auto &ChildII : II.Children)
595 dump(OS, ChildII, Indent + 2);
596}
597
598void GsymReader::dump(raw_ostream &OS, std::optional<FileEntry> FE) {
599 if (FE) {
600 // IF we have the file from index 0, then don't print anything
601 if (FE->Dir == 0 && FE->Base == 0)
602 return;
603 StringRef Dir = getString(FE->Dir);
604 StringRef Base = getString(FE->Base);
605 if (!Dir.empty()) {
606 OS << Dir;
607 if (Dir.contains('\\') && !Dir.contains('/'))
608 OS << '\\';
609 else
610 OS << '/';
611 }
612 if (!Base.empty()) {
613 OS << Base;
614 }
615 if (!Dir.empty() || !Base.empty())
616 return;
617 }
618 OS << "<invalid-file>";
619}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
Function Alias Analysis Results
#define HEX16(v)
#define HEX64(v)
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)
Definition Value.cpp:483
static Split data
A class that represents an address range.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
Represents either an error or a value T.
Definition ErrorOr.h:56
reference get()
Definition ErrorOr.h:149
std::error_code getError() const
Definition ErrorOr.h:152
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
Error takeError()
Take ownership of the stored error.
Definition Error.h:612
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 "-".
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
constexpr StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
Definition StringRef.h:591
constexpr bool empty() const
Check if the string is empty.
Definition StringRef.h:141
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.
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.
Definition GsymReader.h:173
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
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:184
bool isLittleEndian() const
Definition GsymReader.h:67
LLVM_ABI std::optional< GlobalData > getGlobalData(GlobalInfoType Type) const
Get the GlobalData entry for a section type.
ArrayRef< uint8_t > AddrOffsets
Definition GsymReader.h:55
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.
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.
Definition GsymReader.h:422
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::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.
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.
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:440
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
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...
Definition GlobalData.h:26
constexpr uint32_t GSYM_MAGIC
Definition Header.h:25
constexpr uint32_t GSYM_CIGAM
Definition Header.h:26
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:558
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Definition Error.h:1321
FunctionAddr VTableAddr uintptr_t uintptr_t Version
Definition InstrProf.h:334
FunctionAddr VTableAddr uintptr_t uintptr_t Data
Definition InstrProf.h:221
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1916
LLVM_ABI Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
Definition Error.cpp:107
endianness
Definition bit.h:71
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:874
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.
Definition FileEntry.h:38
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.
Definition GlobalData.h:61
static LLVM_ABI llvm::Expected< GlobalData > decode(GsymDataExtractor &GsymData, uint64_t &Offset)
Decode a GlobalData entry from a binary data stream.
GlobalInfoType Type
Definition GlobalData.h:62
static constexpr uint32_t getVersion()
Return the version of this header.
Definition HeaderV2.h:83
static constexpr uint32_t getVersion()
Return the version of this header.
Definition Header.h:89
Inline information stores the name of the inline function along with an array of address ranges.
Definition InlineInfo.h:61
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