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.
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']
.
There actually are pretty printers for qt: http://nikosams.blogspot.com/2009/10/gdb-qt-pretty-printers.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With