question

simonx-0248 avatar image
1 Vote"
simonx-0248 asked MartinBa answered

Is it OK to set Visual C++ compiler's "Debug Information Format" to Program Data (/Zi)" in a Release build?

I have Visual Studio 2019 (app is Visual C++, unmanaged code, not .NET). I would like to generate a program database file (.PDB) even in release builds of my application. I don't plan to distribute the PDB file. But if I have one, and the application crashes, users can report the crash module and offset details (info available in the Event Viewer) and if I have the PDB file, I can use that to try and work out where the crash occurred and what caused it. I know it won't always help but sometimes it might. I have found that in order to generate a .PDB file, I have to set the compiler "Debug Information Format" to "Program Database (/Zi)". However, I don't want my release build to be negatively affected by my doing this. I propose to leave the release build optimisation at "Maximum Optimization (Favor Speed) (/O2)".

My question is: what are the implications of using the compiler's /Zi setting in a release build? Is there any reason I should be aware of, not to do it? Is it likely to affect the way that app runs? Will it be slower?

c++vs-generalvs-debugging
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

You'll also want to set the linker option /DEBUG:FULL. This ensures that a complete PDB is generated.

0 Votes 0 ·
DavidLowndes-6766 avatar image
0 Votes"
DavidLowndes-6766 answered

I don't believe it would affect the code generation, but the way to be sure is to check it; generate asm listings with and without it and see if there's any difference.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

DarranRowe avatar image
1 Vote"
DarranRowe answered

The /Zi option description states that the option doesn't affect optimisations. So all it should do is create a section in the executable header to store information about the .PDB file and make the build a little slower because the compiler and linker has to generate symbols.
The majority of the Windows libraries and executables have debug symbols, and I doubt Microsoft would do something like this if it had a significant impact on performance.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

MartinBa avatar image
0 Votes"
MartinBa answered

It is not only OK, you should do this. Valid PDB Files are vital when debugging or analyzing crash dumps.

  • /Zi is the release default in VS2019 anyway

  • What's also relevant is that you also set the /DEBUG switch "Generate Debug Info" in the linker options to get a pdb file for your output binary. Yes: you set the /DEBUG linker switch in release mode.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.