Skip to content

Commit 0b8b4db

Browse files
authored
Merge pull request #3104 from v-thepet/debugger3
Refresh autos-and-locals-windows and watch-and-quickwatch-windows
2 parents 142c3d5 + f8a4a2a commit 0b8b4db

File tree

2 files changed

+227
-200
lines changed

2 files changed

+227
-200
lines changed
Lines changed: 95 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
2-
title: "Inspect Variables in the Autos and Locals Windows | Microsoft Docs"
2+
title: "Inspect variables in the Autos and Locals windows | Microsoft Docs"
33
ms.custom: "H1Hack27Feb2017"
4-
ms.date: "04/17/2017"
4+
ms.date: "04/17/2018"
55
ms.technology: "vs-ide-debug"
66
ms.topic: "conceptual"
77
f1_keywords:
@@ -17,64 +17,102 @@ manager: douge
1717
ms.workload:
1818
- "multiple"
1919
---
20-
# Inspect Variables in the Autos and Locals Windows in Visual Studio
21-
The **Autos** window (while debugging, **CTRL+ALT+V, A**, or **Debug > Windows > Autos**) and the **Locals** window (while debugging, **CTRL+ALT+V, L**, or **Debug > Windows > Locals**) are quite useful when you want to see variable values while you are debugging. The **Locals** window displays variables that are defined in the local scope, which is generally the function or method that is currently being executed. The **Autos** window displays variables used around the current line (the place where the debugger is stopped). Exactly which variables display in this window is different in different languages. See [What variables appear in the Autos Window?](#bkmk_whatvariables) below.
22-
23-
If you need more information about basic debugging, see [Getting Started with the Debugger](../debugger/getting-started-with-the-debugger.md).
24-
25-
## Looking at objects in the Autos and Locals windows
26-
Arrays and objects are displayed in the Autos and Locals windows as tree controls. Click on the arrow to the left of the variable name to expand the view to show fields and properties. Here is an example of a <xref:System.IO.FileStream?displayProperty=fullName> object in the **Locals** window:
20+
# Inspect variables in the Autos and Locals windows
21+
22+
The **Autos** and **Locals** windows show variable values while you are debugging. The windows are only available during a debugging session.
23+
24+
The **Autos** window shows variables used around the current breakpoint. The **Locals** window shows variables defined in the local scope, which is usually the current function or method.
2725

28-
![Locals&#45;FileStream](../debugger/media/locals-filestream.png "Locals-FileStream")
26+
To open the **Autos** window, while debugging, select **Debug** > **Windows** > **Autos**, or press **Ctrl**+**Alt**+**V** > **A**.
27+
28+
To open the **Locals** window, while debugging, select **Debug** > **Windows** > **Locals**, or press **Alt**+**4**.
29+
30+
If you need more information about basic debugging, see [Getting started with the Debugger](../debugger/getting-started-with-the-debugger.md).
31+
32+
## Use the Autos and Locals windows
33+
34+
Arrays and objects show in the **Autos** and **Locals** windows as tree controls. Select the arrow to the left of a variable name to expand the view to show fields and properties. Here is an example of a <xref:System.IO.FileStream?displayProperty=fullName> object in the **Locals** window:
2935

30-
## <a name="bkmk_whatvariables"></a> What variables appear in the Autos window?
31-
You can use the **Autos** window in C#, Visual Basic, and C++ code. The **Autos** window does not support JavaScript or F#.
36+
![Locals-FileStream](../debugger/media/locals-filestream.png "Locals-FileStream")
3237

33-
In C# and Visual Basic, the **Autos** window displays any variable used on the current or preceding line. For example, if you declare four variables and set them as follows:
38+
A red value in the **Locals** or **Autos** window means the value has changed since the last evaluation. The change could be from a previous debugging session, or because you have changed the value in the window.
3439

35-
```csharp
36-
public static void Main()
37-
{
38-
int a, b, c, d;
39-
a = 1;
40-
b = 2;
41-
c = 3;
42-
d = 4;
43-
}
44-
```
40+
The default numeric format in debugger windows is decimal. To change it to hexadecimal, right-click in the **Locals** or **Autos** window and select **Hexadecimal Display**. This change affects all debugger windows.
41+
42+
## Edit variable values in the Autos or Locals window
4543

46-
If you set a breakpoint on the line `c = 3`; and run the debugger, when execution stops the **Autos** window will look like this:
44+
To edit the values of most variables in the **Autos** or **Locals** windows, double-click the value and enter the new value.
4745

48-
![Autos&#45;CSharp](../debugger/media/autos-csharp.png "Autos-CSharp")
46+
You can enter an expression for a value, for example `a + b`. The debugger accepts most valid language expressions.
4947

50-
Note that the value of `c` is 0, because the line `c = 3` has not yet been executed.
48+
In native C++ code, you might have to qualify the context of a variable name. For more information, see [Context operator (C++)](../debugger/context-operator-cpp.md).
49+
50+
>[!CAUTION]
51+
>Make sure you understand the consequences before you change values and expressions. Some possible issues are:
52+
>
53+
>- Evaluating some expressions can change the value of a variable or otherwise affect the state of your program. For example, evaluating `var1 = ++var2` changes the value of both `var1` and `var2`. These expressions are said to have [side effects](https://en.wikipedia.org/wiki/Side_effect_\(computer_science\)). Side effects can cause unexpected results if you are not aware of them.
54+
>
55+
>- Editing floating-point values can result in minor inaccuracies because of decimal-to-binary conversion of fractional components. Even a seemingly harmless edit can result in changes to some of the bits in the floating-point variable.
56+
57+
## Change the context for the Autos or Locals window
5158

52-
In C++ the **Autos** window displays the variables used at least three lines before the current line (the line at which execution is stopped). If you declare six variables:
59+
You can use the **Debug Location** toolbar to select a desired function, thread, or process, which changes the context for the **Autos** and **Locals** windows.
5360

54-
```C++
55-
void main() {
56-
int a, b, c, d, e, f;
57-
a = 1;
58-
b = 2;
59-
c = 3;
60-
d = 4;
61-
e = 5;
62-
f = 6;
63-
}
64-
```
61+
To enable the **Debug Location** toolbar, click in an empty part of the toolbar area and select **Debug Location** from the dropdown, or select **View** > **Toolbars** > **Debug Location**.
6562

66-
If you set a breakpoint on the line `e = 5;` and run the debugger, when execution stops the **Autos** window will look like this:
67-
68-
![Autos&#45;Cplus](../debugger/media/autos-cplus.png "Autos-Cplus")
69-
70-
Note that the variable e is uninitialized because the code on the line `e = 5;` has not yet been executed.
71-
72-
You can also see the return values of functions and methods in certain circumstances. See [View return values of method calls](#bkmk_returnValue) below.
63+
Set a breakpoint and start debugging. When the breakpoint is hit, execution pauses and you can see the location in the **Debug Location** toolbar.
7364

65+
![Debug Location toolbar](../debugger/media/debuglocationtoolbar.png "Debug Location toolbar")
66+
67+
## <a name="bkmk_whatvariables"></a> Variables in the Autos window
68+
69+
The **Autos** window is available for C#, Visual Basic, and C++ code, but not for JavaScript or F#.
70+
71+
Different code languages display different variables in the **Autos** window.
72+
73+
- In C# and Visual Basic, the **Autos** window displays any variable used on the current or preceding line. For example, in C# or Visual Basic code, declare the following four variables:
74+
75+
```csharp
76+
public static void Main()
77+
{
78+
int a, b, c, d;
79+
a = 1;
80+
b = 2;
81+
c = 3;
82+
d = 4;
83+
}
84+
```
85+
86+
Set a breakpoint on the line `c = 3;`, and start the debugger. When execution pauses, the **Autos** window will display:
87+
88+
![Autos-CSharp](../debugger/media/autos-csharp.png "Autos-CSharp")
89+
90+
The value of `c` is 0, because the line `c = 3` has not yet been executed.
91+
92+
- In C++, the **Autos** window displays the variables used in at least three lines before the current line where execution is paused. For example, in C++ code, declare six variables:
93+
94+
```C++
95+
void main() {
96+
int a, b, c, d, e, f;
97+
a = 1;
98+
b = 2;
99+
c = 3;
100+
d = 4;
101+
e = 5;
102+
f = 6;
103+
}
104+
```
105+
106+
Set a breakpoint on the line `e = 5;` and run the debugger. When execution stops, the **Autos** window will display:
107+
108+
![Autos-C++](../debugger/media/autos-cplus.png "Autos-C++")
109+
110+
The variable `e` is uninitialized, because the line `e = 5` has not yet been executed.
111+
74112
## <a name="bkmk_returnValue"></a> View return values of method calls
75-
In .NET and C++ code you can examine return values when you step over or out of a method call. This functionality is useful when the result of a method call is not stored in a local variable, for example when a method is used as a parameter or as a return value of another method.
113+
In .NET and C++ code, you can examine return values in the **Autos** window when you step over or out of a method call. Viewing method call return values can be useful when they are not stored in local variables. A method could be used as a parameter, or as the return value of another method.
76114
77-
The following C# code adds the return values of two functions:
115+
For example, the following C# code adds the return values of two functions:
78116
79117
```csharp
80118
static void Main(string[] args)
@@ -98,37 +136,13 @@ private static int subtractVars(int i, int j)
98136
}
99137
```
100138

101-
Set a breakpoint on the `int x = sumVars(a, b) + subtractVars(c, d);` line.
102-
103-
Start debugging, and when execution breaks at the first breakpoint, press **F10 (Step Over)**. You should see the following in the **Autos** window:
104-
105-
![AutosReturnValueCSharp2](../debugger/media/autosreturnvaluecsharp2.png "AutosReturnValueCSharp2")
106-
107-
## Why are variable values sometimes red in Locals and Autos windows?
108-
You may notice that the value of a variable is sometimes red in the **Locals** and **Autos** windows. These are variable values that have been changed since the last evaluation. The change could be from a previous debugging session, or because the value was changed in the window.
109-
110-
## Changing the numeric format of a variable window
111-
The default numeric format is decimal, but you can change it to hexadecimal. Right-click inside a **Locals** or **Autos** window and select **Hexadecimal Display**. The change affects all debugger windows.
112-
113-
## Editing a value in a Variable window
114-
You can edit the values of most variables that appear in the **Autos**, **Locals**, **Watch**, and **QuickWatch** windows. For information about **Watch** and **QuickWatch** windows, see [Watch and QuickWatch Windows](../debugger/watch-and-quickwatch-windows.md). Just double-click the value you want to change and add the new the value.
115-
116-
You can enter an expression for a value, for example `a + b`. The debugger accepts most valid language expressions.
117-
118-
In native C++ code, you might have to qualify the context of a variable name. For more information, see [Context Operator (C++)](../debugger/context-operator-cpp.md).
119-
120-
However, you should exercise caution when changing values. Here are some possible issues:
121-
122-
- Evaluating some expressions can change the value of a variable or otherwise affect the state of your program. For example, evaluating `var1 = ++var2` changes the value of `var1` and `var2`.
123-
124-
Expressions that change data are said to have [side effects](https://en.wikipedia.org/wiki/Side_effect_\(computer_science\)), which can produce unexpected results if you are not aware of them. Make sure you understand the consequences of such a change before you make it.
125-
126-
- Editing floating-point values can result in minor inaccuracies because of decimal-to-binary conversion of fractional components. Even a seemingly harmless edit can result in changes to some of the least significant bits in the floating-point variable.
127-
128-
## Changing the window context
129-
You can use the **Debug Location** toolbar to select the desired function, thread, or process, which changes the context for the variable windows. Set a breakpoint and start debugging. (If you do not see this toolbar, you can enable it by clicking in an empty part of the toolbar area. You should see a list of toolbars; select **Debug Location**). When the breakpoint is hit, execution stops and you can see the Debug Location toolbar, which is the bottom row of the following illustration.
130-
131-
![DebugLocationToolbar](../debugger/media/debuglocationtoolbar.png "DebugLocationToolbar")
132-
133-
## See Also
134-
[Debugger Windows](../debugger/debugger-windows.md)
139+
To see the return values of the `sumVars()` and `subtractVars()` method calls in the Autos window:
140+
141+
1. Set a breakpoint on the `int x = sumVars(a, b) + subtractVars(c, d);` line.
142+
143+
1. Start debugging, and when execution pauses at the breakpoint, select **Step Over** or press **F10**. You should see the following return values in the **Autos** window:
144+
145+
![Autos return value C#](../debugger/media/autosreturnvaluecsharp2.png "Autos return value C#")
146+
147+
## See also
148+
[Debugger windows](../debugger/debugger-windows.md)

0 commit comments

Comments
 (0)