簡體   English   中英

如何在gdb中轉儲STL容器數據?

[英]How to dump STL container data in gdb?

我無法在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-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

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

地圖容器的gdb輸出:

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> > >

你的gdb --configuration輸出缺少--with-python子句,所以我假設你的gdb實際上不能使用python擴展。 根據這個SO回答gdb漂亮的打印不起作用似乎有必要漂亮的打印工作。

我的ubuntu 14.04在docker中配備了漂亮的打印工作,並且gdb是使用--with-python配置的。 看來,你的gdb安裝是以某種方式定制的。 您可以使用正確的選項從源重新編譯gdb,也可以嘗試從分發包中清除重新安裝gdb。

試試看看: https//gcc.gnu.org/svn/gcc/trunk/libstdc++-v3/python/

並將這些行添加到您的: ~/.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

如果它不起作用,您可以從SVN中檢出較舊的版本,該版本更接近您正在使用的GDB版本。

注意:假設您的GDB啟用了python后端。

更新:如果您正在使用Ubuntu軟件包中的gdb軟件包,您可以嘗試安裝以下軟件包以添加對“STL漂亮打印”的支持libstdc++6-4.8-dbg
有了這個更新,gdb應該自動支持STL容器的漂亮打印。

1)舊版本的gdb不需要Python來打印STL對象。 python的錯誤與你的配置有關。

gdbinit不是gdb配置

2)有一個解決方案無論如何都可以工作:卸載並重新安裝舊的解決方案(在你的發行版上查找stl漂亮的打印包)gdb dbg包也檢查你的用戶的.bashrc(你可以用gdb做一些你不想要的東西) ),清除它,重新啟動終端,它會工作。

注意有最新版本的gdb需要python只有特定的版本和風格 ,它們有很多錯誤,一些Linux發行版包含它們作為默認值,這是他們的問題,gdb不是一回事 - 它是一個事物樹。 確保你得到正確的,我認為它應該與python無關。

下面是描述gdb中引入這個壞主意的鏈接以及為什么人們似乎喜歡它https://bbs.archlinux.org/viewtopic.php?id=87299

我的猜測是你的系統中安裝了2個gdb二進制文件:

  • Ubuntu 14.04附帶的那個
  • 你自己建造的那個

根據gdb --configure輸出,你自己構建的那個不支持python pretty打印機,因為它沒有配置--with-python選項。 在命令提示符下鍵入gdb時,將調用此gdb二進制文件。

但是應該從Ubuntu dpkg包中安裝另一個二進制文件。 它應該位於/usr/bin/gdb並且應該支持漂亮的打印。 嘗試使用完整路徑調用它:

/usr/bin/gdb
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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM