Debugging the release version of a program

Something a lot of programmers don't know is that you can debug the release version of a program
as easy as the debug version. I didn't know this until I've read John Robbins
'Bugslayer' column in the 'Microsoft System Journal', April 1998 (Vol 13, No 4):

In MSVC you can set all of your project's configurations in the Project Settings dialog.

1.Select the All Configurations option in the Settings For combobox.
2.On the C/C++ tab, select Program Database in the Debug info combobox.
3.On the Link tab, with the Category combobox on Debug, check the Debug info checkbox and the Microsoft format.

If you use your own make file use /Zi switch with CL.EXE and
use the use the /DEBUG and /PDB: switches for LINK.EXE,
That's all there is, now you can set breakpoints and watch variables as usual. Be aware that due to
the optimizer not all symbols can be watch and the execution of the line may be in a different order!

A common error that affects only the release version of a program is when you use ASSERT
instead of VERIFY. Remember ASSERTs will compile to nothing in a release version but
VERIFY does. So if you call a function like ASSERT(DoSomething()) this function will not be called
in the release version!

A release version of a program can behave different than the debug version due to optimzier settings. If you find a strange/buggy
behavoir disable every optimazion and try again.

How to debug another exe from existing application.

I have an application (vc++6.0), which calls another application (vc++ 6.0), which is on same machine. When i try to debug by putting break points in the called exe code, its not going into the code (called exe code). Can any one help me in this?

debugging information not in precompiled heade

if I turn on the described switches, I get the warning C4650 and the error C2859. They told me, that the precompiled header has no debug information. Accordingly I have to do something else.
What do I have to do ????

"...debugging relase versions in MSVC..."

For a good reference on this topic see Chapter 7 in McKay & Woodring's, "Debugging With the Visual C++ Debugger". It outlines VC++ project settings that keep the debuggable release version file size as small as possible. It also discusses test phiosophy on release vs debug.

global variables

One remark though. Has anyone encountered a problem with global variable that seem to be unallocated in the release version?

A short example:

------------------------------

global.h:

extern fstream tracefile;

------------------------------

global.cxx:

fstream tracefile("trace.txt");

// and nothing else in this file (i.e. no explicit use of tracefile)

------------------------------

I compile this with /O2 and /D NDEBUG under MSVC++ v6.0 with Service Pack 5 to make a static library, say globals.lib.

Then there is a main.cxx:

#include "global.h"

int main()
{
tracefile << "Hello World" << endl;
}

which gets linked with the static library globals.lib.
This crashes almost immediately at runtime. It works correctly when switching off /O2.
Defining the tracefile variable in the main.cxx and removing the definition from global.cxx cures the problem.
It looks like the optimizer thinks the tracefile variable in global.cxx is not needed and, hence, does not allocate it.

even worse things can happen

I've found that program behaving differently when built with release cofig is not the worst case. I've even ended up with program acting right when executed from the VC6 IDE and acting wrong when executed simply from Windows.

Top White Papers and Webcasts

When individual departments procure cloud service for their own use, they usually don't consider the hazardous organization-wide implications. Read this paper to learn best practices for setting up an internal, IT-based cloud brokerage function that service the entire organization. Find out how this approach enables you to retain top-down visibility and control of network security and manage the impact of cloud traffic on your WAN.

U.S. companies are desperately trying to recruit and hire skilled software engineers and developers, but there is simply not enough quality talent to go around. Tiempo Development is a nearshore software development company. Our headquarters are in AZ, but we are a pioneer and leader in outsourcing to Mexico, based on our three software development centers there. We have a proven process and we are experts at providing our customers with powerful solutions. We transform ideas into reality.