The Vivandiere
The Vivandiere

Reputation: 3201

Visual Studio - how to watch variable values in Release Mode

I would like to run my C++ program in Visual Studio such that I am allowed to watch the values of my variables like I can in debug mode, by adding them to the watch window, while at the same time not have the performance reducing error checking that happens in a debug build.

In other words, I would like the speed of release and the debug capability of debug, I do not care for error checking, it's a relatively safe application without real world implications - My buffers could overflow, etc.

Please any suggestions how this could be accomplished?

Upvotes: 3

Views: 3076

Answers (2)

Latency
Latency

Reputation: 442

That does not do anything to solve the problem.

You should be able to debug it just fine with /Zi enabled.

However, what you will need to do is turn off the Optomizations /Ox or lower them.

This worked for me. The rest of the settings mentioned are default settings for release builds. It is helpful if you may have changed them ONLY!!!

Upvotes: 2

metacubed
metacubed

Reputation: 7301

The MSDN website has a good starting article listing the series of steps to follow.

How to: Debug a Release Build

To paraphrase the steps:

  1. Open the Property Pages dialog box for the project.
  2. Click the C/C++ node. Set Debug Information Format to C7 compatible (/Z7) or Program Database (/Zi).
  3. Expand Linker and click the General node. Set Enable Incremental Linking to No (/INCREMENTAL:NO).
  4. Select the Debugging node. Set Generate Debug Info to Yes (/DEBUG).
  5. Select the Optimization node. Set References to /OPT:REF and Enable COMDAT Folding to /OPT:ICF.

You can now debug your release build application. To find a problem, step through the code (or use Just-In-Time debugging) until you find where the failure occurs, and then determine the incorrect parameters or code.

Play around with these options to determine what works best in your situation. There are more advanced steps to selectively turn on debug information - explore the related pages at the bottom of that link.

Another option is to keep running a DEBUG build, but turn off the run-time checks that you mentioned. There are different levels of checks, described at /RTC (Run-Time Error Checks).

  1. Open the project's Property Pages dialog box. For details, see How to: Open Project Property Pages.
  2. Click the C/C++ folder.
  3. Click the Code Generation property page.
  4. Modify one or both of the following properties: Basic Runtime Checks or Smaller Type Check.

Upvotes: 2

Related Questions