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

simonx 126 Reputation points
2020-11-12T17:38:08.02+00:00

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?

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
4,572 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,516 questions
Visual Studio Debugging
Visual Studio Debugging
Visual Studio: A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.Debugging: The act or process of detecting, locating, and correcting logical or syntactical errors in a program or malfunctions in hardware. In hardware contexts, the term troubleshoot is the term more frequently used, especially if the problem is major.
935 questions
{count} vote

3 answers

Sort by: Most helpful
  1. Darran Rowe 561 Reputation points
    2020-11-12T21:39:10.307+00:00

    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.

    1 person found this answer helpful.
    0 comments No comments

  2. David Lowndes 4,711 Reputation points
    2020-11-12T19:02:05.04+00:00

    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.

    0 comments No comments

  3. Martin Ba 1 Reputation point
    2020-11-13T07:19:29.35+00:00

    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.
    0 comments No comments