将 .pdb 调试符号信息嵌入到 Visual Studio 中的 .exe 文件中
我正在试验一种分析工具,可以分析Windows中嵌入调试符号信息的可执行文件。在几个开源项目上尝试此工具时,我意识到大多数构建不会在可执行文件中保留符号信息。我可以使用 VS (2008) 编译源代码,但构建通常将调试信息保存在单独的 .pdb 文件中,而不是保存在 .exe 文件中(不幸的是,我只想从 .exe 文件中读取调试信息,而不是.pdb 文件:-()。
有人知道如何使用 Visual Studio 将符号调试信息嵌入到单个 .exe 文件中吗?
I am experimenting an analysis tool that can analyze executable files with embedded debug symbol information in Windows. While trying this tool on several open source projects, I realize that most of the builds do not keep symbolic information in executable files. I am able to compile the source code with VS (2008), but the build normally keeps the debug information in a separated .pdb file, not in the .exe file (unfortunately I only want to read debug information from .exe file and not .pdb file :-().
Does anybody know a way to embed symbol debug information into a single .exe file using Visual Studio?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我很确定 PDB 始终是独立的文件。 VC++ 曾经有一个开关,可以使其向“CodeView”.DBG 文件发出(与 PDB 相比有限)符号信息,该文件默认嵌入在 EXE 中。然而,较新的(6.x 之后?)版本的编译器似乎不再支持该开关。
I'm pretty sure PDBs were always stand-alone files. VC++ used to have a switch that would cause it to emit (limited compared to PDB) symbol information to a "CodeView" .DBG file that by default was embedded in the EXE. However, that switch appears to no longer be supported in the newer (post 6.x ?) versions of the compiler.
我知道这是一个相当老的问题,但此功能最近已合并到 Roslyn 中: https://github .com/dotnet/roslyn/issues/12390
I know this is a pretty old issue but this feature has recently been merged into Roslyn: https://github.com/dotnet/roslyn/issues/12390
MSDN 说这是不可能的。
The MSDN says that it isn't possible.
我还不知道如何做到这一点 - 但 MSDN 上有一篇文章讨论了它。
可移植的可执行文件(即
.exe
或.dll
)可以具有 标头中存在标志:(存档)这意味着调试信息可以在可执行文件中,并且可以选择删除并存储在单独的
.dbg<中/代码> 文件。
来自 MSDN 文章DBG 文件:< em>(存档)
描述 COFF 格式的知识库文章提到了
dumpbin
实用程序,它是/SYMBOLS
选项:下一步,即回答我们问题的部分是:
但是答案“无法完成”似乎是不正确的。
另请参阅
i don't know, yet, how to do it - but there's article on MSDN that talks about it.
A portable executable (i.e
.exe
or.dll
) can have a flag present in the header: (archive)This implies that debugging information can be in the executable, and has the option of being removed and stored in a separate
.dbg
file.From MSDN article DBG Files: (archive)
A knowledge base article describing the COFF format mentions the
dumpbin
utility, and it's/SYMBOLS
option:The next step, and the part that would answer our question is:
But the answer "it cannot be done" seems to be incorrect.
See also
Visual Studio 中没有对此类操作的内置支持(至少对于托管语言而言)。 .PDB 和 .EXE 文件是同时创建的,并且没有嵌入选项。我什至不确定 .EXE 格式是否支持嵌入 PDB 符号,尽管我在这一点上可能是错的。
我能看到的唯一方法是将 PDB 作为资源嵌入到 .EXE 中。然而,这必须是构建后的步骤,因为两者是同时构建的。如果您在构建 EXE 后对其进行修改,则可能会导致 PDB 的某些部分无效。
您尝试这样做有什么特殊原因吗?我想它最终会给你带来很多痛苦,因为 1)据我所知它不受支持,2)工具链旨在在同一目录中而不是在 .EXE 中查找 PDB。部署 2 个文件一开始有点烦人,但现在就是这样完成的。
There is no built-in support in Visual Studio for this type of operation (at least for managed languages). The .PDB and .EXE files are created at the same time and have no option for embedding. I'm not even sure the .EXE format supports embedding PDB symbols although I could be wrong on this point.
The only course I can see is embedding the PDB as a resource in th e .EXE. However that would have to be a post build step since the two are built at the same time. And there is the potential for invalidating parts of the PDB if you modify the EXE after it's been built.
Is there a particular reason you're trying to do this? I'm imagining it's going to end up causing you a lot of pain as 1) it's not supported AFAIK and 2) the tool chain is geared towards looking for PDB in the same directory not within the .EXE. Deploying 2 files is a bit annoying at first but it's how its done at this point.