Question

I've searched a lot on how to enable pretty printing in KDevelop with no hope.

I had found this link and implemented what was mentioned there. Then in "launcher configuration" I've added my gdbinit file as the "config gdb script". But it has no effect.

It was working well in older version of KDevelop without no manual configurations needed, but upgrading my Ubuntu to 14.04 and upgrading KDevelop to v4.6.0 seems like a miss.

Any ideas how to enable pretty printing in KDevelop?

Was it helpful?

Solution

Yes, I also had this same problem with Ubuntu 13.10 and KDevelop 4.5.1. Below, I've included both the problem and the solution.

Problem:

Ubuntu 13.10 uses GDB 7.61, which reads Python3 pretty-printer scripts, but Ubuntu 13.10 shipped with Python2 pretty-printer scripts. Oops!

Solution:

  • First, make sure that you have the needed “.gdbinit” file in your home folder – the one that your hyperlink references. This will inform GDB where to look for the required Python3 pretty-printer scripts. It goes without saying, you might have to update the path in “.gdbinit”. Mine, looks like this:

    python
    import sys

    sys.path.insert(0, '/usr/share/kde4/apps/kdevgdb/printers')

    from qt4 import register_qt4_printers
    register_qt4_printers (None)

    from kde4 import register_kde4_printers
    register_kde4_printers (None)

    from libstdcxx import register_libstdcxx_printers
    register_libstdcxx_printers (None)

    end

  • Now, you need to use the “2to3” shell command to convert the Python2 scripts to Python3 scripts. For example:

    2to3 -w /usr/share/kde4/apps/kdevgdb/printers/qt4.py

    2to3 -w /usr/share/kde4/apps/kdevgdb/printers/libstdcxx.py

    I didn't need to convert the kde4.py script: it was already a Python3 script.

    Note: Just to be on the safe side, backup the script files before you do the conversion – you never know.

That's all there is to it, fire-up KDevelop and away you go...

Actually, you can use the gdb shell command to fire-up GDB and make sure that all of your Python scripts are version 3: if you don't get any read errors, you know you're okay. If it generates read errors, simply convert those scripts.

FYI: To get out of GDB, just enter “quit” and press the “Enter” key: (gdb) quit

Addendum:

If your system doesn't contain the libstdcxx.py file, you'll need to do the following:

  • In the folder that contains your other pretty-printer scripts, create a file and name it libstdcxx.py

  • Go to the following web page:

    http://gcc.gnu.org/svn/gcc/trunk/libstdc++-v3/python/libstdcxx/v6/printers.py

    Now, copy the web page contents and paste it to your newly created libstdcxx.py file.

    Since this file comes from gcc, it's more than likely a Python3 script - you'll have to see.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top