I\'ve followed the instructions on the GDB wiki to install the python pretty-printers for viewing STL containers. My ~/.gdbinit now looks like this:
<
Instead of methods listed in the link you mentioned, you can try the script here,
Do as follows:
1) Download the script to /your/path. Name it to some name e.g. your_name.conf.
2) Add a ~/.gdbinit file to home directory if you don't have one.
3) Add a line source /your/path/your_name.conf to your ~/.gdbinit.
4) Restart gdb. Try pvector
You can find help information with commands like help pvector.
e.g.
pvector vec 5 # Prints element[5] in vec
pvector vec 5 10 # Prints elements in range [5, 10] in vec. (5, 6, 7, 8, 9, 10)
FYI, the script adds several commands (pvector, plist, pmap etc.) to gdb whose function is to print the elements of STL. It also adds print pretty, yielding nice format like this:
Also, if you wanna know how exactly the elements of STL are accessed in gdb, just read the code of the commands. There's no secret in the code. ^_^
e.g.
vectors are accessed by ._M_impl._M_start
p vec._M_impl._M_start + 4 # prints vec[4]