gdb
2009-05-27 Tom Tromey <tromey@redhat.com> Thiago Jung Bauermann <bauerman@br.ibm.com> Phil Muldoon <pmuldoon@redhat.com> Paul Pluzhnikov <ppluzhnikov@google.com> * python/python.c (_initialize_python): Call gdbpy_initialize_types. (GdbMethods): Add "lookup_type". * python/python-value.c (value_object) <type>: New field. (valpy_dealloc): Decref type. (valpy_new): Initialize type. (valpy_get_type): New function. (value_to_value_object): Initialize type. (valpy_cast): New function. (value_object_getset): Add "type". (value_object_methods): Add "cast". * python/python-internal.h (type_to_type_object): Declare. (type_object_to_type): Likewise. (gdbpy_initialize_types): Likewise. (gdbpy_lookup_type): Declare. * Makefile.in (SUBDIR_PYTHON_OBS): Add python-type.o. (SUBDIR_PYTHON_SRCS): Add python-type.c. (python-type.o): New target. * python/python-type.c: New file. gdb/doc 2009-05-27 Thiago Jung Bauermann <bauerman@br.ibm.com> Tom Tromey <tromey@redhat.com> * gdb.texinfo (Types In Python): New node. (Values From Inferior): "type" is now an attribute. (Python API): Update. gdb/testsuite 2009-05-27 Thiago Jung Bauermann <bauerman@br.ibm.com> Tom Tromey <tromey@redhat.com> Pedro Alves <pedro@codesourcery.com> Paul Pluzhnikov <ppluzhnikov@google.com> * gdb.python/python-template.exp: New file. * gdb.python/python-template.cc: New file. * gdb.python/python.exp (gdb_py_test_multiple): Add two objfile tests. * gdb.python/python-value.exp (py_objfile_tests): New proc. Call it. (test_value_after_death): New proc. * gdb.python/python-value.c (PTR): New typedef. (main): New variable 'x'.
This commit is contained in:
parent
89c73adef9
commit
2c74e83381
13 changed files with 1339 additions and 6 deletions
|
@ -59,6 +59,7 @@ typedef struct {
|
|||
PyObject_HEAD
|
||||
struct value *value;
|
||||
PyObject *address;
|
||||
PyObject *type;
|
||||
} value_object;
|
||||
|
||||
/* Called by the Python interpreter when deallocating a value object. */
|
||||
|
@ -77,6 +78,11 @@ valpy_dealloc (PyObject *obj)
|
|||
Py_DECREF (self->address);
|
||||
}
|
||||
|
||||
if (self->type)
|
||||
{
|
||||
Py_DECREF (self->type);
|
||||
}
|
||||
|
||||
self->ob_type->tp_free (self);
|
||||
}
|
||||
|
||||
|
@ -111,6 +117,7 @@ valpy_new (PyTypeObject *subtype, PyObject *args, PyObject *keywords)
|
|||
|
||||
value_obj->value = value;
|
||||
value_obj->address = NULL;
|
||||
value_obj->type = NULL;
|
||||
release_value (value);
|
||||
value_prepend_to_list (&values_in_python, value);
|
||||
|
||||
|
@ -161,6 +168,24 @@ valpy_get_address (PyObject *self, void *closure)
|
|||
return val_obj->address;
|
||||
}
|
||||
|
||||
/* Return type of the value. */
|
||||
static PyObject *
|
||||
valpy_get_type (PyObject *self, void *closure)
|
||||
{
|
||||
value_object *obj = (value_object *) self;
|
||||
if (!obj->type)
|
||||
{
|
||||
obj->type = type_to_type_object (value_type (obj->value));
|
||||
if (!obj->type)
|
||||
{
|
||||
obj->type = Py_None;
|
||||
Py_INCREF (obj->type);
|
||||
}
|
||||
}
|
||||
Py_INCREF (obj->type);
|
||||
return obj->type;
|
||||
}
|
||||
|
||||
/* Implementation of gdb.Value.string ([encoding] [, errors]) -> string
|
||||
Return Unicode string with value contents. If ENCODING is not given,
|
||||
the string is assumed to be encoded in the target's charset. */
|
||||
|
@ -195,6 +220,34 @@ valpy_string (PyObject *self, PyObject *args, PyObject *kw)
|
|||
return unicode;
|
||||
}
|
||||
|
||||
/* Cast a value to a given type. */
|
||||
static PyObject *
|
||||
valpy_cast (PyObject *self, PyObject *args)
|
||||
{
|
||||
PyObject *type_obj;
|
||||
struct type *type;
|
||||
struct value *res_val = NULL; /* Initialize to appease gcc warning. */
|
||||
volatile struct gdb_exception except;
|
||||
|
||||
if (! PyArg_ParseTuple (args, "O", &type_obj))
|
||||
return NULL;
|
||||
|
||||
type = type_object_to_type (type_obj);
|
||||
if (! type)
|
||||
{
|
||||
PyErr_SetString (PyExc_RuntimeError, "argument must be a Type");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
TRY_CATCH (except, RETURN_MASK_ALL)
|
||||
{
|
||||
res_val = value_cast (type, ((value_object *) self)->value);
|
||||
}
|
||||
GDB_PY_HANDLE_EXCEPTION (except);
|
||||
|
||||
return value_to_value_object (res_val);
|
||||
}
|
||||
|
||||
static Py_ssize_t
|
||||
valpy_length (PyObject *self)
|
||||
{
|
||||
|
@ -744,6 +797,7 @@ value_to_value_object (struct value *val)
|
|||
{
|
||||
val_obj->value = val;
|
||||
val_obj->address = NULL;
|
||||
val_obj->type = NULL;
|
||||
release_value (val);
|
||||
value_prepend_to_list (&values_in_python, val);
|
||||
}
|
||||
|
@ -855,16 +909,20 @@ gdbpy_initialize_values (void)
|
|||
values_in_python = NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static PyGetSetDef value_object_getset[] = {
|
||||
{ "address", valpy_get_address, NULL, "The address of the value.",
|
||||
NULL },
|
||||
{ "is_optimized_out", valpy_get_is_optimized_out, NULL,
|
||||
"Boolean telling whether the value is optimized out (i.e., not available).",
|
||||
NULL },
|
||||
{ "type", valpy_get_type, NULL, "Type of the value.", NULL },
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
static PyMethodDef value_object_methods[] = {
|
||||
{ "cast", valpy_cast, METH_VARARGS, "Cast the value to the supplied type." },
|
||||
{ "dereference", valpy_dereference, METH_NOARGS, "Dereferences the value." },
|
||||
{ "string", (PyCFunction) valpy_string, METH_VARARGS | METH_KEYWORDS,
|
||||
"string ([encoding] [, errors]) -> string\n\
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue