The Debugger

The debugger allows you to step through the execution of a program and stop at any point you choose so that you can track down bugs in your code. What makes our debugger an unusually powerful tool is that it allows you to modify the values of fields and variables while debugging! First, we will explain a little bit about how the debugger works in general, and then we will explain how you can use the Interactions Pane to modify field and variable values during runtime and thus more quickly zero in on problems in your code.

To enable the debugger, select "Debugger, Debug Mode". This will launch the debug panel in the lower part of DrJava, right above the Interactions Pane.

Debug Panel: The Debug Panel has three tabs to help you track control flow in your program. These tabs are labeled Watches, Stack, and Threads.

Breakpoints. Another important part of the debugger is the breakpoints panel. Even when the debugger is not enabled, you can set breakpoints using the Ctrl+B shortcut or by selecting the "Toggle Breakpoint" command from the Debugger menu or the context menu. This will highlight the current line in red, and the debugger will stop the running program when it reaches this line. To remove a breakpoint again, place the cursor on the same line and press Ctrl+B again.

To view all the breakpoints you have set and to navigate between them, you can open the Breakpoints Panel by pressing Ctrl+Shift+B or selecting the "Breakpoints" command from the Debugger menu. In this panel, all currently set breakpoints are listed, sorted by document and line number. To move the cursor to the location of a breakpoint, double-click on one of the entries in the Breakpoints panel, or select it and press the "Go to" button.

You can also select one or more breakpoints and use the "Enable" or "Disable" button to temporarily enable or disable the selected breakpoints. If a breakpoint is disabled, it remains set, but the program will not stop there. This is useful if you may need a breakpoint again later, but want it ignored right now.

With the "Remove" button, you can remove one or more selected breakpoints. The "Remove All" button clears the entire list of breakpoints.

Breakpoints are considered part of a project and are therefore saved to and restored from a project file.