开发者

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 开发者_如何学JAVApartically 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.


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


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜