What is Autos Window?

The developers in Microsoft have done a great job by bringing a great number of nice features, however, some of these features are poorly documented or even not documented at all.

Autos Window in the Visual Studio Debugger is one of the best example of the gaps between implementation and documentation. I'm sure you have seen this window before, as it's shown by default while you are debugging, if not, you can always find it from the Debug menu:

The MSDN document hasn't been updated since Visual Studio .NET 2003, which can be found at http://msdn.microsoft.com/en-us/library/aa290702.aspx:

The Autos window displays variables used in the current statement and the previous statement. (For Visual Basic, it displays variables in the current statement and three statements on either side of the current statement.) 

The document does leave us with some questions:

  1. What's the definition of variable? Is this the same concept as we are talking about the compiler frontends?
  2. What's the definition of used? What happens if I have a parameter that never got reference inside the function?
  3. What's the definition of statement? Is this the same concept as we are talking about parsing in compiler frontends?
  4. What's the meaning of previous statement? Is it based on the execution order (note that some statements donnot execute at all, such like plain variable definition) or just a lexical thing?
  5. How should I interpret "three statements on either side of the current statement"?

Generally speaking, debuggers wouldn't care about source code, it knows nothing about the C++ preprocessing or the syntax (the only exception is the expression evaluator, which would be another topic). The magic of source debugging was brought by symbol files. The private PDB contains the path and checksum of source files, as well as the line number information (PDB actually supports line and column number, and this has been used in C# already), debugger just read from the symbols to get these information.

Let's open Visual Studio 2010 and take a look at the following snippet in C:

int x;
int y;
int z;
int a;
int b;
int c;
int main(int argc)
  return b + c;

Set a breakpoint at the line of return statement, bring up the Autos Window:

First, it looks like the ordering in the Autos Window is based on variable name, so we got another question "what would happen if there is a duplicated variable name?".

Now let's switch to another snippet:

int foo(int* x)
  return *x;

int main(int argc)
  return foo(&argc);

When we hit the breakpoint, the Autos Window would be:

Step into the function foo and step out, now the Autos Window would look like:

As you see, the return value is displayed as "foo returned" in the Autos Window, if you right click and select Add Watch, you will be welcomed with an error message CXX0013: Error: missing operator.

Okay, I've given enough questions and hints, now it is time to try out by yourself, hopefully you could understand a bit more on what the Autos Window is and the way it works.

Skip to main content