在gdb中显示解除引用的STL迭代器

kch*_*se2 12 c++ gdb iterator stl dbx

我有一个map元素的迭代器,我希望gdb向我展示迭代器的"first"和"second"元素的值.例如:

std::map<int,double> aMap;
...fill map...
std::map<int,double>::const_iterator p = aMap.begin();
Run Code Online (Sandbox Code Playgroud)

我可以在代码中使用p.first和p.second,但是在gdb中看不到它们.对于它的价值,在dbx中可以执行类似"print p.node.second_"的操作,但我可以在gbd中找到类似的东西.

我完全愿意有一个函数,我传递对象类型,但我也无法让它工作.

有任何想法吗?谢谢!

Joh*_*itb 18

我是这样做的:

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)
Run Code Online (Sandbox Code Playgroud)