Since GDB 7.0, the concept of pretty-printer has been added. The simple understanding is that he can let you write a string of scripts in Python, and then let GDB read the script, and you can freely output the format you want to define yourself. Let's give a simple example:
#include <QString>int main (intChar *argv[]) { "ABC " ; int 3 ; 0 ;}
Here we want to print the value of a, we stop the breakpoint to int i = 3, and then p a can see the output below
(GDB) p a$1= {Static NULL= {<no data fields>},StaticShared_null = {ref={_q_value=2}, Alloc =0, size =0, the data=0xb7fb14d2<qstring::shared_null+ -Clean =0, SimpleText =0, RightToLeft=0, Asciicache =0, capacity =0, reserved =0, array = {0}}, StaticShared_empty = {ref= {_q_value =1}, Alloc =0, size =0, the data=0xb7fb14be<qstring::shared_empty+ -Clean =0, SimpleText =0, RightToLeft=0, Asciicache =0, capacity =0, reserved =0, array = {0}}, D=0x804b008,StaticCodecforcstrings =0x0}
This is obviously not acceptable to us, so Google a few, found that there is really a printer about QT, is actually a py file, down after we need to join in our own. Gdbinit
python import sys sys.path.insert (0'/home/rickyk/.gdb'1
You can see that the Register_qt4_printers function is called and the relevant registration is completed, and the next good qt4.py is placed in the. GdB and then re-gdb to see the value of a.
(GDB) p a$ 1 " ABC "
Haha, finished, at this time the qstring variable can also be smoothly output.
PS: The debug helper for Qt creator and the principle of this article is a little different, QT creator use of the debug technology as long as the use of Python dumper. Because of compatibility issues, Qt Creator is guaranteed to be available on most machines, so the GDB version must meet 6.8.50 to support Python scripts for pretty Printer, If so, there is no guarantee that all machines can see the QT built-in variables correctly. So QT Creator used gdb more common features----Compiled dumpers, so, Qt creator himself wrote a dumper specifically to cooperate with Debug, this solves the platform compatibility problem. Of course, there are many QT creator installation package will bring a Python support for the GDB is also for this reason, in short, the two sets of principles are not the same, that is, if you want your terminal gdb normal output, you still have to go with a set of printer can.
Reference Link: http://blog.csdn.net/dbzhang800/article/details/6830638
Http://nikosams.blogspot.com/2010/01/gdb-qt-pretty-printers-updated.html
Resolve GDB output QT built-in type display problems