我在我的Mac上使用gdb,想要实现这里描述的漂亮打印效果,但是遇到了困难。我通过macports下载了最新版本的gdb,并使用
gcc-4.8
。我加载了~/.gdbinit
文件并注册了打印机,但每当我调用print myVector
时,它都会给出原始输出。你有什么建议吗?非常感谢!有什么建议吗?
您可以尝试直接从gdb命令行注册漂亮的打印机,绕过.gdbinit文件以缩小问题范围:
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)
/home/ks/stlPrettyPrinter
文件夹中的漂亮打印机。ks@ks-comp:~$ ls -a /home/ks/stlPrettyPrinter
. .. hook.in index.html libstdcxx Makefile.am Makefile.in patch.txt .svn
ks@ks-comp:~$
(gdb) p v $1 = {<_Vector_base<double, std::allocator<double> >> = { _M_impl = {<allocator<double>> = {<new_allocator<double>> = {<No data fields>}, <No data fields>}, _M_start = 0x1004000a0, _M_finish = 0x1004000f0, _M_end_of_storage = 0x1004000f0}}, <No data fields>}
。我使用 g++-4.8 -g -std=c++11 main.cpp 编译了代码。我对 gdb 比较陌生,不知道如何解决问题:/ - user3428018clang
默认的libc++
的STL实现,GDB将不知道如何漂亮地打印STL容器。libstdc++
,在gdb
中使用STL漂亮打印就可以了。libc++
不提供符合GDB Python漂亮打印API的STL漂亮打印程序。由于你从MacPorts获得了你的gcc-4.8
和MacPorts:使用正确的编译器声称gcc-*
默认为libstdc++
,所以当使用gcc时,应避免传递-stdlib=
选项。
gcc-4.8
吗? - scottt