本文介绍了在gdb中显示取消引用的STL迭代器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个迭代器到map元素,我想gdb显示迭代器的第一和第二元素的值。
例如:
I have an iterator to a map element, and I would like gdb to show me the values of the "first" and "second" elements of that iterator.For example:
std::map<int,double> aMap;
...fill map...
std::map<int,double>::const_iterator p = aMap.begin();
我可以在代码中使用p.first和p.second, gdb。对于什么是值得的,在dbx中可以做一些像print p.node.second_,但是我可以在gbd中找到类似的东西。
I can use p.first and p.second in the code, but can't see them in gdb. For what it's worth, in dbx one could do something like "print p.node.second_", but I can find anything similar in gbd.
我完全愿意有一个函数,我传递的对象类型,但我已经无法让它工作。
I am totally willing to have a function into which I pass the object types, but I've been unable to get that to work either.
任何想法?
谢谢!
Any ideas?Thanks!
推荐答案
这是我怎么做:
This GDB was configured as "i686-pc-linux-gnu"...
(gdb) list
1 #include <iostream>
2 #include <map>
3
4 int main()
5 {
6 std::map<int, int> a;
7 a[10] = 9;
8 std::map<int, int>::iterator it = a.begin();
9 ++it;
10 }
(gdb) b test.cpp:9
Breakpoint 1 at 0x8048942: file test.cpp, line 9.
(gdb) r
Starting program: /home/js/cpp/a.out
Breakpoint 1, main () at test.cpp:9
9 ++it;
(gdb) set print pretty on
(gdb) p it
$1 = {
_M_node = 0x94fa008
}
(gdb) p *it
$2 = (class std::pair<const int, int> &) @0x94fa018: {
first = 10,
second = 9
}
(gdb)
这篇关于在gdb中显示取消引用的STL迭代器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!