Customizing the appearence of your own classes in debug windows

Environment: Visual C++ 6

You may have noticed that for example CString instaces do not show up as `{...}4 in debug windows (watch, variable, etc. and in tooltip when you move the pointer on a variable). Rather, CString "smartly" shows up as `{"string"}4. This feature can be customized to make your own classes appear smartly while debugging, so that you can see the most crucial member varibles at first glance rather than having to expand the non-meaningful `{...}4 at first.

The definitions for the custom formatting reside in autoexp.dat in Common\MSDev98\Bin directory. The file has a fairly good documentation in it, and some good examples as well (including the CString one.) As with the usertype.dat (that has been dealt with in another article here), you'll have to restart MSVC to have the changes take effect.

This is a snippet from the file itself - it explains the syntax quite well.

; type=[text]...
;
; 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 0x0012fde8,s "Hello world"
; su Unicode string 0x007200c4,su "Hello world"
; st String in ANSI or Unicode depending on current setting
;
; The special format <,t> specifies the name of the most-derived 
; type of the object. This is especially useful with pointers or
; references to a base class.
;
; If there is no rule for a class, the base classes are checked for
; a matching rule.

For example, the line for CString is

CString =<m_pchData,st>

If you have a class like this,

class Goo
{
int width;
double height;
char* name;
};

you might define the apperance as follows:

Goo =<name,s> width: <width,i> height: <height,g> 

which would result in the following outlook in the debug window:

{"a goo" width: 5 height: 3.1}

Date Last Updated: April 18, 1999



Comments

  • child window

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

    Originally posted by: chandrika

    hi

    i want to know how to create a child window from a dialog box.

    the appwizard what i've generated can open a dialog box.
    when i click the ok button here it should popup a window.

    thanks for suggestions

    Reply
  • How about CStringArray?

    Posted by Legacy on 12/14/1999 12:00am

    Originally posted by: robin

    I still have a problem with CStringArray

    Reply
  • Re: Displaying arrays

    Posted by Legacy on 04/26/1999 12:00am

    Originally posted by: Ville Herva

    (This was intended to be a reply to the "Displaying arrays"
    
    comment, but I couldn't post it there (the connection just
    hanged.)

    You can use a macro. Here is a rough sketch, you'll propably
    want to customize that.


    Sub EvalArray()
    'DESCRIPTION: Evaluate multiple array items while debugging
    Dim arrayname
    arrayname = InputBox("Enter array name:")

    Dim fromstr
    fromstr = InputBox("from index:")

    Dim tostr
    tostr = InputBox("to index:")

    Dim fromi
    Dim toi
    fromi = fromstr
    toi = tostr

    Dim result

    Dim i
    for i = fromi to toi
    result = result & cstr(i) & ": "
    result = result & Debugger.Evaluate(arrayname & "[" & cstr(i) & "]") & chr(13)
    next


    MsgBox(result)
    End Sub


    To get even better results (such as resizable dialogs to
    evaluate the items in) you can write an add-in. I'm actually
    doing that sort of thing, but it is not ready yet. If
    someone is interested, let be know.

    Reply
  • Visual C++ 5.0

    Posted by Legacy on 04/22/1999 12:00am

    Originally posted by: Philippe Lhoste

    Also found autoexp.dat in DevStudio\SharedIDE\bin for Visual C++ 5.0

    Reply
  • Extending the debug window even more...

    Posted by Legacy on 04/22/1999 12:00am

    Originally posted by: Rick Vestal

    You can use the auto expand functionality to display
    
    very complex data types in practically any manner.

    For instance, we have a datatype that is very
    similar to XML. The data in an instance of this
    class can be very large and very nested. We have
    a tree view that can display these structures, but
    the watch window can only do so much. By adding
    a method to the class that serializes the data into
    a character stream, the auto expand functionality
    can display much more data. If object.fs() is the
    method to produce the character stream, you can add:

    XML =val=<fs(), s>

    to the autoexp.dat file to display the character
    stream.

    NOTE that the debugger doesn't always display this
    right and that sometimes you have to step another
    line or two before the function is truly evaluated
    by the debugger...if anybody knows a solution to
    this, I'd appreciate a note.


    If you want to take this to another level, you can
    write an AddIn that can display the data in the
    hierarchical format (such as the tree view I
    mentioned above). Write the AddIn to create a
    window with your treeview (or whatever) and
    have a place for the user to enter in the
    variable expression. When they want it evaluated, the
    following code can go to the debugger to get
    the serialized data, which can then be processed
    by the data structure and displayed.

    // assuming this is a XML stream....
    CComBSTR str = szBuffer; // the expression to evaluate
    CComBSTR strResult;
    HRESULT hr = pIDebugger->Evaluate(str, &strResult);
    if (FAILED(hr)) {
    MessageBox(hWnd, "Failed to evaluate expression",
    "Error",
    MB_OK | MB_ICONEXCLAMATION);
    SetWindowText(hwndTree, "error in xml format");
    break;
    }

    CString strTemp(strResult);
    XMLTree tree;
    tree.ParseString(strTemp);

    // go display it....


    Reply
  • Does anyone know what the $BUILTIN token does?

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

    Originally posted by: Dave Leigh

    Does anyone know what the $BUILTIN token does?

    I would like to be able to alter the display string based on the state of the object. Is $BUILTIN the key to this?

    Also, does anyone know how enumerated types are converted from integral values into strings?

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

Top White Papers and Webcasts

  • The latest release of SugarCRM's flagship product gives users new tools to build extraordinary customer relationships. Read an in-depth analysis of SugarCRM's enhanced ability to help companies execute their customer-facing initiatives from Ovum, a leading technology research firm.

  • The operational costs of managing an x86 base are taxing IT budgets, making it difficult to fund and staff new initiatives. Today's IT organization must seek efficiencies in its operations and shift to a more agile infrastructure that's flexible enough to adapt to future changes in the business. Read this Q & A session with Jed Scaramella, research manager for IDC's Enterprise Platforms and Data Center Trends, to learn how the integrated nature of the blade platform delivers critically needed efficiencies …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds