STL Support Tools
When you try to use GDB's "print" command to display the contents of a vector, a stack, or any other GDB abstract data structure, you will get useless results. Instead, download and install one of following tools to properly view the contents of STL containers from within GDB.
gdb-stl-views is a set of GDB macros that can display the contents of many STL containers: list, vector, map, multimap, set, multiset, dequeue, stack, queue, priority_queue, bitset, string, and widestring. Writen and currently maintained by Dan Marinescu - PhD. The author formally disclaims copyright to this source code. In place of a legal notice, here is a blessing: May you do good and not evil. May you find forgiveness for yourself and forgive others. May you share freely, never taking more than you give.
You can download it here.
Tutorials and an alternative download are hosted at yolinux.com.
gdb++ is a Perl script which extends gdb. It comes bundled as part of the Devel::GDB::Reflect Perl module. First use CPAN to install the module, then follow the gdb++ usage instructions. Developed by Stanford PhD student Antal Novak.
There are other options. Tom Malnar wrote a set of GDB macros similar to Dan's ( http://thread.gmane.org/gmane.comp.gcc.g++.general/4060/focus=4167 ) but it doesn't cover as wide a variety of containers. Gilad Mishne wrote a different set of macros ( http://www.stanford.edu/~afn/gdb_stl_utils/ ) but it is long unmaintained and it works only with SGI's STL implementation, which very few GCC users use.
Iterators: how to display the item the iterator points at (tested on gdb 6 with a list): print *(iter._M_current)
Automatic STL support
GDB does not yet have automatic support for STL types, but we're working on it:
The Python branch has pretty-printers for many libstdc++ types:
basic_string<char>
basic_string<wchar_t>
basic_string<char16_t>
basic_string<char32_t>
bitset
deque
list
map
multimap
multiset
priority_queue
queue
set
stack
vector
shared_ptr
weak_ptr
unique_ptr
unordered_map
unordered_set
unordered_multimap
unordered_multiset
slist
See PythonGdb for information on checking out the branch.