This is the mail archive of the mailing list for the Archer project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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
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
$ ../build/gdb/gdb -nx
GNU gdb (GDB)
Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <>
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:
(gdb) python execfile('')
(gdb) print $double(1)
Segmentation fault (core dumped)

Possible fix:

Author: Jim Blandy <>
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;
+    }
     error (_("Could not convert Python object: %s"),
           PyString_AsString (PyObject_Str (obj)));

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]