2016-04-27 67 views
1

我正在调试一些模板代码,并希望lldb向我展示一个帧变量的实际类型(c型),而不是一个怪异复杂的typedef。实际的类型可能类似于“int”或“unsigned char”,但是它只显示typedef,就好像它不知道具体的模板实例。可以显示typedef的实际类型吗?

例如:

template <typename T> 
struct helper 
{ 
    using type = long; 
}; 

int main(int argc, const char * argv[]) { 

    using var_t = typename helper<short>::type; 

    var_t foo = 1; 
} 

在对 “var_t富= 1” 设置断点停止显示

foo = (var_t)0 

我真的需要看到类似

foo = (long)0 

有任何方式来做到这一点,或找出解决的类型是什么?

我使用的XCode 7.3和LLDB-350.0.21.3

回答

3

有没有办法告诉变量打印机显示解析类型,而不是声明变量的类型。你可以找出了一个typedef解析的类型使用的image lookup类型搜索模式:

(lldb) image lookup -t var_t 
1 match found in /private/tmp/foo: 
id = {0x000000b2}, name = "var_t", byte-size = 8, decl = foo.cpp:9, compiler_type = "typedef var_t" 
    typedef 'var_t': id = {0x00000043}, name = "helper<short>::type", byte-size = 8, decl = foo.cpp:4, compiler_type = "typedef helper<short>::type" 
    typedef 'helper<short>::type': id = {0x000000eb}, name = "long int", qualified = "long", byte-size = 8, compiler_type = "long" 

这里的另一种方式来获得从Python API相同的信息,如果你想使用:

(lldb) script 
Python Interactive Interpreter. To exit, type 'quit()', 'exit()' or Ctrl-D. 
>>> foo_var = lldb.frame.FindVariable("foo") 
>>> foo_type = foo_var.GetType() 
>>> print foo_type 
typedef var_t 
>>> print foo_type.GetCanonicalType() 
long 

如果你需要做很多事情,你可以编写一个基于Python的lldb命令来打印完全解析的类型。有信息在这里:

http://lldb.llvm.org/python-reference.html

如何做到这一点。

+1

这让我走上了一条有用的轨道。它仍然报告类型而不考虑具体的模板实例。我发现添加-A标志至少会显示所有可能的解析类型。我想要的就是在那里 - 我只需要眼睛看看哪一个匹配我正在检查的模板实例。也许一个python脚本可以自动执行此操作。这太糟糕了,我无法使用“图像查找-t template_name :: var_t”等。 –

相关问题