Tuesday, December 22, 2009

Better display of wxTypes in MSVS debugger

This is a quick note about displaying a few wx types in MSVS (2003 and later) debugger as I just discovered, to some surprise, that some people using wx don't know about it. Let me show what I mean with an example: I have the following in my %VSINSTALLDIR%\Common7\Packages\Debugger\autoexp.dat:

[AutoExpand]
... all the existing stuff ...
; wxWidgets types
wxPoint=<x>,<y>
wxSize=<x>*<y>
wxRect=<x>,<y> <width>*<height>

wxDateTime=<m_time.m_ll>ms
wxLongLong=<m_ll>
wxString=<m_impl>


This allows to see the contents of the variables of the types above in a much better way than the default display (e.g. by default tooltips for wxRects only show x, y and width values but the height is truncated -- hardly convenient). I wonder if others have more types to add to this list?

Of course, there are limits to this approach. For example, I'd really prefer to see an ISO 8601 representation of wxDateTime instead of the number of milliseconds since the Unix Epoch which is currently shown. But this probably requires writing a custom visualizer which is a bit more difficult (would anyone have done this already by chance?).

Still, debugging is much nicer when previewing wxStrings is as simple as hovering a mouse over them so if you don't have the above in your autoexp.dat you should really add it there. Just remember that wxString expansion is for 2.9, if you are using 2.8 you need to use <m_pchData,s> instead.

3 comments:

Unknown said...

It is possible to make the visualizer call a user method in code.

I haven't tried this myself, but it should be possible to make a call to return a string representation of wxDateTime. Someone has done this with boost::date_time already.

See both these links:
boost__DateTime.msvc8.vis.txt
date_time_visualizer.hpp

VZ said...

Interesting, thanks!

Unfortunately it doesn't work quite how I'd like it to: you can see the value of the object in the "Quick Watch" dialog but not in the tooltip. At least not with what I did which was:

wxDateTime{
preview (#if ($e.IsValid()) ([wxDumpDate(&($e)),s]) #else (#("NIL")))
}

(reminder: this goes into the "Visualizer" section of the file).

With the above, "NIL" is always shown in the tooltip -- but if you open the "Quick Watch" dialog you see the full date string immediately (without having to expand it, as with boost version), which is nice.

Even more strangely, you just have to use the "#if", without it the visualizer is not taken into account at all somehow.

So this is not perfect but still useful and very simple to do.

SamB said...

Maybe this should go into the documentation for wx, not just the blog? (And if it was already there, maybe it needs to be made easier to find that part?)