I have tried to declare a convenience function as described in the documentation [1] but I am unable to call the new function afterwards. This has been tried using GDB 7.5 on Gentoo GNU/Linux as well as GDB 7.5 on MacOS X (installed via Homebrew) with the same result. Here is the result when running the example from the documentation: (gdb) python >import gdb >class Greet(gdb.Function): > def __init__(self): > super(Greet, self).__init__('greet') > > def invoke(self, name): > return 'Hello %s' % name.string() > >Greet () >end (gdb) greet test Undefined command: "greet". Try "help". (gdb) greet Undefined command: "greet". Try "help". gdb.Command and gdb.Parameter both work as expected in the two GDB installations that I tried gdb.Function in. GDB 7.5 on OSX: $ uname -a Darwin moonglow.local 12.2.0 Darwin Kernel Version 12.2.0: Sat Aug 25 00:48:52 PDT 2012; root:xnu-2050.18.24~1/RELEASE_X86_64 x86_64 $ gcc -v Using built-in specs. Target: i686-apple-darwin11 Configured with: /private/var/tmp/llvmgcc42/llvmgcc42-2336.11~67/src/configure --disable-checking --enable-werror --prefix=/Applications/Xcode.app/Contents/Developer/usr/llvm-gcc-4.2 --mandir=/share/man --enable-languages=c,objc,c++,obj-c++ --program-prefix=llvm- --program-transform-name=/^[cg][^.-]*$/s/$/-4.2/ --with-slibdir=/usr/lib --build=i686-apple-darwin11 --enable-llvm=/private/var/tmp/llvmgcc42/llvmgcc42-2336.11~67/dst-llvmCore/Developer/usr/local --program-prefix=i686-apple-darwin11- --host=x86_64-apple-darwin11 --target=i686-apple-darwin11 --with-gxx-include-dir=/usr/include/c++/4.2.1 Thread model: posix gcc version 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00) $ gdb GNU gdb (GDB) 7.5 [..] This GDB was configured as "x86_64-apple-darwin12.1.0". GDB 7.5 on Gentoo: $ uname -a Linux moonglow-gentoo 3.5.2-gentoo #3 SMP PREEMPT Sat Aug 25 07:32:50 CEST 2012 x86_64 Intel(R) Core(TM) i7-2720QM CPU @ 2.20GHz GenuineIntel GNU/Linux $ gcc -v Using built-in specs. COLLECT_GCC=/usr/x86_64-pc-linux-gnu/gcc-bin/4.6.3/gcc COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-pc-linux-gnu/4.6.3/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: /var/tmp/portage/sys-devel/gcc-4.6.3/work/gcc-4.6.3/configure --prefix=/usr --bindir=/usr/x86_64-pc-linux-gnu/gcc-bin/4.6.3 --includedir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.3/include --datadir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.6.3 --mandir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.6.3/man --infodir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.6.3/info --with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.3/include/g++-v4 --host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu --disable-altivec --disable-fixed-point --with-ppl --with-cloog --disable-ppl-version-check --with-cloog-include=/usr/include/cloog-ppl --enable-lto --disable-nls --with-system-zlib --enable-obsolete --disable-werror --enable-secureplt --enable-multilib --enable-libmudflap --disable-libssp --enable-libgomp --with-python-dir=/share/gcc-data/x86_64-pc-linux-gnu/4.6.3/python --enable-checking=release --disable-libgcj --enable-languages=c,c++,fortran --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu --enable-targets=all --with-bugurl=http://bugs.gentoo.org/ --with-pkgversion='Gentoo 4.6.3 p1.6, pie-0.5.2' Thread model: posix gcc version 4.6.3 (Gentoo 4.6.3 p1.6, pie-0.5.2) $ gdb GNU gdb (Gentoo 7.5 p1) 7.5 [..] This GDB was configured as "x86_64-pc-linux-gnu". [1] http://sourceware.org/gdb/current/onlinedocs/gdb/Functions-In-Python.html#Functions-In-Python
The convenience function shows up when running 'show convenience' but I'm still not able to call it. I also tried calling it as '$greet'. (gdb) show convenience $greet = <internal function greet> $_thread = 0 $_siginfo = void $_probe_arg11 = <error: No frame selected> $_probe_arg10 = <error: No frame selected> $_probe_arg9 = <error: No frame selected> $_probe_arg8 = <error: No frame selected> $_probe_arg7 = <error: No frame selected> $_probe_arg6 = <error: No frame selected> $_probe_arg5 = <error: No frame selected> $_probe_arg4 = <error: No frame selected> $_probe_arg3 = <error: No frame selected> $_probe_arg2 = <error: No frame selected> $_probe_arg1 = <error: No frame selected> $_probe_arg0 = <error: No frame selected> $_probe_argc = <error: No frame selected> $_sdata = void $_tlb = void
Having reread the chapter on GDB convenience functions [1] I believe I misunderstood the purpose of them. I thought it would be similar to a user-defined command [2] but I see now it is something else and actually much more useful. :) [1] http://sourceware.org/gdb/current/onlinedocs/gdb/Convenience-Funs.html#Convenience-Funs [2] http://sourceware.org/gdb/current/onlinedocs/gdb/Define.html
CVSROOT: /cvs/src Module name: src Changes by: tromey@sourceware.org 2012-11-05 19:36:40 Modified files: gdb/doc : ChangeLog gdb.texinfo Log message: PR python/14802: * gdb.texinfo (Functions In Python): Add example. Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/doc/ChangeLog.diff?cvsroot=src&r1=1.1376&r2=1.1377 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/doc/gdb.texinfo.diff?cvsroot=src&r1=1.1016&r2=1.1017
I added an example to the documentation that should help future readers.
Awesome, thank you Tom! ..and thank you for the Python API for GDB. We have made some really great debugging aids with them at work that has saved us numerous hours of interpreting data.