This is the mail archive of the
gdb@sourceware.org
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
git://repo.or.cz/gdb.git
and you can browse the code/changes at:
http://repo.or.cz/w/gdb.git?a=log;h=python
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:
(gdb)
-var-create V * v
^done,name="V",numchild="1",value="{...}",type="std::vector<int,std::allocator<int> >"
(gdb)
-var-set-pretty-printer V format_vector
^done
(gdb)
-var-evaluate-expression V
^done,value="[1,2]"
(gdb)
Here, format_vector is a name of Python function, which is defined
in .gdbinit, like follows:
python
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 + ']'
return result
def list_vector_children (v):
return [("first", gdb.value_from_int(1)), ("second", gdb.value_from_int(15))]
end
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
is incomplete.
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.
- Volodya