【问题标题】:Debug issues with libc++ in Xcode 4.4在 Xcode 4.4 中调试 libc++ 的问题
【发布时间】:2012-09-15 16:55:37
【问题描述】:

当我尝试在 c++ 上调试列表迭代时遇到问题。

我做了一个简单的测试应用:

int main(int argc, const char * argv[])
{
// insert code here...
std::cout << "Hello, World!\n";

std::list<int> list;
list.push_back(1);
list.push_back(2);
--> list.push_back(3);    //Line before step over
    for (std::list<int>::const_iterator i = list.begin(); i != list.end(); i++)
    {
      std::cout << *i << std::endl;
    }
    return 0;
}

在调试时,当我在标有箭头的行上时,当我跨过时,它开始从 c++ 文件中的代码:'list' 中单步执行。 我必须跳过大约 15 次,直到它最终到达 for 语句中的代码。

这个问题只发生在 Xcode 4.4 中。在 Xcode 4.3 中,调试工作完美。

这里有一些不同的场景会有不同的结果:

  1. 使用 LLVM GCC 4.2 作为编译器 → 可以正常工作。
  2. 使用 Apple LLVM 编译器 4.0 并为 C++ 标准库设置 libstdc++(GNU C++ 标准库)→ 可以正常工作。
  3. Apple LLVM 编译器 4.0 并为 C++ 标准库设置 libc++(支持 C++11 的 LLVM C++ 标准库)→ 出现问题。

在我正在进行的项目中,我们使用 Apple LLVM 编译器 4.0 和 libc++(支持 C++11 的 LLVM C++ 标准库),所以我需要解决方案 3 的这个问题。

有人知道会发生什么以及是否有解决办法吗?

【问题讨论】:

  • 这无济于事,但我在使用 Xcode 时总是遇到这种情况。 gdb 似乎比 lldb 更普遍,但两者都不是很好。这种方式已经很长时间了。当我提交有关它的错误时,通常它会得到修复,但随后会在其他地方弹出另一个实例。我不确定为什么 Xcode 有这些问题,而其他流行的开发工具却没有。

标签: c++ debugging xcode4.4 lldb libc++


【解决方案1】:

这是 lldb / llvm 与 libc++ 交互的问题,自从我们启用它以来我就已经看到了,尽管我认为只有 libc++ / lldb 开发人员才能知道那是什么。

虽然这不是一个解决方案,但它似乎是命令行与 llvm 3.1(当前版本与 Xcode 4.5)的问题。如果我这样做:

clang++ -g -O0 -stdlib=libc++ -std=c++11 test.cpp -o test
lldb test
breakpoint set --file test.cpp --line 8

...然后尝试使用 'n' 单步执行直到 main 结束,它会跳转到 list 的源代码:

* thread #1: tid = 0x1c03, 0x00000001000010a2 test`main [inlined] std::__1::__list_imp<int, std::__1::allocator<int> >::begin() at list:543, stop reason = step over
    frame #0: 0x00000001000010a2 test`main [inlined] std::__1::__list_imp<int, std::__1::allocator<int> >::begin() at list:543
   540      {
   541  #if _LIBCPP_DEBUG_LEVEL >= 2
   542          return iterator(__end_.__next_, this);
-> 543  #else
   544          return iterator(__end_.__next_);
   545  #endif
   546      }

我同意,这确实会减慢开发/调试时间,应该报告给lldb devs

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-12-31
    • 1970-01-01
    • 2017-09-30
    • 2017-02-02
    • 2012-07-26
    • 1970-01-01
    • 2015-10-05
    • 1970-01-01
    相关资源
    最近更新 更多