Creating a C++ Project from a PDB file: PDB Project [[Version 2.0]]
We are thrilled to announce version 2.0 of the PDB Project extension on the Visual Studio Gallery. PDB Project, as the name suggests, takes the information contained in a .pdb file to create a C++ project. The Information extracted from the .pdb includes both the source files (.c, .cpp) used for building, as well as the sources of the linked libraries. The generated project will light up the IDE features including Find all References, GoToDefinition, and IntelliSense operations. One limitation of the current version of the extension is that the generated project cannot be built; so this extension cannot yet replace the build system.
Why Would I Use the PDB Project Extension?
Visual Studio IDE requires a .vcxproj for Browsing and IntelliSense operations. Many of the build systems used today are still based on non-vcxproj designs that are incompatible with Visual Studio. The PDB project extension helps bridge the gap: .pdb files produced from the legacy build can be used to generate .vcxproj files that be opened in Visual Studio to enable power capabilities of the IDE.
How to Use the Extension
The PDB Project Extension is publicly available on the Visual Studio Gallery. If you already have a previous version installed, please uninstall it prior to installing version 2.
Once version 2 is installed, you will be able to open a .pdb file by invoking the File->Open->Project/Solution command. Select a .pdb file you want to convert. A list of source files from the PDB will be displayed. Some files might be automatically resolved, if they are in the same location on the disk. In case there are unresolved files, use the “Folder Mapping” dialog to provide a mapping between the directory that was used when the .pdb was created (e.g. by the build system) and a directory where the sources are stored (e.g. a remote source server). Press “Refresh” to see the results of each directory mapping. After all files are resolved, click “Finish” and select the save file location. The tool will load the newly created project into the current solution.
Watch the demo on Channel 9!
Starting with version 2.0, the extension is integrated into the Visual Studio debugger. If you right-click on a row in the Call Stack window during a Visual Studio debug session, you will now have an option to generate a project from the associated .pdb. The generated project will silently be loaded into the current solution, in order to avoid having too many unwanted projects in the solution. This is most useful while debugging unfamiliar code: in a few minutes, you can have complete Browsing and IntelliSense information for every stack frame of the program that you’re debugging.
Command line tool: In addition to the UI based tool, the latest update has a command line tool which enables users to automate their conversion tasks. To extract the tool, you need to change the file extension from “vsix” to “zip”.
Refresh Feature: Whenever the user opens a PDB-generated project, the user will get a prompt to re-generate the project if the .pdb from which it was generated has changed. Also, if you right click in Solution Explorer on a project that was generated from a .pdb, you will see an option to “Refresh PDB project”.
Peeking Under the Hood
The PDB loader uses the DIA SDK to extract the information from the PDB. The extraction engine is based on the sample included in the DIA SDK.
The project creator uses MSBuild Construction Model to create the .vcxproj file. Because PDB is an extension, it cannot use the internal APIs of the project system. As a side effect, the project file will be slightly different from a normal .vcxproj file.
One major issue during development, we found Intellisense was about ~20 seconds slower per cpp file. On average, it should take no more than 2-3 seconds. With some investigation, we found that missing header files was causing the Intellisense to ignore using PCH. PCH skips for completeness because once a PCH is created, it only tracks the files used to construct it. Any missing files aren’t tracked. When header file would appear later, the PCH would not trigger a refresh. To address slow load, PDB Project will detect missing header files and create a blank dummy file. This will let Intellisense to be fast even when dealing with incomplete projects.
Is PDB Project for everyone?
No. Most VC users would not need this extension. It is targeted for advances users who have non-vcxproj-based project system. Without a project, the IDE cannot provide its rich features. The PDB project will help bridge this gap.
We Want Your Feedback
If you use PDB Project, we would love your feedback. Feel free to post comments to this blog or email Felix, Balaji or Oleg
Felix Huang (firstname.lastname@example.org), Balaji Thumbavanam Kachapeswaran (email@example.com), Oleg Kharitonov (firstname.lastname@example.org) and the VC++ team