Using a Debugger
- A debugger is a tool that you can used to track down logical errors in your code. When executing the code, select "debug" rather than "run".
- The interface for a debugger can be very different depending on the tool, but that all have these basic concepts in common.
- You can:
- Set or toggle a break point - this stops execution at the specified point in the code. You can then control the execution and also examine variables.
- Step over - execute the next line of code and then break. This does not follow into the body of a function or method.
- Step into - follows execution into a function or method.
- Step return - continue until a function or method return.
- Continue - run code until the next break-point is hit.
- In Java, examine what is called the stack trace to see how the currently suspended code came to be executed.
- You can examine the values of your variables that are currently in-scope.
- You can set a watch, which breaks executions based on a particular variable's value.
- You can execute a line of code by typing it in.
No programmer can perform well without knowing how to use their debugger. This, along with drawing your code and using trace statements wisely, are the top skills you will use when tracking down and fixing a bug.