当我尝试在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中,调试效果很好。
这里有一些具有不同结果的不同方案:
在我正在从事的项目中,我们使用的是Apple LLVM编译器4.0和libc++(具有C++ 11支持的LLVM C++标准库),因此我需要解决方案3的问题。
是否有人知道会发生什么情况以及是否有解决办法?
最佳答案
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结尾,它会跳转到列表的源代码:
* 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