How to dump STL container data in gdb?

I cannot reset the values ​​of the unstable values ​​of the STL container in gdb. variable type std :: unordered_map <> var;

my gdb version is 7.7.1 gdb configuration:

configure --host=x86_64-linux-gnu --target=x86_64-linux-gnu --with-auto-load-dir=$debugdir:$datadir/auto-load --with-auto-load-safe-path=$debugdir:$datadir/auto-load --with-expat --with-gdb-datadir=/usr/local/share/gdb (relocatable) --with-jit-reader-dir=/usr/local/lib/gdb (relocatable) --without-libunwind-ia64 --with-lzma --with-separate-debug-dir=/usr/local/lib/debug (relocatable) --with-system-gdbinit=/etc/gdb/gdbinit --with-zlib --without-babeltrace 

g ++ (Ubuntu 4.8.4-2ubuntu1 ~ 14.04.3) 4.8.4

What is the correct way to print STL n gdb container values?

output of gdb map container:

p var

 $3 = {<std::__allow_copy_cons<true>> = {<No data fields>}, [13/5219] _M_h = {<std::__detail::_Hashtable_base<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<std::basic_string<char, std::char_traits<char>, std::allocator<ch ar> > const, Metrics_s*>, std::__detail::_Select1st, std::equal_to<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::hash<std::basic_string<char, std::ch ar_traits<char>, std::allocator<char> > >, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Hashtable_traits<true, false, true> >> = {<std::__detail:: _Hash_code_base<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> > const, Metric s_s*>, std::__detail::_Select1st, std::hash<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > 
+8
c ++ stl containers gdb
source share
5 answers

Your gdb --configuration output is missing the --with-python clause, so I assume that your gdb really cannot use python extensions. In accordance with this answer SO gdb does not work quite well , it seems that this is necessary for working with printed printing.

My ubuntu 14.04 in docker comes with pretty-printed work, and gdb is configured using --with-python. It seems your gdb installation is somehow configured. You can recompile gdb from sources with the correct parameters or try to clean the reinstallation of gdb from your distribution packages.

+4
source share

Try checking this out: https://gcc.gnu.org/svn/gcc/trunk/libstdc++-v3/python/

And adding this line to yours: ~/.gdbinit

 python import sys sys.path.insert(0, '<Path to SVN Checkout Directory>') from libstdcxx.v6.printers import register_libstdcxx_printers register_libstdcxx_printers (None) end 

If this does not work, you can check the earlier version of SVN closer to the version of GDB that you are using.

Note. . Assuming your GDB has native python support.

Update: In case you use the gdb package from Ubuntu packages, you can try installing the following package to add support for "STL pretty-printing": libstdc++6-4.8-dbg .
With this update, gdb should automatically support pretty print for the STL container.

+2
source share

1) Python is not required by older versions of gdb to print STL objects. The error with python has something to do with your configurations.

gdbinit is not a gdb configuration

2) There is a solution that will work independently: uninstall and reinstall the old ones (look at stl pretty printed packages in your distribution) gdb dbg packages will also check your .bashrc user (you can do something with gdb there, you don’t want to), clean it, restart the terminal and it will work.

Note that there are recent versions of gdb that require python only of a specific version and taste , and they have quite a few errors, and some Linux distributions include them by default, and this is their problem, gdb is not one - it is a tree of things. Make sure you understand correctly, in my opinion, this has nothing to do with python.

Here is a link describing when this bad idea was introduced in gdb and why people liked it https://bbs.archlinux.org/viewtopic.php?id=87299

+2
source share

I assume that you have 2 gdb binaries installed on your system:

  • the one that comes with Ubuntu 14.04
  • the one you created yourself

The one you created yourself does not support beautiful python printers since it was not configured with the --with-python option according to gdb --configure output gdb --configure . This gdb binary is called when you type gdb at the command prompt.

But there must be another binary installed from the Ubuntu dpkg package. It must be located in /usr/bin/gdb and must support printing. Try calling it with the full path:

 /usr/bin/gdb 
0
source share
 define dump_map #arg0 is your unordered map address set $map = $arg0 set $i = 0 set $itr = $map._M_h._M_buckets[0]->_M_nxt while $i < $map._M_h._M_element_count printf "Object name = [ %s ] and Object address = [0x%llx]\n", ((char *)((<give your map name> *)($itr))->_name) , $itr set $itr = $itr->_M_nxt set $i = ($i + 1) end end 
0
source share

All Articles