Boost logo

Boost Users :

From: Daniel Krügler (dsp_at_[hidden])
Date: 2008-03-03 03:58:32


Hello,

just recently I introduced boost::optional as default
type to represent optional/nullable types in a sub-project
of our company, which generates C++ code out of UML models.

While this worked seamless, programmers not yet used to
boost::optional complained that they could not really see,
what such type "contains" if they try to observe it in the
debugger. I searched for a solution, only finding the discussion
around the article

"how to see the actual value of a 'boost::optional<__int64>' in VS2005
debugger"

from 2006-07-26, which did not gave a satisfactory answer.

Please ignore this message, if the here described solution (or
a better one), which I worked out this weekend, is already
well-known (but I would appreciate if someone could give me
a link to the already known solution).

My approach was to modify the unofficially supported debugger
configuration file autoexp.dat, which typically is found at

${SomePath}\Microsoft Visual Studio 8\Common7\Packages\Debugger\autoexp.dat

If you never have heard of this file, you should make a copy
of it, before doing the modifications I discuss here. A more
detailled description what can be done with this file, can be
read here (but you don't need to do that, if you just want to
get the results I propose here):

http://www.virtualdub.org/blog/pivot/entry.php?id=120

Just use your preferred text editor to open the autoexp.dat, jump
at the end of it and go five rows back. You should be +/- 1 row
about the line with the content:

; This section lets you define your own errors for the HRESULT display.

Go one row back (row 1957 in my file), which should be the end of the
so-called [Visualizer] section. Now insert here the text provided at the
end of this article and just start you debugger session (you don't need
to restart the studio) - you should have a nice view on each
boost::optional, even those which are optionals of references. I tested
the visualizer for the following boost versions:

1.30.0
1.31.0
1.32.0
1.33.0
1.33.1
1.34.1

and all of them worked.

I would like to thank the boost developers for their great
contributions (where boost::optional is only one of them) and
I hope you can even more enjoy boost::optional with this trick.
Unfortunately I have not found similar solutions for other
compilers yet, e.g for gcc, which probably is due to my lack
of experience with them but I would appreciate if someone else
publishes them, too.

Greetings from Bremen,

Daniel Krügler

;------------------------------------------------------------------------------
; Visualizer for boost::optional, boost::optional_detail::optional_base
;------------------------------------------------------------------------------

boost::optional<*>|boost::optional_detail::optional_base<*> {
         preview
        (
                 #if($e.m_initialized)
                (
                        *(($T1 *) (&$e.m_storage.dummy_.data[0]))
                )
                #else
                (
                        "?"
                )
        )
        
           children
        (
                 #if($e.m_initialized)
                (
                        #(value:
                          *(($T1 *) (&$e.m_storage.dummy_.data[0]))
                        )
                )
                #else
                (
                        "?"
                )
        )
}
;------------------------------------------------------------------------------


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net