Debug issues with libc++ in Xcode 4.4

风流意气都作罢 提交于 2019-12-23 09:42:15

问题


I am having a problem when I try to debug on a list iteration on c++.

I made a simple test app:

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;
}

While debugging, when I am on the line marked with an arrow, when I step over, it starts stepping in on code from a c++ file: 'list'. I have to step over like 15 times until it finally gets to the code inside the for statement.

This issue only happens in Xcode 4.4. In Xcode 4.3 the debug works perfectly.

Here there are some different scenarios with different results:

  1. Use LLVM GCC 4.2 as the compiler → It works ok.
  2. Use Apple LLVM compiler 4.0 and set libstdc++ (GNU C++ standard library) for the C++ Standard library → It works ok.
  3. Apple LLVM compiler 4.0 and set libc++ (LLVM C++ standard library with C++11 support) for the C++ Standard library → The issue happens.

In the project I am working on, we are using Apple LLVM compiler 4.0 and libc++ (LLVM C++ standard library with C++11 support) so I need to solve this issue for scenario 3).

Does anybody knows what could be happening and if there is a fix for it?


回答1:


It's a problem with lldb / llvm interacting with libc++, I've seen it ever since we enabled it, although I think only the libc++ / lldb devs will be able to tell what that is.

While this isn't a solution, it seems to be an issue from the command line with with llvm 3.1 (current release with Xcode 4.5). If I do:

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

... and then try to use 'n' to step through until the end of main, it jumps into list's source at:

* 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      }

I agree, this really slows down development / debugging time, and it should be reported to the lldb devs



来源:https://stackoverflow.com/questions/12439318/debug-issues-with-libc-in-xcode-4-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!