0

I have read all the answers in How do I print the elements of a C++ vector in GDB?. But none of them can solve my problem on OSX 10.9, because nearly all of them are based on the fact that _M_impl is a member of vector, which is not the case on Mac.

Here is the result when I tried to write ~/.gdbinit according to this link

(gdb) pvector palin
There is no member or method named _M_impl.

I tried to read the source code of vector in /usr/include/c++/4.2.1/debug/vector (is this the right file ???), but I found it confusing. I think it is a little beyond my competence.

How can I print the elements of a C++ vector in GDB on OSX 10.9?

Community
  • 1
  • 1
particle128
  • 185
  • 11
  • I dunno anything about OSX, but if you just inspect the vector, what members does it give you? One of them is going to be the equivalent of `_M_impl` - it's just going to be named something different. – Barry Nov 03 '14 at 02:27
  • @Barry I hope so too. But there's no such element there, although here's an element `_M_impl` in `/usr/include/c++/4.2.1/vector`. – particle128 Nov 03 '14 at 02:39
  • 1
    There are two popular standard library implementations, libstdc++ (from GCC) and libc++ (from the LLVM/clang project). Chances are, you are on libc++. Gdb comes with Python pretty-printers that work with libstdc++, but there seems to be no support for libc++. You may have to create a version of pretty-printers for libc++ (requires moderately advanced wizardry) or switch your development to libc++ (requires easy lightweight wizardry, but not a universal solution). – n. m. could be an AI Nov 03 '14 at 04:32

1 Answers1

1

Finally, I turn to lldb, the default debug tool on Mac OSX.

I can print any container now. Thank god.

particle128
  • 185
  • 11