Ways to let GDB support the standard library of STL

Source: Internet
Author: User
Tags svn

This article originates from Http://sourceware.org/gdb/wiki/STLSupport

Under normal circumstances, GDB can not visually print out the STL standard library of the container and so on, debugging is very difficult.

such as Vector,queue, deque, list and so on.

such as vector<int> a

(GDB) p a

$ = {<std::_vector_base<int, std::allocator<int> >> = {
_m_impl = {<std::allocator<int>> = {<__gnu_cxx::new_allocator<int>> = {<No data fields>} , <no data Fields>}, _m_start = 0x804c008, _m_finish = 0x804c00c,
_m_end_of_storage = 0x804c00c}}, <no data fields>}

It's not intuitive.


The original 3 methods are introduced: I have used the first two methods.

I strongly recommend the first method here. The first method is best used to support all containers in the c++11 STL, display the command or P

Even the shared_ptr in c++11 support

Method:

1. Download a Python tool with SVN.

SVN Co Svn://gcc.gnu.org/svn/gcc/trunk/libstdc++-v3/python

When you're done, you'll get a directory named Python in the current directory.

Then you can move it to the right place, like moving to the/home/yourname/lib/gdb_printers/directory.

2. In the open file/home/yourname/.gdbinit that ~/.gitinit file. If not, create it.

Input

Python
import sys
sys.path.insert (0, '/home/yourname/lib/gdb_printers/python ') from
Libstdcxx.v6.printers Import register_libstdcxx_printers
register_libstdcxx_printers (None)
end


And then it's done.

The use of the following:

(GDB) L
5
6 int Main ()
7 {
8 vector<int> A;
9 A.push_back (3);
A.push_back (4);
One a.push_back (5);
return 0;
13
14}
(GDB) p a
$ = std::vector of length 1, capacity 1 = {3}

That's the way it is. Very easy to read.

The std::shared_ptr in C++11 is also supported.


Support for the iterator:

Breakpoint 1, Main () at Test.cpp:8
8 vector<int> A;
(GDB) n
9 A.push_back (3);
(GDB)
A.push_back (4);
(GDB)
One a.push_back (5);
(GDB)
Vector<int>::iterator iter = A.begin ();
(GDB)
return 0;
(GDB) P ITER
$ = 3
(GDB) P *iter
$ = (int &) @0x804c028:3




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.