View STL containers in GDB

Source: Internet
Author: User

View STL containers in GDB

 

(The main content of this article comes from http://sourceware.org/gdb/wiki/STLSupport
)

Currently, GDB cannot print the content of the STL container by default, but there are many ways to do this on the Internet. I tried it and it is easier to do the following:

Table of contents
    • 1 GDB-STL-Views
    • 2 GDB 7.0
1 GDB-STL-Views

This is a macro written by Dan Marinescu to view the content of the gdb container. It supports list, vector, MAP, multimap, set,
Multiset, dequeue, stack, queue, priorityqueue
, Bitset, string,
And widestring, from http://sourceware.org/gdb/wiki/STLSupport? Action = attachfile & Do = view & target = stl-views-1.0.3.gdb

You can download this file and put it in the user directory and rename it. gdbinit. After entering GDB, you can use the following commands to view the container content:

Pvector, plist, pmap, pset, pdequeue, pstack, pqueue, ppqueue, pbitset,
Pstring, pwstring

You can use help to view the help of the command, for example, help pvector. This method supports a wide range of GDB versions. It is said that GDB 4.3 + can be used. I only use GDB 6. x and GDB
7.0 used. However, it seems that GDB in mingw is not supported currently.

2 GDB 7.0

GDB 7.0 is supported by Python scripts. You can write pretty-printers in Python to display STL containers.

The method is to download Python libstdc ++ printers through SVN:

SVN Co SVN: // gcc.gnu.org/svn/gcc/trunk/libstdc?#-v3/python

I put the downloaded Python directory under. GDB in the user directory. Then ~ /. Add the following content to gdbinit:

 
Pythonimport sysimport OSP = OS. Path. expanduser ('~ /. GDB/Python ') print pif OS. Path. exists (P): SYS. Path. insert (0, P) from libstdcxx. v6.printers import register_libstdcxx_printers register_libdcxx_printers (none) End

In this way, pretty-printers is installed for the STL container. In GDB, the direct print container directly prints the container content, instead of the previous mess.

The advantage of this solution is that print is used directly, and you do not need to remember many custom macros. If you want to see the default input of GDB temporarily, you can also use print/R to switch to raw mode output.

But the trouble is that
7.0 and later versions can use such a convenient function, while currently, GDB is installed on many systems, for example, 6. x or even 5. X. Therefore, we can only hope to upgrade each release version to GDB 7.0.

 

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.