简体   繁体   English

lldb可以显示typedef的实际类型吗?

[英]Can lldb show the actual type of a typedef?

I'm debugging some template code, and would like lldb to show me the actual type (c-type) of a frame variable instead of a monstrously complex typedef. 我正在调试一些模板代码,并希望lldb向我展示一个帧变量的实际类型(c-type)而不是一个怪异的复杂typedef。 The actual type would be something like "int" or "unsigned char", but it shows me only the typedef as if it had no knowledge of the specific template instance. 实际类型可能是“int”或“unsigned char”,但它只显示typedef,就好像它不知道特定的模板实例一样。

For example: 例如:

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;
}

Stopping at a breakpoint set on "var_t foo = 1" shows 停止在“var_t foo = 1”上设置的断点处显示

foo = (var_t)0

I really need to see something like 我真的需要看到类似的东西

foo = (long)0

Is there any way to do this, or to find out what the resolved type is? 有没有办法做到这一点,或找出解决的类型是什么?

I'm using XCode 7.3 and lldb-350.0.21.3 我正在使用XCode 7.3和lldb-350.0.21.3

There is no way to tell the variable printer to show the resolved type rather than the declared type of a variable. 没有办法告诉变量打印机显示已解析的类型而不是声明的变量类型。 You can find out what the resolved type for a typedef is using the type search mode of image lookup : 您可以使用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"

Here's another way to get the same info from the Python API if you want to use that: 如果您想使用它,这是从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

If this is something you need to do a lot, you could write a Python based lldb command to print the fully resolved type. 如果您需要做很多事情,可以编写基于Python的lldb命令来打印完全解析的类型。 There's info here: 这里有信息:

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

on how to do that. 如何做到这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM