GDB supports the command
When GDB starts it reads in the file
Example session:
(gdb) print myString $2 = {static null = {<No data fields>}, static shared_null = {ref = {atomic = 39}, alloc = 0, size = 0, data = 0x82174ca, clean = 0, simpletext = 0, righttoleft = 0, asciiCache = 0, reserved = 0, array = {0}}, static shared_empty = {ref = {atomic = 1}, alloc = 0, size = 0, data = 0xf5f71aca, clean = 0, simpletext = 0, righttoleft = 0, asciiCache = 0, reserved = 0, array = {0}}, d = 0x8260b48, static codecForCStrings = 0x0}(gdb) printqstring myString (QString)0x8217658 (length=26): "this is an example QString"(gdb)
As you see above,
The form
This macro was posted by David Faure to the KDE maillist in 2001:
define printqstring set $i=0 while $i < $arg0.d->len print $arg0.d->unicode[$i++].cl endend
It already prints out each character of the QString onto a single line.
A much refined version was posted by Arnaud de Muyser to the qt-interest list the same year:
define ps
end
Qt 4.x
The internal representation of QString changed for Qt 4.x: the length is now stored in d->size and it uses UCS-16 instead of UTF-8 for internal storage. The fact that QStrings are now implicitly shared does not matter in this context though.
So this is my adapted version of the macro:
define printqstring printf "(QString)0x%x (length=%i): "",&$arg0,$arg0.d->size set $i=0 while $i < $arg0.d->size set $c=$arg0.d->data[$i++] if $c < 32 || $c > 127 printf "\\u0xx", $c else printf "%c", (char)$c end end printf ""\n" end