Wednesday, October 31, 2007

The art of debugging


Software debugging is used to troubleshoot a problem in code.

So what is the best way of debugging?
1.  Run through the log statements
2.  Start  a debug session in your favourite IDE. The session can be remote(for a web app) or local.
3.  Narrow down to the problem by reducing the dependencies. Is it because of the framework or your own code, to know that  reduce the  code and test piece by piece.

Option 2, Debugger is the best arsenal for troubleshooting issues in code. Mixing 1,2 and 3 would be the ultimate way to fix the worst problem.
For details of remote debugging in eclipse please refer to my earlier posts.

In eclipse I find the below things very useful in debugging session:
  1. Breakpoints:
1.Put a breakpoint in eclipse. You can also edit the breakpoint properties by right clicking on the breakpoints properties. Here you can put a condition and put S.o.p for quickly identifying the problem 2. Exception breakpoint is a cool feature which will catch the exception which you specify. This will help you find the control flow(especially with nasty Null pointer exceptions). You can specify this by clicking on the "Add Java Exceptions" breakpoint of breakpoints view.
2.If you're running in debug code, you can actually just edit the method and re-invoke it. None of this resetting variables on the fly; just save the new method and do 'drop to stack' to get it to re-run the code. You can't do this if you're not running your application in eclipse, but are rather joined to it as a remore debugger. 3. Variables can be reset in debugging session through expressions or variables view. 4. Short cuts: CTRL+SHIFT +I -- to check a variable after selection. F5, F6, F8 Useful links Jacoozi - Remote Debugging with Eclipse

No comments: