PDB file: required by every developer

Source: Internet
Author: User
PDB files: What every developer must know
Http://www.wintellect.com/CS/blogs/jrobbins/archive/2009/05/11/pdb-files-what-every-developer-must-know.aspx

PDB file: required by every developer

1. What is a PDB file?

Most developers should know that the PDB file is used to debug the software. But we may not be familiar with how he actually works. This article describes the storage and content of PDB files. It also describes how the debugger finds the corresponding PDB file of binay and how the debugger findsSource codeFile. This article applies to all native and managed developers.

Before starting, we define two terms: Private build, which indicates the build generated on the developer's own machine; Public build, which indicates the build generated on the public build machine. Private build is relatively simple, because PDB and binay are in the same place. Generally, the problems we encounter are about public build.
 
The most important thing that all developers need to know is "PDB file and source ".CodeEqually important: "You cannot even debugging without a PDB file. For public build, you must store all the PDBs on the symbol server. Then, when the user reports an error, the debugger can automatically find the corresponding PDB file of binay, visual Studio and windbg both know how to access the symbol server. Before storing PDB and binay to the symbol server, you also need to perform source indexing on the PDB operation. The function of source indexing is to associate PDB and source.
 
In the following section, we assume that the symbol server and source server indexing have been set. Tfs2010 can easily complete source indexing and symbol server copying for a new build.
 

2. Content of the PDB File

The content of PDB is officially started. PDB is not a public file format, but Microsoft provides APIs to help obtain data from PDB.
 
Native C ++ PDB contains the following information:
* Public, private, and static function addresses;
* The name and address of the global variable;
* The Name Of The parameter and local variable and the offset in the stack;
* Class, structure, and Data Type Definitions;
* Frame pointer omission data, used to traverse the native stack on x86;
* Source Code File Name and number of lines;
 
. Net PDB only contains two parts of information:
* Source Code File Name and number of lines;
* And the local variable name;
* All other data is included in. Net metadata;
 

3. How does PDB work?

When you load a module to the address space of the Process, debugger uses the information in 2 to find the corresponding PDB file. The first one is undoubtedly the file name. If zzz. dll and debugger are loaded, query the ZZZ. PDB file. When the file name is the same, debugger also ensures the true match between PDB and binay by embedding the guid of PDB and binay. So even if no code is modified, the binay of yesterday cannot match the PDB of today. You can use dempbin.exe to view the binary guid.

You can view the load sequence of PDB in the symbol file column of the modules window in Visual Studio. The first search path is the path where binary is located. If not, find the build directory recorded by hardcode in binary, such as OBJ \ debug \*. PDB. If no PDB is found in the above two paths, search in the cache of the local symbol server according to the settings of the symbol server, if no corresponding PDB exists in the cache of the local symbol server, it is found in the remote symbol server. The above search sequence shows why the PDB search of public build and private build does not conflict.

For private build, when we need to debug on another machine, we need to copy the corresponding PDB and binary together. net binary, You need to copy the PDB file to the directory of binary similar to C: \ Windows \ Assembly \ gac_msil \ example \ 1.0.0.0 _ 682bc775ff82796a. Another work und is to define the environment variable devpath, instead of using the command gacutil to put binary into GAC. After devpath is defined, you only need to put binary and pdb in the devpath path. Binary in devpath is equivalent to GAC. To use devpath, you must first create a directory and have the write permission on the current build user. Then, create the environment variable devpath and set the value to the directory you just created. config, app. config or machine. enable the Development Mode in config and start the use of devpath.
<Configuration>
<Runtime>
<Developmentmode implements installation = "true"/>
</Runtime>
</Configuration>

After you enable the development mode, if the devpath is not defined or the path does not existProgramAn error occurred while starting "invalid value for registry ". If you enable devpath in machine. config, all other programs will be affected. Therefore, use machine. config with caution.
 
Finally, developers need to know how the source code information is stored in the PDB file. For public builds, after running the source indexing tool, the version control tool stores the code to the Code cache you set. For private builds, only the full path of the PDB file is stored, for example, the source file mycode under c: \ Foo. CPP, the path stored in the PDB file is c: \ Foo \ mycode. CPP. For private builds, you can use a virtual disk to increase the absolute dependency of pdbon. For example, you can use subst.exe to mount the source code path to V:, and mount V: When debugging is performed on another machine :.

 

Complete!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.