STL Support Tools
2015-07-01 16:05
393 查看
When you try to use GDB's "print" command to display the contents of a vector, a stack, or any other GDB abstract data structure, you will get useless results. Instead, download and install one of following tools to properly view the contents
of STL containers from within GDB.
GDB 7.0 will include support for writing pretty-printers in Python. This feature, combined with the pretty-printers in the libstdc++ svn repository, yields the best
way to visualize C++ containers. Some distros (Fedora 11+) ship all this code in a way that requires no configuration; in other cases,
this email message explains how to set everything up. The main points have been redacted here:
Check-out the latest Python libstdc++ printers to a place on your machine. In a local directory, do:
svn co svn://gcc.gnu.org/svn/gcc/trunk/libstdc++-v3/python
Add the following to your ~/.gdbinit. The path needs to match where the python module above was checked-out. So if checked out to: /home/maude/gdb_printers/, the path would be as written in the example:
The path should be the only element that needs to be adjusted in the example above. Once loaded, STL classes that the printers support should printed in a more human-readable format. To print the classes in the old style, use the
/r (raw) switch in the print command (i.e., print /r foo). This will print the classes as if the Python pretty-printers were not loaded.
gdb-stl-views is a set of GDB macros that can display the contents of many STL containers: list, vector, map, multimap, set, multiset, dequeue, stack, queue, priority_queue, bitset, string, and widestring. Writen and currently
maintained by Dan Marinescu - PhD. The author formally disclaims copyright to this source code. In place of a legal notice, here is a blessing: May you do good and not evil. May you find forgiveness for yourself and forgive others. May you share freely, never
taking more than you give!
You can download it
here or
here
Tutorials and an alternative download are
hosted at yolinux.com.
gdb++ is a Perl script which extends gdb. It comes bundled as part of the Devel::GDB::Reflect Perl module. First
use CPAN to install the module, then follow the
gdb++ usage instructions. Developed by Stanford PhD student Antal Novak.
There are other options. Tom Malnar wrote a set of GDB macros similar to Dan's (
http://thread.gmane.org/gmane.comp.gcc.g++.general/4060/focus=4167 ) but it doesn't cover as wide a variety of containers. Gilad Mishne wrote a different set of macros (
http://www.stanford.edu/~afn/gdb_stl_utils/ ) but it is long unmaintained and it works only with SGI's STL implementation, which very few GCC users use.
Iterators: how to display the item the iterator points at (tested on gdb 6 with a list):
print *(iter._M_current)
of STL containers from within GDB.
GDB 7.0 will include support for writing pretty-printers in Python. This feature, combined with the pretty-printers in the libstdc++ svn repository, yields the best
way to visualize C++ containers. Some distros (Fedora 11+) ship all this code in a way that requires no configuration; in other cases,
this email message explains how to set everything up. The main points have been redacted here:
Check-out the latest Python libstdc++ printers to a place on your machine. In a local directory, do:
svn co svn://gcc.gnu.org/svn/gcc/trunk/libstdc++-v3/python
Add the following to your ~/.gdbinit. The path needs to match where the python module above was checked-out. So if checked out to: /home/maude/gdb_printers/, the path would be as written in the example:
python import sys sys.path.insert(0, '/home/maude/gdb_printers/python') from libstdcxx.v6.printers import register_libstdcxx_printers register_libstdcxx_printers (None) end
The path should be the only element that needs to be adjusted in the example above. Once loaded, STL classes that the printers support should printed in a more human-readable format. To print the classes in the old style, use the
/r (raw) switch in the print command (i.e., print /r foo). This will print the classes as if the Python pretty-printers were not loaded.
gdb-stl-views is a set of GDB macros that can display the contents of many STL containers: list, vector, map, multimap, set, multiset, dequeue, stack, queue, priority_queue, bitset, string, and widestring. Writen and currently
maintained by Dan Marinescu - PhD. The author formally disclaims copyright to this source code. In place of a legal notice, here is a blessing: May you do good and not evil. May you find forgiveness for yourself and forgive others. May you share freely, never
taking more than you give!
You can download it
here or
here
Tutorials and an alternative download are
hosted at yolinux.com.
gdb++ is a Perl script which extends gdb. It comes bundled as part of the Devel::GDB::Reflect Perl module. First
use CPAN to install the module, then follow the
gdb++ usage instructions. Developed by Stanford PhD student Antal Novak.
There are other options. Tom Malnar wrote a set of GDB macros similar to Dan's (
http://thread.gmane.org/gmane.comp.gcc.g++.general/4060/focus=4167 ) but it doesn't cover as wide a variety of containers. Gilad Mishne wrote a different set of macros (
http://www.stanford.edu/~afn/gdb_stl_utils/ ) but it is long unmaintained and it works only with SGI's STL implementation, which very few GCC users use.
Iterators: how to display the item the iterator points at (tested on gdb 6 with a list):
print *(iter._M_current)
相关文章推荐
- 使用C++实现JNI接口需要注意的事项
- Linux 自检和 SystemTap
- 关于指针的一些事情
- Python 七步捉虫法
- c++ primer 第五版 笔记前言
- share_ptr的几个注意点
- 路由器的配置与调试
- 对于技术人员的出现了运行时间错误,是否要进行调试的解决方法
- Lua教程(一):在C++中嵌入Lua脚本
- Lua教程(二):C++和Lua相互传递数据示例
- C++联合体转换成C#结构的实现方法
- C++编写简单的打靶游戏
- C++ 自定义控件的移植问题
- C++变位词问题分析
- C/C++数据对齐详细解析
- C++基于栈实现铁轨问题
- C++中引用的使用总结
- C++中调用Lua函数实例
- Lua和C++的通信流程代码实例
- C与C++之间相互调用实例方法讲解