LLVM 23.0.0git
HeaderV2.h
Go to the documentation of this file.
1//===- HeaderV2.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_HEADERV2_H
10#define LLVM_DEBUGINFO_GSYM_HEADERV2_H
11
14#include "llvm/Support/Error.h"
15
16#include <cstddef>
17#include <cstdint>
18
19namespace llvm {
20class raw_ostream;
21
22namespace gsym {
23class FileWriter;
25
26/// Encoding format for the string table.
28 /// A list of NULL-terminated strings (same as V1). The first string at
29 /// offset zero must be the empty C string.
31};
32
33/// The GSYM V2 header.
34///
35/// The GSYM V2 header is found at the start of a stand alone GSYM file, or as
36/// the first bytes in a section when GSYM is contained in a section of an
37/// executable file (ELF, mach-o, COFF).
38///
39/// The header structure is encoded exactly as it appears in the structure
40/// definition with no gaps between members. Alignment should not change from
41/// system to system as the members are laid out so that they will align the
42/// same on different architectures.
43///
44/// When endianness of the system loading a GSYM file matches, the file can
45/// be mmap'ed in and a pointer to the header can be cast to the first bytes
46/// of the file (stand alone GSYM file) or section data (GSYM in a section).
47/// When endianness is swapped, HeaderV2::decode() is used to read the header.
48///
49/// The V2 file layout is:
50/// [HeaderV2 - 20 bytes fixed]
51/// [GlobalData entries - array of 20-byte entries, terminated by EndOfList]
52/// [Data sections at arbitrary file offsets, zero-padded for alignment]
53///
54/// Each GlobalData entry (see GlobalData.h) describes a section by its type,
55/// file offset, and file size. The sections can appear in any order in the
56/// file since each GlobalData entry contains an offset from the first byte of
57/// the GSYM header. The GlobalData array is terminated by an entry with type
58/// EndOfList and all other fields set to zero. See GlobalInfoType (in
59/// GlobalData.h) for all section types.
60struct HeaderV2 {
61 /// The magic bytes should be set to GSYM_MAGIC. This helps detect if a file
62 /// is a GSYM file by scanning the first 4 bytes of a file or section.
63 /// This value might appear byte swapped when endianness is swapped.
65 /// The version number determines how the header is decoded. As version
66 /// numbers increase, "Magic" and "Version" members should always appear at
67 /// offset zero and 4 respectively to ensure clients figure out if they can
68 /// parse the format.
70 /// The size in bytes of each address offset in the address offsets table.
72 /// String table encoding. Allows for future encoding for string table.
74 /// The 64 bit base address that all address offsets in the address offsets
75 /// table are relative to. Storing a full 64 bit address allows our address
76 /// offsets table to be smaller on disk.
78 /// The number of addresses stored in the address offsets table and the
79 /// address info offsets table.
81
82 /// Return the version of this header.
83 static constexpr uint32_t getVersion() { return 2; }
84
85 /// Return the on-disk encoded size of the header in bytes.
86 /// This may differ from sizeof(HeaderV2) due to struct padding at the end.
87 static constexpr uint64_t getEncodedSize() { return 20; }
88
89 /// Return the size in bytes of address info offsets.
90 static constexpr uint8_t getAddressInfoOffsetSize() { return 8; }
91
92 /// Return the size in bytes of string table offsets.
93 static constexpr uint8_t getStringOffsetSize() { return 8; }
94
95 /// Check if a header is valid and return an error if anything is wrong.
96 ///
97 /// This function can be used prior to encoding a header to ensure it is
98 /// valid, or after decoding a header to ensure it is valid and supported.
99 ///
100 /// Check a correctly byte swapped header for errors:
101 /// - check magic value
102 /// - check that version number is supported
103 /// - check that the address offset size is supported
104 /// - check that the string table encoding is supported
105 ///
106 /// \returns An error if anything is wrong in the header, or Error::success()
107 /// if there are no errors.
109
110 /// Decode an object from a binary data stream.
111 ///
112 /// \param Data The binary stream to read the data from. This object must
113 /// have the data for the object starting at offset zero. The data
114 /// can contain more data than needed.
115 ///
116 /// \returns A HeaderV2 or an error describing the issue that was
117 /// encountered during decoding.
119
120 /// Encode this object into FileWriter stream.
121 ///
122 /// \param O The binary stream to write the data to at the current file
123 /// position.
124 ///
125 /// \returns An error object that indicates success or failure of the
126 /// encoding process.
128};
129
130LLVM_ABI bool operator==(const HeaderV2 &LHS, const HeaderV2 &RHS);
132 const llvm::gsym::HeaderV2 &H);
133
134} // namespace gsym
135} // namespace llvm
136
137#endif // LLVM_DEBUGINFO_GSYM_HEADERV2_H
#define LLVM_ABI
Definition Compiler.h:213
#define H(x, y, z)
Definition MD5.cpp:56
Value * RHS
Value * LHS
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
Tagged union holding either a T or a Error.
Definition Error.h:485
A simplified binary data writer class that doesn't require targets, target definitions,...
Definition FileWriter.h:30
A DataExtractor subclass that adds GSYM-specific string offset support.
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
LLVM_ABI raw_ostream & operator<<(raw_ostream &OS, const CallSiteInfo &CSI)
bool operator==(const FunctionInfo &LHS, const FunctionInfo &RHS)
StringTableEncoding
Encoding format for the string table.
Definition HeaderV2.h:27
@ Default
A list of NULL-terminated strings (same as V1).
Definition HeaderV2.h:30
This is an optimization pass for GlobalISel generic memory operations.
FunctionAddr VTableAddr uintptr_t uintptr_t Data
Definition InstrProf.h:221
The GSYM V2 header.
Definition HeaderV2.h:60
static constexpr uint32_t getVersion()
Return the version of this header.
Definition HeaderV2.h:83
static constexpr uint64_t getEncodedSize()
Return the on-disk encoded size of the header in bytes.
Definition HeaderV2.h:87
uint64_t BaseAddress
The 64 bit base address that all address offsets in the address offsets table are relative to.
Definition HeaderV2.h:77
uint32_t Magic
The magic bytes should be set to GSYM_MAGIC.
Definition HeaderV2.h:64
static constexpr uint8_t getAddressInfoOffsetSize()
Return the size in bytes of address info offsets.
Definition HeaderV2.h:90
static constexpr uint8_t getStringOffsetSize()
Return the size in bytes of string table offsets.
Definition HeaderV2.h:93
static LLVM_ABI llvm::Expected< HeaderV2 > decode(GsymDataExtractor &Data)
Decode an object from a binary data stream.
Definition HeaderV2.cpp:56
uint32_t NumAddresses
The number of addresses stored in the address offsets table and the address info offsets table.
Definition HeaderV2.h:80
uint16_t Version
The version number determines how the header is decoded.
Definition HeaderV2.h:69
StringTableEncoding StrTableEncoding
String table encoding. Allows for future encoding for string table.
Definition HeaderV2.h:73
uint8_t AddrOffSize
The size in bytes of each address offset in the address offsets table.
Definition HeaderV2.h:71
LLVM_ABI llvm::Error checkForError() const
Check if a header is valid and return an error if anything is wrong.
Definition HeaderV2.cpp:35
LLVM_ABI llvm::Error encode(FileWriter &O) const
Encode this object into FileWriter stream.
Definition HeaderV2.cpp:77