How to pretty-print STL containers in GDB?

前端 未结 9 585
一整个雨季
一整个雨季 2020-11-30 20:45

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:

<         


        
9条回答
  •  抹茶落季
    2020-11-30 21:25

    If you type info type _Rep after the Python exception, gdb will inform you about the classes loaded that match _Rep. That list could help you to find why python cannot find your std::string class.

    I just faced your problem and in my case was intel c compiler, icc, who broke pretty printing. In particular, unqualified icc name for std::string results in:

    std::basic_string, std::allocator >::std::basic_string, std::allocator >::_Rep;
    

    but pretty printer was looking for unqualified gcc name:

    std::basic_string, std::allocator::_Rep;
    

    What I did to solve my problem was modifying class StdStringPrinter in printers.py, adding the unqualified name of the string to the typename to look in gdb. Replacing the line:

    reptype = gdb.lookup_type (str (realtype) + '::_Rep').pointer ()
    

    with this:

    reptype = gdb.lookup_type (str (realtype) + '::' + str (realtype) + '::_Rep').pointer ()
    

    With the obtained list from info type you could fix your pretty printers to make them work.

提交回复
热议问题