lldb在clang ++编译时无法调试字符串

lldb can't debug string when compiled by clang++

这是测试代码。

#include <string>

int main(int argc, char const *argv[]) {
    std::string a = "hello";
    std::string b = "world";
    return 0;
}

我是通过命令编译的:

clang++ test.cpp -g

那我调试一下:

lldb a.out

我在 a = "hello" 运行后的第 4 行添加了中断。我尝试通过 p a 打印 a,它显示以下错误:

error: incomplete type 'string' (aka 'std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >') where a complete type is requ
ired

note: forward declaration of 'std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >'
error: 1 errors parsing expression

我想不通。

虽然我尝试用 g++ 编译,但没问题。

这是因为 clang 没有发出 std::string 的调试信息。确保您安装了 libstdc++ 的调试信息。有关详细信息,请参阅此 invalid bug

Looks like you don't have debug information for libstdc++ installed:

Missing separate debuginfos, use: dnf debuginfo-install libgcc-5.1.1-4.fc22.x86_64 libstdc++-5.1.1-4.fc22.x86_64

Clang 没有发出 std::string 的调试信息,因为它是 告诉 libstdc++ 提供它(但在你的情况下,它不是 安装);这是 GCC 显然对调试大小进行的优化 不执行。