Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do some programs work when using the debugger, but not when running a normal debug execution?

I've had several times where I was writing a program using Visual Studio and something, somewhere along the line breaks. Naturally, my first thought is to set a breakpoint early on in the program and then step through the code slowly, line by line until I reach the error.

But often times I find that everything works correctly when slowly stepping through code in the debugger. However, when I just try to run the program without breakpoints something goes wrong.

Why does this happen? Is stepping through the code line by line actually different from just running the program in dubug mode?

(I'm not talking about debug vs release, i'm talking about debug vs line-by-line debugging)

like image 948
xcdemon05 Avatar asked Jun 26 '26 06:06

xcdemon05


2 Answers

One reason could be that you have timing issues between multiple executing threads that occur differently when the program runs "at full speed" and when you pause a thread in a debugger.

like image 73
Daniel Lundmark Avatar answered Jun 28 '26 09:06

Daniel Lundmark


It could be due to a some thread unsafe operations that seem to happen correctly when stepping through the code but not at run time. Compiler optimizations are ruled out because you are sure that you are running a debug build.

like image 24
SNce Avatar answered Jun 28 '26 10:06

SNce