![]() |
JSwat ProjectHow To: Variables |
The values of variables are displayed in the local variables panel. The values in that panel are updated as you single-step through your program. The panel is displayed using a tree, so objects show their field variable values as child nodes. You can expand the nodes to "burrow" down into the fields and their values. Objects are shown using the diamond-shaped box icon. The
type of the object is shown in parentheses. The number
following the type indicates the unique identifier used to
identify this object in the debuggee VM. This is not the hash
code of the object, and the value will change from one
instance of the VM to another. You can see examples of these
identifiers in the screen shot shown here. The variable
called ' Nodes in the tree that are shown with a circular arrow
indicate that the variable is an object reference that refers
back to an object already shown higher up the variable tree
heirarchy. It indicates a loop in the object references,
which would generally be confusing if not clearly indicated.
In the screen shot shown here, the
' Arrays are indicated with an icon that looks like a bulleted list of three lines. The type of the array is shown in parentheses and the size of the array is shown in brackets. Entries in the array are shown as child nodes of the array node. The number in brackets is the array index and the type is shown in parentheses. The value for the entry is shown following the colon. Double-clicking on the "..." entry will expand the entire array, showing all of the array elements. This is not advisable for large arrays. |
![]() |
Another way of watching the values of field variables as they change is with the watch panel. This panel allows you to watch any field variable of any object as well as local variables. To watch a variable, first suspend the debuggee VM using a breakpoint. Try to set the breakpoint in a method that is within the scope of the variable to be watched. When the debuggee VM stops, type the name of the variable into the watch panel's empty "name" cell, then hit Enter. You will now see the watch panel display the changing value of the variable as you single step through code. In the screen shot shown here, the
' To stop watching a variable, simply erase the name and hit Enter again. The table row will be removed and the watch point will be deleted. |
![]() |
Local variables can also be displayed with the
'locals
' command, which will display all the
visible variables and their values. However, this will not show
field values of objects. Instead, use the
'dump
' command described below.
Another way to see the values of variables is with the
'print
' command. This takes the name of a
variable and prints its value to the message window. The
'print
' command can even take the name of an
object with a reference to a field variable. For example, if a
local variable called "date" is a Date object and you
want to print the "hourField" field variable of that
object, you would type 'print date.hourField
'
on the JSwat command line.
The 'dump
' command operates much like
'print
' except that it shows all the field
variables and their values.
Variable values can be modified using the set
command. It is currently possible to set values that are constants.
The type of the rvalue (value on the right of the equals sign) is
ascertained by the type of the lvalue (variable referenced on the
left side of the equals sign). That is, if the variable being set
is an Integer or int type, then the rvalue is interpreted as an
integer value.