aboutsummaryrefslogtreecommitdiff
path: root/gdb/python
diff options
context:
space:
mode:
authorTom Tromey <tromey@redhat.com>2010-08-23 20:21:28 +0000
committerTom Tromey <tromey@redhat.com>2010-08-23 20:21:28 +0000
commit702c27113693b383728d0b423f58389544a80614 (patch)
tree4eb3528024efcf2a3e34cd0f8b567bc9fde6e456 /gdb/python
parent832bafd3314b6f1fb7f7c0e7abe596b11e6364ba (diff)
downloadgdb-702c27113693b383728d0b423f58389544a80614.zip
gdb-702c27113693b383728d0b423f58389544a80614.tar.gz
gdb-702c27113693b383728d0b423f58389544a80614.tar.bz2
gdb
PR python/11915: * python/py-type.c (typy_array): New function. (type_object_methods): Add "array". gdb/doc PR python/11915: * gdb.texinfo (Types In Python): Document array method. gdb/testsuite PR python/11915: * gdb.python/py-type.exp (test_fields): Add tests for array.
Diffstat (limited to 'gdb/python')
-rw-r--r--gdb/python/py-type.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
index 529f301..ea6c8e5 100644
--- a/gdb/python/py-type.c
+++ b/gdb/python/py-type.c
@@ -262,6 +262,54 @@ typy_strip_typedefs (PyObject *self, PyObject *args)
return type_to_type_object (check_typedef (type));
}
+/* Return an array type. */
+
+static PyObject *
+typy_array (PyObject *self, PyObject *args)
+{
+ int n1, n2;
+ PyObject *n2_obj = NULL;
+ struct type *array = NULL;
+ struct type *type = ((type_object *) self)->type;
+ volatile struct gdb_exception except;
+
+ if (! PyArg_ParseTuple (args, "i|O", &n1, &n2_obj))
+ return NULL;
+
+ if (n2_obj)
+ {
+ if (!PyInt_Check (n2_obj))
+ {
+ PyErr_SetString (PyExc_RuntimeError,
+ _("Array bound must be an integer"));
+ return NULL;
+ }
+ n2 = (int) PyInt_AsLong (n2_obj);
+ if (PyErr_Occurred ())
+ return NULL;
+ }
+ else
+ {
+ n2 = n1;
+ n1 = 0;
+ }
+
+ if (n2 < n1)
+ {
+ PyErr_SetString (PyExc_ValueError,
+ _("Array length must not be negative"));
+ return NULL;
+ }
+
+ TRY_CATCH (except, RETURN_MASK_ALL)
+ {
+ array = lookup_array_range_type (type, n1, n2);
+ }
+ GDB_PY_HANDLE_EXCEPTION (except);
+
+ return type_to_type_object (array);
+}
+
/* Return a Type object which represents a pointer to SELF. */
static PyObject *
typy_pointer (PyObject *self, PyObject *args)
@@ -836,6 +884,9 @@ static PyGetSetDef type_object_getset[] =
static PyMethodDef type_object_methods[] =
{
+ { "array", typy_array, METH_VARARGS,
+ "array (N) -> Type\n\
+Return a type which represents an array of N objects of this type." },
{ "const", typy_const, METH_NOARGS,
"const () -> Type\n\
Return a const variant of this type." },