STL GDB pretty printer

  1. Checkout printer

    $ svn co svn://gcc.gnu.org/svn/gcc/trunk/libstdc++-v3/python
    or 
    $ svn co svn://gcc.gnu.org/svn/gcc/branches/gcc-4_8-branch/libstdc++-v3/python
    
  2. Add following to your ~/.gdbinit

    python
    import sys
    sys.path.insert(0, '/home/hyungchan/gdb_printers/python') # abs path require
    from libstdcxx.v6.printers import register_libstdcxx_printers
    register_libstdcxx_printers (None)
    end
    
  3. Now just print it

    // hello.cpp
    #include <string>
    
    std::string str = "hello world";
    
    int main ()
    {
        return 0;
    }
    
    $ g++ --version
    g++ (Ubuntu 4.8.4-2ubuntu1~14.04) 4.8.4
    Copyright (C) 2013 Free Software Foundation, Inc.
    This is free software; see the source for copying conditions.  There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    $ g++ -g -o hello hello.cpp
    $ gdb hello
    (gdb) b main
    Breakpoint 1 at 0x400881: file hello.cpp, line 7.
    (gdb) r
    Starting program: /home/hyungchan/source/gdb_printer/hello 
    
    Breakpoint 1, main () at hello.cpp:7
    7       return 0;
    (gdb) print str
    $1 = "hello world"
    (gdb)