Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What to do, if debug behaviour differs from normal execution? [closed]

I have a problem with debugging sessions. My program executes very well in a debug session but if I start a normal run, it behaves completely different.
The problem is, that I cannot say, why it acts different.

One possible reason is the slower execution time because you alway have to press F6 or so.
I tried to insert Thread.sleep(1000); but I don't get the instruction causing the different behaviour.

So: What are hints, best practices to get to know why it acts so different in debug sessions?

like image 690
guerda Avatar asked Jul 10 '09 07:07

guerda


People also ask

How does debugger allows you to control the execution of your program?

The debugger lets you place breakpoints in your program. When program execution reaches one of these breakpoints, the debugger can either perform predefined actions and continue program execution or suspend program execution and return control to you.

What is the last step you should do when debugging?

Debugging, in computer programming and engineering, is a multistep process that involves identifying a problem, isolating the source of the problem, and then either correcting the problem or determining a way to work around it. The final step of debugging is to test the correction or workaround and make sure it works.


3 Answers

I tried to check my assumption I did and check them once more.

Excessive logging could be helpful in some situations, but not always. In my case, it didn't help that much.
With logging you can see, where your assumptions are correct and which of them fail.

My personal solution was Java specific. The Java ClassLoader does not load classes completely since JDK 1.5. In a debug session, it has to be loaded completely. So some variables were not initialized well and the output differed from the normal run.
That reason is very hard to find.

like image 197
guerda Avatar answered Oct 01 '22 14:10

guerda


Two solutions:

a) Use poor man's debugger (print to the console) or use a logging framework. After the error happens, analyze the output.

b) Write a test case that tries to reproduce the problem. Even if you can't find it that way, this will clean your code and sometimes solve the issue.

like image 11
Aaron Digulla Avatar answered Oct 11 '22 05:10

Aaron Digulla


You might observe a race-condition that only occurs when there are no debug statements that slow down execution. It could be helpful to start with reviewing your threading model and to watch out for any possible locks.

like image 6
pmr Avatar answered Oct 11 '22 07:10

pmr