Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pretty printing STL with GDB and Clang

I have GDB 7.5 installed in my machine. It seems pretty-printers for STL already comes bundled with this version, since running:

(gdb) info pretty-printers

prints a long list of all available STL printers.

Debugging a C++ code that has been compiled with g++ gets the correct behaviour of pretty printing. However, the same is not observed if the same code is compiled with clang++.

Below is an output when I run gdb:

BFD: /usr/lib/libstdc++.6.dylib(i386:x86-64): unknown load command 0x2a
BFD: /usr/lib/libstdc++.6.dylib(i386:x86-64): unknown load command 0x2b
BFD: /usr/lib/libSystem.B.dylib(i386:x86-64): unknown load command 0x2a
BFD: /usr/lib/libSystem.B.dylib(i386:x86-64): unknown load command 0x2b
BFD: /usr/lib/libc++abi.dylib(i386:x86-64): unknown load command 0x2a
BFD: /usr/lib/libc++abi.dylib(i386:x86-64): unknown load command 0x2b
BFD: /usr/lib/system/libcache.dylib(i386:x86-64): unknown load command 0x2a
BFD: /usr/lib/system/libcache.dylib(i386:x86-64): unknown load command 0x2b
BFD: /usr/lib/system/libcommonCrypto.dylib(i386:x86-64): unknown load command 0x2a
BFD: /usr/lib/system/libcommonCrypto.dylib(i386:x86-64): unknown load command 0x2b
BFD: /usr/lib/system/libcompiler_rt.dylib(i386:x86-64): unknown load command 0x2a
BFD: /usr/lib/system/libcompiler_rt.dylib(i386:x86-64): unknown load command 0x2b
BFD: /usr/lib/system/libcopyfile.dylib(i386:x86-64): unknown load command 0x2a
BFD: /usr/lib/system/libcopyfile.dylib(i386:x86-64): unknown load command 0x2b
BFD: /usr/lib/system/libdispatch.dylib(i386:x86-64): unknown load command 0x2a
BFD: /usr/lib/system/libdispatch.dylib(i386:x86-64): unknown load command 0x2b
BFD: /usr/lib/system/libdnsinfo.dylib(i386:x86-64): unknown load command 0x2a
BFD: /usr/lib/system/libdnsinfo.dylib(i386:x86-64): unknown load command 0x2b
BFD: /usr/lib/system/libdyld.dylib(i386:x86-64): unknown load command 0x2a
BFD: /usr/lib/system/libdyld.dylib(i386:x86-64): unknown load command 0x2b
BFD: /usr/lib/system/libkeymgr.dylib(i386:x86-64): unknown load command 0x2a
BFD: /usr/lib/system/libkeymgr.dylib(i386:x86-64): unknown load command 0x2b
BFD: /usr/lib/system/liblaunch.dylib(i386:x86-64): unknown load command 0x2a
BFD: /usr/lib/system/liblaunch.dylib(i386:x86-64): unknown load command 0x2b
BFD: /usr/lib/system/libmacho.dylib(i386:x86-64): unknown load command 0x2a
BFD: /usr/lib/system/libmacho.dylib(i386:x86-64): unknown load command 0x2b
BFD: /usr/lib/system/libquarantine.dylib(i386:x86-64): unknown load command 0x2a
BFD: /usr/lib/system/libquarantine.dylib(i386:x86-64): unknown load command 0x2b
BFD: /usr/lib/system/libremovefile.dylib(i386:x86-64): unknown load command 0x2a
BFD: /usr/lib/system/libremovefile.dylib(i386:x86-64): unknown load command 0x2b
BFD: /usr/lib/system/libsystem_blocks.dylib(i386:x86-64): unknown load command 0x2a
BFD: /usr/lib/system/libsystem_blocks.dylib(i386:x86-64): unknown load command 0x2b
BFD: /usr/lib/system/libsystem_c.dylib(i386:x86-64): unknown load command 0x2a
BFD: /usr/lib/system/libsystem_c.dylib(i386:x86-64): unknown load command 0x2b
BFD: /usr/lib/system/libsystem_dnssd.dylib(i386:x86-64): unknown load command 0x2a
BFD: /usr/lib/system/libsystem_dnssd.dylib(i386:x86-64): unknown load command 0x2b
BFD: /usr/lib/system/libsystem_info.dylib(i386:x86-64): unknown load command 0x2a
BFD: /usr/lib/system/libsystem_info.dylib(i386:x86-64): unknown load command 0x2b
BFD: /usr/lib/system/libsystem_kernel.dylib(i386:x86-64): unknown load command 0x2a
BFD: /usr/lib/system/libsystem_kernel.dylib(i386:x86-64): unknown load command 0x2b
BFD: /usr/lib/system/libsystem_m.dylib(i386:x86-64): unknown load command 0x2a
BFD: /usr/lib/system/libsystem_m.dylib(i386:x86-64): unknown load command 0x2b
BFD: /usr/lib/system/libsystem_network.dylib(i386:x86-64): unknown load command 0x2a
BFD: /usr/lib/system/libsystem_network.dylib(i386:x86-64): unknown load command 0x2b
BFD: /usr/lib/system/libsystem_notify.dylib(i386:x86-64): unknown load command 0x2a
BFD: /usr/lib/system/libsystem_notify.dylib(i386:x86-64): unknown load command 0x2b
BFD: /usr/lib/system/libsystem_sandbox.dylib(i386:x86-64): unknown load command 0x2a
BFD: /usr/lib/system/libsystem_sandbox.dylib(i386:x86-64): unknown load command 0x2b
BFD: /usr/lib/system/libunc.dylib(i386:x86-64): unknown load command 0x2a
BFD: /usr/lib/system/libunc.dylib(i386:x86-64): unknown load command 0x2b
BFD: /usr/lib/system/libunwind.dylib(i386:x86-64): unknown load command 0x2a
BFD: /usr/lib/system/libunwind.dylib(i386:x86-64): unknown load command 0x2b
BFD: /usr/lib/system/libxpc.dylib(i386:x86-64): unknown load command 0x2a
BFD: /usr/lib/system/libxpc.dylib(i386:x86-64): unknown load command 0x2b
BFD: /usr/lib/system/libcorecrypto.dylib(i386:x86-64): unknown load command 0x2a
BFD: /usr/lib/system/libcorecrypto.dylib(i386:x86-64): unknown load command 0x2b
BFD: /usr/lib/libobjc.A.dylib(i386:x86-64): unknown load command 0x2a
BFD: /usr/lib/libobjc.A.dylib(i386:x86-64): unknown load command 0x2b
BFD: /usr/lib/libauto.dylib(i386:x86-64): unknown load command 0x2a
BFD: /usr/lib/libauto.dylib(i386:x86-64): unknown load command 0x2b
BFD: /usr/lib/libc++.1.dylib(i386:x86-64): unknown load command 0x2a
BFD: /usr/lib/libc++.1.dylib(i386:x86-64): unknown load command 0x2b

I would like to know how I can get STL containers pretty-printed when the code was compiled with clang++? Note that I can debug the application; I just cannot pretty print the STL contents.

like image 279
Allan Avatar asked Oct 22 '12 22:10

Allan


1 Answers

The gdb you're using has a list of known Mach-O load command numbers but two new ones were added in Mac OS X 10.8 (LC_SOURCE_VERSION, 0x2a and LC_DYLIB_CODE_SIGN_DRS, 0x2b) and it is complaining that it doesn't know about these. It doesn't need to know about these, there's nothing necessary for the debugger in these load commands. The warnings should be harmless.

You're far better off using either the Apple provided gdb (which doesn't have python support, I know) or using the new debugger supported by Apple, LLDB. lldb is a pretty exciting new debugger that is improving rapidly, Apple has been developing it from scratch (leveraging llvm's existing infrastructure and features as much as possible) over the past few years and it is quite capable today. It was designed from the beginning to be extendable via Python and it is easy to create new data formatters for container types that you may come across.

If you haven't used lldb before, but are familiar with gdb, a useful cheat sheet is the command equivalences page over at http://lldb.llvm.org/lldb-gdb.html

Give lldb a try. It's the future of supported debugging on Mac OS X - there's a lot there to like today and it's getting better every release. It's also open source, you can check it out from http://lldb.llvm.org/ and play with it yourself.

like image 134
Jason Molenda Avatar answered Sep 19 '22 21:09

Jason Molenda