我有一个映射元素的迭代器,我希望 gdb 显示该迭代器的“第一个”和“第二个”元素的值。
例如:
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 中找到类似的操作。
我完全愿意有一个函数来传递对象类型,但我也无法让它工作。
有任何想法吗?
谢谢!
我是这样做的:
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)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)