如何在gdb中转储STL容器数据? [英] How to dump STL container data in gdb?

查看:211
本文介绍了如何在gdb中转储STL容器数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法在gdb中转储STL无序映射容器值。变量类型是
std :: unordered_map<> var;



我的gdb版本 - 7.7.1
Gdb配置:

  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-jit-reader-dir = / usr / local / lib / gdb(可重新定位)
--without- libunwind-ia64
--with-lzma
--with-separate-debug-dir = / usr / local / lib / debug(可重新定位)
--with-system-gdbinit = / etc / gdb / gdbinit
--with-zlib
--without-babeltrace

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

打印STL容器值的正确方法是什么n gdb?



地图容器的gdb输出:

p var

  $ 3 = {< std :: __ allow_copy_cons< true>> = {<无数据字段>},[13/5219] 
_M_h = {< std :: __ detail :: _ Hashtable_base< std :: basic_string< char,std :: char_traits< char> std ::分配器<炭> >,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,公制
s_s *> ;, std :: __ detail :: _ Select1st,std :: hash< std :: basic_string< char,std :: char_traits< char>,std :: allocator< char> > >


解决方案

您的 gdb --configuration 输出缺少 - with-python 子句,所以我假设你的gdb确实不能使用python扩展。根据这个SO回答 gdb漂亮打印不工作它似乎是必要的为漂亮打印工作。

我的docker中的ubuntu 14.04带有漂亮的打印工作,以及gdb使用--with-python配置。看来,你的gdb安装是以某种方式定制的。您可以使用正确的选项从源代码重新编译gdb,也可以尝试从发行包中重新安装gdb。


I am not able to dump STL unordered map container values in gdb. variable type is std::unordered_map<> var;

my gdb version - 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 right way to print STL container values n gdb?

gdb output of 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> > >

解决方案

Your gdb --configuration output is missing --with-python clause, so I assume your gdb really cannot use python extensions. According to this SO answer gdb pretty printing is not working it seems to be necessary for pretty-print to work.

My ubuntu 14.04 in docker comes with pretty-print working as well as gdb is configured using --with-python. It seems, your gdb installation is somehow customized. You can either recompile the gdb from sources with correct options or try to clean reinstall gdb from your distribution packages.

这篇关于如何在gdb中转储STL容器数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆