符号和符号文件Symbols and Symbol Files

链接应用程序、库、驱动程序或操作系统时,创建 .exe 和 .dll 文件的链接器还会创建多个称为符号文件的附加文件。When applications, libraries, drivers, or operating systems are linked, the linker that creates the .exe and .dll files also creates a number of additional files known as symbol files.

符号文件保存多个数据,这些数据在运行二进制文件时实际上并不需要,但在调试过程中可能非常有用。Symbol files hold a variety of data which are not actually needed when running the binaries, but which could be very useful in the debugging process.

通常,符号文件可能包含:Typically, symbol files might contain:

  • 全局变量Global variables

  • 局部变量Local variables

  • 函数名称和其入口点的地址Function names and the addresses of their entry points

  • 帧指针省略(FPO)记录Frame pointer omission (FPO) records

  • 源行号Source-line numbers

其中每个项分别称为一个符号Each of these items is called, individually, a symbol. 例如,单个符号文件 Myprogram.exe 可能包含几百个符号,包括全局变量和函数名以及数百个局部变量。For example, a single symbol file Myprogram.pdb might contain several hundred symbols, including global variables and function names and hundreds of local variables. 通常,软件公司会发布每个符号文件的两个版本:包含公共符号私有符号的完整符号文件以及只包含公共符号的减少(去除)文件。Often, software companies release two versions of each symbol file: a full symbol file containing both public symbols and private symbols, and a reduced (stripped) file containing only public symbols. 有关详细信息,请参阅公共和私有符号For details, see Public and Private Symbols.

调试时,必须确保调试器能够访问与正在调试的目标关联的符号文件。When debugging, you must make sure that the debugger can access the symbol files that are associated with the target you are debugging. 实时调试和调试崩溃转储文件都需要符号。Both live debugging and debugging crash dump files require symbols. 你必须获取要调试的代码的正确符号,并将这些符号加载到调试器中。You must obtain the proper symbols for the code that you wish to debug, and load these symbols into the debugger.

Windows 符号Windows Symbols

Windows 在扩展名为 .pdb 的文件中保留其符号。Windows keeps its symbols in files with the extension .pdb.

编译器和链接器控制符号格式。The compiler and the linker control the symbol format. 可视化C++链接器会将所有符号置于 .pdb 文件中。The Visual C++ linker, places all symbols into .pdb files.

Windows 操作系统内置于两个版本中。The Windows operating system was built in two versions. 免费生成(或零售内部版本)的二进制文件相对较小,且检查的生成(或调试版本)具有更大的二进制文件,代码本身中的调试符号更多。The free build (or retail build) has relatively small binaries, and the checked build (or debug build) has larger binaries, with more debugging symbols in the code itself. 在 Windows 10 版本1803之前,已检查的生成在 windows 的早期版本上可用。Checked builds were available on older versions of Windows before Windows 10, version 1803. 其中每个生成都有自己的符号文件。Each of these builds had its own symbol files. 在 Windows 上调试目标时,必须使用与目标上的 Windows 生成匹配的符号文件。When debugging a target on Windows, you must use the symbol files that match the build of Windows on the target.

下表列出了标准 Windows 符号树中存在的几个目录:The following table lists several of the directories which exist in a standard Windows symbol tree:

DirectoryDirectory 包含的符号文件Contains Symbol Files for

ACMACM

Microsoft 音频压缩管理器文件Microsoft Audio Compression Manager files

COMCOM

可执行文件(.com)Executable files (.com)

CPLCPL

控制面板程序Control Panel programs

DLLDLL

动态链接库文件(.dll)Dynamic-link library files (.dll)

WINSPOOL.DRVDRV

驱动程序文件(. winspool.drv)Driver files (.drv)

.EXEEXE

可执行文件(.exe)Executable files (.exe)

SCRSCR

屏幕保护程序文件Screen-saver files

系统SYS

驱动程序文件(.sys)Driver files (.sys)