This is the mail archive of the
archer@sourceware.org
mailing list for the Archer project.
Re: Python convenience functions that return GDB values cause segfault
El vie, 06-02-2009 a las 17:19 -0200, Thiago Jung Bauermann escribiÃ:
> El vie, 06-02-2009 a las 10:59 -0800, Jim Blandy escribiÃ:
> > On Wed, Feb 4, 2009 at 8:31 AM, Jim Blandy <jimb@red-bean.com> wrote:
> > > I've run out of time to play with this right now, but if I can later
> > > I'll try to change the patch as you suggest.
> >
> > (I don't know why I thought this was going to be more involved...)
>
> :-)
>
> I would have done it, but I have some related local changes from a
> convert_value_from_python fix that I wasn't able to push yet. Are you
> able to push this?
Ok, I committed the following, which includes a test for the bug, just
in case.
--
[]'s
Thiago Jung Bauermann
IBM Linux Technology Center
gdb/
2009-02-08 Jim Blandy <jimb@red-bean.com>
* python/python-value.c (convert_value_from_python):
Properly hand off GDB values returned by convenience
functions.
gdb/testsuite/
2009-02-08 Thiago Jung Bauermann <bauerman@br.ibm.com>
* gdb.python/python-function.exp: Add test for function returning
a GDB value.
diff --git a/gdb/python/python-value.c b/gdb/python/python-value.c
index 8b817a1..55361d6 100644
--- a/gdb/python/python-value.c
+++ b/gdb/python/python-value.c
@@ -821,7 +821,7 @@ convert_value_from_python (PyObject *obj)
}
}
else if (PyObject_TypeCheck (obj, &value_object_type))
- value = ((value_object *) obj)->value;
+ value = value_copy (((value_object *) obj)->value);
else
PyErr_Format (PyExc_TypeError, _("Could not convert Python object: %s"),
PyString_AsString (PyObject_Str (obj)));
diff --git a/gdb/testsuite/gdb.python/python-function.exp b/gdb/testsuite/gdb.python/python-function.exp
index 3ffc5aa..7feca2b 100644
--- a/gdb/testsuite/gdb.python/python-function.exp
+++ b/gdb/testsuite/gdb.python/python-function.exp
@@ -63,3 +63,17 @@ gdb_py_test_multiple "input convenience function" \
"end" ""
gdb_test "print \$test_func (\"ugh\")" "= \"test_func output, arg = ugh\"" "call function"
+
+# Test returning a gdb.Value from the function. This segfaulted GDB at one point.
+
+gdb_py_test_multiple "input value-returning convenience function" \
+ "python" "" \
+ "class Double (gdb.Function):" "" \
+ " def __init__ (self):" "" \
+ " super (Double, self).__init__ (\"double\")" "" \
+ " def invoke (self, n):" "" \
+ " return n*2" "" \
+ "Double ()" "" \
+ "end" ""
+
+gdb_test "print \$double (1)" "= 2" "call value-returning function"