Introduction
A portable PDB holds the debug information of a .NET assembly: for each method the source files and the sequence points that map IL offsets to lines, the local variables and constants with their scopes, the
namespaces imported at each point, the state machines the compiler made for async and iterator methods, and custom information such as SourceLink. The .NET SDK writes one beside each assembly, or embeds it in the assembly
(DebugType embedded). It is a separate format from the Windows PDB, which is a file system of numbered streams (MSF) and shares only the extension. A portable PDB has the same layout as .NET metadata:
a root with the signature BSJB, streams, and tables.
The assembly and its PDB are matched by an ID: the PDB ID in the #Pdb stream (a GUID and a stamp) is stored in the assembly’s debug directory, so a debugger can pick the right file.
Structure
Metadata rootthe signatureBSJB, root version 1.1, the version stringPDB v1.0and the stream headersfile offset 0#Pdbthe 20-byte PDB ID, the entry point token and the row counts of the assembly’s tables that the debug tables refer tostream layout#~the debug tables 0x30 to 0x37, in the layout of the metadata tablesdebug tables#Strings, #GUID, #Blobthe heaps: names, GUIDs, and the blobs (document names, sequence points, import lists)heaps
What the explorer shows
A file that starts with BSJB opens as a portable PDB (a .pdb starting Microsoft C/C++ MSF 7.00 is a Windows PDB and is named so). The tree shows the root, the streams, the PDB ID and the entry point, every row of every
debug table with its columns decoded (documents, scopes, variable names), and the heaps. The problems list reports the same structure faults as for an assembly. The model lists the documents (with their decoded names), the methods with their sequence points (first and last position) and the local scopes with their variable names. An assembly built with an embedded PDB keeps a Deflate-compressed copy of one in its
debug directory (entry type 17: the letters MPDB, the uncompressed size, then the data): the explorer unpacks it, shows the same lists, writes each sequence point as a // .line comment before its instruction in the IL listing, and uses the variable names in .locals (option Debug information).
The explorer’s reading was compared with Microsoft’s System.Reflection.Metadata field by field on the portable PDBs written by the C#, F# and Visual Basic compilers (see the .NET assembly page for the numbers). The documents, the sequence points of every method and the local scopes and
variables were also compared with its portable PDB reader, for 26 PDB files and one embedded PDB: 85 documents, 684 methods, 2,619 sequence points and 750 scopes, no differences.
Documents, sequence points and local scopes
A document name is a blob: a separator character (one UTF-8 character, or a zero byte for none) and then parts, each the index of a blob holding one part of the path (0 for an empty part); the parts are joined with the separator. The row also has a hash and the GUIDs of the hash algorithm and the language.
The sequence points of a method are one blob of the MethodDebugInformation row, written with the compressed integers of signatures: a header with the local variable signature (a StandAloneSig row, 0 for none) and, when the row names no document, the first document; then records. The first record starts with an IL offset, the others with the distance from the previous offset. A record whose distance is 0 after the first is not a point: it names a new document for the points that follow. Otherwise the record gives the number of lines the point spans and the number of columns (unsigned if it stays on one line, signed otherwise); if both are 0 the point is hidden (IL that has no source, which a debugger steps over). A visible point then gives its start line and column: absolute for the first visible point, and for the others as a signed distance from the previous visible point’s start. The end is the start plus the spans.
A local scope row names a method, an IL range (start offset and length), the first of its local variables and constants (the lists run to the next scope’s first) and an import scope. A variable gives its slot number in the local signature, its name and flags.
Other formats that use .pdb
The portable PDB is a different format from the Windows PDB: they share only the extension.
- Microsoft program database (MSF) – the Windows PDB of C and C++ programs: numbered streams in an MSF container, a different format that also uses
.pdb
Not described
Known, not yet covered
- Reference: the import scope blobs and the custom debug information kinds (SourceLink JSON, embedded source with its compression, state machine hoisted locals, edit-and-continue maps) are in the portable PDB specification and are not described yet (see the debug tables); the local constants (LocalConstant has no row in any file used for the check).
- Viewer: the import scope and custom debug information blobs show as bytes; a PDB that is a separate file is not joined to its assembly (the explorer opens one file at a time): only an embedded PDB is.
Also used for
- Microsoft program database – Debug symbols for Windows programs, in numbered streams.
- Protein Data Bank Format – Legacy 80-column text format for molecular structures.
Links
Software
Developers
- MetadataReaderProvider – System.Reflection.Metadata’s portable PDB reader (.NET)
Reference
- Portable PDB v1.0: Format specification – the tables, the #Pdb stream and the blob encodings