Why doesn't Eclipse use GDB for printing?

I am using Eclipse 4.4.2 on Ubuntu 14.04 and GDB 7.7.1. I am trying to check the contents of some containers of the C ++ standard library in the Eclipse debugger.

What I tried so far: following the instructions here , I ran the command

svn co svn://gcc.gnu.org/svn/gcc/trunk/libstdc++-v3/python

Copy it to /home/myusername/prettyprint.

Then I copied this text to my .gdbinit:

python
import sys
sys.path.insert(0, '/home/myusername/prettyprint/python')
from libstdcxx.v6.printers import register_libstdcxx_printers
register_libstdcxx_printers (None)
end

When I started gdb, I received this error message:

Traceback (most recent call last):
  File "<string>", line 4, in <module>
  File "/home/myusername/prettyprint/python/libstdcxx/v6/printers.py", line 1266, in register_libstdcxx_printers
    gdb.printing.register_pretty_printer(obj, libstdcxx_printer)
  File "/usr/myusername/gdb/python/gdb/printing.py", line 146, in register_pretty_printer
    printer.name)
RuntimeError: pretty-printer already registered: libstdc++-v6

I was looking for help on this and found that the second last line in the file ( register_libstdcxx_printers (None)) was not needed, so I deleted it. Then, when I started gdband typed:

info pretty-print

I got this output, indicating that the backend was installed correctly:

global pretty-printers:
  .*
    bound
  libstdc++-v6
    __gnu_cxx::_Slist_iterator
    __gnu_cxx::__7::_Slist_iterator
    __gnu_cxx::__7::__normal_iterator
    __gnu_cxx::__7::slist
    __gnu_cxx::__normal_iterator
    __gnu_cxx::slist
    __gnu_debug::_Safe_iterator
    std::_Deque_const_iterator
    std::_Deque_iterator
    std::_List_const_iterator
    std::_List_iterator
    std::_Rb_tree_const_iterator
    std::_Rb_tree_iterator
    std::__7::_Deque_const_iterator
    std::__7::_Deque_iterator
    std::__7::_List_const_iterator
    std::__7::_List_iterator
    std::__7::_Rb_tree_const_iterator
---Type <return> to continue, or q <return> to quit---
    std::__7::_Rb_tree_iterator
    std::__7::__cxx11::basic_string
    std::__7::basic_string
    std::__7::bitset
    std::__7::deque
    std::__7::forward_list
    std::__7::list
    std::__7::map
    std::__7::multimap
    std::__7::multiset
    std::__7::priority_queue
    std::__7::queue
    std::__7::set
    std::__7::shared_ptr
    std::__7::stack
    std::__7::tuple
    std::__7::unique_ptr
    std::__7::unordered_map
    std::__7::unordered_multimap
    std::__7::unordered_multiset
    std::__7::unordered_set
    std::__7::vector
    [... many more lines of output omitted]

For a good measure, I added the following lines to .gdbinit:

set print pretty on
set print object on
set print static-members on
set print vtbl on
set print demangle on
set demangle-style gnu-v3
set print sevenbit-strings off

, Eclipse , , :

Debugger still using ugly print

, GDB; ?

+4
1

, , STL. AFAIK, , , , .

.gdbinit, , ; - , ( Eclipse Mars.1):

  • :

    svn co svn://gcc.gnu.org/svn/gcc/trunk/libstdc++-v3/python
    
  • /home/<user>/.gdbinit :

    python
    import sys
    sys.path.insert(0, '/path/to/prettyprint/python')
    from libstdcxx.v6.printers import register_libstdcxx_printers
    end
    
  • GDB Eclipse (Window- > Preferences- > C/++ → Debug- > GDB) GDB .gdbinit.

  • (Run- > Debug Configurations), - , , GDB "".

, GDB ( ):

  • test.cpp:

    #include <map>
    int main() {
        std::map<char, int> first;
        first['a'] = 10;
        first['b'] = 20;
    }
    
  • g++:

    $ g++ -g -o test test.cpp
    
  • gdb:

    $ gdb test
    
  • :

    (gdb) b test.cpp:5
    Breakpoint 1 at 0x40093f: file src/test.cpp, line 5.
    
  • :

    (gdb) run
    Starting program: /path/to/test
    
  • gdb. :

    (gdb) p first
    

    , :

    $1 = std::map with 1 elements = {[97 'a'] = 10}
    
+4

All Articles