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

WEBINAR:
On-Demand

Full Text Search: The Key to Better Natural Language Queries for NoSQL in Node.js


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

  • Microsoft Azure® is a leading choice for businesses looking to take advantage of the cloud. Azure is particularly appealing to businesses that have already invested in Microsoft on-premises and are now considering running these applications and other workloads in the cloud. To understand how to make this move to Azure, many businesses are turning to managed service providers (MSPs) with specific Azure expertise. Read this white paper to learn the eight key areas to focus on when considering an MSP for an …

  • Mobility is reaching an inflection point in enterprise. Smart enterprises are moving away from tactical point solutions for mobile device management, looking instead for a secure, comprehensive, unified, and future-proof mobile-app platform. Enterprise applications are now at the heart of mobile productivity, data is shared outside the enterprise walls, and the data itself may reside on multiple devices and clouds. Read this guide to learn how a unified endpoint management (UEM) solution is critical to …

Most Popular Programming Stories

More for Developers

RSS Feeds

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