- Starting a Debugging Session
- Attaching the Debugger to a Running Application
- Starting the Debugger Outside of the Project's Main Class
- Stepping Through Code
- Setting Breakpoints
- Managing Breakpoints
- Customizing Breakpoint Behavior
- Monitoring Variables and Expressions
- Backing Up from a Method to Its Call
- Monitoring and Controlling Execution of Threads
- Fixing Code During a Debugging Session
- Viewing Multiple Debugger Windows Simultaneously
Customizing Breakpoint Behavior
There are a number of things that you can do to customize when a breakpoint is hit and what happens in the IDE when a breakpoint is hit. The following subtopics cover some of those things.
Logging Breakpoints without Suspending Execution
If you would like to monitor when a breakpoint is hit without suspending execution each time the breakpoint is hit, you can configure the breakpoint so that it does not cause suspension of execution. When such a breakpoint is hit in the code, a message is printed in the Debugger Console window.
To turn off suspension of execution when a breakpoint is hit:
- Open the Breakpoints window by choosing Window | Debugging | Breakpoints (Alt-Shift-5).
- In the Breakpoints window, double-click the breakpoint to open the Customize Breakpoint window. (For line breakpoints, right-click the breakpoint and choose Customize.)
- In the Action combo box, select No Thread (Continue).
Customizing Console Messages When Breakpoints Are Hit
You can customize the text that is printed to the console when a breakpoint is hit in your code.
To customize the console message that is printed when a breakpoint is reached:
- Open the Breakpoints window by choosing Window | Debugging | Breakpoints (Alt-Shift-5).
- In the Breakpoints window, double-click the breakpoint to open the Customize Breakpoint window. (For line breakpoints, right-click the breakpoint and choose Customize.)
- In the Print Text combo box, modify the text that you want printed.
To make the printed text more meaningful, you can use some substitution codes to have things like the thread name and the line number printed. See Table 5-6 for a list of the substitution codes available.
Table 5-6. Substitution Codes for Breakpoint Console Text
Substitution Code |
Prints |
{className} |
The name of the class where the breakpoint is hit. This code does not work for thread breakpoints. |
{lineNumber} |
The line number at which execution is suspended. This code does not work for thread breakpoints. |
{methodName} |
The method in which execution is suspended. This code does not work for thread breakpoints. |
{threadName} |
The thread in which the breakpoint is hit. |
{variableValue} |
The value of the variable (for breakpoints set on variables) or the value of the exception (for exception breakpoints). |
{variableType} |
The variable type (for breakpoints set on variables) or the exception type (for exception breakpoints). |
Making Breakpoints Conditional
You can set up a breakpoint to suspend execution of the code only if a certain condition is met. For example, if you have a long For loop, and you want to see what happens just before the loop finishes, you can make the breakpoint contingent on the iterator's reaching a certain value.
Here are some examples of conditions you can place upon a breakpoint:
- i==4 (which means that the execution will stop on the breakpoint only if the variable i equals 4 in the current scope)
- ObjectVariable !=null (which means that execution will not stop at the breakpoint until ObjectVariable is assigned a value)
- MethodName (where Method has a Boolean return type and execution will stop at the breakpoint only if Method returns true)
- CollectionX .contains( ObjectX ) (which means that execution will stop at the breakpoint only if ObjectX is in the collection)
To make a breakpoint conditional:
- Open the Breakpoints window by pressing Alt-Shift-5.
- In the Breakpoints window, right-click the breakpoint that you want to place a condition on and choose Customize.
- In the Customize Breakpoint dialog box, fill in the Condition field with the condition that needs to be satisfied for execution to be suspended at the breakpoint.