test.cc
非常简单:
#include <iostream>
#include <vector>
using namespace std;
int main(int argc, char *argv[])
{
vector<int32_t> vec{1,2,3};
return 0;
}
clang++ test.cc -std=c++17 -stdlib=libc++ -g
guo@dllab$ gdb ./a.out
GNU gdb (Ubuntu 7.7.1-0ubuntu5~14.04.3) 7.7.1
Copyright (C) 2014 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".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./a.out...done.
(gdb) l
1 #include <iostream>
2 #include <vector>
3
4 using namespace std;
5
6 int main(int argc, char *argv[])
7 {
8 vector<int32_t> vec{1,2,3};
9
10 return 0;
(gdb) b 9
Breakpoint 1 at 0x400ca5: file test.cc, line 9.
(gdb) r
Starting program: /home/guo/a.out
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Breakpoint 1, main (argc=1, argv=0x7fffffffd718) at test.cc:10
10 return 0;
(gdb) p vec
$1 = {
<std::__1::__vector_base<int, std::__1::allocator<int> >> = {
<std::__1::__vector_base_common<true>> = {<No data fields>},
members of std::__1::__vector_base<int, std::__1::allocator<int> >:
__begin_ = 0x603010,
__end_ = 0x60301c,
__end_cap_ = {
<std::__1::__compressed_pair_elem<int*, 0, false>> = {
__value_ = 0x60301c
},
<std::__1::__compressed_pair_elem<std::__1::allocator<int>, 1, true>> = {
<std::__1::allocator<int>> = {<No data fields>}, <No data fields>}, <No data fields>}
}, <No data fields>}
(gdb) pvector vec
There is no member or method named _M_impl.
我已经通过
cat stl-views-1.0.3.gdb > ~/.gdbinit
安装了 STL-views-1.0.3.gdb 。所以应该使用
pvector
。 最佳答案
STL-views 是一种在 gdb 中检查 C++ 容器的过时方法。相反,对于 libstdc++,有 python pretty printers 是 gcc 的一部分。在许多 Linux 发行版中,它们都是开箱即用的。对于 libc++,没有官方的 pretty-print ,但是在 3rd Party implementation 中推荐了一个 libc++ documentation :
关于c++ - 没有名为_M_impl的成员或方法,如何使用pvector打印clang++和libc++编译的C++的STL vector ,,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46473660/