开发者

Embed .pdb debug symbol information into an .exe file in Visual Studio

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 info开发者_运维技巧rmation into a single .exe file using Visual Studio?


I know this is a pretty old issue but this feature has recently been merged into Roslyn: https://github.com/dotnet/roslyn/issues/12390


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.


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

  • IMAGE_FILE_HEADER structure (archive)
  • LOADED_IMAGE structure (archive)
  • DBG Files (archive)
  • Microsoft PE and COFF Specification (archive)
  • An In-Depth Look into the Win32 Portable Executable File Format (archive)
  • KB121460 - Common Object File Format (COFF) (archive)


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜