LLDB 在编译时无法调试字符串

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

本文关键字:调试 字符串 编译 LLDB      更新时间:2023-10-16

这是测试代码。

#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++编译时,它是OK的

这是因为clang没有为std::string发出调试信息。确保安装了libstdc++的调试信息。有关更多信息,请参阅此无效错误:

好像没有安装libstdc++的调试信息:

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

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