Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best practices and tools for debugging differences between Debug and Release builds?

Tags:

c++

c

I've seen posts talk about what might cause differences between Debug and Release builds, but I don't think anybody has addressed from a development standpoint what is the most efficient way to solve the problem.

The first thing I do when a bug appears in the Release build but not in Debug is I run my program through valgrind in hopes of a better analysis. If that reveals nothing, -- and this has happened to me before -- then I try various inputs in hopes of getting the bug to surface also in the Debug build. If that fails, then I would try to track changes to find the most recent version for which the two builds diverge in behavior. And finally I guess I would resort to print statements.

Are there any best software engineering practices for efficiently debugging when the Debug and Release builds differ? Also, what tools are there that operate at a more fundamental level than valgrind to help debug these cases?

EDIT: I notice a lot of responses suggesting some general good practices such as unit testing and regression testing, which I agree are great for finding any bug. However, is there something specifically tailored to this Release vs. Debug problem? For example, is there such a thing as a static analysis tool that says "Hey, this macro or this code or this programming practice is dangerous because it has the potential to cause differences between your Debug/Release builds?"

like image 597
Eric Avatar asked Jun 22 '10 07:06

Eric


2 Answers

One other "Best Practice", or rather a combination of two: Have Automated Unit Tests, and Divide and Conquer.

If you have a modular application, and each module has good unit tests, then you may be able to quickly isolate the errant piece.

like image 73
djna Avatar answered Oct 11 '22 17:10

djna


The very existence of two configurations is a problem from debugging point of view. Proper engineering would be such that the system on the ground and in the air behave the same way, and achieve this by reducing the number of ways by which the system can tell the difference.

Debug and Release builds differ in 3 aspects:

  • _DEBUG define
  • optimizations
  • different version of the standard library

The best way around, the way I often work, is this:

  • Disable optimizations where performance is not critical. Debugging is more important. Most important is disable function auto-inlining, keep standard stack frame and variable reuse optimizations. These annoy debug the most.
  • Monitor code for dependence on DEBUG define. Never use debug-only asserts, or any other tools sensitive to DEBUG define.
  • By default, compile and work /release.
like image 26
Pavel Radzivilovsky Avatar answered Oct 11 '22 17:10

Pavel Radzivilovsky