且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在 Visual Studio 2012 中加载符号

更新时间:2023-01-30 21:48:02

添加符号位置

打开设置:工具->选项->调试->符号并添加您的.PDB文件所在的目录.

Adding Symbols Location

Open Settings: Tools->Options -> Debugging -> Symbols and add directory, where your .PDB files are located.

此菜单所在的 Visual Studio 界面的屏幕截图

您可以为每个项目添加自定义路径,也可以编辑公共路径,Visual Studio 将在其中保存所有 .pdb 缓存.

You can add custom path, like for each project, and also you can edit common path, where Visual Studio will save all .pdb cache.

我在每个项目中进行了编译后事件,将所有 .pdb 复制到一个文件夹中,这样我就将所有内容放在一个地方.但是您可以单独存储它,我发现这不太方便,因为每次编辑位置列表时都需要.

I made in each project post-compile event, which copy all .pdb to one folder, by this i have all in one place. But you can store it separately, which i found not so convenient, as it require each time edit list of locations.

将 .pdb 和 .dll 复制到 Symbols 缓存位置的调试后脚本示例:

xcopy /Y /R "$(TargetDir)$(ProjectName).pdb" "D:\VS_CACHE\"
xcopy /Y /R "$(TargetDir)$(ProjectName).dll" "D:\VS_CACHE\"

解决未找到符号的问题

当您处于调试模式时,由于某种原因找不到符号,可能是由于多种原因:

  1. 您在符号缓存中有 .pdb,但它已经过时(如果是这种情况,您可以得到,如果您在代码中放置断点并将其悬停)
  2. 您有多个使用这部分代码的 .dll (如果是这种情况,您可以得到,如果您在代码中放置断点并将其悬停)
  3. 符号未加载,在这种情况下,您可以通过以下方式进行检查:调试-> Windows -> 模块并尝试加载所需的模块.
  1. You have .pdb in Symbols cache, but it's outdated (you can get if this a case, if you put breakpoint in code and hover it)
  2. You have multiple .dll which use this part of code (you can get if this a case, if you put breakpoint in code and hover it)
  3. Symbols not loaded, in this case you can check it by going to: Debug-> Windows -> Modules and trying to load needed module.

Visual Studio 界面模块截图 -> 加载符号

要将 VS Debugger 重新附加到正在运行的应用程序,我建议使用这个免费的 Visual Studio 附加组件(支持 VS 2015):

To re-attach VS Debugger to running application, i recommend to use this free Visual Studio add-on (support VS 2015):

重新连接:visualstudiogallery.msdn.microsoft.com/8cccc206-b9de-42ef-8f5a-160ad0f017ae

ReAttach: visualstudiogallery.msdn.microsoft.com/8cccc206-b9de-42ef-8f5a-160ad0f017ae

它会为您节省很多时间!:)

It will save you a lot of time! :)