gdb with Qt pretty printers
Asked Answered
B

3

11

My goal is to allow pretty printing of Qt classes in gdb. I.e if i have:

QString str("str"); 

in my code and execute

(gdb) print qwe 

I want str content to be printed(not real QString structure).

gdb itself support pretty-printers to be defined using python, and it seems that Qt Creator partically use this feature.

The ideal solution would be use pretty printers shipped with Qt(can be found in QT_INSTALLATION\share\qtcreator\gdbmacros) or maybe even whole debugger(can be found in QT_INSTALLATION\pythongdb).

Anyway, trolls build a new api to define pretty printers over standard gdb api, and I cannot figure out how to enable it in plain gdb debugger.

So, is there a way to run gdb with Qt's pretty printers enabled without Qt Creator, or maybe any info about how to manage this.

Beautify answered 11/2, 2011 at 9:21 Comment(0)
H
3

There actually are pretty printers for qt: http://nikosams.blogspot.com/2009/10/gdb-qt-pretty-printers.html

Hildahildagard answered 2/6, 2011 at 18:37 Comment(0)
L
3

I don't think Qt Creator uses pretty printers on the strict sense, they probably use the GDB/MI interface to directly access variables and their contents. If you want to use Pretty Printers to display QString contents, you could simple inspect where in the type is the real string and then show it. Here is an example for the C++ std::string type:

 class StdStringPrinter:
     "Print a std::string"

     def __init__ (self, val):
         self.val = val

     def to_string (self):
         return self.val['_M_dataplus']['_M_p']

     def display_hint (self):
         return 'string'

Note the access of the interval variables of the class on val['_M_dataplus']['_M_p'].

Lacto answered 15/2, 2011 at 17:9 Comment(0)
H
3

There actually are pretty printers for qt: http://nikosams.blogspot.com/2009/10/gdb-qt-pretty-printers.html

Hildahildagard answered 2/6, 2011 at 18:37 Comment(0)
M
0

Qt Creator indeed uses gdb's python scripting for pretty printing, but it does not use gdb's python based pretty printing mechanism which does not handle more complex cases like QObject properties. This mechanism produces gdb/MI-style (looks a bit like JSON) output, though, so it's not easily readable by humans on the command line. There's some minimalistic documentation of the interface on http://doc.qt.nokia.com/qtcreator-snapshot/creator-debugging-helpers.html

Marou answered 24/5, 2011 at 13:12 Comment(1)
Does this mean, there is no chance to use qtcreator's Python scripts and to use it e.g. in VScode + GDB? All the posts related to this topic are quite old, is there an update available maybe?Buhrstone

© 2022 - 2024 — McMap. All rights reserved.