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

  • You may already know about some of the benefits of Bluemix, IBM's open platform for developing and deploying mobile and web applications. Check out this webcast that focuses on building an Android application using the MobileData service, with a walk-through of the real process and workflow used to build and link the MobileData service within your application. Join IBM's subject matter experts as they show you the way to build a base application that will jumpstart you into building your own more complex app …

  • Targeted attacks and advanced threats are customized to infiltrate your unique IT infrastructure, evade conventional defenses, and remain hidden while stealing your corporate data. To detect these criminal intrusions, analysts and security experts agree that organizations should deploy advanced threat protection as part of an expanded security monitoring strategy. For this comparative analysis of breach detection systems, product analysis reports and comparative analysis reports are used to create the security …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds