在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中,调试工作非常完美。
这里有一些不同的场景,结果不同:
- 使用LLVM GCC 4.2作为编译器→它还可以
- 使用Apple LLVM编译器4.0并为C++标准库设置libstdc++(GNU C++标准库)→它还可以
- Apple LLVM编译器4.0,并为C++标准库设置libc++(支持C++11的LLVM C++标准库)→问题发生了
在我正在进行的项目中,我们使用的是Apple LLVM编译器4.0和libc++(支持C++11的LLVM C++标准库),所以我需要为场景3)解决这个问题。
有人知道会发生什么吗?如果有解决办法的话?
lldb/llvm与libc++交互是个问题,自从我们启用它以来,我就见过它,尽管我认为只有lib++/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结束,它跳到列表的源:
* 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 报告