GDB 7.6 STL pretty print with gcc-4.8 and mac os 10.9

你。 提交于 2020-01-14 19:42:06

问题


I'm struggling to get the pretty prints as described here in gdb working on my mac. I downloaded the latest gdb through macports and using gcc-4.8. I loaded the ~/.gdbinit file and the printers are registered, but whenever I call print myVector it gives me the raw output. Any suggestions what I could do? Thanks a lot guys!


回答1:


To have pretty printer with libc++ (new library used in Clang++/LLVM) use this new pretty printer:

https://github.com/koutheir/libcxx-pretty-printers

The .gdbinit is almost the same (see sample)

I've just tried with Eclipse Luna on OS X 10.10 and it works.




回答2:


Any suggestions what I could do?

You can try to register pretty printers directly from gdb command line, bypassing .gdbinit file to narrow down the problem:

ks@ks-comp:~$ gdb -n
GNU gdb (GDB) 7.6.1-ubuntu
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
(gdb) python
>import sys
>sys.path.insert(0, '/home/ks/stlPrettyPrinter')
>from libstdcxx.v6.printers import register_libstdcxx_printers
>register_libstdcxx_printers (None)
>end
(gdb) 

Note, that I've checked out pretty printers in /home/ks/stlPrettyPrinter folder:

ks@ks-comp:~$ ls -a /home/ks/stlPrettyPrinter
.  ..  hook.in  index.html  libstdcxx  Makefile.am  Makefile.in  patch.txt  .svn
ks@ks-comp:~$ 



回答3:


  • If you're using the STL implementation in libc++ (the default with clang), GDB won't know how to pretty print the STL containers
  • Switch to using GNU libstdc++, and STL pretty printing in gdb should work.
  • STL pretty printers are implemented as Python programs that know about the implementation details of the STL containers and are maintained along with the STL implementations.
  • libc++ does not ship STL pretty printers that confirm to the GDB Python pretty printer API

Since you got your gcc-4.8 from MacPorts and MacPorts: Using the Right Compiler claims that gcc-* defaults to libstdc++ you should just avoid passing the -stdlib= option when using gcc.



来源:https://stackoverflow.com/questions/22449829/gdb-7-6-stl-pretty-print-with-gcc-4-8-and-mac-os-10-9

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!