Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gdb with Qt pretty printers

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.

like image 219
Eugene Loy Avatar asked Feb 11 '11 09:02

Eugene Loy


2 Answers

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'].

like image 68
Tarantula Avatar answered Oct 23 '22 09:10

Tarantula


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

like image 2
Niko Sams Avatar answered Oct 23 '22 10:10

Niko Sams