Debug issues with libc++ in Xcode 4.4
Asked Answered
N

1

6

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?

Niemann answered 15/9, 2012 at 16:55 Comment(1)
This doesn't help, but I run into this sort of thing all the time with Xcode. It seems more prevalent with gdb than with lldb, but neither works great. It has been this way for a very long time. When I file a bug about it, usually it gets fixed, but then another instance of it pops up elsewhere. I'm not sure why Xcode has these problems but other popular development tools don't.Tahsildar
D
2

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

Displayed answered 25/9, 2012 at 18:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.