How can I get sensible variable displays when usin

2019-06-22 05:14发布

问题:

I'm using Xcode 4.3.1's C++11 language dialect along with libc++ as the standard library. The language support in this combination is amazing, but debugging is torture. Neither Xcode's "Summary Format" nor lldb's summary format features display any of the standard types (std::string, std::vector, etc.) with pretty printing. Writing a pretty printer for these types is highly non-trivial due to their complexity. (E.g., std::string is remarkably complex in libc++.)

How in the world are other developers getting decent variable displays for STL types in this situation? Or is no one else using libc++ with Xcode/lldb yet?

回答1:

W ell there is support in the lldb repository. This is what I did:

svn co http://llvm.org/svn/llvm-project/lldb/trunk lldb

(I got revision 160855) In the lldb shell of Xcode you can than do:

command script import  /Users/arne/oss/lldb/examples/synthetic/libcxx.py

After that lldb formats std::vector, std::map, std::string and std::map more nicely:

(lldb) p rv
(std::__1::vector<unsigned long, std::__1::allocator<unsigned long> >) $3 = size=2 {
  (unsigned long) [0] = 503
  (unsigned long) [1] = 503
}

I have tested this with Xcode 4.4. Should work similar with Xcode 4.3

You can put the command in your .lldbinit init file. Even Xcode will then display the structures nicely formatted.



回答2:

This feature works correctly in Xcode 4.4. The best solution for Xcode 4.3 users is simply to update Xcode.