Pretty print of stdlib C++

Sysprogs forums Forums VisualGDB Pretty print of stdlib C++

Viewing 15 posts - 1 through 15 (of 18 total)
  • Author
    Posts
  • #548
    Nox Metus
    Participant

    I’m considering to use VisualGDB to debug remotely Linux applications in Visual Studio. I’m curious whether VisualGDB will pretty print standard library structures, like std::vector, std::map, std::list, etc?

    #2344
    support
    Keymaster

    Yes, this is supported since v2.4. If you are encountering problems with your version of the STL library, please provide us a screenshot of the expanded watch window so that we can diagnose your problem further.

    #2345
    Nox Metus
    Participant

    It’s not that I’m encountering problems, I accidentally stumbled upon this product and contemplating should I try it or not :). It sounds like worth trying. If it supports VS2012.

    #2346
    support
    Keymaster

    Hi,

    Yes, we support VS2012 starting from v2.7.

    #2347
    kbzowski
    Participant

    Hi, I think that I have similar problem with VisualGDB 3.0
    What information should I see while debugging std::map container? I have seen something like that (screenshoot attached) , but where are the keys/values? I was hoping to see something like a dictionary in C#.

    #2348
    support
    Keymaster

    Hi,

    Are you using clang to compile your code? Clang has a known debug information generation bug that prevents VisualGDB from obtaining a reference to the tree nodes. Could you please provide us with the errors listed in the “GDB Session” window?

    #2349
    kbzowski
    Participant

    Hi,
    I am using gcc (GCC) 4.4.6 20120305 (Red Hat 4.4.6-4) (from Scientific Linux)
    and gdb 7.5.1.

    I compiled that version of GDB myself, but I have checked also GDB from my distro’s rpm repository – GNU gdb (GDB) Red Hat Enterprise Linux (7.2-56.el6). Same situation has occurred.

    GDB Session window contains:

    No type “_Rep_type” within class or namespace “std::map, std::allocator > >”.

    #2333
    support
    Keymaster

    Hi. Sorry for the delayed reply. We were trying to reproduce the problem on our Linux setups, but were unsuccessful.
    Your problem is caused by VisualGDB trying to get cast the tree node pointer to a class that contains information about the descendents and the value. Normally this class is available as std::map<...>::_Rep_type::_Link_type.
    It looks like your version of STL has different names for it. Please try the following steps to get the name of the tree node class:

    1. Create a trivial program:

    std::map test;
    test[3] = 3.5;

    2. Step into the second line by pressing F11.
    3. Keep stepping into the STL code until you reach the _M_end() method:

    _Link_type
    _M_end()
    { return static_cast<_link_type>(&this->_M_impl._M_header); }

    4. Please take a note of the return type of _M_end(). In our case it’s _Link_type.
    5. Use the ‘call stack’ window to find the innermost frame that belongs to the map class itself. In our case this is map<...>::lower_bound():

    iterator
    lower_bound(const key_type& __x)
    { return _M_t.lower_bound(__x); }

    6. Find where _M_t is declared and take a note of its type. In our case it’s _Rep_type:

    _Rep_type _M_t;

    7. In the GDB Console select ‘All GDB interaction’ and find the line causing the error you mentioned. Copy it and rerun the command to ensure that GDB still complains.
    8. Modify the line to use the node type name you have derived. Ensure that GDB executes the command successfully.
    9. Send us the node type name you have found. We will update our type visualizers to support your version of STL.

    #2334
    kbzowski
    Participant

    Hi,
    In call stack window I had seen something like:

     std::_Rb_tree, std::_Select1st >, std::less, std::allocator > >::_M_end()	C/C++
    std::_Rb_tree
    , std::_Select1st >, std::less, std::allocator > >::lower_bound() C/C++
    > std::map
    , std::allocator > >::lower_bound() C/C++
    std::map
    , std::allocator > >::operator[]() C/C++
    main() C/C++

    I have selected third line. The code was exactly like yours:

          iterator
    lower_bound(const key_type& __x)
    { return _M_t.lower_bound(__x); }

    On 127 line of stl_map.h there is a declaration like:

          /// The actual tree structure.
    _Rep_type _M_t;

    I checked “GDB Session” and used command which had caused error before:

    -data-evaluate-expression "(void *)((std::map, std::allocator > >::_Rep_type::_Link_type)0x0)->_M_left"

    Same error was still appearing:

    No type "_Rep_type" within class or namespace "std::map, std::allocator > >".

    Moreover I have found another errors

    -var-create - * "_Rep_type"
    mi_cmd_var_create: unable to create variable object

    I am attaching whole log to this post.

    Edit.
    I have attached log for simple project. Previous was based on my current project.

    #2335
    support
    Keymaster

    Hi,

    Please find where exactly _Rep_Type is declared on your machine (i.e. within which class). Alternatively you can add _M_t to the watch window (use correct stack frame) and see the type column for more hints.

    #2336
    kbzowski
    Participant

    Hi,
    If I’ve understood you correctly _M_t is according ‘Watch Window’ declared as:

    std::_Rb_tree, std::_Select1st >, std::less, std::allocator > >
    #2337
    support
    Keymaster

    Hi,

    That is correct. However, we need to find a type that can be represented from the type of your map. E.g. std::map<...>::some_name. I.e. there should be a definition ‘typedef std::_Rb_tree<...> some_name;’ somewhere inside the std::map implementation. The name used in this typedef is what we are looking for.

    Please try to find the declaration of _M_t. The code is pretty obscure, so you might need to use search instead of ‘go to definition’. Let us know the type used in the declaration.

    #2338
    kbzowski
    Participant

    Is this what you mean?

    typedef _Rb_tree, key_compare, _Pair_alloc_type> _Rep_type;
    #2339
    support
    Keymaster

    This can be it. Is it declared directly inside std::map<> or somewhere else? How exactly is _M_t declared?

    #2340
    kbzowski
    Participant

    Yes, it is declared in stl_map.h inside class map.
    First few lines. You can find there declaration of _Rep_type and _M_t

      template ,
    typename _Alloc = std::allocator > >
    class map
    {
    public:
    typedef _Key key_type;
    typedef _Tp mapped_type;
    typedef std::pair value_type;
    typedef _Compare key_compare;
    typedef _Alloc allocator_type;

    private:
    // concept requirements
    typedef typename _Alloc::value_type _Alloc_value_type;
    __glibcxx_class_requires(_Tp, _SGIAssignableConcept)
    __glibcxx_class_requires4(_Compare, bool, _Key, _Key,
    _BinaryFunctionConcept)
    __glibcxx_class_requires2(value_type, _Alloc_value_type, _SameTypeConcept)

    public:
    class value_compare
    : public std::binary_function
    {
    friend class map<_Key, _Tp, _Compare, _Alloc>;
    protected:
    _Compare comp;

    value_compare(_Compare __c)
    : comp(__c) { }

    public:
    bool operator()(const value_type& __x, const value_type& __y) const
    { return comp(__x.first, __y.first); }
    };

    private:
    /// This turns a red-black tree into a [multi]map.
    typedef typename _Alloc::template rebind::other
    _Pair_alloc_type;

    typedef _Rb_tree,
    key_compare, _Pair_alloc_type> _Rep_type;

    /// The actual tree structure.
    _Rep_type _M_t;

    I have checked newest version of stl_map.h from gcc 4.8.0 and declaration of _Rep_type is the same. I can not understand, how that can cause problems.

Viewing 15 posts - 1 through 15 (of 18 total)
  • You must be logged in to reply to this topic.