[llvm-exegesis] Program should succeed if benchmark returns StringError.
[llvm-core.git] / docs / PDB / index.rst
blob5300588b1d8aee8f622f4f980aa7c95fd5a2cca9
1 =====================================\r
2 The PDB File Format\r
3 =====================================\r
4 \r
5 .. contents::\r
6    :local:\r
7 \r
8 .. _pdb_intro:\r
9 \r
10 Introduction\r
11 ============\r
13 PDB (Program Database) is a file format invented by Microsoft and which contains\r
14 debug information that can be consumed by debuggers and other tools.  Since\r
15 officially supported APIs exist on Windows for querying debug information from\r
16 PDBs even without the user understanding the internals of the file format, a\r
17 large ecosystem of tools has been built for Windows to consume this format.  In\r
18 order for Clang to be able to generate programs that can interoperate with these\r
19 tools, it is necessary for us to generate PDB files ourselves.\r
21 At the same time, LLVM has a long history of being able to cross-compile from\r
22 any platform to any platform, and we wish for the same to be true here.  So it\r
23 is necessary for us to understand the PDB file format at the byte-level so that\r
24 we can generate PDB files entirely on our own.\r
26 This manual describes what we know about the PDB file format today.  The layout\r
27 of the file, the various streams contained within, the format of individual\r
28 records within, and more.\r
30 We would like to extend our heartfelt gratitude to Microsoft, without whom we\r
31 would not be where we are today.  Much of the knowledge contained within this\r
32 manual was learned through reading code published by Microsoft on their `GitHub\r
33 repo <https://github.com/Microsoft/microsoft-pdb>`__.\r
35 .. _pdb_layout:\r
37 File Layout\r
38 ===========\r
40 .. important::\r
41    Unless otherwise specified, all numeric values are encoded in little endian.\r
42    If you see a type such as ``uint16_t`` or ``uint64_t`` going forward, always\r
43    assume it is little endian!\r
45 .. toctree::\r
46    :hidden:\r
47    \r
48    MsfFile\r
49    PdbStream\r
50    TpiStream\r
51    DbiStream\r
52    ModiStream\r
53    PublicStream\r
54    GlobalStream\r
55    HashStream\r
56    CodeViewSymbols\r
57    CodeViewTypes\r
59 .. _msf:\r
61 The MSF Container\r
62 -----------------\r
63 A PDB file is really just a special case of an MSF (Multi-Stream Format) file.\r
64 An MSF file is actually a miniature "file system within a file".  It contains\r
65 multiple streams (aka files) which can represent arbitrary data, and these\r
66 streams are divided into blocks which may not necessarily be contiguously\r
67 laid out within the file (aka fragmented).  Additionally, the MSF contains a\r
68 stream directory (aka MFT) which describes how the streams (files) are laid\r
69 out within the MSF.\r
71 For more information about the MSF container format, stream directory, and\r
72 block layout, see :doc:`MsfFile`.\r
74 .. _streams:\r
76 Streams\r
77 -------\r
78 The PDB format contains a number of streams which describe various information\r
79 such as the types, symbols, source files, and compilands (e.g. object files)\r
80 of a program, as well as some additional streams containing hash tables that are\r
81 used by debuggers and other tools to provide fast lookup of records and types\r
82 by name, and various other information about how the program was compiled such\r
83 as the specific toolchain used, and more.  A summary of streams contained in a\r
84 PDB file is as follows:\r
86 +--------------------+------------------------------+-------------------------------------------+\r
87 | Name               | Stream Index                 | Contents                                  |\r
88 +====================+==============================+===========================================+\r
89 | Old Directory      | - Fixed Stream Index 0       | - Previous MSF Stream Directory           |\r
90 +--------------------+------------------------------+-------------------------------------------+\r
91 | PDB Stream         | - Fixed Stream Index 1       | - Basic File Information                  |\r
92 |                    |                              | - Fields to match EXE to this PDB         |\r
93 |                    |                              | - Map of named streams to stream indices  |\r
94 +--------------------+------------------------------+-------------------------------------------+\r
95 | TPI Stream         | - Fixed Stream Index 2       | - CodeView Type Records                   |\r
96 |                    |                              | - Index of TPI Hash Stream                |\r
97 +--------------------+------------------------------+-------------------------------------------+\r
98 | DBI Stream         | - Fixed Stream Index 3       | - Module/Compiland Information            |\r
99 |                    |                              | - Indices of individual module streams    |\r
100 |                    |                              | - Indices of public / global streams      |\r
101 |                    |                              | - Section Contribution Information        |\r
102 |                    |                              | - Source File Information                 |\r
103 |                    |                              | - FPO / PGO Data                          |\r
104 +--------------------+------------------------------+-------------------------------------------+\r
105 | IPI Stream         | - Fixed Stream Index 4       | - CodeView Type Records                   |\r
106 |                    |                              | - Index of IPI Hash Stream                |\r
107 +--------------------+------------------------------+-------------------------------------------+\r
108 | /LinkInfo          | - Contained in PDB Stream    | - Unknown                                 |\r
109 |                    |   Named Stream map           |                                           |\r
110 +--------------------+------------------------------+-------------------------------------------+\r
111 | /src/headerblock   | - Contained in PDB Stream    | - Unknown                                 |\r
112 |                    |   Named Stream map           |                                           |\r
113 +--------------------+------------------------------+-------------------------------------------+\r
114 | /names             | - Contained in PDB Stream    | - PDB-wide global string table used for   |\r
115 |                    |   Named Stream map           |   string de-duplication                   |\r
116 +--------------------+------------------------------+-------------------------------------------+\r
117 | Module Info Stream | - Contained in DBI Stream    | - CodeView Symbol Records for this module |\r
118 |                    | - One for each compiland     | - Line Number Information                 |\r
119 +--------------------+------------------------------+-------------------------------------------+\r
120 | Public Stream      | - Contained in DBI Stream    | - Public (Exported) Symbol Records        |\r
121 |                    |                              | - Index of Public Hash Stream             |\r
122 +--------------------+------------------------------+-------------------------------------------+\r
123 | Global Stream      | - Contained in DBI Stream    | - Global Symbol Records                   |\r
124 |                    |                              | - Index of Global Hash Stream             |\r
125 +--------------------+------------------------------+-------------------------------------------+\r
126 | TPI Hash Stream    | - Contained in TPI Stream    | - Hash table for looking up TPI records   |\r
127 |                    |                              |   by name                                 |\r
128 +--------------------+------------------------------+-------------------------------------------+\r
129 | IPI Hash Stream    | - Contained in IPI Stream    | - Hash table for looking up IPI records   |\r
130 |                    |                              |   by name                                 |\r
131 +--------------------+------------------------------+-------------------------------------------+\r
133 More information about the structure of each of these can be found on the\r
134 following pages:\r
135    \r
136 :doc:`PdbStream`\r
137    Information about the PDB Info Stream and how it is used to match PDBs to EXEs.\r
139 :doc:`TpiStream`\r
140    Information about the TPI stream and the CodeView records contained within.\r
142 :doc:`DbiStream`\r
143    Information about the DBI stream and relevant substreams including the Module Substreams,\r
144    source file information, and CodeView symbol records contained within.\r
146 :doc:`ModiStream`\r
147    Information about the Module Information Stream, of which there is one for each compilation\r
148    unit and the format of symbols contained within.\r
150 :doc:`PublicStream`\r
151    Information about the Public Symbol Stream.\r
153 :doc:`GlobalStream`\r
154    Information about the Global Symbol Stream.\r
156 :doc:`HashStream`\r
157    Information about the Hash Table stream, and how it can be used to quickly look up records\r
158    by name.\r
160 CodeView\r
161 ========\r
162 CodeView is another format which comes into the picture.  While MSF defines\r
163 the structure of the overall file, and PDB defines the set of streams that\r
164 appear within the MSF file and the format of those streams, CodeView defines\r
165 the format of **symbol and type records** that appear within specific streams.\r
166 Refer to the pages on :doc:`CodeViewSymbols` and :doc:`CodeViewTypes` for\r
167 more information about the CodeView format.\r