Auto-Expanding User-Defined (and STL) Types in the Debugger

Have you ever wondered why CStrings, CPoints, and CRects always display their contents in the debugger, while std::strings and your own data types don't? I have, especially since I've started using the Standard Library. I find it especially annoying to click on the little plus sign to view the contents of a std::string object.

In Visual C++ 5 (and probably 6, although I don't have it to test), there is an undocumented feature that controls this display (called auto-expansion). It is controlled by a file named AutoExp.DAT in the \DevStudio\SharedIDE\Bin directory. That file is pretty much self-documenting. An excerpt from the file reads:

"While debugging, Data Tips and items in the Watch and Variable windows are automatically expanded to show their most important elements. The expansion follows the format given by the rules in this file. You can add rules for your types or change the predefined rules."

To resolve my frustration with std::string, I simply added the following lines in the [AutoExpand] section of the file:

; from string
std::basic_string<char,std::char_traits<char>,std::allocator<char>> =<_Ptr,s>

Note that the spacing (or lack thereof) is important. Also note that I was not able to use just std::string or std::basic_string<. I needed to use the fully expanded type, including all template parameters.

If you use Unicode and std::wstring, you'll need an entry such as the following (untested):

std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t>> =<_Ptr,su>

You'll also need to change the DisplayUnicode setting to 1 in the [Unicode] section of the file so that Unicode strings are automatically expanded as text, rather than arrays of unsigned short.


  • Problems with pointers

    Posted by Legacy on 03/20/2002 12:00am

    Originally posted by: John Culham

    This is a great tip, however I can't make it work for pointers. I use:
    CMyClass =Name:<oName.m_pchData,st> length:<length,lu>
    which works great for anything defined as
    CMyClass oMyObject;
    but if I define it as a pointer (90% of the time for this class)
    CMyClass* opMyObject = new CMyClass;
    then the values for name and length in the tooltip are just "???". Has anyone else come across this problem? Or better yet solved it?

  • Beware of the evil member function call

    Posted by Legacy on 03/21/2000 12:00am

    Originally posted by: JCAB

    This tip is great. I found a nasty bug in the debugger,
    though, when I tried to get fancy. Just try this:


    It'll work (amazing, isn't it?).


    Try this program:

    void func(const std::vector<int> &k)
    printf("%d\n", k.size());

    void main(void)
    std::vector<int> k(3, 0);

    If you trace into the func() call, you're up to a surprise.
    At least, when you have the call stack window open.
    The problem is that the call stack window displays the
    values of the parameters of the function call, and it
    doesn't like calling functions in your process for that.

    It's funny: if you have threads, they'll actually run even
    if you have the program stopped inside the function...

  • stlport version + options

    Posted by Legacy on 02/28/2000 12:00am

    Originally posted by: Ian Tory

    for stlpost 3.2 do:

    stlport::_String_base<char,stlport::allocator<char> >=<_M_start,s>

    also, for all versions, missing out the ending ",s" gives address plus string, including it gives string only

    - Ian

  • Similar rule for Objectspace STL

    Posted by Legacy on 10/21/1999 12:00am

    Originally posted by: Jon Hanson

    ; from string
    lc_bst_helper =<handle_->data_,s>

  • I nominate this for tip of the year!

    Posted by Legacy on 03/24/1999 12:00am

    Originally posted by: Chris Hafey

    I always wanted to do this, but never knew how. I am so glad MS put this in a config file instead of hard coding it. Thanks for posting the tip!

  • std::base_string already defined in VC++ 6.0

    Posted by Legacy on 03/16/1999 12:00am

    Originally posted by: Franky Braem

    Thanks for this tip : It's a great help for debugging an application.
    remarks :
    In Version 6.0 of VC++ std::basic_string is already defined
    in the autoexp.dat file.

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • The open source cloud computing project OpenStack has come a long way since NASA and Rackspace launched it in 2010. Backed by leading technology infrastructure providers including Cisco, Dell, EMC, HP, IBM, Intel, and VMware, OpenStack underpins significant workloads at an increasingly diverse set of organizations, including BWM, CERN, Comcast, eBay, and Wal-Mart. For CIOs engaged in broader programs to win, serve, and retain customers -- and refocus business technology (BT) spend -- a planned and pragmatic …

  • Today there's no such thing as "one size fits all" when it comes to enterprise mobile computing for field services workers. While the business benefits of automation are clear (e.g. decreased downtime, increased customer satisfaction), selecting the right mobile device mix for the job is becoming more complex. This whitepaper examines 3 challenges organizations face when considering a mobile device deployment for field teams: Integrating new mobile devices with legacy technology Adapting to multi-generational …

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date