This is the mail archive of the
archer@sourceware.org
mailing list for the Archer project.
Python convenience functions that return GDB values cause segfault
- From: Jim Blandy <jimb at red-bean dot com>
- To: archer at sourceware dot org
- Date: Tue, 3 Feb 2009 17:09:24 -0800
- Subject: Python convenience functions that return GDB values cause segfault
It seems that convenience functions implemented in Python that return
GDB value objects don't properly hand off the underlying GDB value to
Python --- they get freed when the Python object goes away.
$ cat c.py
import gdb
class Double(gdb.Function):
"Return twice the argument."
def __init__(self):
super(Double, self).__init__("double")
def invoke(self, n):
return n*2
Double()
$ ../build/gdb/gdb -nx
GNU gdb (GDB) 6.8.50.20090106-cvs
Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-pc-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
(gdb) python execfile('c.py')
(gdb) print $double(1)
Segmentation fault (core dumped)
$
Possible fix:
Author: Jim Blandy <jimb@red-bean.com>
Date: Tue Feb 3 17:05:18 2009 -0800
Properly hand off GDB values returned by convenience functions.
diff --git a/gdb/python/python-value.c b/gdb/python/python-value.c
index 37e2fec..f3a2ca6 100644
--- a/gdb/python/python-value.c
+++ b/gdb/python/python-value.c
@@ -820,7 +820,11 @@ convert_value_from_python (PyObject *obj)
do_cleanups (old);
}
else if (PyObject_TypeCheck (obj, &value_object_type))
- value = ((value_object *) obj)->value;
+ {
+ value_object *value_obj = (value_object *) obj;
+ value = value_obj->value;
+ value_obj->owned_by_gdb = 1;
+ }
else
error (_("Could not convert Python object: %s"),
PyString_AsString (PyObject_Str (obj)));