views:

49

answers:

1

I am getting confused as to what is the difference between the compiler and linker PDB files respectively (i.e. in Visual Studio, Project Properties > C/C++ > Output Files > Program Database File Name vs Project Properties > Linker > Debugging). I have tried to find the answer online and so far I know (may be wrong) that a PDB file by the compiler is generated for obj files while the PDB file by the linker is generated for the binary (exe or dll) and is the one used for debugging.

If that is not true, please explain the difference. Either way, what to do when I am creating a DLL where I have the option to select the output PDB file for the compiler as well as the linker and what to do when I am creating a LIB file where only the compiler generates the PDB files as there is no linking performed.

Background: The libraries/dlls are used by several projects, which then need the PDB files for debugging. In the case of a lib file, there is no ambiguity as there is only one PDB file generated. But in the case of a DLL however, do I need both the PDB files to properly debug or just the one generated by the linker?

+2  A: 

I honestly don't know what exactly the .pdb file generated by the compile step is used for - I assume that it's some intermediate information the gets pulled into the final .pdb file by the linker.

However, the bottom line is that for debugging purposes all you need is the .pdb file that is produced by the linker.


Update: A little digging netted this from http://blogs.msdn.com/b/yash/archive/2007/10/12/pdb-files-what-are-they-and-how-to-generate-them.aspx:

What are the two types of .PDB files?

==============================

There are two types of PDB files. One generated by the compiler named as VCx0.PDB(e.g. vc80.pdb), and another the .PDB.

The VCx0.PDB file is generated by the compiler and it is related to the .OBJ file. It contains the type information only.

The .PDB files are generated by the linker and it is related with the target executable or the DLL. This file contains the complete debug info. When we are debugging, we need this ‘.pdb’ file for aligning to the symbols. The timestamp of the target file and the PDB should match.

Michael Burr
(Posted this before your Update, but it applies to the update as well)So when I create the `lib` file (that is, a static library), and only the compiler can generate the `pdb` file since the linker is no longer needed, does this mean that the now the `pdb` file generated by the compiler is the one needed for debugging?
Samaursa
.lib files aren't involved in the execution or debugging of a program. They are only inputs to the linker. The appropriate 'stuff' in a lib file is either made part of the binary (in the case of a static library) or is used to create dynamic links to DLLs (in the case of an import library).In either of those cases, the .pdb file you'd need for debugging is the one produced by the linker when the actual .exe or .dll file is produced.
Michael Burr
Great, thanks for elaborating Michael, I will go ahead and check this as the right answer. Although since we _are_ on the subject, if you can answer this. Havok SDK is statically linked, and all its libraries come with their respective `PDB` files. The interesting bit is, if you link against the libraries without the `PDB` files accompanying them in the same directory, then Visual Studio gives a ton of warnings that `Debug info is missing, compiling as if no debug info provided` (I am paraphrasing)
Samaursa
Do you know what timestamp is? Is it means LastWriteTime?
Benjamin
@Benjamin: the timestamp used by the debugger to verify a .pdb file matches a binary is embedded in the file data by the linker - the file system's time stamps are not used. At least that's my recollection (much of my materials are inaccessible to me right now).
Michael Burr
@Michael: Got it. Thanks Michael.
Benjamin