将 .pdb 调试符号信息嵌入到 Visual Studio 中的 .exe 文件中

发布于 2024-09-16 10:32:19 字数 245 浏览 10 评论 0原文

我正在试验一种分析工具,可以分析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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

计㈡愣 2024-09-23 10:32:20

我很确定 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.

长梦不多时 2024-09-23 10:32:19

我知道这是一个相当老的问题,但此功能最近已合并到 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

只为守护你 2024-09-23 10:32:19

MSDN 说这是不可能的。

无法创建包含调试信息的 .exe 或 .dll。调试信息始终放置在 .pdb 文件中。

The MSDN says that it isn't possible.

It is not possible to create an .exe or .dll that contains debug information. Debug information is always placed in a .pdb file.

江城子 2024-09-23 10:32:19

我还不知道如何做到这一点 - 但 MSDN 上有一篇文章讨论了它。

可移植的可执行文件(即 .exe.dll)可以具有 标头中存在标志(存档)

<前><代码>IMAGE_FILE_DEBUG_STRIPPED

调试信息已被删除并单独存储在 .dbg 文件中。

这意味着调试信息可以可执行文件中,并且可以选择删除并存储在单独的.dbg<中/代码> 文件。

来自 MSDN 文章DBG 文件:< em>(存档)

DBG 文件是可移植可执行 (PE) 格式文件,其中包含 Visual Studio 调试器的 Codeview 格式的调试信息(也可能是其他格式,具体取决于 DBG 的创建方式)。当您没有某些代码(例如库或 Windows API)的源代码时,DBG 文件允许调试。 DBG 文件还允许您进行 OLE RPC 调试。

DBG 文件已被 PDB 文件取代,PDB 文件现在更常用于调试。

您可以使用 REBASE.EXE 实用程序从 PE 格式的可执行文件中删除调试信息并将其存储在 DBG 文件中。 PE 文件头中的文件特征字段 IMAGE_FILE_DEBUG_STRIPPED 告诉调试器 Codeview 信息已被剥离到单独的 DBG 文件中。

描述 COFF 格式的知识库文章提到了 dumpbin 实用程序,它是 /SYMBOLS 选项:

/SYMBOLS      Setting this option causes DUMPBIN to display the COFF symbol
              table. Symbol tables exist in all object files. A COFF symbol
              table appears in an image file only if it is linked with
              /DEBUG /DEBUGTYPE:COFF

下一步,即回答我们问题的部分是:

  • 什么格式是嵌入的调试信息?
  • 嵌入式调试信息存储在PE的什么位置? (资源?,数据部分?)

但是答案“无法完成”似乎是不正确的。

另请参阅

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)

IMAGE_FILE_DEBUG_STRIPPED

Debugging information was removed and stored separately in stored separately in a .dbg file.

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)

DBG files are portable executable (PE) format files that contain debug information in Codeview format for the Visual Studio debugger (and possibly other formats, depending on how the DBG was created). When you do not have source for certain code, such as libraries or Windows APIs, DBG files permit debugging. DBG files also permit you to do OLE RPC debugging.

DBG files have been superseded by PDB files, which are now more commonly used for debugging.

You can use the REBASE.EXE utility to strip debug information from a PE-format executable and store it in a DBG file. The file characteristic field IMAGE_FILE_DEBUG_STRIPPED in the PE file header tells the debugger that Codeview information has been stripped to a separate DBG file.

A knowledge base article describing the COFF format mentions the dumpbin utility, and it's /SYMBOLS option:

/SYMBOLS      Setting this option causes DUMPBIN to display the COFF symbol
              table. Symbol tables exist in all object files. A COFF symbol
              table appears in an image file only if it is linked with
              /DEBUG /DEBUGTYPE:COFF

The next step, and the part that would answer our question is:

  • what format is the embedded debugging information?
  • where in the PE is the embedded debugging information stored? (resource?, data section?)

But the answer "it cannot be done" seems to be incorrect.

See also

破晓 2024-09-23 10:32:19

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文