This is the mail archive of the
mailing list for the GDB project.
Python scripting prototype
- From: Vladimir Prus <vladimir at codesourcery dot com>
- To: gdb at sources dot redhat dot com
- Date: Tue, 19 Feb 2008 22:37:14 +0300
- Subject: Python scripting prototype
The Python scripting prototype is now available
from the 'python' branch of the git repository at
and you can browse the code/changes at:
At present, it allows to customize how the
-var-evaluate-expression gets the string, for example, if
'v' is a variable in the program, of std::vector type,
one can do:
-var-create V * v
-var-set-pretty-printer V format_vector
Here, format_vector is a name of Python function, which is defined
in .gdbinit, like follows:
def format_vector (v):
impl = gdb.value_element (v, '_M_impl')
start = gdb.value_element (impl, '_M_start')
finish = gdb.value_element (impl, '_M_finish')
result = '['
current = start
first = 1
while not gdb.value_equal (current, finish):
if not first: result = result + ','
first = 0
result = result + gdb.value_string(gdb.value_dereference(current))
current = gdb.value_increment (current, 1)
result = result + ']'
def list_vector_children (v):
return [("first", gdb.value_from_int(1)), ("second", gdb.value_from_int(15))]
here, 'python' is a new command that executes python code, and any function
defined remain in python's namespace, and are available for use.
The current problems:
1. The code exposing gdb values to python leaks like crazy.
2. The Python interface for values in procedural, and should
be object-oriented -- with class 'value' that one can
add, subscribe, etc. Internally, we now use integers
to represent value*, and we should use properly define a new
class in C.
3. The linking to python is basically hardcoded in makefile.in
4. The code for dynamically computing the children of varobj
To build the code, you might need to change python2.5 and python25
strings hardcoded in Makefile.in to whatever version of Python you have.
I don't expect the current code to be very useful, but since I've promised
to publish it, here it goes. I intend to improve on points (1-4) above,
and then it will be suitable for submission, hopefully soon.