【发布时间】:2017-03-18 09:03:07
【问题描述】:
在调试时,我在内存中有一个地址,并且知道驻留在该地址的对象的类型,并且我希望调试器显示该对象的该实例。对于不是模板的类型,这可以通过 print 命令完成,但对于作为模板实例化的类型似乎会失败。
查看此示例代码:
template<typename T>
class X
{
public:
X() {
printf("a\n");
}
};
class Y
{
public:
Y() {
printf("a\n");
}
};
int main(void)
{
X<int> x;
Y y;
return 1;
}
当我运行程序时,进入 main 并尝试将随机有效地址解释为指向 X 和 Y 对象的指针,前者失败:
(lldb) p *(Y*)0x0000000100000ee6
(Y) $0 = {}
(lldb) p *(X<int>*)0x0000000100000ee6
warning: could not load any Objective-C class information. This will significantly reduce the quality of type information available.
error: use of undeclared identifier 'X'
error: expected '(' for function-style cast or type construction
error: expected expression
有没有办法在 lldb 中做到这一点? (编辑:Mac OS X lldb-360.1.65 和 lldb-310.2.37)
【问题讨论】: