Warning, /sdk/kde-dev-scripts/kde-devel-gdb is written in an unsupported language. File is not indexed.

0001 # This file defines handy gdb macros for printing out Qt types
0002 # To use it, add this line to your ~/.gdbinit :
0003 # source /path/to/kde/sources/kdesdk/scripts/kde-devel-gdb
0004 
0005 # Please don't use tabs in this file. When pasting a
0006 # macro definition to gdb, tabs are interpreted as completion.
0007 
0008 # Note for macro development: when working a macro,
0009 # disable the confirmation before gdb allows to redefine a macro, using "set confirm 0".
0010 
0011 # Disable printing of static members. Qt has too many, it clutters the output
0012 set print static-members off
0013 
0014 # Remember history over restarts
0015 set history save
0016 set history filename ~/.gdb_history
0017 
0018 # Show the real classname of object instances - e.g. (Kded *) 0x8073440 instead of (class QObject *) 0x8073440
0019 set print object
0020 
0021 define printq4string
0022     printq4stringdata ($arg0).d
0023 end
0024 document printq4string
0025   Prints the contents of a Qt4 QString
0026 end
0027 define printq5string
0028     printq5stringdata ($arg0).d
0029 end
0030 document printq5string
0031   Prints the contents of a Qt5 QString
0032 end
0033 
0034 define printq4stringdata
0035     set $d = ('QString::Data'*) $arg0
0036     set $i = 0
0037     # abort after a '-1' character, to avoid going on forever when printing a garbage string
0038     while $i < $d->size && ($i == 0 || (char)$d->data[$i-1] != -1)
0039         printf "%c", (char)($d->data[$i++] & 0xff)
0040     end
0041     printf "\n"
0042 end
0043 document printq4stringdata
0044   Prints the contents of a Qt4 QString::Data
0045   This is useful when the output of another command (e.g. printqmap)
0046   shows {d = 0xdeadbeef} for a QString, i.e. the qstringdata address
0047   instead of the QString object itself.
0048   printq4string $s and printq4stringdata $s.d are equivalent.
0049 end
0050 
0051 define printq5stringdata
0052     set $d = ('QString::Data'*) $arg0
0053     set $data_char = (char*)$d + $d->offset
0054     set $data = (unsigned short*) $data_char
0055     set $size = $d->size
0056     set $i = 0
0057     while $i < $size
0058       set $c = (char)($data[$i++] & 0xff)
0059       printf "%c", $c
0060       # abort after a '-1' character, to avoid going on forever when printing a garbage string
0061       if $i != 0 && $c == -1
0062         printf "\n<output terminated: junk data?>"
0063         loop_break
0064       end
0065     end
0066     printf "\n"
0067 end
0068 document printq5stringdata
0069   Prints the contents of a Qt5 QString::Data
0070   This is useful when the output of another command (e.g. printqmap)
0071   shows {d = 0xdeadbeef} for a QString, i.e. the qstringdata address
0072   instead of the QString object itself.
0073   printq5string $s and printq5stringdata $s.d are equivalent.
0074 end
0075 
0076 define print_utf8_char
0077   set $uc = $arg0
0078   if ( $uc < 0x80 )
0079     printf "%c", (unsigned char)($uc & 0x7f)
0080   else
0081     if ( $uc < 0x0800 )
0082       printf "%c", (unsigned char)(0xc0 | ($uc >> 6))
0083     else
0084       printf "%c", (unsigned char)(0xe0 | ($uc >> 12)
0085       printf "%c", (unsigned char)(0x80 | (($uc > 6) &0x3f)
0086     end
0087     printf "%c", (unsigned char)(0x80 | ((uchar) $uc & 0x3f))
0088   end
0089 end
0090 document print_utf8_char
0091   Prints a unicode value (stored as an unsigned short) as UTF-8.
0092 end
0093 
0094 define printq4string_utf8
0095    set $i=0
0096    set $s = $arg0
0097    while $i < $s.d->size
0098      set $uc = (unsigned short) $s.d->data[$i++]
0099      print_utf8_char $uc
0100    end
0101    printf "\n"
0102 end
0103 document printq4string_utf8
0104   Prints the contents of a Qt4 QString encoded in utf8.
0105   Nice if you run your debug session in a utf8 enabled terminal.
0106 end
0107 
0108 define printq5string_utf8
0109    set $i=0
0110    set $s = $arg0
0111    set $d = $s.d
0112    set $data_char = (char*)$d + $d->offset
0113    set $data = (unsigned short*) $data_char
0114    set $size = $d->size
0115    while $i < $size
0116      print_utf8_char $data[$i++]
0117    end
0118    printf "\n"
0119 end
0120 document printq5string_utf8
0121   Prints the contents of a Qt5 QString encoded in utf8.
0122   Nice if you run your debug session in a utf8 enabled terminal.
0123 end
0124 
0125 define printqcstring
0126     print ($arg0).shd.data
0127     print ($arg0).shd.len
0128 end
0129 document printqcstring
0130   Prints the contents of a QCString (char * data, then length)
0131 end
0132 
0133 define printq4bytearray
0134     print ($arg0)->d->data
0135 end
0136 document printq4bytearray
0137   Prints the contents of a Qt4 QByteArray (when it contains a string)
0138 end
0139 
0140 define printqfont
0141     print *($arg0).d
0142     printqstring ($arg0).d->request.family
0143     print ($arg0).d->request.pointSize
0144 end
0145 document printqfont
0146   Prints the main attributes from a QFont, in particular the requested
0147   family and point size
0148 end
0149 
0150 define printqcolor
0151     printf "(%d,%d,%d)\n", ($arg0).red(), ($arg0).green(), ($arg0).blue()
0152 end
0153 document printqcolor
0154   Prints a QColor as (R,G,B).
0155   Usage: 'printqcolor <QColor col>
0156 end
0157 
0158 define printqmemarray
0159     # Maybe we could find it out the type by parsing "whatis $arg0"?
0160     set $arr = $arg0
0161     set $sz = sizeof($arg1)
0162     set $len = $arr->shd->len / $sz
0163     output $len
0164     printf " items in the array\n"
0165     set $i = 0
0166     while $i < $len
0167        # print "%s[%d] = %s\n", $arr, $i, *($arg1 *)(($arr->vec)[$i])
0168        print *($arg1 *)(($arr->shd->data) + ($i * $sz))
0169        set $i++
0170     end
0171 end
0172 document printqmemarray
0173   Prints the contents of a QMemArray. Pass the type as second argument.
0174 end
0175 
0176 define printqptrvector
0177     # Maybe we could find it out the type by parsing "whatis $arg0"?
0178     set $arr = $arg0
0179     set $len = $arr->len
0180     output $len
0181     printf " items in the vector\n"
0182     set $i = 0
0183     while $i < $len
0184        # print "%s[%d] = %s\n", $arr, $i, *($arg1 *)(($arr->vec)[$i])
0185        print *($arg1 *)(($arr->vec)[$i])
0186        set $i++
0187     end
0188 end
0189 document printqptrvector
0190   Prints the contents of a QPtrVector. Pass the type as second argument.
0191 end
0192 
0193 define printqptrvectoritem
0194     set $arr = $arg0
0195     set $i = $arg2
0196     print ($arg1 *)(($arr->vec)[$i])
0197     print *($arg1 *)(($arr->vec)[$i])
0198 end
0199 document printqptrvectoritem
0200   Print one item of a QPtrVector
0201   Usage: printqptrvectoritem vector type index
0202 end
0203 
0204 define printq4map
0205     set $map = $arg0
0206     set $len = $map.d->size
0207     output $len
0208     printf " items in the map\n"
0209     set $it = $map.e->forward[0]
0210     set $_qmap_end = $map.e
0211     ## Requires a process...
0212     set $_qmap_payload = $map->payload()
0213     while $it != $map.e
0214         set $_qmap_nodeaddress = (char*)($it) - $_qmap_payload
0215         set $_qmap_node = ('QMap<$arg1,$arg2>::Node' *)($_qmap_nodeaddress)
0216         printf " key="
0217         output $_qmap_node->key
0218         printf " value="
0219         output $_qmap_node->value
0220         printf "\n"
0221         # just in case the key and/or the value is a qstring, try printq4string on it
0222         # (if this is too noisy with other types, remove it, and use
0223         #  printq4stringdata on the shown d pointers instead, by hand)
0224         printq4string $_qmap_node->key
0225         printq4string $_qmap_node->value
0226         set $it = $it->forward[0]
0227     end
0228 end
0229 document printq4map
0230   Prints the full contents of a Qt 4 QMap
0231   Usage: 'printq4map map keytype valuetype'
0232 end
0233 
0234 define printqptrlist
0235     set $list = $arg0
0236     set $len = $list.numNodes
0237     output $len
0238     printf " items in the list\n"
0239     set $it = $list.firstNode
0240     while $it != 0
0241         output $it->data
0242         printf "\n"
0243         set $it = $it->next
0244     end
0245 end
0246 document printqptrlist
0247   Prints the contents of a QPtrList.
0248   Usage: printqptrlist mylist
0249 end
0250 
0251 define printqvaluelist
0252     set $list = $arg0
0253     set $len = $list.sh->nodes
0254     output $len
0255     printf " items in the list\n"
0256     set $it = $list.sh->node->next
0257     set $end = $list.sh->node
0258     while $it != $end
0259         output $it->data
0260         printf "\n"
0261         set $it = $it->next
0262     end
0263 end
0264 document printqvaluelist
0265   Prints the contents of a QValueList.
0266   Usage: printqvaluelist mylist
0267 end
0268 
0269 define printqstringlist
0270     set $list = $arg0
0271     set $len = $list.sh->nodes
0272     output $len
0273     printf " items in the list\n"
0274     set $it = $list.sh->node->next
0275     set $end = $list.sh->node
0276     while $it != $end
0277         printqstring $it->data
0278         set $it = $it->next
0279     end
0280 end
0281 document printqstringlist
0282   Prints the contents of a QStringList.
0283   Usage: printqstringlist mylist
0284 end
0285 
0286 define printqregion
0287     printqmemarray ($arg0).rects() QRect
0288 end
0289 document printqregion
0290   Prints the rectangles that make up a QRegion. Needs a running process.
0291   Usage: printqregion myregion
0292 end
0293 
0294 # Bad implementation, requires a running process.
0295 # Needs to be refined, i.e. figuring out the right void* pointers casts.
0296 # Simon says: each Node contains the d pointer of the QString.
0297 define printq4stringlist
0298     # This is ugly, but we need to avoid conflicts with printq4string's own vars...
0299     set $q4sl_i = 0
0300     set $q4sl_d = & $arg0
0301     set $q4sl_sz = $q4sl_d->size()
0302     while $q4sl_i < $q4sl_sz
0303         output $q4sl_i
0304         printf " "
0305         printq4string $q4sl_d->at($q4sl_i++)
0306     end
0307 end
0308 document printq4stringlist
0309   Prints the contents of a Qt4 QStringList.
0310   Usage: printq4stringlist mylist
0311 end
0312 
0313 define identifyq4object
0314     set $obj=$arg0
0315     set $objectName=((QObjectPrivate *)($obj->d_ptr))->objectName
0316     printf " name:"
0317     printq4string $objectName
0318     printf " class:"
0319     # this requires a process, though
0320     print $obj->metaObject()->className()
0321 end
0322 
0323 # You print QString's too often to type the long name :-)
0324 # Change when Qt6 is the default
0325 define qs
0326   printq5string $arg0
0327 end
0328 
0329 define qs5
0330   printq5string $arg0
0331 end
0332 
0333 define qs4
0334   printq4string $arg0
0335 end
0336 
0337 define printqdatetime
0338   printqdate ($arg0).d
0339   printqtime ($arg0).t
0340 end
0341 document printqdatetime
0342   Prints a QDateTime
0343   Usage: printqdatetime myqdt
0344 end
0345 define printqdate
0346   printf "(Y:%d M:%d D:%d)\n", ($arg0).year(), ($arg0).month(), ($arg0).day()
0347 end
0348 document printqdate
0349   Prints a QDate
0350   Usage: printqdate mydate
0351 end
0352 define printqtime
0353   printf "(H:%d M:%d S:%d)\n", ($arg0).hour(), ($arg0).minute(), ($arg0).second()
0354 end
0355 document printqtime
0356   Prints a QTime
0357   Usage: printqtime mytime
0358 end
0359 
0360 # You are at f(g(h(i(), j(k(l())...) and you want to enter f: type fs <enter> <enter> <enter>
0361 # fs=finish+step
0362 define fs
0363        finish
0364        step
0365 end