1 =====================================
2 The PDB DBI (Debug Info) Stream
3 =====================================
13 The PDB DBI Stream (Index 3) is one of the largest and most important streams
14 in a PDB file. It contains information about how the program was compiled,
15 (e.g. compilation flags, etc), the compilands (e.g. object files) that
16 were used to link together the program, the source files which were used
17 to build the program, as well as references to other streams that contain more
18 detailed information about each compiland, such as the CodeView symbol records
19 contained within each compiland and the source and line information for
20 functions and other symbols within each compiland.
27 At offset 0 of the DBI Stream is a header with the following layout:
32 struct DbiStreamHeader {
33 int32_t VersionSignature;
34 uint32_t VersionHeader;
36 uint16_t GlobalStreamIndex;
38 uint16_t PublicStreamIndex;
39 uint16_t PdbDllVersion;
40 uint16_t SymRecordStream;
43 int32_t SectionContributionSize;
44 int32_t SectionMapSize;
45 int32_t SourceInfoSize;
46 int32_t TypeServerMapSize;
47 uint32_t MFCTypeServerIndex;
48 int32_t OptionalDbgHeaderSize;
49 int32_t ECSubstreamSize;
55 - **VersionSignature** - Unknown meaning. Appears to always be ``-1``.
57 - **VersionHeader** - A value from the following enum.
61 enum class DbiStreamVersion : uint32_t {
69 Similar to the :doc:`PDB Stream <PdbStream>`, this value always appears to be
70 ``V70``, and it is not clear what the other values are for.
72 - **Age** - The number of times the PDB has been written. Equal to the same
73 field from the :ref:`PDB Stream header <pdb_stream_header>`.
75 - **GlobalStreamIndex** - The index of the :doc:`Global Symbol Stream <GlobalStream>`,
76 which contains CodeView symbol records for all global symbols. Actual records
77 are stored in the symbol record stream, and are referenced from this stream.
79 - **BuildNumber** - A bitfield containing values representing the major and minor
80 version number of the toolchain (e.g. 12.0 for MSVC 2013) used to build the
81 program, with the following layout:
85 uint16_t MinorVersion : 8;
86 uint16_t MajorVersion : 7;
87 uint16_t NewVersionFormat : 1;
89 For the purposes of LLVM, we assume ``NewVersionFormat`` to be always ``true``.
90 If it is ``false``, the layout above does not apply and the reader should consult
91 the `Microsoft Source Code <https://github.com/Microsoft/microsoft-pdb>`__ for
94 - **PublicStreamIndex** - The index of the :doc:`Public Symbol Stream <PublicStream>`,
95 which contains CodeView symbol records for all public symbols. Actual records
96 are stored in the symbol record stream, and are referenced from this stream.
98 - **PdbDllVersion** - The version number of ``mspdbXXXX.dll`` used to produce this
99 PDB. Note this obviously does not apply for LLVM as LLVM does not use ``mspdb.dll``.
101 - **SymRecordStream** - The stream containing all CodeView symbol records used
102 by the program. This is used for deduplication, so that many different
103 compilands can refer to the same symbols without having to include the full record
104 content inside of each module stream.
106 - **PdbDllRbld** - Unknown
108 - **MFCTypeServerIndex** - The index of the MFC type server in the
109 :ref:`dbi_type_server_map_substream`.
111 - **Flags** - A bitfield with the following layout, containing various
112 information about how the program was built:
116 uint16_t WasIncrementallyLinked : 1;
117 uint16_t ArePrivateSymbolsStripped : 1;
118 uint16_t HasConflictingTypes : 1;
119 uint16_t Reserved : 13;
121 The only one of these that is not self-explanatory is ``HasConflictingTypes``.
122 Although undocumented, ``link.exe`` contains a hidden flag ``/DEBUG:CTYPES``.
123 If it is passed to ``link.exe``, this field will be set. Otherwise it will
124 not be set. It is unclear what this flag does, although it seems to have
125 subtle implications on the algorithm used to look up type records.
127 - **Machine** - A value from the `CV_CPU_TYPE_e <https://msdn.microsoft.com/en-us/library/b2fc64ek.aspx>`__
128 enumeration. Common values are ``0x8664`` (x86-64) and ``0x14C`` (x86).
130 Immediately after the fixed-size DBI Stream header are ``7`` variable-length
131 `substreams`. The following ``7`` fields of the DBI Stream header specify the
132 number of bytes of the corresponding substream. Each substream's contents will
133 be described in detail :ref:`below <dbi_substreams>`. The length of the entire
134 DBI Stream should equal ``64`` (the length of the header above) plus the value
135 of each of the following ``7`` fields.
137 - **ModInfoSize** - The length of the :ref:`dbi_mod_info_substream`.
139 - **SectionContributionSize** - The length of the :ref:`dbi_sec_contr_substream`.
141 - **SectionMapSize** - The length of the :ref:`dbi_section_map_substream`.
143 - **SourceInfoSize** - The length of the :ref:`dbi_file_info_substream`.
145 - **TypeServerMapSize** - The length of the :ref:`dbi_type_server_map_substream`.
147 - **OptionalDbgHeaderSize** - The length of the :ref:`dbi_optional_dbg_stream`.
149 - **ECSubstreamSize** - The length of the :ref:`dbi_ec_substream`.
156 .. _dbi_mod_info_substream:
158 Module Info Substream
159 ^^^^^^^^^^^^^^^^^^^^^
161 Begins at offset ``0`` immediately after the :ref:`header <dbi_header>`. The
162 module info substream is an array of variable-length records, each one
163 describing a single module (e.g. object file) linked into the program. Each
164 record in the array has the format:
170 struct SectionContribEntry {
175 uint32_t Characteristics;
176 uint16_t ModuleIndex;
182 uint16_t ModuleSymStream;
183 uint32_t SymByteSize;
184 uint32_t C11ByteSize;
185 uint32_t C13ByteSize;
186 uint16_t SourceFileCount;
189 uint32_t SourceFileNameIndex;
190 uint32_t PdbFilePathNameIndex;
195 - **SectionContr** - Describes the properties of the section in the final binary
196 which contain the code and data from this module.
198 ``SectionContr.Characteristics`` corresponds to the ``Characteristics`` field
199 of the `IMAGE_SECTION_HEADER <https://msdn.microsoft.com/en-us/library/windows/desktop/ms680341(v=vs.85).aspx>`__
203 - **Flags** - A bitfield with the following format:
207 // ``true`` if this ModInfo has been written since reading the PDB. This is
208 // likely used to support incremental linking, so that the linker can decide
209 // if it needs to commit changes to disk.
211 // ``true`` if EC information is present for this module. EC is presumed to
212 // stand for "Edit & Continue", which LLVM does not support. So this flag
213 // will always be be false.
216 // Type Server Index for this module. This is assumed to be related to /Zi,
217 // but as LLVM treats /Zi as /Z7, this field will always be invalid for LLVM
222 - **ModuleSymStream** - The index of the stream that contains symbol information
223 for this module. This includes CodeView symbol information as well as source
224 and line information. If this field is -1, then no additional debug info will
225 be present for this module (for example, this is what happens when you strip
226 private symbols from a PDB).
228 - **SymByteSize** - The number of bytes of data from the stream identified by
229 ``ModuleSymStream`` that represent CodeView symbol records.
231 - **C11ByteSize** - The number of bytes of data from the stream identified by
232 ``ModuleSymStream`` that represent C11-style CodeView line information.
234 - **C13ByteSize** - The number of bytes of data from the stream identified by
235 ``ModuleSymStream`` that represent C13-style CodeView line information. At
236 most one of ``C11ByteSize`` and ``C13ByteSize`` will be non-zero. Modern PDBs
237 always use C13 instead of C11.
239 - **SourceFileCount** - The number of source files that contributed to this
240 module during compilation.
242 - **SourceFileNameIndex** - The offset in the names buffer of the primary
243 translation unit used to build this module. All PDB files observed to date
244 always have this value equal to 0.
246 - **PdbFilePathNameIndex** - The offset in the names buffer of the PDB file
247 containing this module's symbol information. This has only been observed
248 to be non-zero for the special ``* Linker *`` module.
250 - **ModuleName** - The module name. This is usually either a full path to an
251 object file (either directly passed to ``link.exe`` or from an archive) or
252 a string of the form ``Import:<dll name>``.
254 - **ObjFileName** - The object file name. In the case of an module that is
255 linked directly passed to ``link.exe``, this is the same as **ModuleName**.
256 In the case of a module that comes from an archive, this is usually the full
259 .. _dbi_sec_contr_substream:
261 Section Contribution Substream
262 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
263 Begins at offset ``0`` immediately after the :ref:`dbi_mod_info_substream` ends,
264 and consumes ``Header->SectionContributionSize`` bytes. This substream begins
265 with a single ``uint32_t`` which will be one of the following values:
269 enum class SectionContrSubstreamVersion : uint32_t {
270 Ver60 = 0xeffe0000 + 19970605,
271 V2 = 0xeffe0000 + 20140516
274 ``Ver60`` is the only value which has been observed in a PDB so far. Following
275 this is an array of fixed-length structures. If the version is ``Ver60``,
276 it is an array of ``SectionContribEntry`` structures (this is the nested structure
277 from the ``ModInfo`` type. If the version is ``V2``, it is an array of
278 ``SectionContribEntry2`` structures, defined as follows:
282 struct SectionContribEntry2 {
283 SectionContribEntry SC;
287 The purpose of the second field is not well understood. The name implies that
288 is the index of the COFF section, but this also describes the existing field
289 ``SectionContribEntry::Section``.
292 .. _dbi_section_map_substream:
294 Section Map Substream
295 ^^^^^^^^^^^^^^^^^^^^^
296 Begins at offset ``0`` immediately after the :ref:`dbi_sec_contr_substream` ends,
297 and consumes ``Header->SectionMapSize`` bytes. This substream begins with an ``4``
298 byte header followed by an array of fixed-length records. The header and records
299 have the following layout:
303 struct SectionMapHeader {
304 uint16_t Count; // Number of segment descriptors
305 uint16_t LogCount; // Number of logical segment descriptors
308 struct SectionMapEntry {
309 uint16_t Flags; // See the SectionMapEntryFlags enum below.
310 uint16_t Ovl; // Logical overlay number
311 uint16_t Group; // Group index into descriptor array.
313 uint16_t SectionName; // Byte index of segment / group name in string table, or 0xFFFF.
314 uint16_t ClassName; // Byte index of class in string table, or 0xFFFF.
315 uint32_t Offset; // Byte offset of the logical segment within physical segment. If group is set in flags, this is the offset of the group.
316 uint32_t SectionLength; // Byte count of the segment or group.
319 enum class SectionMapEntryFlags : uint16_t {
320 Read = 1 << 0, // Segment is readable.
321 Write = 1 << 1, // Segment is writable.
322 Execute = 1 << 2, // Segment is executable.
323 AddressIs32Bit = 1 << 3, // Descriptor describes a 32-bit linear address.
324 IsSelector = 1 << 8, // Frame represents a selector.
325 IsAbsoluteAddress = 1 << 9, // Frame represents an absolute address.
326 IsGroup = 1 << 10 // If set, descriptor represents a group.
329 Many of these fields are not well understood, so will not be discussed further.
331 .. _dbi_file_info_substream:
335 Begins at offset ``0`` immediately after the :ref:`dbi_section_map_substream` ends,
336 and consumes ``Header->SourceInfoSize`` bytes. This substream defines the mapping
337 from module to the source files that contribute to that module. Since multiple
338 modules can use the same source file (for example, a header file), this substream
339 uses a string table to store each unique file name only once, and then have each
340 module use offsets into the string table rather than embedding the string's value
341 directly. The format of this substream is as follows:
345 struct FileInfoSubstream {
347 uint16_t NumSourceFiles;
349 uint16_t ModIndices[NumModules];
350 uint16_t ModFileCounts[NumModules];
351 uint32_t FileNameOffsets[NumSourceFiles];
352 char NamesBuffer[][NumSourceFiles];
355 **NumModules** - The number of modules for which source file information is
356 contained within this substream. Should match the corresponding value from the
359 **NumSourceFiles**: In theory this is supposed to contain the number of source
360 files for which this substream contains information. But that would present a
361 problem in that the width of this field being ``16``-bits would prevent one from
362 having more than 64K source files in a program. In early versions of the file
363 format, this seems to have been the case. In order to support more than this, this
364 field of the is simply ignored, and computed dynamically by summing up the values of
365 the ``ModFileCounts`` array (discussed below). In short, this value should be
368 **ModIndices** - This array is present, but does not appear to be useful.
370 **ModFileCountArray** - An array of ``NumModules`` integers, each one containing
371 the number of source files which contribute to the module at the specified index.
372 While each individual module is limited to 64K contributing source files, the
373 union of all modules' source files may be greater than 64K. The real number of
374 source files is thus computed by summing this array. Note that summing this array
375 does not give the number of `unique` source files, only the total number of source
376 file contributions to modules.
378 **FileNameOffsets** - An array of **NumSourceFiles** integers (where **NumSourceFiles**
379 here refers to the 32-bit value obtained from summing **ModFileCountArray**), where
380 each integer is an offset into **NamesBuffer** pointing to a null terminated string.
382 **NamesBuffer** - An array of null terminated strings containing the actual source
385 .. _dbi_type_server_map_substream:
387 Type Server Map Substream
388 ^^^^^^^^^^^^^^^^^^^^^^^^^
389 Begins at offset ``0`` immediately after the :ref:`dbi_file_info_substream`
390 ends, and consumes ``Header->TypeServerMapSize`` bytes. Neither the purpose
391 nor the layout of this substream is understood, although it is assumed to
392 related somehow to the usage of ``/Zi`` and ``mspdbsrv.exe``. This substream
393 will not be discussed further.
395 .. _dbi_ec_substream:
399 Begins at offset ``0`` immediately after the
400 :ref:`dbi_type_server_map_substream` ends, and consumes
401 ``Header->ECSubstreamSize`` bytes. This is presumed to be related to Edit &
402 Continue support in MSVC. LLVM does not support Edit & Continue, so this
403 stream will not be discussed further.
405 .. _dbi_optional_dbg_stream:
407 Optional Debug Header Stream
408 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
409 Begins at offset ``0`` immediately after the :ref:`dbi_ec_substream` ends, and
410 consumes ``Header->OptionalDbgHeaderSize`` bytes. This field is an array of
411 stream indices (e.g. ``uint16_t``'s), each of which identifies a stream
412 index in the larger MSF file which contains some additional debug information.
413 Each position of this array has a special meaning, allowing one to determine
414 what kind of debug information is at the referenced stream. ``11`` indices
415 are currently understood, although it's possible there may be more. The
416 layout of each stream generally corresponds exactly to a particular type
417 of debug data directory from the PE/COFF file. The format of these fields
418 can be found in the `Microsoft PE/COFF Specification <https://www.microsoft.com/en-us/download/details.aspx?id=19509>`__.
419 If any of these fields is -1, it means the corresponding type of debug info is
420 not present in the PDB.
422 **FPO Data** - ``DbgStreamArray[0]``. The data in the referenced stream is an
423 array of ``FPO_DATA`` structures. This contains the relocated contents of
424 any ``.debug$F`` section from any of the linker inputs.
426 **Exception Data** - ``DbgStreamArray[1]``. The data in the referenced stream
427 is a debug data directory of type ``IMAGE_DEBUG_TYPE_EXCEPTION``.
429 **Fixup Data** - ``DbgStreamArray[2]``. The data in the referenced stream is a
430 debug data directory of type ``IMAGE_DEBUG_TYPE_FIXUP``.
432 **Omap To Src Data** - ``DbgStreamArray[3]``. The data in the referenced stream
433 is a debug data directory of type ``IMAGE_DEBUG_TYPE_OMAP_TO_SRC``. This
434 is used for mapping addresses between instrumented and uninstrumented code.
436 **Omap From Src Data** - ``DbgStreamArray[4]``. The data in the referenced stream
437 is a debug data directory of type ``IMAGE_DEBUG_TYPE_OMAP_FROM_SRC``. This
438 is used for mapping addresses between instrumented and uninstrumented code.
440 **Section Header Data** - ``DbgStreamArray[5]``. A dump of all section headers from
441 the original executable.
443 **Token / RID Map** - ``DbgStreamArray[6]``. The layout of this stream is not
444 understood, but it is assumed to be a mapping from ``CLR Token`` to
445 ``CLR Record ID``. Refer to `ECMA 335 <http://www.ecma-international.org/publications/standards/Ecma-335.htm>`__
446 for more information.
448 **Xdata** - ``DbgStreamArray[7]``. A copy of the ``.xdata`` section from the
451 **Pdata** - ``DbgStreamArray[8]``. This is assumed to be a copy of the ``.pdata``
452 section from the executable, but that would make it identical to
453 ``DbgStreamArray[1]``. The difference between these two indices is not well
456 **New FPO Data** - ``DbgStreamArray[9]``. The data in the referenced stream is a
457 debug data directory of type ``IMAGE_DEBUG_TYPE_FPO``. Note that this is different
458 from ``DbgStreamArray[0]`` in that ``.debug$F`` sections are only emitted by MASM.
459 Thus, it is possible for both to appear in the same PDB if both MASM object files
460 and cl object files are linked into the same program.
462 **Original Section Header Data** - ``DbgStreamArray[10]``. Similar to
463 ``DbgStreamArray[5]``, but contains the section headers before any binary translation
464 has been performed. This can be used in conjunction with ``DebugStreamArray[3]``
465 and ``DbgStreamArray[4]`` to map instrumented and uninstrumented addresses.