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.



Comments

  • 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?

    Reply
  • 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:

    std::vector<*>=<size()>

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

    But....

    Try this program:

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

    void main(void)
    {
    std::vector<int> k(3, 0);
    func(k);
    }
    ---8<--------------------------------

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

    Reply
  • 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

    Reply
  • 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>

    Reply
  • 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!

    Reply
  • 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.

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

Top White Papers and Webcasts

  • On-demand Event Event Date: September 10, 2014 Modern mobile applications connect systems-of-engagement (mobile apps) with systems-of-record (traditional IT) to deliver new and innovative business value. But the lifecycle for development of mobile apps is also new and different. Emerging trends in mobile development call for faster delivery of incremental features, coupled with feedback from the users of the app "in the wild." This loop of continuous delivery and continuous feedback is how the best mobile …

  • Java developers know that testing code changes can be a huge pain, and waiting for an application to redeploy after a code fix can take an eternity. Wouldn't it be great if you could see your code changes immediately, fine-tune, debug, explore and deploy code without waiting for ages? In this white paper, find out how that's possible with a Java plugin that drastically changes the way you develop, test and run Java applications. Discover the advantages of this plugin, and the changes you can expect to see …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds