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

时间:2016-09-01 03:03:10

标签: c++ clang lldb

这是测试代码。

#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行添加了break。我尝试按a打印p 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 ++编译时,没关系。

1 个答案:

答案 0 :(得分:1)

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

  

看起来您没有安装libstdc ++的调试信息:

     
    

缺少单独的debuginfos,请使用:dnf debuginfo-install libgcc-5.1.1-4.fc22.x86_64 libstdc ++ - 5.1.1-4.fc22.x86_64

  
     

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