LLVM 23.0.0git
GsymReaderV2.cpp
Go to the documentation of this file.
1//===- GsymReaderV2.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
14#include "llvm/ADT/STLExtras.h"
19
20using namespace llvm;
21using namespace gsym;
22
23GsymReaderV2::GsymReaderV2(std::unique_ptr<MemoryBuffer> Buffer,
25 : GsymReader(std::move(Buffer), Endian) {}
26
27/// For V2 file layout, see HeaderV2.h
29 if (auto Err = parseHeader(Hdr, SwappedHdr))
30 return Err;
32}
33
35 OS << *Hdr << "\n";
36
37 // Print GlobalData entries.
38 OS << "Global Data Sections:\n";
39 OS << "TYPE FILE OFFSET FILE SIZE\n";
40 OS << "=============== ================== ==================\n";
41 /// Re-parse the GlobalData entries to ensure we show the GlobalData
42 /// in the exact order it appears in the GSYM data.
43 const StringRef Buf = MemBuffer->getBuffer();
44 const uint64_t BufSize = Buf.size();
47 while (Offset + sizeof(GlobalData) <= BufSize) {
48 auto GDOrErr = GlobalData::decode(Data, Offset);
49 assert(GDOrErr && "GlobalData::decode() should not fail");
50 const GlobalData &GD = *GDOrErr;
51
52 OS << formatv("{0,-15} ", getNameForGlobalInfoType(GD.Type).data())
53 << HEX64(GD.FileOffset) << " " << HEX64(GD.FileSize) << "\n";
54
55 // Stop printing after the end of list entry.
57 break;
58 }
59 OS << "\n";
60
61 // Print UUID if present.
63 OS << "UUID:\n";
64 for (uint8_t Byte : *UUIDBytes)
65 OS << format_hex_no_prefix(Byte, 2);
66 OS << "\n\n";
67 }
68
69 OS << "Address Table:\n";
70 OS << "INDEX OFFSET ";
71 switch (getAddressOffsetSize()) {
72 case 1:
73 OS << "8 ";
74 break;
75 case 2:
76 OS << "16";
77 break;
78 case 4:
79 OS << "32";
80 break;
81 case 8:
82 OS << "64";
83 break;
84 default:
85 OS << "??";
86 break;
87 }
88 OS << " (ADDRESS 64)\n";
89 OS << "====== ========================================\n";
90 for (uint32_t I = 0; I < getNumAddresses(); ++I) {
91 OS << formatv("[{0,4}] ", I);
92 switch (getAddressOffsetSize()) {
93 case 1:
94 OS << HEX8(getAddrOffsets<uint8_t>()[I]);
95 break;
96 case 2:
97 OS << HEX16(getAddrOffsets<uint16_t>()[I]);
98 break;
99 case 4:
100 OS << HEX32(getAddrOffsets<uint32_t>()[I]);
101 break;
102 case 8:
103 OS << HEX32(getAddrOffsets<uint64_t>()[I]);
104 break;
105 default:
106 break;
107 }
108 OS << " (" << HEX64(*getAddress(I)) << ")\n";
109 }
110 OS << "\nAddress Info Offsets:\n";
111 OS << "INDEX OFFSET 64 (FILE OFFSET 64)\n";
112 OS << "====== ========================================\n";
113 for (uint32_t I = 0; I < getNumAddresses(); ++I) {
114 uint64_t RelOffset = I * getAddressInfoOffsetSize();
115 uint64_t RelValue =
116 AddrInfoOffsetsData.getUnsigned(&RelOffset, getAddressInfoOffsetSize());
117 OS << formatv("[{0,4}] ", I) << HEX64(RelValue) << " ("
118 << HEX64(*getAddressInfoOffset(I)) << ")\n";
119 }
120 OS << "\nFiles:\n";
121 OS << "INDEX DIRECTORY BASENAME PATH\n";
122 OS << "====== ========== ========== "
123 "========================================\n";
124 // Since we don't store the total number of files in the file table, loop
125 // until we get a null entry which means the index is out of range.
126 for (uint32_t I = 0;; ++I) {
127 auto FE = getFile(I);
128 if (!FE)
129 break;
130 OS << formatv("[{0,4}] ", I) << HEX32(FE->Dir) << ' ' << HEX32(FE->Base)
131 << ' ';
132 dump(OS, FE);
133 OS << "\n";
134 }
135 OS << "\n";
136 gsym::dump(OS, StrTab, 8);
137 OS << "\n";
138
139 for (uint32_t I = 0; I < getNumAddresses(); ++I) {
140 OS << "FunctionInfo @ " << HEX32(*getAddressInfoOffset(I)) << ": ";
141 if (auto FI = getFunctionInfoAtIndex(I))
142 dump(OS, *FI);
143 else
144 logAllUnhandledErrors(FI.takeError(), OS, "FunctionInfo:");
145 }
146}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define HEX64(v)
#define HEX32(v)
#define I(x, y, z)
Definition MD5.cpp:57
This file contains some templates that are useful if you are working with the STL at all.
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
constexpr size_t size() const
size - Get the string size.
Definition StringRef.h:143
constexpr const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
Definition StringRef.h:137
A DataExtractor subclass that adds GSYM-specific string offset support.
uint64_t getNumAddresses() const override
Get the number of addresses in this GSYM file.
GsymReaderV2(std::unique_ptr< MemoryBuffer > Buffer, llvm::endianness Endian)
uint8_t getAddressInfoOffsetSize() const override
Get the address info offset byte size for this GSYM file.
uint8_t getAddressOffsetSize() const override
Get the address offset byte size for this GSYM file.
LLVM_ABI void dump(raw_ostream &OS) override
Dump the entire Gsym data contained in this object.
llvm::Error parseHeaderAndGlobalDataEntries() override
For V2 file layout, see HeaderV2.h.
llvm::Error parseGlobalDataEntries(uint64_t Offset)
Parse GlobalData entries starting at Offset into 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::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:336
GsymDataExtractor AddrInfoOffsetsData
Definition GsymReader.h:57
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.
std::unique_ptr< MemoryBuffer > MemBuffer
Definition GsymReader.h:50
LLVM_ABI llvm::Expected< FunctionInfo > getFunctionInfoAtIndex(uint64_t AddrIdx) const
Get the full function info given an address index.
llvm::endianness Endian
Definition GsymReader.h:51
LLVM_ABI std::optional< StringRef > getOptionalGlobalDataBytes(GlobalInfoType Type) const
Get the raw bytes for an optional GlobalData section as a StringRef.
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
void dump(raw_ostream &OS, const StringTable &S, uint8_t StringOffsetSize)
Definition StringTable.h:37
LLVM_ABI StringRef getNameForGlobalInfoType(GlobalInfoType Type)
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:532
LLVM_ABI void logAllUnhandledErrors(Error E, raw_ostream &OS, Twine ErrorBanner={})
Log all errors (if any) in E to OS.
Definition Error.cpp:61
auto formatv(bool Validate, const char *Fmt, Ts &&...Vals)
FormattedNumber format_hex_no_prefix(uint64_t N, unsigned Width, bool Upper=false)
format_hex_no_prefix - Output N as a fixed width hexadecimal.
Definition Format.h:204
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:1917
endianness
Definition bit.h:71
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:870
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 uint64_t getEncodedSize()
Return the on-disk encoded size of the header in bytes.
Definition HeaderV2.h:87