前提条件

(1)需要安装python

[danni@vm-xxx-18 develop]$ python --version
Python 2.6.6

(2)需要有gcc

[danni@vm-xxx-18 develop]$ gcc --version
gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-18)

(3)需要有gdb。并且在gdb安装的时候需要设置python选项。确保GDB版本为7.0或更高版本,这样它支持Python脚本。

[danni@vm-bestgame-18 ~]$ gdb --version
GNU gdb (GDB) 7.4.1

支持查看STL类型的数据的查看的gdb安装
(1)完成基本的gdb安装

wget http://ftp.gnu.org/gnu/gdb/gdb-7.4.1.tar.gz
tar xvzf gdb-7.4.1.tar.gz
cd gdb-7.4.1
./configuration --with-python='/usr/bin/python'

通过操作./configuration -h可以发现并没有发现--with-python的安装选项,不过可以自己加上这个安装选项,可以通过which python找到python的执行路径,通过--with-python='/usr/bin/python'来设置的python的路径
查看python所在的地址:

[danni@vm-xxx-18 gdb-7.4.1]$ which python
/usr/bin/python

(2)激活python的gdb功能
首先checkout:svn checkout svn://gcc.gnu.org/svn/gcc/trunk/libstdc++-v3/python stlprettyprinter
并在用户目录(cd ~)下编写.gdbinit文件,其中sys.path.insert(0, '/home/danni/stlprettyprinter')中的路径即为你svncheckout的目录

[danni@vm-xxx-18 ~]$ cd ~
[danni@vm-xxx-18 ~]$ vim .gdbinit
python
import sys
sys.path.insert(0, '/home/danni/stlprettyprinter')
from libstdcxx.v6.printers import register_libstdcxx_printers
register_libstdcxx_printers (None)
end

(3)如果现在你的gdb可以查看string类型,可以查看vector类型,但是不能查看map类型的数据,则需要检查你的gcc版本
如果你的gcc版本小于4.7,则需要使用另一个printer.py文件替换刚才checkout的文件

[danni@vm-xxx-18 v6]$ cd ~/stlprettyprinter/libstdcxx/v6
[danni@vm-xxx-18 v6]$ rm printers.py
[danni@vm-xxx-18 v6]$ wget https://gcc.gnu.org/svn/gcc/branches/gcc-4_6-branch/libstdc++-v3/python/libstdcxx/v6/printers.py

实例演示
首先编写一个测试文件:

#include <string>
#include <vector>
#include <map>
using namespace std;
int main()
{string a("test string");vector<int> v;v.push_back(1);v.push_back(2);map<int,int> iMap;iMap.insert(make_pair(1,2));return 0;
}

通过 b xxx 进行断点,通过 r 运行程序,通过 p 查看对象的值

[danni@vm-bestgame-18 testStr]$ g++ -g Test.cpp
[danni@vm-bestgame-18 testStr]$ gdb ./a.out
GNU gdb (GDB) 7.4.1
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-unknown-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/danni/testStr/a.out...done.
(gdb) b main
Breakpoint 1 at 0x400ae2: file Test.cpp, line 7.
(gdb) r
Starting program: /home/danni/testStr/a.out Breakpoint 1, main () at Test.cpp:7
7           string a("test string");
(gdb) n
9           vector<int> v;
(gdb) p a
$1 = "test string"
(gdb) n
10          v.push_back(1);
(gdb) n
11          v.push_back(2);
(gdb) p v
$2 = std::vector of length 1, capacity 1 = {1}
(gdb) n
13          map<int,int> iMap;
(gdb) n
14          iMap.insert(make_pair(1,2));
(gdb) n
16          return 0;
(gdb) p iMap
$3 = std::map with 1 elements = {[1] = 2}
(gdb) 

使gdb支持string、vector、map等STL类型数据的查看(linux)相关推荐

  1. string.Format()之格式化数值类型数据

    实列: namespace Demo {class Program{static void Main(string[] args){/*金额显示取整*///Console.WriteLine(stri ...

  2. java解析excel存入map,java解析excel数据,将excel数据转换为实体类,存入数据库

    前一段时间写了一个功能,从数据库中抽取出来的字段,写入到excel文件里:java使用poi把从数据库中取出的数据写入excel 最近实现了一个相反的功能,前台传一个excel文件,在后台解析该exc ...

  3. STL中map和string, vector 用法详解

    1. map 用法详解 std map是STL的一个关联容器,它提供一对一(其中第一个可以称为关键字,每个关键字只能在map中出现一次,第二个可能称为该关键字的值)的数据处理能力,由于这个特性,它完成 ...

  4. C++ STL常用标准库容器入门(vector,map,set,string,list...)

    STL常用标准库容器 C++ STL中最基本以及最常用的类或容器无非就是以下几个: 目录 string vector deque list forward_list queue priority_qu ...

  5. centos升级gdb支持pretty-printer

    centos升级gdb支持pretty-printer pretty-printer说明 升级GDB 配置.gdbinit 常见错误: vscode调试开启pretty-printer 结束语 参考博 ...

  6. c++ list, vector, map, set 区别与用法比较

    List封装了链表,Vector封装了数组, list和vector得最主要的区别在于vector使用连续内存存储的,他支持[]运算符,而list是以链表形式实现的,不支持[]. Vector对于随机 ...

  7. list, vector, map, set 区别与用法比较

    List封装了链表,Vector封装了数组, list和vector得最主要的区别在于vector使用连续内存存储的,他支持[]运算符,而list是以链表形式实现的,不支持[]. Vector对于随机 ...

  8. c++:list, vector, map, set 区别与用法比较

    List封装了链表,Vector封装了数组, list和vector得最主要的区别在于vector使用连续内存存储的,他支持[]运算符,而list是以链表形式实现的,不支持[]. Vector对于随机 ...

  9. std的list, vector, map,multimap, set 区别与用法比较

    List封装了链表,Vector封装了数组, list和vector得最主要的区别在于vector使用连续内存存储的,他支持[]运算符,而list是以链表形式实现的,不支持[]. Vector对于随机 ...

最新文章

  1. linux系统中find怎么用,linux系统中‘find’的详细用法
  2. Ubuntu Server 16.04服务器版配置图解教程06 - 安装MySql
  3. sklearn:sklearn.GridSearchCV函数的简介、使用方法之详细攻略
  4. go语言中文网中的资源
  5. python—range() 函数—步长为正,左闭右开;步长为负,左开右闭
  6. 具有system权限的进程无法访问sdcard
  7. ColorUI从0开始搭建项目
  8. matlab bp结果,BP-networkmatlab BP神经网络实现手写数字识别,使用 。内有测试数据及实验结果,非常适合入门 276万源代码下载- www.pudn.com...
  9. 支付宝小程序开发笔记
  10. 论手机网站(wap)网页广告防屏蔽的方法
  11. 游戏汉化技术内幕——第3章索引和资源的说明
  12. 关于我如何解决了xlsm文件格式的问题
  13. 智能眼镜上可否能有“MIUI”?
  14. 研究开源项目发现的一个人性化的Go语言库
  15. Python @property 详解
  16. 如何制作全息视频--3D max+AE搞定
  17. 7-10 sdut-求交错序列前N项和分数 10
  18. 7-4 王小二分饼 (15分) __C++
  19. mysql front mac安装_Mac下配置安装数据库-MySQL
  20. iOS 内购(In-App Purchase)详解

热门文章

  1. 链表模拟队列quene---C语言
  2. 成功解决ValueError: Expected 2D array, got 1D array instead
  3. 如何更改iTunes备份地址(修改iphone ipad 备份地址) itunes文件目录修改方法 【亲测有效,附带原理说明】...
  4. 求矩阵行列式的值(方阵)——C
  5. 美国名校口味刁钻 最重个人魅力
  6. iphone用微信扫二维码下载app跳转问题解决心得
  7. 分时ddx指标是什么意思 1000字
  8. TensorFlow 之基于Inception V3的多标签分类 retrain
  9. RTL8188CUS Raspberry Pi AP设置
  10. 在Ubuntu中安装eclipse图文详解