我调试了一些模板代码,并希望lldb向我展示一个帧变量的实际类型(c-type),而不是一个怪异的复杂typedef。实际类型将类似于" int"或" unsigned char",但它只显示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;
}
在&#34; var_t foo = 1&#34;设置的断点处停止示出了
foo = (var_t)0
我真的需要看到像
这样的东西foo = (long)0
有没有办法做到这一点,或找出已解决的类型是什么?
我正在使用XCode 7.3和lldb-350.0.21.3
答案 0 :(得分:3)
无法告诉变量打印机显示已解析的类型而不是声明的变量类型。您可以使用image lookup
的类型搜索模式找出typedef的已解析类型:
(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
关于如何做到这一点。