When the program is suspended, you can inspect variables and arguments in the context of the currently selected frame: view their values and edit them on the fly. To change the context, simply select another frame on the Frames pane.
Viewing variables values
You have several opportunities to view variables values.
The default way to examine variables values is use the Variables pane of the Debug window. Note that if a variable is of a complex type, you can expand the corresponding node in the pane to see values that the variable contains.
Sometimes, you may notice that some variables change their color. This happens when the variable value has changed since the last evaluation.
Note that you can quickly navigate from a variable on the Variables pane to its declaration in the source code.
To navigate to the source code
- Do one of the following:
Select the desired item in the Variables tab and press F4.
Right-click the desired item in the Variables tab, and select Jump to Source from the context menu.
Inline with code
One more way to see variables values is to look at the code in the editor. By default, JetBrains Rider shows the values of variables at the end of the lines where these variables are declared.
Note, that changed values are also displayed with a different color.
If, for some reason, you want to disable showing values inline with code, in the Debug tool window, click and turn off Show Values Inline.
The editor also provides tooltips for each variable in code. Simply hold the mouse cursor over a particular variable and a tooltip with the variable value will be shown. Note that as well as the Variables pane, tooltips provide the ability to examine nodes' children.
Function return values
The Variables pane will display the return value of any function that is called. This is useful when the result of a method call is not stored in a local variable, for example when just returning another function’s return value or when using method chaining.
Editing variables values
While the program is suspended, you can edit values of almost any variables. This may be convenient, for example, when you want to reproduce a particular context for the debugged function.
To edit a variable value
In the Variables pane of the Debug tool window, select the desired variable.
- Do one of the following:
Right-click the variable and select Set Value... on the context menu.
Specify the new value and press Enter.
Comparing variables values
During debugging, you can compare variables values with the value in the clipboard. This may be especially helpful when debugging strings.
To compare a variable value with the clipboard
In the Variables pane of the Debug tooll window, select the desired variable.
Right-click the variable and select Compare Value with Clipboard on the context menu.
The comparison result will be displayed in the Differences viewer.
Tracking out-of-scope objects
While debugging, you may need to track an object that is already out of scope of the current execution context. You can do this by marking a particular object variable on the Variables pane.
To track an object
Suspend program execution to get to the object in the desired scope.
In the Variables pane of the Debug tool window, right-click the object variable and select Mark Object on the context menu.
In the Select Label window, specify label name and its color.
Add a watch to the Variables pane. When adding the watch, specify the name of the label created on the previous step.
For instance, in the example below we marked the first element of the array with the
firstString label. Even if the element is already out of scope, we still see its value on the Variables pane.