Search code examples
c++visual-studiosconsdebug-symbolspdb-files

Attaching .pdb to a compiled .exe in Visual Studio 2022


I am trying to debug a .exe file with a .pdb. The project is using SCons, and here is the part where it compiles in sconstruct:

env.Append( CCFLAGS=["/EHsc"]) 
env.Append( CCFLAGS=["/DEBUG", "/Zi", "/Fdgame.pdb"])
env.Program('game', ['game.cpp', Glob('feather/*.cpp')], LIBS=['SDL2', 'SDL2_image', 'SDL2_ttf', 'SDL2_mixer', 'SDL2main'], LIBPATH='lib/Windows/lib')

So I'm adding the flags that are correct (I think) to generate the .pdb. The pdb shows up in my project directory, in the same location where the .exe is. After looking at its contents, I'm pretty sure that it has the correct information to work (at least, it is not empty). I am setting game.exe as the startup item, then running it from VS 2022. However, after running the .exe, Visual Studio claims that the "Binary was not built with debug information."

Modules tab showing this message under "Symbol Status."

According this page on the Microsoft VS documentation, it says:

The debugger searches for symbol files in the following locations:

  1. The project folder.
  2. The location that is specified inside the DLL or the executable (.exe) file. By default, if you have built a DLL or an .exe file on your computer, the linker places the full path and filename of the associated .pdb file in the DLL or .exe file. The debugger checks to see if the symbol file exists in that location.
  3. The same folder as the DLL or .exe file.

My .pdb should fulfill conditions 1 and 3, so I'm confused as to why it can't be found (if that's the issue). The docs do mention that this applies when you build a project, but I've seen other video tutorials online where they just attach .pdbs to running processes and it still works. Is there anything I'm missing?


Solution

  • Try changing to

    env.Append( CCFLAGS=["/EHsc"]) 
    env.Append( CCFLAGS=["/DEBUG", "/Zi"])
    env.Program('game', 
                ['game.cpp', Glob('feather/*.cpp')], 
                LIBS=['SDL2', 'SDL2_image', 'SDL2_ttf', 'SDL2_mixer', 'SDL2main'], 
                LIBPATH='lib/Windows/lib', PDB="game.pdb")
    

    If that's still not in the correct location then change to

    PDB="${TARGET.dir}/game.pdb"
    

    See the manpage for info on the PDB environment variable: https://scons.org/doc/production/HTML/scons-man.html#cv-PDB