Sunday, October 18, 2009

Gdb Qt pretty printers

The recently released gdb 7.0 adds a really great feature: python scripting for pretty printers. It makes it really easy to write pretty printers for any class.
Basically it's the same as QtCreator supports, however with a few differences:
  • also works in plain gdb on commandline
  • no compiled debug-helper library needed
  • a gdb-only solution
Example showing a QStringList:

Of course everything can be combined, as seen here:

Currently supported classes are: QString, QByteArray, QList, QMap, QDate, QTime, QDateTime

The code can be found in KDevelop git (gdb plugin uses them by default). For using in cli you need the following in ~/.gdbinit:
python
import sys

sys.path.insert(0, '/home/niko/kdesvn/kde-git/kdevelop/debuggers/gdb/printers')
from qt4 import register_qt4_printers
register_qt4_printers (None)

end
set print pretty 1

Gdb also supports autoloading the pretty printers - they could be included in -dev packages. The merge request that would add it to qt is still pending.

And now I'm off watching an episode of dexter :D

13 comments:

  1. I've added support for KTExtEditor::Cursor & Range in the meantime. You'll have to use this as .gdbinit:

    ~~~~~~~~
    python
    import sys

    sys.path.insert(0, '/home/niko/kdesvn/kde-git/kdevelop/debuggers/gdb/printers')
    from qt4 import register_qt4_printers
    register_qt4_printers (None)

    from kde4 import register_kde4_printers
    register_kde4_printers (None)

    end
    set print pretty 1
    ~~~~~~~~

    Of course, don't forget to get kde4.py from svn.

    ReplyDelete
  2. OOOOOO nice job ;). Too bad I never use GDB other than getting backtraces because I usually find my issues through there. Any syntax highlighting? ;þ And thank you guys. I love you <3

    ReplyDelete
  3. Qt Creator uses python dumpers for a while now (basically since that feature became first available in GDB). Are you sharing code there or did you reimplement the whole thing?

    ReplyDelete
  4. @Anonymous:
    creator works completely different. They also don't work in plain gdb on the commandline.
    No codesharing happened, as creators are very different. Maybe nowadays it could be possible to borrow stuff...

    ReplyDelete
  5. Hmmm... creator works fine with my gdb from ubuntu, so it does not seem to need a customized GDB. The binary debugging helpers are no longer required either, so it seems to be all python now.

    ReplyDelete
  6. @Anonymous: You are right. Qt Creator always worked with the normal "machine interface" of gdb (FSF gdb on Linux and Window, Apple's branch on Mac). Until gdb's python scripting became available with gdb 6.8.50, a kind of "pretty printing" was available using the "compiled dumpers" Niko mentioned. This is nowadays replaced by a normal (gdb) python script on all platforms that have a python-enabled gdb (i.e. Linux, Windows, Symbian, but not on Mac which still has to use the compiled version).

    ReplyDelete
  7. Niko,

    Thanks for this!
    There's only one limitation, though: Qt can be built with a custom namespace and, because of how the matching is done on the class name, gdb won't pretty-print my Qt types.
    I could solve this by changing lines in 'build_dictionary' from something like:
    ---
    pretty_printers_dict[re.compile('^QQueue')] = lambda val: QListPrinter(val, 'QQueue', None)
    ---

    into
    ---
    pretty_printers_dict[re.compile('^([a-zA-Z0-9_]*::)?QQueue')] = lambda val: QListPrinter(val, 'QQueue', None)
    ---

    Best,
    Arnaud.

    ReplyDelete
  8. A huge thanks to you for sharing this Blog your blog content is very nice ,I have read your blog your blog information is very usefull
    Web Design Company India

    ReplyDelete
  9. A huge thanks to you for sharing this Blog your blog content is very nice ,I have read your blog your blog information is very usefull
    Web Design Company India

    ReplyDelete
  10. Good publish you have performed the following. I am really very happy you just read this kind of. That is a quite useful subject matter you are preferred. keep writing.nimble phone number

    ReplyDelete
  11. You’ve made some good points there. It’s a good idea! Please visit https://goo.gl/av79wc

    ReplyDelete
  12. Above all the points to consider to choose my new domain time. I get it clear idea website design topic. It's really helpful to improve my web hosting knowledgeAndroid Phone Applications

    ReplyDelete
  13. telasmosquiteira-sp.com.br

    telas mosquiteira
    telas mosquiteiro

    As telas mosquiteira sp , telas mosquiteiro sp garantem ar puro por toda casa livrando-a completamente dos mosquitos e insetos indesejáveis. As telas mosquiteira garantem um sono tranquilo a toda família, livrando e protegendo-nas dos mais diversos insetos. Muitos destes insetos são transmissores de doenças e a tela mosquiteira é indispensável no combate a mosquitos transmissores de doenças.

    A dengue, por exemplo, já matou centenas de pessoas só na capital de São Paulo e um pequeno investimento em nossas telas mosquiteiras podem salvar vidas. As telas mosquiteiras também impedem a entrada de insetos peçonhentos como as aranhas e os escorpiões, estes insetos também oferecem risco, pois seu veneno em poucos minutos podem levar uma criança a morte.
    telas mosquiteira jundiai
    telas mosquiteiro jundiai
    telas mosquiteira São Paulo
    telas mosquiteiro São Paulo
    telas mosquiteira granja viana
    telas mosquiteiro granja vinana
    telas mosquiteira cotia
    telas mosquiteiro cotia
    telas mosquiteira sao paulo
    telas mosquiteiro sao paulo

    A chegada da temporada Primavera/Verão traz consigo a elevação da temperatura e a maior ocorrência de chuvas. Mas não é só isso. As estações mais quentes do ano causam muita dor de cabeça e muitos zumbidos indesejáveis em função das pragas urbanas – pernilongos, baratas, cupins e outros insetos -, que afetam todas as regiões brasileiras.

    Nossa missão é oferecer telas mosquiteiras de qualidade a um preço acessível, fazendo com que as telas mosquiteiras sejam uma opção viável para muitas pessoas.

    telas mosquiteiras Jundiaí
    telas mosquiteiro Jundiai
    telas mosquiteiras jundiai
    telas mosquiteiro industria
    telas mosquiteira restaurante
    telas mosquiteiro restaurante
    telas mosquiteira empresa
    telas mosquiteiro empresa

    ReplyDelete