配置GDB支持STL调试

原生GDB不能支持STL调试,要进行STL调试必须进行一些配置才行,但网上的一些配置说明已经过时了,因此重新总结一下。

环境

Ubuntu 14.04 32位

GDB 7.7

步骤

  1. Check-out最新的调试工具到本地一个文件夹下,比如 ~/yourname/gdb_printers

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

  2. 将下列内容添加到 ~/.gdbinit 文件夹中, 其中的路径名改成上一步Check-out的工具对应的路径名

    python
    import sys
    sys.path.insert(0, '/home/yourname/gdb_printers/python')
    sys.path.append("/home/yourname/gdb_printers/python/libstdcxx/v6")
    from libstdcxx.v6.printers import register_libstdcxx_printers
    end

使用效果

如果代码是这样的:

vector a = {2, 3, 6, 7};

调试效果是这样的:

(gdb) p a
$1 = std::vector of length 4, capacity 4 = {2, 3, 6, 7}

参考

http://sourceware.org/gdb/wiki/STLSupport

http://stackoverflow.com/questions/26205564/gdb-pretty-printing-importerror-no-module-named-printers

http://blog.csdn.net/fdl19881/article/details/8710636

本文章迁移自http://blog.csdn.net/timberwolf_2012/article/details/40478407

/** * RECOMMENDED CONFIGURATION VARIABLES: EDIT AND UNCOMMENT THE SECTION BELOW TO INSERT DYNAMIC VALUES FROM YOUR PLATFORM OR CMS. * LEARN WHY DEFINING THESE VARIABLES IS IMPORTANT: https://disqus.com/admin/universalcode/#configuration-variables*/ /* var disqus_config = function () { this.page.url = PAGE_URL; // Replace PAGE_URL with your page's canonical URL variable this.page.identifier = PAGE_IDENTIFIER; // Replace PAGE_IDENTIFIER with your page's unique identifier variable }; */ (function() { // DON'T EDIT BELOW THIS LINE var d = document, s = d.createElement('script'); s.src = 'https://chenzz.disqus.com/embed.js'; s.setAttribute('data-timestamp', +new Date()); (d.head || d.body).appendChild(s); })();