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/GUID.h"
14 #include "llvm/DebugInfo/CodeView/TypeRecord.h"
15 #include "llvm/Support/Endian.h"
19 // This struct is defined as "SO" in langapi/include/pdb.h.
20 struct SectionOffset {
21 support::ulittle32_t Off;
22 support::ulittle16_t Isect;
28 support::ulittle32_t Off; // Offset in the symbol record stream
29 support::ulittle32_t CRef;
32 // This struct is defined as `SC` in include/dbicommon.h
33 struct SectionContrib {
34 support::ulittle16_t ISect;
36 support::little32_t Off;
37 support::little32_t Size;
38 support::ulittle32_t Characteristics;
39 support::ulittle16_t Imod;
41 support::ulittle32_t DataCrc;
42 support::ulittle32_t RelocCrc;
45 // This struct is defined as `SC2` in include/dbicommon.h
46 struct SectionContrib2 {
47 // To guarantee SectionContrib2 is standard layout, we cannot use inheritance.
49 support::ulittle32_t ISectCoff;
52 // This corresponds to the `OMFSegMap` structure.
54 support::ulittle16_t SecCount; // Number of segment descriptors in table
55 support::ulittle16_t SecCountLog; // Number of logical segment descriptors
58 // This corresponds to the `OMFSegMapDesc` structure. The definition is not
59 // present in the reference implementation, but the layout is derived from
60 // code that accesses the fields.
62 support::ulittle16_t Flags; // Descriptor flags. See OMFSegDescFlags
63 support::ulittle16_t Ovl; // Logical overlay number.
64 support::ulittle16_t Group; // Group index into descriptor array.
65 support::ulittle16_t Frame;
66 support::ulittle16_t SecName; // Byte index of the segment or group name
67 // in the sstSegName table, or 0xFFFF.
68 support::ulittle16_t ClassName; // Byte index of the class name in the
69 // sstSegName table, or 0xFFFF.
70 support::ulittle32_t Offset; // Byte offset of the logical segment
71 // within the specified physical segment.
72 // If group is set in flags, offset is the
73 // offset of the group.
74 support::ulittle32_t SecByteLength; // Byte count of the segment or group.
77 /// Some of the values are stored in bitfields. Since this needs to be portable
78 /// across compilers and architectures (big / little endian in particular) we
79 /// can't use the actual structures below, but must instead do the shifting
80 /// and masking ourselves. The struct definitions are provided for reference.
82 /// uint16_t IncrementalLinking : 1; // True if linked incrementally
83 /// uint16_t IsStripped : 1; // True if private symbols were
85 /// uint16_t HasCTypes : 1; // True if linked with /debug:ctypes.
86 /// uint16_t Reserved : 13;
87 static const uint16_t FlagIncrementalMask = 0x0001;
88 static const uint16_t FlagStrippedMask = 0x0002;
89 static const uint16_t FlagHasCTypesMask = 0x0004;
93 /// uint16_t MinorVersion : 8;
94 /// uint16_t MajorVersion : 7;
95 /// uint16_t NewVersionFormat : 1;
96 static const uint16_t BuildMinorMask = 0x00FF;
97 static const uint16_t BuildMinorShift = 0;
99 static const uint16_t BuildMajorMask = 0x7F00;
100 static const uint16_t BuildMajorShift = 8;
103 /// The fixed size header that appears at the beginning of the DBI Stream.
104 struct DbiStreamHeader {
105 support::little32_t VersionSignature;
106 support::ulittle32_t VersionHeader;
108 /// How "old" is this DBI Stream. Should match the age of the PDB InfoStream.
109 support::ulittle32_t Age;
111 /// Global symbol stream #
112 support::ulittle16_t GlobalSymbolStreamIndex;
114 /// See DbiBuildNo structure.
115 support::ulittle16_t BuildNumber;
117 /// Public symbols stream #
118 support::ulittle16_t PublicSymbolStreamIndex;
120 /// version of mspdbNNN.dll
121 support::ulittle16_t PdbDllVersion;
123 /// Symbol records stream #
124 support::ulittle16_t SymRecordStreamIndex;
126 /// rbld number of mspdbNNN.dll
127 support::ulittle16_t PdbDllRbld;
129 /// Size of module info stream
130 support::little32_t ModiSubstreamSize;
132 /// Size of sec. contrib stream
133 support::little32_t SecContrSubstreamSize;
135 /// Size of sec. map substream
136 support::little32_t SectionMapSize;
138 /// Size of file info substream
139 support::little32_t FileInfoSize;
141 /// Size of type server map
142 support::little32_t TypeServerSize;
144 /// Index of MFC Type Server
145 support::ulittle32_t MFCTypeServerIndex;
147 /// Size of DbgHeader info
148 support::little32_t OptionalDbgHdrSize;
150 /// Size of EC stream (what is EC?)
151 support::little32_t ECSubstreamSize;
153 /// See DbiFlags enum.
154 support::ulittle16_t Flags;
156 /// See PDB_MachineType enum.
157 support::ulittle16_t MachineType;
160 support::ulittle32_t Reserved;
162 static_assert(sizeof(DbiStreamHeader) == 64, "Invalid DbiStreamHeader size!");
164 struct SectionContribEntry {
165 support::ulittle16_t Section;
167 support::little32_t Offset;
168 support::little32_t Size;
169 support::ulittle32_t Characteristics;
170 support::ulittle16_t ModuleIndex;
172 support::ulittle32_t DataCrc;
173 support::ulittle32_t RelocCrc;
176 /// The header preceeding the File Info Substream of the DBI stream.
177 struct FileInfoSubstreamHeader {
178 /// Total # of modules, should match number of records in the ModuleInfo
180 support::ulittle16_t NumModules;
182 /// Total # of source files. This value is not accurate because PDB actually
183 /// supports more than 64k source files, so we ignore it and compute the value
184 /// from other stream fields.
185 support::ulittle16_t NumSourceFiles;
187 /// Following this header the File Info Substream is laid out as follows:
188 /// ulittle16_t ModIndices[NumModules];
189 /// ulittle16_t ModFileCounts[NumModules];
190 /// ulittle32_t FileNameOffsets[NumSourceFiles];
191 /// char Names[][NumSourceFiles];
192 /// with the caveat that `NumSourceFiles` cannot be trusted, so
193 /// it is computed by summing the `ModFileCounts` array.
196 struct ModInfoFlags {
197 /// uint16_t fWritten : 1; // True if DbiModuleDescriptor is dirty
198 /// uint16_t fECEnabled : 1; // Is EC symbolic info present? (What is EC?)
199 /// uint16_t unused : 6; // Reserved
200 /// uint16_t iTSM : 8; // Type Server Index for this module
201 static const uint16_t HasECFlagMask = 0x2;
203 static const uint16_t TypeServerIndexMask = 0xFF00;
204 static const uint16_t TypeServerIndexShift = 8;
207 /// The header preceeding each entry in the Module Info substream of the DBI
208 /// stream. Corresponds to the type MODI in the reference implementation.
209 struct ModuleInfoHeader {
210 /// Currently opened module. This field is a pointer in the reference
211 /// implementation, but that won't work on 64-bit systems, and anyway it
212 /// doesn't make sense to read a pointer from a file. For now it is unused,
213 /// so just ignore it.
214 support::ulittle32_t Mod;
216 /// First section contribution of this module.
217 SectionContribEntry SC;
219 /// See ModInfoFlags definition.
220 support::ulittle16_t Flags;
222 /// Stream Number of module debug info
223 support::ulittle16_t ModDiStream;
225 /// Size of local symbol debug info in above stream
226 support::ulittle32_t SymBytes;
228 /// Size of C11 line number info in above stream
229 support::ulittle32_t C11Bytes;
231 /// Size of C13 line number info in above stream
232 support::ulittle32_t C13Bytes;
234 /// Number of files contributing to this module
235 support::ulittle16_t NumFiles;
237 /// Padding so the next field is 4-byte aligned.
240 /// Array of [0..NumFiles) DBI name buffer offsets. In the reference
241 /// implementation this field is a pointer. But since you can't portably
242 /// serialize a pointer, on 64-bit platforms they copy all the values except
243 /// this one into the 32-bit version of the struct and use that for
244 /// serialization. Regardless, this field is unused, it is only there to
245 /// store a pointer that can be accessed at runtime.
246 support::ulittle32_t FileNameOffs;
248 /// Name Index for src file name
249 support::ulittle32_t SrcFileNameNI;
251 /// Name Index for path to compiler PDB
252 support::ulittle32_t PdbFilePathNI;
254 /// Following this header are two zero terminated strings.
255 /// char ModuleName[];
256 /// char ObjFileName[];
259 // This is PSGSIHDR struct defined in
260 // https://github.com/Microsoft/microsoft-pdb/blob/master/PDB/dbi/gsi.h
261 struct PublicsStreamHeader {
262 support::ulittle32_t SymHash;
263 support::ulittle32_t AddrMap;
264 support::ulittle32_t NumThunks;
265 support::ulittle32_t SizeOfThunk;
266 support::ulittle16_t ISectThunkTable;
268 support::ulittle32_t OffThunkTable;
269 support::ulittle32_t NumSections;
272 // The header preceeding the global TPI stream.
273 // This corresponds to `HDR` in PDB/dbi/tpi.h.
274 struct TpiStreamHeader {
276 support::little32_t Off;
277 support::ulittle32_t Length;
280 support::ulittle32_t Version;
281 support::ulittle32_t HeaderSize;
282 support::ulittle32_t TypeIndexBegin;
283 support::ulittle32_t TypeIndexEnd;
284 support::ulittle32_t TypeRecordBytes;
286 // The following members correspond to `TpiHash` in PDB/dbi/tpi.h.
287 support::ulittle16_t HashStreamIndex;
288 support::ulittle16_t HashAuxStreamIndex;
289 support::ulittle32_t HashKeySize;
290 support::ulittle32_t NumHashBuckets;
292 EmbeddedBuf HashValueBuffer;
293 EmbeddedBuf IndexOffsetBuffer;
294 EmbeddedBuf HashAdjBuffer;
297 const uint32_t MinTpiHashBuckets = 0x1000;
298 const uint32_t MaxTpiHashBuckets = 0x40000;
300 /// The header preceeding the global PDB Stream (Stream 1)
301 struct InfoStreamHeader {
302 support::ulittle32_t Version;
303 support::ulittle32_t Signature;
304 support::ulittle32_t Age;
308 /// The header preceeding the /names stream.
309 struct PDBStringTableHeader {
310 support::ulittle32_t Signature; // PDBStringTableSignature
311 support::ulittle32_t HashVersion; // 1 or 2
312 support::ulittle32_t ByteSize; // Number of bytes of names buffer.
315 const uint32_t PDBStringTableSignature = 0xEFFEEFFE;