【问题标题】:lldb can't debug string when compiled by clang++lldb在clang++编译时无法调试字符串
【发布时间】:2017-01-08 18:41:28
【问题描述】:

这是测试代码。

#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++编译,但是没问题。

【问题讨论】:

  • 一个疯狂的猜测 - 编译器对其进行了优化,因为它未使用,然后不包括类型定义(因为它们“不再需要”)。现在调试器无法访问它们。
  • 你在电脑上测试过吗?这只是发生在我身上吗?

标签: c++ clang lldb


【解决方案1】:

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

您似乎没有安装 libstdc++ 的调试信息:

缺少单独的调试信息,使用:dnf debuginfo-install libgcc-5.1.1-4.fc22.x86_64 libstdc++-5.1.1-4.fc22.x86_64

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-02-03
    • 2016-10-15
    • 2021-08-11
    • 2016-02-06
    • 2020-01-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多