用gdb检查标准容器(std :: map)内容 [英] Inspecting standard container (std::map) contents with gdb

查看:218
本文介绍了用gdb检查标准容器(std :: map)内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设有这样的事情:

  #include< map> 
int main(){
std :: map< int,int>米;
m [1] = 2;
m [2] = 4;
return 0;
}

我想能够检查运行程序的地图的内容从gdb。

如果我尝试使用下标运算符,我得到:

 (gdb)pm [1 ] 
尝试取值不在内存中的地址。

使用find方法不会产生更好的结果:

 (gdb)p m.find(1)
无法评估函数 - 可能内联

有没有办法完成这个?

解决方案

我认为没有,至少不是如果你的源被优化等等,但是有一些gdb的宏可以检查STL容器:



http://sourceware.org/ml/gdb/2008-02/msg00064.html



但是,我不使用,所以YMMV


Supposing to have something like this:

#include <map>
int main(){
    std::map<int,int> m;
    m[1] = 2;
    m[2] = 4;
    return 0;
}

I would like to be able to inspect the contents of the map running the program from gdb.
If I try using the subscript operator I get:

(gdb) p m[1]
Attempt to take address of value not located in memory.

Using the find method does not yield better results:

(gdb) p m.find(1)
Cannot evaluate function -- may be inlined

Is there a way to accomplish this?

解决方案

I think there isn't, at least not if your source is optimized etc. However, there are some macros for gdb that can inspect STL containers for you:

http://sourceware.org/ml/gdb/2008-02/msg00064.html

However, I don't use this, so YMMV

这篇关于用gdb检查标准容器(std :: map)内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆