Suppose you have a class foo like this:

And you have a variable f(1, 2, 3) what you watch in your Watch window. The window looks like this:

Default expansion for foo

The field Value shows a default expansion of the object, {X=1 Y=2 Z=3}. However, this can be changed by modifying a file called autpexp.dat, located in the Visual Studio installation folder, under Common7\Packages\Debugger. This file allows the control of several things in the debugger, such as the string displayed in the Value column, the functions the debugger skips when stepping, etc. One important limitation however, is that it does not support complex expression, for which it simply displays “???”. This file is loaded each time you start the debugger.

The Autoexp.dat file consists in a set of rules, called AutoExpand rules, specified on a single line and having the format:


where

The AutoExpand rules must be located under the [AutoExpand] section, because the file also contains rules for visualizing types when the object is expanded. These visualization rules are located under [Visualizer] and are a feature new in VS2005.

Going back to our foo class, suppose you use this class heavily and you don’t like the default string shown in the Value column, and you would like it to be like this: {X=0×00000001, Y=0×00000002, Z=0×00000008}. That means using comma to separate the fields and display the values as hexadecimal numbers. What you would have to do is adding a AutoExpand rule like this:

It says something like this: display X followed by = and the value of member X of foo in hexadicimal, followed by comma, space, Y and = followed by the value of member Y of foo in hexadecimal, and so on. Debugging now, will show a different string:

Custom auto expand string for foo

But now let’s imagine that our foo class was actually a template class, like this:

The rule above would not help for an object foo f(1, 2, 3) and the default format would be used. That is so because template types have a different form: we need to use <*>.

With this rule the string is the same as in the above image (the type though changes to foo).

What is this good for? Well, I have shown you a simple example here, but suppose you have complex types, with a lot of members, and the default string shown by the debugger doesn’t help you. To see the info you actually need in the watch window or when you put the mouse over the variable you would have to expand the object and scroll down, perhaps expand aggregated objects, etc. to reach what you actually need on a regular basis. Creating a custom rule for the auto displayed value allows you to show exactly the information you need, in the form you want. For instance you may always want to see the numeric values of X,Y and Z from foo as hexadecimal, but you switched for decimal view in the debugger (from the context menu of the Watch window). That won’t affect the way you view your type, because of the custom rule.

A second part of autoexp.dat file is dedicated to visualization rules. These are mappings from types to display form, shown when you expand the object. Unlike the simple AutoExpand rules, these are more complex and have a dedicated scripting language, which unfortunatelly is not documented.

The basic form of a rule is:

The three sections have the following purpose:

  • preview: an expression (string literal or expression) to be shown in the Watch, QuickWatch or Command window; if the preview section is present and you also have a AutoExpand rulu for it, the AutoExpand rule is ignored;
  • children: offer the possibility to construct hierarchies;
  • stringview: used to compose the string that is shown in the Text, XML or HTML visualizer; for instance when you have a string, it shows a magnifying glass on the right; clicking it opens a modal dialog that displays the full content of the variable

Considering the template version of foo, the visualizer template bellow sets the text to be shown in the preview. It’s the same result as with the AutoExpand rule.

If you are interested to see the sum of the values, in decimal, you could add a children element like this:


The Watch window now looks like this:

Visualizer with childrens

But now the X, Y and Z members are gone. You can shown them modifying the children:

Visualizer with childrens

To show original members with the auto evaluation, you can use [$c, !]. However, the parser seems to be unstable, and many times it yields errors that may confuse it, or it could work in a way you don’t understand. At least that’s my case.

The visualizers are more complicated. They allow displaying of array, lists, trees, and could contain conditional statements. You actually have to use variable $c to dereference the current variable. A good attempt to document it can be found at http://www.virtualdub.org/blog/pivot/entry.php?id=120. I recommend reading this article for more information avout visualizers.

Hits for this post: 38657 .
Trackback

5 comments untill now

  1. Gravatar
  2. Gravatar
    mariusbancila @ 2007-04-09 13:16

    No, it wouldn’t have been more easier because autoexp.dat is a mean for customizing the native debugger. What you show is an attribute for managed types.

  3. Gravatar
    Ghanshyam mann @ 2009-05-08 12:59

    hi Marius
    i have some question in custumize the autoexp.dat, below is scenario-
    if i have my own class and i want the attribute os this class to be cast in other class. for example-
    class A(
    int d_a;
    )
    class B
    {
    }

    in Autoexp.dat can i cast the d_a to B class?

  4. Gravatar
    Ermoghen @ 2010-07-07 12:03

    And what can be done if you have
    std::vector vect;
    vect[index]?
    Now, when trying to evaluate that, you will get
    CXX0058: Error: overloaded operator not found on Visual Studio 2008.

  5. Gravatar

Add your comment now