How to debug a function in release mode

29 07 2015


The Visual Studio IDE provides different optimization options that help us to create code for maximum speed or minimum size. Mostly we select /O1 optimizes code for minimum size when we build our project in release configuration. But you might be observed that the variable values may not be displayed correctly in the watch window if we try to debug our source code in release configuration. Of-course, we have options to enable debugging support in release mode. But just think in case if you want to debug just one function in release mode!!!

Pragma directives specify machine- or operating-specific compiler features. The compiler optimization can be performed on a function-by-function basis using #prgma optimize statement.

#pragma optimize( "[optimization-list]", {on | off} )

We can disable the optimization using the optimize pragma with the empty string (“”).

#pragma optimize( "", off )
void FunctionToDebug()
{
}
#pragma optimize( "", on ) 


Some pragmas provide the same functionality as compiler options. When a pragma is encountered in source code, it overrides the behavior specified by the compiler option.

Advertisements




How to debug a release build?

7 01 2012

To enable debugging of a release build, change the following release build options.

  1. Open solution’s Property Pages dialog.
  2. In the C/C++ -> Optimization, select Disabled (/Od).
  3. In the C/C++ -> General -> Debug Information Format, select Program Database (/Zi).
  4. In the Linker -> Debugging -> Generate Debug Info , select Yes (/DEBUG).

After doing this, rebuild and test your program. You can now debug your release build application. 🙂