Inspecting standard container (std::map) contents with gdb(使用 gdb 检查标准容器 (std::map) 内容)
问题描述
假设有这样的东西:
#include <map>
int main(){
std::map<int,int> m;
m[1] = 2;
m[2] = 4;
return 0;
}
我希望能够从 gdb 中检查运行该程序的地图的内容.
如果我尝试使用下标运算符,我会得到:
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.
使用 find 方法不会产生更好的结果:
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?
推荐答案
我认为没有,至少如果你的源代码经过优化等没有.但是,有一些 gdb 宏可以为你检查 STL 容器:
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
不过,我不使用这个,所以YMMV
However, I don't use this, so YMMV
这篇关于使用 gdb 检查标准容器 (std::map) 内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 gdb 检查标准容器 (std::map) 内容


基础教程推荐
- 运算符重载的基本规则和习语是什么? 2022-10-31
- 如何在 C++ 中处理或避免堆栈溢出 2022-01-01
- C++,'if' 表达式中的变量声明 2021-01-01
- 什么是T&&(双与号)在 C++11 中是什么意思? 2022-11-04
- 设计字符串本地化的最佳方法 2022-01-01
- C++ 标准:取消引用 NULL 指针以获取引用? 2021-01-01
- 您如何将 CreateThread 用于属于类成员的函数? 2021-01-01
- C++ 程序在执行 std::string 分配时总是崩溃 2022-01-01
- 调用std::Package_TASK::Get_Future()时可能出现争用情况 2022-12-17
- 如何定义双括号/双迭代器运算符,类似于向量的向量? 2022-01-01