Pretty printers for cards throwing an error like

I set up pretty printers using http://wiki.eclipse.org/CDT/User/FAQ#How_can_I_inspect_the_contents_of_STL_containers.3F . It works successfully for vector and other containers. However, I cannot check the cards, as in the example below:

#include <map> #include <iostream> using namespace std; int main () { map <int, string> mapIntToString; map <int, int> mapInt2; mapIntToString.insert (map <int, string>::value_type (3, "Three")); mapInt2.insert (map <int, int>::value_type (3, 4)); return 0; } 

When printing using gdb, the following error appears:

 (gdb) p mapInt2 $1 = std::map with 1 elementsTraceback (most recent call last): File "/home/myuser/opt/gdb_printers/python/libstdcxx/v6/printers.py", line 422, in children rep_type = find_type(self.val.type, '_Rep_type') File "/home/myuser/opt/gdb_printers/python/libstdcxx/v6/printers.py", line 45, in find_type raise ValueError, "Cannot find type %s::%s" % (str(orig), name) ValueError: Cannot find type std::map<int, int, std::less<int>, std::allocator<std::pair<int const, int> > >::_Rep_type 
+6
source share
2 answers

Which compiler (and which version) did you use to create the test source?

I assume this was not the latest version of g++ . Here is what I get with g++ 4.4.3-4ubuntu5 :

 $ gdb -q ./a.out Reading symbols from /tmp/a.out...done. (gdb) b 12 Breakpoint 1 at 0x400de3: file t.cc, line 12. (gdb) r Breakpoint 1, main () at t.cc:12 12 return 0; (gdb) p mapInt2 $1 = std::map with 1 elements = {[3] = 4} 

Update:

This is what I get for the version: g ++ (Ubuntu 4.4.3-4ubuntu5) 4.4.3

I see a problem. The instructions you referenced are incorrect .

In particular, the instructions show: svn co svn://gcc.gnu.org/svn/gcc/trunk/libstdc++-v3/python , but the problem is that the python code reaches the internal elements of libstdc++ and therefore must match these internal elements ( for this reason, pretty printers are part of GCC, not part of GDB, a fact bruce.banner complained about).

When you made the new svn co ... , you received a copy of the python code that no longer matches your internal libstdc++ elements, and that causes problems.

Specifically, svn log shows that find_type was added here:

 r183732 | tromey | 2012-01-30 08:25:11 -0800 (Mon, 30 Jan 2012) | 27 lines 

This is much later than gcc-4.4.3 . What you want to do is get pretty printers matching your version of libstdc++ , for example:

 svn co svn://gcc.gnu.org/svn/gcc/branches/gcc_4_4_3_release/libstdc++-v3/python 

With the exception of the command, the above will not work, because gcc 4.4.3 precedes cute printers.

Regardless, the implementation of std::map (and most of the remaining internal STL elements) has not changed between 4.4.3 and 4.6, and this command works:

  svn co svn://gcc.gnu.org/svn/gcc/branches/gcc-4_6-branch/libstdc++-v3/python 
+18
source

On my system, the type _Rep_type not a public type std::map (this is a private typedef), so the script is trying to determine the type of the variable <yourmap>._M_t , which is of type _Rep_type ...

I tried:

 typedef std::map<int,int> map_t; map_t m; m.insert(map_t::value_type(3,4)); 

then in gdb I can print key 3 like this (after the print function from the script, I linked below):

 p *(int*)(void*)(m._M_t._M_impl._M_header._M_left+1) 

Where _M_t in std::map is of type _Rb_tree , but the type is not publicly available on the map (you can see this in the map header, namely in the <path/to/std-headers/dir/bits/stl_map.h .

Not sure if this helps one bit, basically it seems to be a problem with the beautiful python print function that you are loading.

I just tried adding material from the GNU GDB Debugger Command Cheat Sheet from yolinux.com to .gdbinit (I googled for gdb pretty print ), and with this I get a reasonable output:

 (gdb) pmap m int int elem[0].left: $3 = 3 elem[0].right: $4 = 4 
0
source

Source: https://habr.com/ru/post/907433/


All Articles