LLVM 24.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
18
19using namespace llvm;
20using namespace gsym;
21
22GsymReaderV2::GsymReaderV2(std::unique_ptr<MemoryBuffer> Buffer,
24 : GsymReader(std::move(Buffer), Endian) {}
25
26/// For V2 file layout, see HeaderV2.h
28 if (auto Err = parseHeader(Hdr, SwappedHdr))
29 return Err;
31}
32
34 OS << *Hdr << "\n";
35
36 // Print GlobalData entries.
37 OS << "Global Data Sections:\n";
38 OS << "TYPE FILE OFFSET FILE SIZE\n";
39 OS << "=============== ================== ==================\n";
40 /// Re-parse the GlobalData entries to ensure we show the GlobalData
41 /// in the exact order it appears in the GSYM data.
42 const StringRef Buf = MemBuffer->getBuffer();
43 const uint64_t BufSize = Buf.size();
46 while (Offset + sizeof(GlobalData) <= BufSize) {
47 auto GDOrErr = GlobalData::decode(Data, Offset);
48 assert(GDOrErr && "GlobalData::decode() should not fail");
49 const GlobalData &GD = *GDOrErr;
50
51 OS << formatv("{0,-15} ", getNameForGlobalInfoType(GD.Type).data())
52 << HEX64(GD.FileOffset) << " " << HEX64(GD.FileSize) << "\n";
53
54 // Stop printing after the end of list entry.
56 break;
57 }
58 OS << "\n";
59
60 // Print UUID if present.
62 OS << "UUID:\n";
63 for (uint8_t Byte : *UUIDBytes)
64 OS << format_hex_no_prefix(Byte, 2);
65 OS << "\n\n";
66 }
67
68 OS << "Address Table:\n";
69 OS << "INDEX OFFSET ";
70 switch (getAddressOffsetSize()) {
71 case 1:
72 OS << "8 ";
73 break;
74 case 2:
75 OS << "16";
76 break;
77 case 4:
78 OS << "32";
79 break;
80 case 8:
81 OS << "64";
82 break;
83 default:
84 OS << "??";
85 break;
86 }
87 OS << " (ADDRESS 64)\n";
88 OS << "====== ========================================\n";
89 for (uint32_t I = 0; I < getNumAddresses(); ++I) {
90 OS << formatv("[{0,4}] ", I);
91 switch (getAddressOffsetSize()) {
92 case 1:
93 OS << HEX8(getAddrOffsets<uint8_t>()[I]);
94 break;
95 case 2:
96 OS << HEX16(getAddrOffsets<uint16_t>()[I]);
97 break;
98 case 4:
99 OS << HEX32(getAddrOffsets<uint32_t>()[I]);
100 break;
101 case 8:
102 OS << HEX32(getAddrOffsets<uint64_t>()[I]);
103 break;
104 default:
105 break;
106 }
107 OS << " (" << HEX64(*getAddress(I)) << ")\n";
108 }
109 OS << "\nAddress Info Offsets:\n";
110 OS << "INDEX OFFSET 64 (FILE OFFSET 64)\n";
111 OS << "====== ========================================\n";
112 for (uint32_t I = 0; I < getNumAddresses(); ++I) {
113 uint64_t RelOffset = I * getAddressInfoOffsetSize();
114 uint64_t RelValue =
115 AddrInfoOffsetsData.getUnsigned(&RelOffset, getAddressInfoOffsetSize());
116 OS << formatv("[{0,4}] ", I) << HEX64(RelValue) << " ("
117 << HEX64(*getAddressInfoOffset(I)) << ")\n";
118 }
119 OS << "\nFiles:\n";
120 OS << "INDEX DIRECTORY BASENAME PATH\n";
121 OS << "====== ========== ========== "
122 "========================================\n";
123 // Since we don't store the total number of files in the file table, loop
124 // until we get a null entry which means the index is out of range.
125 for (uint32_t I = 0;; ++I) {
126 auto FE = getFile(I);
127 if (!FE)
128 break;
129 OS << formatv("[{0,4}] ", I) << HEX32(FE->Dir) << ' ' << HEX32(FE->Base)
130 << ' ';
131 dump(OS, FE);
132 OS << "\n";
133 }
134 OS << "\n";
135 gsym::dump(OS, StrTab, 8);
136 OS << "\n";
137
138 for (uint32_t I = 0; I < getNumAddresses(); ++I) {
139 OS << "FunctionInfo @ " << HEX32(*getAddressInfoOffset(I)) << ": ";
140 if (auto FI = getFunctionInfoAtIndex(I))
141 dump(OS, *FI);
142 else
143 logAllUnhandledErrors(FI.takeError(), OS, "FunctionInfo:");
144 }
145}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define HEX64(v)
#define HEX32(v)
#define I(x, y, z)
Definition MD5.cpp:57
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
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
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.
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_ABI 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:189
bool isLittleEndian() const
Definition GsymReader.h:68
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
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:577
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:177
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:878
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