GDB pretty printer: linux下用gdb调试c++时如何更好的查看STL容器值
来源:互联网 发布:迪士尼影业 知乎 编辑:程序博客网 时间:2024/06/05 14:09
GDB pretty printer 提供了更方便的STL容器显示方法能够方便debug,虽然以前也有通过其它脚本方式显示STL内容的方法,
但是这种方案应该是效果最好的。
看下效果:
对于一个 vector<vector<Leaf> > m_nodeLevel;的显示如下
(gdb) p ngram_builder.m_nodeLevel
$3 = std::vector of length 3, capacity 3 = {std::vector of length 2, capacity 2 = {
{<ngram::Model::Leaf> = {id = 0, {freq = 908576172, pr = 2.49999994e-06}},
child = 0, bow = 0.0666622296}, {<ngram::Model::Leaf> = {id = 16777215, {
freq = 1, pr = 1.40129846e-45}}, child = 99097, bow = 0}},
std::vector of length 99098, capacity 99098 = {{<ngram::Model::Leaf> = {id = 10,
{freq = 1037405847, pr = 0.104275875}}, child = 0, bow = 1.53522229},
{<ngram::Model::Leaf> = {id = 129, {freq = 858932647, pr = 4.1507203e-08}},
…..
对于下面的程序,显示一个string
#include <string>
std::string str = "hello world";
int main ()
{
return 0;
}
原来GDB显示效果:
(gdb) print str
$1 = {static npos = 4294967295,
_M_dataplus = {<std::allocator<char>> = {<__gnu_cxx::new_allocator<char>> = {<No data fields>}, <No data fields>}, _M_p = 0x804a014 "hello world"}}
现在的显示效果:
(gdb) print str
$1 = hello world
如何使用:
1.下载一个支持python support 的gdb,似乎官网的gdb就可以但是我安装之后显示还是不支持
Python脚本,最后google 到了下面这个可以用的
http://github.com/jellycn/gdb-python/
./configure && make && make install即可
2.下载最新的 Python libstdc++ printers 放到你的机器上
svn co svn://gcc.gnu.org/svn/gcc/trunk/libstdc++-v3/python
3.在你的~路径下的.gdbinit文件中加上下面的东西, 注意'/home/suhaibo/soft/python'替换成2步骤你具体放置的路径。
python
import sys
sys.path.insert(0, '/home/chg/soft/python')
from libstdcxx.v6.printers import register_libstdcxx_printers
register_libstdcxx_printers (None)
end
但是这种方案应该是效果最好的。
看下效果:
对于一个 vector<vector<Leaf> > m_nodeLevel;的显示如下
(gdb) p ngram_builder.m_nodeLevel
$3 = std::vector of length 3, capacity 3 = {std::vector of length 2, capacity 2 = {
{<ngram::Model::Leaf> = {id = 0, {freq = 908576172, pr = 2.49999994e-06}},
child = 0, bow = 0.0666622296}, {<ngram::Model::Leaf> = {id = 16777215, {
freq = 1, pr = 1.40129846e-45}}, child = 99097, bow = 0}},
std::vector of length 99098, capacity 99098 = {{<ngram::Model::Leaf> = {id = 10,
{freq = 1037405847, pr = 0.104275875}}, child = 0, bow = 1.53522229},
{<ngram::Model::Leaf> = {id = 129, {freq = 858932647, pr = 4.1507203e-08}},
…..
对于下面的程序,显示一个string
#include <string>
std::string str = "hello world";
int main ()
{
return 0;
}
原来GDB显示效果:
(gdb) print str
$1 = {static npos = 4294967295,
_M_dataplus = {<std::allocator<char>> = {<__gnu_cxx::new_allocator<char>> = {<No data fields>}, <No data fields>}, _M_p = 0x804a014 "hello world"}}
现在的显示效果:
(gdb) print str
$1 = hello world
如何使用:
1.下载一个支持python support 的gdb,似乎官网的gdb就可以但是我安装之后显示还是不支持
Python脚本,最后google 到了下面这个可以用的
http://github.com/jellycn/gdb-python/
./configure && make && make install即可
2.下载最新的 Python libstdc++ printers 放到你的机器上
svn co svn://gcc.gnu.org/svn/gcc/trunk/libstdc++-v3/python
3.在你的~路径下的.gdbinit文件中加上下面的东西, 注意'/home/suhaibo/soft/python'替换成2步骤你具体放置的路径。
python
import sys
sys.path.insert(0, '/home/chg/soft/python')
from libstdcxx.v6.printers import register_libstdcxx_printers
register_libstdcxx_printers (None)
end
- GDB pretty printer: linux下用gdb调试c++时如何更好的查看STL容器值
- gdb调试-查看STL容器
- gdb 查看 STL 容器值
- GDB调试STL容器
- Linux下的c如何进行GDB调试
- GDB对STL容器的查看
- gdb调试c++的STL容器
- Linux下C语言的调试 - gdb
- Linux下C语言的gdb调试
- linux下用gdb调试c程序
- linux下用gdb调试c程序
- gdb 查看 stl容器 zz
- Qt Creater、Gdb之Pretty Printer小记
- GDB调试STL复杂容器
- 使用GDB调试STL容器
- gdb调试,查看stl容器信息,string,vector等
- linux下的gdb调试
- Linux下的GDB调试
- oracle时间 格式代码出现两次,小时值必须介于 1 和 12 之间
- asp.net 读取xml节点下的内容
- 在 Linux 上实现基于 Socket 的多进程实时通信
- Java类型
- YUV的一些资料
- GDB pretty printer: linux下用gdb调试c++时如何更好的查看STL容器值
- JNI的某些数组和字符串类型转换(转)
- 输入法核心数据结构及算法的设计
- qt 中使用正则表达式去除匹配到的内容
- C# webBrowser禁止在新窗口打开,强制在本窗口打开 (转载)
- const用法详解
- 【操作系统】文件--文件再解
- LGP993使用心得和Android手机使用建议
- Android开发知识点总结