1 //===- RawTypes.h -----------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_DEBUGINFO_PDB_RAW_RAWTYPES_H
11 #define LLVM_DEBUGINFO_PDB_RAW_RAWTYPES_H
13 #include "llvm/DebugInfo/CodeView/TypeRecord.h"
14 #include "llvm/Support/Endian.h"
18 // This struct is defined as "SO" in langapi/include/pdb.h.
19 struct SectionOffset {
20 support::ulittle32_t Off;
21 support::ulittle16_t Isect;
27 support::ulittle32_t Off; // Offset in the symbol record stream
28 support::ulittle32_t CRef;
31 // This struct is defined as `SC` in include/dbicommon.h
32 struct SectionContrib {
33 support::ulittle16_t ISect;
35 support::little32_t Off;
36 support::little32_t Size;
37 support::ulittle32_t Characteristics;
38 support::ulittle16_t Imod;
40 support::ulittle32_t DataCrc;
41 support::ulittle32_t RelocCrc;
44 // This struct is defined as `SC2` in include/dbicommon.h
45 struct SectionContrib2 {
46 // To guarantee SectionContrib2 is standard layout, we cannot use inheritance.
48 support::ulittle32_t ISectCoff;
51 // This corresponds to the `OMFSegMap` structure.
53 support::ulittle16_t SecCount; // Number of segment descriptors in table
54 support::ulittle16_t SecCountLog; // Number of logical segment descriptors
57 // This corresponds to the `OMFSegMapDesc` structure. The definition is not
58 // present in the reference implementation, but the layout is derived from
59 // code that accesses the fields.
61 support::ulittle16_t Flags; // Descriptor flags. See OMFSegDescFlags
62 support::ulittle16_t Ovl; // Logical overlay number.
63 support::ulittle16_t Group; // Group index into descriptor array.
64 support::ulittle16_t Frame;
65 support::ulittle16_t SecName; // Byte index of the segment or group name
66 // in the sstSegName table, or 0xFFFF.
67 support::ulittle16_t ClassName; // Byte index of the class name in the
68 // sstSegName table, or 0xFFFF.
69 support::ulittle32_t Offset; // Byte offset of the logical segment
70 // within the specified physical segment.
71 // If group is set in flags, offset is the
72 // offset of the group.
73 support::ulittle32_t SecByteLength; // Byte count of the segment or group.
76 // Used for serialized hash table in TPI stream.
77 // In the reference, it is an array of TI and cbOff pair.
78 struct TypeIndexOffset {
79 codeview::TypeIndex Type;
80 support::ulittle32_t Offset;
83 /// Some of the values are stored in bitfields. Since this needs to be portable
84 /// across compilers and architectures (big / little endian in particular) we
85 /// can't use the actual structures below, but must instead do the shifting
86 /// and masking ourselves. The struct definitions are provided for reference.
88 /// uint16_t IncrementalLinking : 1; // True if linked incrementally
89 /// uint16_t IsStripped : 1; // True if private symbols were
91 /// uint16_t HasCTypes : 1; // True if linked with /debug:ctypes.
92 /// uint16_t Reserved : 13;
93 static const uint16_t FlagIncrementalMask = 0x0001;
94 static const uint16_t FlagStrippedMask = 0x0002;
95 static const uint16_t FlagHasCTypesMask = 0x0004;
99 /// uint16_t MinorVersion : 8;
100 /// uint16_t MajorVersion : 7;
101 /// uint16_t NewVersionFormat : 1;
102 static const uint16_t BuildMinorMask = 0x00FF;
103 static const uint16_t BuildMinorShift = 0;
105 static const uint16_t BuildMajorMask = 0x7F00;
106 static const uint16_t BuildMajorShift = 8;
109 /// The fixed size header that appears at the beginning of the DBI Stream.
110 struct DbiStreamHeader {
111 support::little32_t VersionSignature;
112 support::ulittle32_t VersionHeader;
114 /// How "old" is this DBI Stream. Should match the age of the PDB InfoStream.
115 support::ulittle32_t Age;
117 /// Global symbol stream #
118 support::ulittle16_t GlobalSymbolStreamIndex;
120 /// See DbiBuildNo structure.
121 support::ulittle16_t BuildNumber;
123 /// Public symbols stream #
124 support::ulittle16_t PublicSymbolStreamIndex;
126 /// version of mspdbNNN.dll
127 support::ulittle16_t PdbDllVersion;
129 /// Symbol records stream #
130 support::ulittle16_t SymRecordStreamIndex;
132 /// rbld number of mspdbNNN.dll
133 support::ulittle16_t PdbDllRbld;
135 /// Size of module info stream
136 support::little32_t ModiSubstreamSize;
138 /// Size of sec. contrib stream
139 support::little32_t SecContrSubstreamSize;
141 /// Size of sec. map substream
142 support::little32_t SectionMapSize;
144 /// Size of file info substream
145 support::little32_t FileInfoSize;
147 /// Size of type server map
148 support::little32_t TypeServerSize;
150 /// Index of MFC Type Server
151 support::ulittle32_t MFCTypeServerIndex;
153 /// Size of DbgHeader info
154 support::little32_t OptionalDbgHdrSize;
156 /// Size of EC stream (what is EC?)
157 support::little32_t ECSubstreamSize;
159 /// See DbiFlags enum.
160 support::ulittle16_t Flags;
162 /// See PDB_MachineType enum.
163 support::ulittle16_t MachineType;
166 support::ulittle32_t Reserved;
168 static_assert(sizeof(DbiStreamHeader) == 64, "Invalid DbiStreamHeader size!");
170 struct SectionContribEntry {
171 support::ulittle16_t Section;
173 support::little32_t Offset;
174 support::little32_t Size;
175 support::ulittle32_t Characteristics;
176 support::ulittle16_t ModuleIndex;
178 support::ulittle32_t DataCrc;
179 support::ulittle32_t RelocCrc;
182 /// The header preceeding the File Info Substream of the DBI stream.
183 struct FileInfoSubstreamHeader {
184 /// Total # of modules, should match number of records in the ModuleInfo
186 support::ulittle16_t NumModules;
188 /// Total # of source files. This value is not accurate because PDB actually
189 /// supports more than 64k source files, so we ignore it and compute the value
190 /// from other stream fields.
191 support::ulittle16_t NumSourceFiles;
193 /// Following this header the File Info Substream is laid out as follows:
194 /// ulittle16_t ModIndices[NumModules];
195 /// ulittle16_t ModFileCounts[NumModules];
196 /// ulittle32_t FileNameOffsets[NumSourceFiles];
197 /// char Names[][NumSourceFiles];
198 /// with the caveat that `NumSourceFiles` cannot be trusted, so
199 /// it is computed by summing the `ModFileCounts` array.
202 struct ModInfoFlags {
203 /// uint16_t fWritten : 1; // True if DbiModuleDescriptor is dirty
204 /// uint16_t fECEnabled : 1; // Is EC symbolic info present? (What is EC?)
205 /// uint16_t unused : 6; // Reserved
206 /// uint16_t iTSM : 8; // Type Server Index for this module
207 static const uint16_t HasECFlagMask = 0x2;
209 static const uint16_t TypeServerIndexMask = 0xFF00;
210 static const uint16_t TypeServerIndexShift = 8;
213 /// The header preceeding each entry in the Module Info substream of the DBI
214 /// stream. Corresponds to the type MODI in the reference implementation.
215 struct ModuleInfoHeader {
216 /// Currently opened module. This field is a pointer in the reference
217 /// implementation, but that won't work on 64-bit systems, and anyway it
218 /// doesn't make sense to read a pointer from a file. For now it is unused,
219 /// so just ignore it.
220 support::ulittle32_t Mod;
222 /// First section contribution of this module.
223 SectionContribEntry SC;
225 /// See ModInfoFlags definition.
226 support::ulittle16_t Flags;
228 /// Stream Number of module debug info
229 support::ulittle16_t ModDiStream;
231 /// Size of local symbol debug info in above stream
232 support::ulittle32_t SymBytes;
234 /// Size of C11 line number info in above stream
235 support::ulittle32_t C11Bytes;
237 /// Size of C13 line number info in above stream
238 support::ulittle32_t C13Bytes;
240 /// Number of files contributing to this module
241 support::ulittle16_t NumFiles;
243 /// Padding so the next field is 4-byte aligned.
246 /// Array of [0..NumFiles) DBI name buffer offsets. In the reference
247 /// implementation this field is a pointer. But since you can't portably
248 /// serialize a pointer, on 64-bit platforms they copy all the values except
249 /// this one into the 32-bit version of the struct and use that for
250 /// serialization. Regardless, this field is unused, it is only there to
251 /// store a pointer that can be accessed at runtime.
252 support::ulittle32_t FileNameOffs;
254 /// Name Index for src file name
255 support::ulittle32_t SrcFileNameNI;
257 /// Name Index for path to compiler PDB
258 support::ulittle32_t PdbFilePathNI;
260 /// Following this header are two zero terminated strings.
261 /// char ModuleName[];
262 /// char ObjFileName[];
265 /// Defines a 128-bit unique identifier. This maps to a GUID on Windows, but
266 /// is abstracted here for the purposes of non-Windows platforms that don't have
267 /// the GUID structure defined.
268 struct PDB_UniqueId {
272 inline bool operator==(const PDB_UniqueId &LHS, const PDB_UniqueId &RHS) {
273 return 0 == ::memcmp(LHS.Guid, RHS.Guid, sizeof(LHS.Guid));
276 // The header preceeding the global TPI stream.
277 // This corresponds to `HDR` in PDB/dbi/tpi.h.
278 struct TpiStreamHeader {
280 support::little32_t Off;
281 support::ulittle32_t Length;
284 support::ulittle32_t Version;
285 support::ulittle32_t HeaderSize;
286 support::ulittle32_t TypeIndexBegin;
287 support::ulittle32_t TypeIndexEnd;
288 support::ulittle32_t TypeRecordBytes;
290 // The following members correspond to `TpiHash` in PDB/dbi/tpi.h.
291 support::ulittle16_t HashStreamIndex;
292 support::ulittle16_t HashAuxStreamIndex;
293 support::ulittle32_t HashKeySize;
294 support::ulittle32_t NumHashBuckets;
296 EmbeddedBuf HashValueBuffer;
297 EmbeddedBuf IndexOffsetBuffer;
298 EmbeddedBuf HashAdjBuffer;
301 const uint32_t MinTpiHashBuckets = 0x1000;
302 const uint32_t MaxTpiHashBuckets = 0x40000;
304 /// The header preceeding the global PDB Stream (Stream 1)
305 struct InfoStreamHeader {
306 support::ulittle32_t Version;
307 support::ulittle32_t Signature;
308 support::ulittle32_t Age;
312 /// The header preceeding the /names stream.
313 struct PDBStringTableHeader {
314 support::ulittle32_t Signature; // PDBStringTableSignature
315 support::ulittle32_t HashVersion; // 1 or 2
316 support::ulittle32_t ByteSize; // Number of bytes of names buffer.
319 const uint32_t PDBStringTableSignature = 0xEFFEEFFE;