Viewing Local Variables in the Debugger
The Local Variables window enables you to monitor or detect changes to parameters and local variables used in your methods.
If call stack capturing is enabled, you can view the creation or deletion call stack of an object. For details, see "Viewing Creation or Deletion Call Stack Information", later in this chapter.
To display the Local Variables window if it is not already displayed
-
Select the View menu Local Variables command.
As the Local Variables window automatically monitors all parameters and local variables in your methods, you do not have to access the Watch Variable dialog to specify each variable that you want to watch in the Watches window.
The Local Variables window, shown in the following image, displays the values of all local variables in your methods. As your code executes, the values of the items change and the Local Variables window is updated. Local variables being watched are highlighted when values change.
To better display longer and multiple line values, you can resize the Local Variables window.
For each local variable being watched, the name and value of the item are displayed. The value that is displayed is:
-
The current value of the variable, if the item is a primitive type
-
An oid, if the variable contains an object reference
-
<null>, if the variable has no value assigned to it
-
[Out of scope], if the variable is not within the scope of the method currently selected in the Call Stack window, or it is declared but not used in the method currently selected in the Call Stack window
-
self, if the method references the current instance (method receiver) in any expression
Local variable values being watched are highlighted when they change.
Position the cursor over a local variable in a line of code in the Method Source window to display the current value of that item in bubble help. (For details about the circumstances under which bubble help is displayed by default, see "Displaying Code in the Method Source Window", earlier in this chapter.)
By default, the variables in the Local Variables window are displayed in the order in which they appear in the method. You can sort the table of displayed variables by clicking on the fixed column cell of the table. Clicking in the fixed part or a column causes the entries to be displayed alphabetically sorted (case‑insensitive) by that column for the rest of the debugger session. For example, clicking on an identifier in the Name column sorts the list by identifier name. Clicking the sorted fixed column cell again inverts the sorted list.
If the table is sorted, a numeric sorting indicator is displayed in the fixed cell of the column. If the column selected for sorting is not the identifier column, the identifier column is the second sort key.
To select a method, view the Call Stack window (by selecting the Call Stack command from the View menu), and then select one of the methods in the list.
As the methods are selected, the Local Variables list is updated to reflect the values that are within the scope of the selected method. If no method is selected, the values are displayed for the method that is currently executing.
You can watch:
-
Method parameters
-
Local variables
You can inspect or modify variables selected in the Local Variables window. For details, see "Inspecting and Modifying Values", later in this chapter.