【发布时间】:2018-12-23 04:49:32
【问题描述】:
似乎对于几个 STL 容器,GDB 省略了打印其模板参数。例如
(gdb) whatis a
type = std::vector<int>
这给我带来了麻烦。
(gdb) whatis std::vector<int>::_M_impl
No type "vector<int>" within class or namespace "std".
(gdb) p *reinterpret_cast<std::vector<int>*>(0x7fffffffd920)
A syntax error in expression, near `*>(0x7fffffffd920)'.
要得到我想要的,我必须手动添加未显示的模板参数。
(gdb) whatis std::vector<int, std::allocator<int> >::_M_impl
type = std::_Vector_base<int, std::allocator<int> >::_Vector_impl
(gdb) p *reinterpret_cast<std::vector<int, std::allocator<int> >*>(0x7fffffffd920)
$5 = ......
但是,这并不理想,因为很难在通用程序中添加这些省略的模板参数。比如给定std::map<int, double>,我怎么知道有多余的模板参数Compare和Allocator,从而能够得到std::less<Key>和std::allocator<std::pair<const Key, T> >
有没有办法让 GDB 在不省略模板参数的情况下打印类型?还是有其他方法可以解决我的问题?
【问题讨论】:
-
@Jans 怎么是重复的?