开发者

How to see values in boost:unordered_map in debug mode with vs2010

开发者 https://www.devze.com 2023-04-01 02:29 出处:网络
I have the following code... typedef boost::unordered_map<开发者_如何学JAVAint, boost::unordered_map<int, float>* > User_item_rating_map;

I have the following code...

typedef boost::unordered_map<开发者_如何学JAVAint, boost::unordered_map<int, float>* > User_item_rating_map;

As you can see, the value of the map is a pointer. How can I get the value in the map. If I use (*(ret[int]))[int], I can't seem to get the value. What am I doing wrong?


The file AUTOEXP.DAT is the file that tells Visual Studio how to represent data structures in the debugger.

Some of the descriptions can be quite easy, like this one for CSize:

CSize =cx=<cx> cy=<cy>

But they can also be very complex, like this one for bitset:

std::bitset<*>{
    preview
    (
        #(
        "[",
            $c.digits,
        "](",
        #array
        (
            expr :  ($c._Array[$i / $c._Bitsperword] >> ($i % $c._Bitsperword)),
            size :  $c.digits
        ) : [($e & 1),d],
        ")"
        )
    )
    children
    (
        #array
        (
            expr :  ($c._Array[$i / $c._Bitsperword] >> ($i % $c._Bitsperword)),
            size :  $c.digits
        ) : (bool)($e & 1))
}

You can either write your own description for the boost unordered_map, or possibly someone else already did it for you. Take a look at https://svn.boost.org/trac/boost/ticket/4209 (this seems like the thing you need).


I had the same trouble, went to see whether the suggested fix from Boost Ticket #4209 worked, which didn't. I could see the total number of the elements, but not the content.

So, the choices are, to switch to VS2012, for which there is a Plug-In, or invest in figuring out the format in VS2010 and fixing the existing suggested code.

Or, and that's what I did, use std::tr1::unordered_set / map instead. There is a visualizer for it in Visual Studio. And, later on, after debugging, if you wish, switch back to boost.


Open your file autoexp.dat with a text editor. You usually find it in:

C:\Program Files\Microsoft Visual Studio 10.0\Common7\Packages\Debugger\autoexp.dat

Add the following code to the section [Visualizer]. This code should be added after the definition of another visualizer.

;------------------------------------------------------------------------------
;  boost unordered collections
;------------------------------------------------------------------------------
boost::unordered::unordered_map<*,*,*,*,*>{
    preview (
    #(
        "[",
        $e.table_.size_,
        "](",
        #list(
            head: $e.table_.buckets_[$e.table_.bucket_count_].next_,
            size: $e.table_.size_,
            next: next_
        ) : #(*((std::pair<$T1 const ,$T2>*)&(*(boost::unordered::detail::ptr_node<std::pair<$T1 const ,$T2> > *)(&$e)).value_base_)),
        ")"
    ))
    children(
    #(
        size: ($e.table_.size_),
        #list(
            head: $e.table_.buckets_[$e.table_.bucket_count_].next_,
            size: $e.table_.size_,
            next: next_
        ) : #(*((std::pair<$T1 const ,$T2>*)&(*(boost::unordered::detail::ptr_node<std::pair<$T1 const ,$T2> > *)(&$e)).value_base_)),
    ))
}


boost::unordered::unordered_set<*,*,*,*>{
    preview (
    #(
        "[",
        $e.table_.size_,
        "](",
        #list(
            head: $e.table_.buckets_[$e.table_.bucket_count_].next_,
            size: $e.table_.size_,
            next: next_
        ) : #(*(($T1*)&((*(boost::unordered::detail::ptr_node<$T1>*)(&$e)).value_base_))),
        ")"
    ))
    children(
    #(
        size: ($e.table_.size_),
        #list(
            head: $e.table_.buckets_[$e.table_.bucket_count_].next_,
            size: $e.table_.size_,
            next: next_
        ) : #(*(($T1*)&((*(boost::unordered::detail::ptr_node<$T1>*)(&$e)).value_base_))),
    ))
}

For instance I have added it before the rows

;------------------------------------------------------------------------------
;  std::plus, etc. from <functional>
;------------------------------------------------------------------------------

On your next debug session it should work.

I've tested it with Microsoft Visual Studio 2010 Version 10.0.40219.1 SP1Rel and boost 1.61.0.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号