13

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?

Ian Boyd
  • 246,734
  • 253
  • 869
  • 1,219
Anh Cuong
  • 131
  • 1
  • 3

5 Answers5

8

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

Shay Rojansky
  • 15,357
  • 2
  • 40
  • 69
6

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.

Kunis
  • 138
  • 1
  • 7
5

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

Ian Boyd
  • 246,734
  • 253
  • 869
  • 1,219
  • 1
    I don't think it's possible _in the .Net framework_, though. Older C++ compilers seemed to have ways of embedding it, yes, though these ways, and the information in it, varied widely based on the compiler and the targeted debugger. – Nyerguds Aug 22 '16 at 09:39
  • Ian, did you ever figure this out for C++? – user541686 Jun 04 '18 at 21:28
  • @Mehrdad I never figured it out *at all!* – Ian Boyd Jun 05 '18 at 15:17
1

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.

JaredPar
  • 733,204
  • 149
  • 1,241
  • 1,454
  • The question makes no mention of managed labguages. Use compiler option /Z7 to embed debug information in the library. – DaveCleland Nov 11 '21 at 23:29
0

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.