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

标签 c++ templates lldb

我正在调试一些模板代码,并希望 lldb 向我显示帧变量的实际类型(c 类型),而不是极其复杂的 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;
}

在“var_t foo = 1”显示的断点处停止

foo = (var_t)0

我真的需要看类似的东西

foo = (long)0

有什么方法可以做到这一点,或者找出解析的类型是什么?

我正在使用 XCode 7.3 和 lldb-350.0.21.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

关于如何做到这一点。

关于c++ - lldb 可以显示 typedef 的实际类型吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36899648/

相关文章:

c++ - 使用 cudaSetDeviceFlags 的正确位置?

c++ - 模板函数中 const 引用的类型推导

xcode - (lldb) 在设备上运行但不在模拟器上运行时出错

ios - iOS 崩溃的 GVR 音频引擎

xcode - 什么是 LLDB RPC 服务器?它什么时候在 Xcode 中崩溃?为什么会崩溃?

C++ 模板类从静态助手调用自己的构造函数

c++ - 为什么变量不变?

c++ - 完美转发和 std::forward<T> 的使用

使用 lambda 对函数模板进行 C++ 类型删除

django - 检查模板中的request.GET变量