prosseek
prosseek

Reputation: 191099

lldb issue with the binary from clang++ on Mac

I have clang++ 4.1

clang++ -v
Apple clang version 4.1 (tags/Apple/clang-421.11.66) (based on LLVM 3.1svn)
Target: x86_64-apple-darwin11.4.2
Thread model: posix

I also have lldb 167.5

lldb -v
LDB-167.5

I compiled simple c++ code with this command.

clang++ testit.cpp -std=c++11 -stdlib=libc++ -g -o a

When I tried to debug it with lldb, I executed lldb ./a, set break point with b main and run.

lldb) r
Process 44582 launched: '/Users/smcho/Desktop/cpp11/lldb/a' (x86_64)
Process 44582 stopped
* thread #1: tid = 0x1f03, 0x00000001000007e8 a`main [inlined] std::__1::__vector_base<std::__1::unique_ptr<A, std::__1::default_delete<A> >, std::__1::allocator<std::__1::unique_ptr<A, std::__1::default_delete<A> > > >::__vector_base() at vector:460, stop reason = breakpoint 1.1
    frame #0: 0x00000001000007e8 a`main [inlined] std::__1::__vector_base<std::__1::unique_ptr<A, std::__1::default_delete<A> >, std::__1::allocator<std::__1::unique_ptr<A, std::__1::default_delete<A> > > >::__vector_base() at vector:460
   457          _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
   458      : __begin_(0),
   459        __end_(0),
-> 460        __end_cap_(0)
   461  {
   462  }
   463  

The C++ source code is in this post: How to print out the content in vector<unique_ptr> with gdb on Mac OS X

What might be wrong?

Upvotes: 0

Views: 295

Answers (2)

Jason Molenda
Jason Molenda

Reputation: 15425

One thing to be aware of is that you're using an older version of clang and lldb. With Xcode 4, when you run

% lldb

You're running lldb from /usr/bin which is installed by the "Command Line Tools" package (an optional download, either from developer.apple.com or from within Xcode - Preferences > Downloads tab > Components). If you instead do

% xcrun lldb

You'll be running the lldb which is included in Xcode.app -- expect to see a version like lldb-179.6. There were some important improvements to the handling of inlined functions (like those in the standard C++ library) in lldb-179 and I think it may help with what you're seeing.

You can also update to the latest Command Line Tools package from within Xcode. It isn't automatically updated by the Mac App Store updates when new Xcode updates are downloaded.

Note that in this particular case your function opens with

main() {
    vector<unique_ptr<A>> v;

the inlining for this ctor on the first line of the function means you're going to see this header file even with the latest tools -- the line table output by clang doesn't give the debugger the information it needs to skip over it. If you just type next or n, you'll be on the next source line of your function.

Upvotes: 1

Enrico Granata
Enrico Granata

Reputation: 3339

Nothing is specifically wrong. You are using libc++ which does heavy inlining (even at -O0, yes) - that means your code in main() is interleaved with libc++ code The first step in your main() is to create a std::vector, and indeed you are stopped in the (inlined) constructor for std::vector (its base class, namely). It simply happens to be the first "user" instruction in your call. You should be able to "next" over it to your user-level code.

Upvotes: 1

Related Questions