Opened 12 years ago

Closed 12 years ago

Last modified 6 years ago

#4209 closed Feature Requests (wontfix)

Visualizer VS 2008 to boost::unordered_map

Reported by: fernandoofj@… Owned by: Daniel James
Milestone: To Be Determined Component: unordered
Version: Boost 1.42.0 Severity: Cosmetic
Keywords: Cc:

Description

I need to visualize the unordered_map for debug. Can you help me?

Attachments (2)

unordered-visualizers.dat (3.4 KB ) - added by Daniel James 12 years ago.
Visualizer for the unordered containers
boost_1_49_0_unordered_VC10.dat (1.4 KB ) - added by JotaDeHace@… 10 years ago.
autoexp.dat entries for unordered map and set visualizers working in VC10.0 for boost 1.49.0

Download all attachments as: .zip

Change History (18)

comment:1 by Daniel James, 12 years ago

Sorry, I don't use Visual Studio, so I can't really. In the past there was an effort to create visualizers, but I don't think they ever attempted creating one of the unordered containers, you can read about it on the wiki, the information there might be helpful if you wish to write one.

comment:2 by stl@…, 12 years ago

See my BoostCon 2010 presentation at http://www.filetolink.com/17ad36ef .

VC's visualizer for std::tr1::unordered_map "cheats" because it's backed by a std::list. If boost::unordered_map isn't represented like this, visualizing it may be difficult or impossible.

comment:3 by fernandoofj@…, 12 years ago

I made this script below for AutoExp.dat and this works for simple cases, however, it dont works for these cases (bold):

boost::unordered_map<unsigned int, boost::unordered_map<unsigned int, int>> boost::unordered_map<unsigned int, std::list<int>>

--> Script <--

boost::unordered_map<*,*,*,*,*>{

preview (

#(

", $e.table_.size_,(", #array (

expr : $e.table_.buckets_[$i], size : $e.table_.bucket_count_,

) : #(

#array (

expr: $e, size: $e.next_ != 0

) : #(

#list(

head : $e.next_, next : next_

) : ((std::pair<$T1 const ,$T2> *)(boost::unordered_detail::value_base<std::pair<$T1 const ,$T2> > *)(boost::unordered_detail::hash_node<std::allocator<std::pair<$T1 const ,$T2> >,boost::unordered_detail::ungrouped> *)&$e)

)

),")"

)

)

children (

#(

[raw members]: [$c,!], #array (

expr : $e.table_.buckets_[$i], size : $e.table_.bucket_count_,

) : #(

#array (

expr: $e, size: $e.next_ != 0

) : #(

#list(

head : $e.next_, next : next_

) : ((std::pair<$T1 const ,$T2> *)(boost::unordered_detail::value_base<std::pair<$T1 const ,$T2> > *)(boost::unordered_detail::hash_node<std::allocator<std::pair<$T1 const ,$T2> >,boost::unordered_detail::ungrouped> *)&$e))

)

)

)

)

}

comment:4 by anonymous, 12 years ago

Owner: changed from Daniel James to John Maddock

comment:5 by John Maddock, 12 years ago

Why has this been assigned to me?

in reply to:  5 comment:6 by anonymous, 12 years ago

Owner: changed from John Maddock to Daniel James

by Daniel James, 12 years ago

Attachment: unordered-visualizers.dat added

Visualizer for the unordered containers

comment:7 by Daniel James, 12 years ago

Milestone: Boost 1.43.0To Be Determined

I couldn't get that to work, so I tried writing one. I've attached what I've got so far. It crashes for uninitialized containers, I'm not sure how to work round that - maybe only display up to a maximum size? I'll try to get back to this, but it might be a while, so don't let that stop you working on it. I think it could be done a little better if I didn't use allocators to pass value_type, which was a bit of an odd thing to do, so I might look into changing that.

comment:8 by Daniel James, 12 years ago

Resolution: wontfix
Status: newclosed

Sorry, this is beyond me. I'm not a Visual C++ user so I'm not going to be able to complete this.

comment:9 by brian.ventre@…, 11 years ago

I started looking at this yesterday, and haven't gotten very far, but wanted to add what I have found so that others can start somewhere.

So far, the original attached file has mostly worked for me under VS2005SP1 (only tested unordered_set & unordered_map). However, as one of the earlier posters noted, it does not work for the case:

boost::unordered_map<int, boost::unordered_set<int> >

The problem is the $T2 substitution. When VS does the text substitution in the pointer cast, it simply replaces $T2 with the second template argument. The problem is the ambiguity with templates and the >> string. The original line is:

((std::pair<$T1 const ,$T2> *)(boost::unordered_detail::value_base<std::pair<$T1 const ,$T2> > *)(boost::unordered_detail::hash_node<std::allocator<std::pair<$T1 const ,$T2> >,boost::unordered_detail::ungrouped> *)&$e)

If you have a plain map, like say unordered_map<int,int>, then this expands to:

((std::pair<int const ,int> *)(boost::unordered_detail::value_base<std::pair<int const ,int> > *)(boost::unordered_detail::hash_node<std::allocator<std::pair<int const ,int> >,boost::unordered_detail::ungrouped> *)&$e)

VS is ok with this, and the visualizer works. If you have a map where the second template argument is itself a template, (like unordered_map<int,unordered_set<int> >), you get:

((std::pair<int const ,unordered_set<int>> *)(boost::unordered_detail::value_base<std::pair<int const ,unordered_set<int>> > *)(boost::unordered_detail::hash_node<std::allocator<std::pair<int const ,unordered_set<int>> >,boost::unordered_detail::ungrouped> *)&$e)

VS is NOT ok with this. The problem is in the >> that results due to the plain text substitution it performs. A workaround would be to add a space after each instance of $T2 in the original line:

((std::pair<$T1 const ,$T2 > *)(boost::unordered_detail::value_base<std::pair<$T1 const ,$T2 > > *)(boost::unordered_detail::hash_node<std::allocator<std::pair<$T1 const ,$T2 > >,boost::unordered_detail::ungrouped> *)&$e)

This fixes the case where the second template argument is itself a template, but breaks the first case (where it is not). So, with all of this, you can have one or the other (templates or no templates...).

My naive workaround (and I don't have it in front of me, sorry), is to double up the entire #array statement, with one version being the "with spaces" and one the "without". This means you end up with double the elements in the visualizer, half of which are always (error), while the other half are correct. That gets me at least half-way there, while being more expensive with screen real-estate.

Hope this helps anyone else who stumbles across this page.

by JotaDeHace@…, 10 years ago

autoexp.dat entries for unordered map and set visualizers working in VC10.0 for boost 1.49.0

comment:10 by anonymous, 10 years ago

After much frustration trying to find working visualizers for unordered_map and unordered_set, I bit the bullet and created a couple that work for me under Visual Studio 10.0 with boost version 1.49.0. I've attached a file to this ticket with those visualizers. Hope it can save someone some of the debugging frustrations I've had with these very useful data structures.

J.D. Herron

email: JotaDeHace@gmail.com

comment:11 by Daniel James, 10 years ago

Thanks for sharing. The data structure had changed since the older visualizers were written, which is why none of them work now. It might be a good idea to share this on the developer list, could possibly start a collection of visualizers somewhere?

This visualizer won't work for allocators with custom pointer types, which don't use ptr_node. I'm not sure if there's anything that can be done about that.

Also, it might break in an upcoming version, as I'm changing the way values are stored. Now that forwarding constructors are possible the hacks used to allocate aligned space might not be needed. At least that should simplify things a bit.

comment:12 by dlaugt@…, 10 years ago

Great the file is still working for boost 1.51 with VC10. Is it possible to have the unordered_multimap and unordered_multiset versions?

comment:13 by dlaugt@…, 10 years ago

It seems that single and multi are the same versions. It works fine for me.

in reply to:  13 comment:14 by anonymous, 10 years ago

How did you make it work? I'm using boost 1.51 and VS 2010. But it shows size of container correctly but not it's contents. Did you modify dat file?

Replying to dlaugt@…:

It seems that single and multi are the same versions. It works fine for me.

comment:15 by Daniel James, 10 years ago

I don't think the relevant people are reading this. I don't know anything about Visual Studio visualizers so I can't help. You might have better luck on the boost user list, or perhaps stackoverflow or a Visual Studio forum.

comment:16 by teolazza@…, 6 years ago

Here is my version. I've tested it on VS2010, SP1 and with boost 1.61.0

;------------------------------------------------------------------------------
;  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_))),
    ))
}
Note: See TracTickets for help on using tickets.