house fly

JSwat Project

How To: Variables


Locals Panel

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 'myList' is a java.util.LinkedList whose identifier is 205.

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 'myList.header' object has two fields, 'next' and 'previous' which refer back to 'myList.header', thus forming a loop.

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.

locals panel

Watch Panel

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 'counter' is a local variable and the 'this.counter' is a field variable. The this keyword can be used in this way to distinquish field variables from same-named local variables. Objects are shown simply as the string returned from their toString() method.

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.

watch panel

Other Views of Variables

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.

Setting Variables

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.



Back to Documentation