简体   繁体   English

如何更改符号文件(pdb)中源文件的位置

[英]How do I change the locations of source files in a symbols file (pdb)

Basically what I want to do it this: a pdb file contains a location of source files (eg C:\\dev\\proj1\\helloworld.cs ). 基本上我想要这样做:pdb文件包含源文件的位置(例如C:\\dev\\proj1\\helloworld.cs )。 Is it possible to modify that pdb file so that it contains a different location (eg \\more\\differenter\\location\\proj1\\helloworld.cs )? 是否可以修改该pdb文件以使其包含不同的位置(例如\\more\\differenter\\location\\proj1\\helloworld.cs )?

您可以使用Windows调试工具的源索引功能,该功能将保存对源存储库中文件的相应修订的引用,作为PDB文件中的备用流。

If you're looking to be more generic about the paths embedded in a pdb file, you could first use the MS-DOS subst command to map a particular folder to a drive letter. 如果您希望对pdb文件中嵌入的路径更通用,可以先使用MS-DOS subst命令将特定文件夹映射到驱动器号。

subst N: <MyRealPath>

Then open your project relative to the N: drive and rebuild it. 然后打开相对于N:驱动器的项目并重建它。 Your PDB files will reference the source files on N:. 您的PDB文件将引用N:上的源文件。 Now it doesn't matter where you place that particular set of source files, so long as you subsequently call the root directory "N:" like you did when you built it. 现在,无论您放置哪一组特定的源文件都无关紧要,只要您随后调用根目录“N:”就像您构建它时一样。

This practice is recommended by John Robbins in his excellent book, Debugging Applications for Microsoft .NET and Microsoft Windows . John Robbins在其出色的书“Microsoft .NET的调试应用程序”和Microsoft Windows中推荐了这种做法。

I wanted to find the answer to this in order to debug a crash dump that occurred in an executable that I did not build on my machine, therefore the path to the source code referenced in the PDB was invalid, as was the path to the PDB referenced in the executable. 我想找到答案,以便调试在我的机器上没有构建的可执行文件中发生的故障转储,因此PDB中引用的源代码的路径无效,PDB的路径也是如此在可执行文件中引用。

After searching around and failing to find something that works, I discovered that if you place the executable and PDB alongside the crash dump file (ie in the same directory) then open and run the crash dump in VS, VS will find and use the PDB/EXE locally. 在搜索并找不到有效的东西后,我发现如果将可执行文件和PDB放在崩溃转储文件旁边(即在同一目录中),然后在VS中打开并运行崩溃转储,VS将找到并使用PDB / EXE本地。 Furthermore, it will also prompt for the location of the source code when clicking on an entry in the call stack: pointing it at whichever source code is relevant, it all works fine, which is great! 此外,它还会在单击调用堆栈中的条目时提示源代码的位置:将其指向任何相关的源代码,一切正常,这很棒!

Anyway, hopefully this helps someone else...:) 无论如何,希望这有助于其他人...... :)

It is certainly possible, as On Freund has already pointed out. 正如On Freund已经指出的那样,这当然是可能的。 But if it is only so that the sources can be located and loaded during debugging, then a better way would be to set the source path correspondingly. 但是,如果仅在调试期间可以定位和加载源,那么更好的方法是相应地设置源路径。 Once set in a debugger, it will preemt all hard coded paths inside PDBs. 一旦设置在调试器中,它将预先显示PDB内的所有硬编码路径。

In windbg (for instance): 在windbg中(例如):

.srcpath+ path_to_source_root .srcpath + path_to_source_root
or this (in case you're debugging remotely): 或者这个(如果您正在远程调试):
.lsrcpath+ path_to_source_root .lsrcpath + path_to_source_root

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM