handle SIG34 nostop noprint pass handle SIG35 nostop noprint pass set print static-members off define xxd dump binary memory dump.bin $arg0 $arg0+$arg1 shell xxd dump.bin ; rm dump.bin end document xxd hex-dump a memory range. @param $arg0 pointer. @param $arg1 size in bytes. end define info_threads set pagination off set logging overwrite on set logging file /tmp/gdb.out set logging redirect on set logging on info threads set logging off set logging redirect off shell perl -ne 'next if /(do_futex_wait(.constprop)?|nanosleep|pthread_cond_(timed)?wait..GLIBC_[\d.]+|epoll_wait|p?poll|read|accept) \(\)/;print' /tmp/gdb.out set pagination on end document info_threads only show interesting threads, which are not sleeping or working on standard I/O functions. end define pshared_ptr p $arg0._M_ptr p "use count" p $arg0._M_refcount._M_pi->_M_use_count p "weak count" p $arg0._M_refcount._M_pi->_M_weak_count end document pshared_ptr print information on a std::shared_ptr @param $arg0 std::shared_ptr object. end ########## C++ functions by Herman Pijl CUJ 200406 ## patched to g++ by Dirk Jagdmann # # on other platorms, you'll have to make some changes # like replacing _C_ by _M_ # # e.g. compile Listing1.cpp # you> aCC -g -AA -o gdbcontainer Listing1.cpp # you> gdb gdbcontainer # (gdb) b main # (gdb) r # ... # (gdb) p l_vec ######################################### define veclen set $veclen = $arg0._M_impl._M_finish - $arg0._M_impl._M_start end document veclen Set the variable $veclen to the length of the vector. @param $arg0 std::vector end ######################################### define pveclen veclen $arg0 output $veclen echo \n end document pveclen Print the length of a vector. @param $arg0 std::vector end ######################################### define pvecidx veclen $arg0 if ($arg1 > $veclen-1) echo idx out of range\n else if ($arg1 < 0) echo idx < 0\n else output *($arg0._M_impl._M_start + $arg1) echo \n end end end document pvecidx Print the i-th element of a vector. @param $arg0 std::vector @param $arg1 index into $arg0 end ######################################### define pvec veclen $arg0 set $lloop = 0 while ($lloop < $veclen) pvecidx $arg0 $lloop set $lloop = $lloop + 1 end echo length: output $veclen echo \n end document pvec Print all the elements of a vector varname. @param $arg0 std::vector end ######################################### define setlen set $setlen = $arg0._M_t._M_impl._M_node_count end document setlen Set the variable $setlen to the length of the set @param $arg0 std::set end ######################################### define psetlen setlen $arg0 output $setlen echo \n end document psetlen Print the length of a set. @param $arg0 std::set end ######################################### define maplen set $maplen = $arg0._M_t._M_impl._M_impl._M_node_count end document maplen Set the variable $maplen to the length of the map. @param $arg0 std::map end ######################################### define pmaplen maplen $arg0 output $maplen echo \n end document pmaplen Print the length of the map. @param $arg0 std::map end ######################################### define pstr output $arg0._M_dataplus._M_p echo \n length: set $pstr = strlen($arg0._M_dataplus._M_p) output $pstr echo \n end document pstr Print the string. @param $arg0 std::string end ############################################################################## # This file defines handy gdb macros for printing out Qt types # To use it, add this line to your ~/.gdbinit : # source /path/to/kde/sources/kdesdk/scripts/kde-devel-gdb # Please don't use tabs in this file. When pasting a # macro definition to gdb, tabs are interpreted as completion. # Disable printing of static members. Qt has too many, it clutters the output set print static-members off define printqstring printqstringdata $arg0.d end document printqstring Prints the contents of a QString end define printqstringdata set $i=0 set $d = (QStringData *)$arg0 while $i < $d->len printf "%c", (char)($d->unicode[$i++].ucs & 0xff) end printf "\n" end document printqstringdata Prints the contents of a QStringData This is useful when the output of another command (e.g. printqmap) shows {d = 0xdeadbeef} for a QString, i.e. the qstringdata address instead of the QString object itself. printqstring $s and printqstringdata $s.d are equivalent. end define printqstring_utf8 set $i=0 set $s = $arg0 while $i < $s.d->len set $uc = (unsigned short) $s.d->unicode[$i++].ucs if ( $uc < 0x80 ) printf "%c", (unsigned char)($uc & 0x7f) else if ( $uc < 0x0800 ) printf "%c", (unsigned char)(0xc0 | ($uc >> 6)) else printf "%c", (unsigned char)(0xe0 | ($uc >> 12) printf "%c", (unsigned char)(0x80 | (($uc > 6) &0x3f) end printf "%c", (unsigned char)(0x80 | ((uchar) $uc & 0x3f)) end end printf "\n" end document printqstring_utf8 Prints the contents of a QString encoded in utf8. Nice if you run your debug session in a utf8 enabled terminal. end define printqcstring print $arg0.shd.data print $arg0.shd.len end document printqcstring Prints the contents of a QCString (char * data, then length) end define printqfont print *($arg0).d printqstring ($arg0).d->request.family print ($arg0).d->request.pointSize end document printqfont Prints the main attributes from a QFont, in particular the requested family and point size end define printqcolor printf "(%d,%d,%d)\n", ($arg0).red(), ($arg0).green(), ($arg0).blue() end document printqcolor Prints a QColor as (R,G,B). Usage: 'printqcolor end define printqmemarray # Maybe we could find it out the type by parsing "whatis $arg0"? set $arr = $arg0 set $sz = sizeof($arg1) set $len = $arr->shd->len / $sz output $len printf " items in the array\n" set $i = 0 while $i < $len # print "%s[%d] = %s\n", $arr, $i, *($arg1 *)(($arr->vec)[$i]) print *($arg1 *)(($arr->shd->data) + ($i * $sz)) set $i++ end end document printqmemarray Prints the contents of a QMemArray. Pass the type as second argument. end define printqptrvector # Maybe we could find it out the type by parsing "whatis $arg0"? set $arr = $arg0 set $len = $arr->len output $len printf " items in the vector\n" set $i = 0 while $i < $len # print "%s[%d] = %s\n", $arr, $i, *($arg1 *)(($arr->vec)[$i]) print *($arg1 *)(($arr->vec)[$i]) set $i++ end end document printqptrvector Prints the contents of a QPtrVector. Pass the type as second argument. end define printqptrvectoritem set $arr = $arg0 set $i = $arg2 print ($arg1 *)(($arr->vec)[$i]) print *($arg1 *)(($arr->vec)[$i]) end document printqptrvectoritem Print one item of a QPtrVector Usage: printqptrvectoritem vector type index end define printqmap set $map = $arg0 set $len = $map.sh->node_count output $len printf " items in the map\n" set $header = $map.sh->header # How to parse the key and value types from whatis? set $it = (QMapNode<$arg1,$arg2> *)($header->left) while $it != $header printf " key=" output $it->key printf " value=" output $it->data printf "\n" _qmapiterator_inc $it set $it = (QMapNode<$arg1,$arg2> *)($ret) end end document printqmap Prints the full contents of a QMap Usage: 'printqmap map keytype valuetype' end define _qmapiterator_inc set $ret = $arg0 if $ret->right != 0 set $ret = $ret->right while $ret->left != 0 set $ret = $ret->left end else set $y = $ret->parent while $ret == $y->right set $ret = $y set $y = $y->parent end if $ret->right != $y set $ret = $y end end end document _qmapiterator_inc Increment a qmap iterator (internal method, used by printqmap) end define printqptrlist set $list = $arg0 set $len = $list.numNodes output $len printf " items in the list\n" set $it = $list.firstNode while $it != 0 output $it->data printf "\n" set $it = $it->next end end document printqptrlist Prints the contents of a QPtrList. Usage: printqptrlist mylist end define printqvaluelist set $list = $arg0 set $len = $list.sh->nodes output $len printf " items in the list\n" set $it = $list.sh->node->next set $end = $list.sh->node while $it != $end output $it->data printf "\n" set $it = $it->next end end document printqvaluelist Prints the contents of a QValueList. Usage: printqvaluelist mylist end define printqstringlist set $list = $arg0 set $len = $list.sh->nodes output $len printf " items in the list\n" set $it = $list.sh->node->next set $end = $list.sh->node while $it != $end printqstring $it->data set $it = $it->next end end document printqstringlist Prints the contents of a QStringList. Usage: printqstringlist mylist end