Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When program run correctly while debugging but otherwise not? [duplicate]

Tags:

c++

debugging

Possible Duplicate:
Common reasons for bugs in release version not present in debug mode

Sometimes I encouter such strange situations that the program run incorrectly while running normally and it will pop-up the termination dialog,but correctly while debugging.This do make me frustrated when I want to use debugger to find the bug inside my code.

Have you ever met this kind of situation and why?

Update:

To prove there are logic reasons that will led such a frustrating situation:

I think one big possibility is heap access volidation.I once wrote a function that allocate a small buffer,but later I step out the boudary.It will run correctly within gdb,cdb,etc(I do not know why,but it do run correctly);but terminate abnormally while running normally.

I am using C++.

I do not think my problem duplicate the above one.

That one is comparision between release mode and debug mode,but mine is between debugging and not debugging,which have a word heisenbug,as many other noted.

thanks.

like image 761
Jichao Avatar asked Feb 04 '10 17:02

Jichao


People also ask

What happens when you debug a program?

Debugging means to run your code step by step in a debugging tool like Visual Studio, to find the exact point where you made a programming mistake. You then understand what corrections you need to make in your code and debugging tools often allow you to make temporary changes so you can continue running the program.

Is debug and run the same?

Run simply launches the application (regardless of what the flavor is). Debug essentially does the same thing but will stop at any breakpoints that you might have set ...


1 Answers

You have a heisenbug.

Debugger might be initializing values

Some environments initialize variables and/or memory to known values like zero in debug builds but not release builds.

Release might be built with optimizations

Modern compilers are good, but it could hypothetically happen that optimized code functions differently than non-optimized code. Edit: These days, compiler bugs are rare. If you find yourself thinking you have one, exhaust all other ideas first.

There can be other reasons for heisenbugs.

like image 51
JeffH Avatar answered Sep 18 '22 09:09

JeffH