Java Reference
In-Depth Information
Figure 6.2
Adding a field watchpoint is an easy
way to track changes to an instance
variable over time.
menu item to bring up the
Breakpoints
dialog (or press
Ctrl+Shift+F8
), and
select the
Field Watchpoints
tab. Like the other types of breakpoints, any cur-
rently defined field watchpoints are listed here. Click the
Add
button to bring up
the
Add Field Watchpoint
dialog, and specify the class and field name you want
to break on. The class name you provide here must be fully qualified. Using the
selection buttons next to each field makes this process easier, because you can nav-
igate to the desired class and field by name or through a tree view of your project.
Once added, your field watchpoint displays a corresponding icon in the edi-
tor's gutter area. It behaves like other breakpoint icons: It can be disabled,
enabled, or removed directly from the gutter area.
You can set field watchpoints directly through the editor. To do so,
right-click the line with declaration of the field you want to watch, and
then select the
Toggle Field Watchpoint
option from the context menu.
This sets the breakpoint and opens the
Breakpoints
dialog.
TIP
Adding a field watchpoint while debugging
There is another way to add a field watchpoint. Although it's more convenient, it
can only be used once a debugging session is underway. After you've suspended
your application, you can add a field watchpoint for an instance variable by right-
clicking its icon in the frame view and selecting the
Add Field Watchpoint
menu
item. This command creates the appropriate field watchpoint and opens the
Breakpoints
dialog. In addition, it prepopulates the instance filter (described in
the next section) with the instance
ID
of the field's source object.
Breaking on field access or modification
Regardless of how you set up your field watchpoints, you must specify under
which circumstance you want the debugger to trigger the breakpoint. These
options are located in the
Wat c h
group of the
Breakpoints
dialog panel.