gdb user defined function

Tom Tromey tromey@redhat.com
Tue Jan 17 16:29:00 GMT 2012


>>>>> "Sinbad" == Sinbad  <sinbad.sinbad@gmail.com> writes:

Sinbad> i've never used python with gdb or python at all. but i want to learn
Sinbad> enough of python to achieve the following. how do one use python
Sinbad> with gdb, will gdb become slow, can you give me some pointers
Sinbad> on how to achieve the following using python.

There are plenty of docs:

    http://sourceware.org/gdb/onlinedocs/gdb/Python.html

What you want is the stuff about writing a function:

    http://sourceware.org/gdb/onlinedocs/gdb/Functions-In-Python.html#Functions-In-Python

and also the Value API.

The core of your function will probably be something along these lines:

    try:
      arg = arg.deref()
      return 1
    except:
      return 0

Untested of course.

About speed... well, evaluating Python does have a cost.  I wouldn't
worry about it in advance; especially if the alternative is using the
gdb CLI, which in general is less well-tuned than Python.  If your
situation is truly performance critical, then (1) measure the effects of
Python, and (2) if it is too slow, write a convenience function in C
instead.

Sinbad> Please don't yell ;)

Don't worry.

Tom



More information about the Gdb mailing list