Customize autoexp.dat for own types in VS2005

Suppose you have a class foo like this:

class foo 
	int X;
	int Y;
	int Z;

	foo(int x = 0, int y = 0, int z = 0): X(x), Y(y), Z(z) {}

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:



type      Name of the type (may be followed by <*> for template
          types such as the ATL types listed below).
text      Any text.Usually the name of the member to display, 
          or a shorthand name for the member.
member    Name of a member to display.
format    Watch format specifier. One of the following:

Letter  Description                 Sample         Display
------  --------------------------  ------------   -------------
d,i     Signed decimal integer      0xF000F065,d   -268373915
u       Unsigned decimal integer    0x0065,u       101
o       Unsigned octal integer      0xF065,o       0170145
x,X     Hexadecimal integer         61541,X        0X0000F065
l,h     long or short prefix for    00406042,hx    0x0c22
          d, i, u, o, x, X
f       Signed floating-point       3./2.,f        1.500000
e       Signed scientific-notation  3./2.,e        1.500000e+000
g       Shorter of e and f          3./2.,g        1.5
c       Single character            0x0065,c       'e'
s       Zero-terminated string      pVar,s         "Hello world"
su      Unicode string              pVar,su        "Hello world"

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=0x00000001, Y=0x00000002, Z=0x00000008}. 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:

foo =X=< X, X >, Y=< Y, X >, Z=< Z, X >

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:

template < typename T >
class foo 
	T X;
	T Y;
	T Z;

	foo(T x, T y, T z): X(x), Y(y), Z(z) {}

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 <*>.

foo< * > =X=< X, X >, Y=< Y, X >, Z=< Z, X >

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:

typename[|typename...] {
    preview (
    stringview (
    children (

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.

foo< * > {
		[$c.X, X], 
		", Y=",
		[$c.Y, X], 
		", Z=",
		[$c.Z, X]

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

	sum: [$c.X + $c.Y + $c.Z, d]

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:

	X: [$c.X, X],
	Y: [$c.Y, X],
	Z: [$c.Z, X],
	[sum]: [$c.X + $c.Y + $c.Z, d]

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 I recommend reading this article for more information avout visualizers.

6 Replies to “Customize autoexp.dat for own types in VS2005”

  1. 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.

  2. 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?

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

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.