diff options
Diffstat (limited to 'gdb')
-rw-r--r-- | gdb/ChangeLog | 6 | ||||
-rw-r--r-- | gdb/doc/ChangeLog | 4 | ||||
-rw-r--r-- | gdb/doc/gdb.texinfo | 7 | ||||
-rw-r--r-- | gdb/python/py-type.c | 67 | ||||
-rw-r--r-- | gdb/testsuite/ChangeLog | 4 | ||||
-rw-r--r-- | gdb/testsuite/gdb.python/py-type.exp | 24 |
6 files changed, 112 insertions, 0 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index b9f8d02..23a7bc0 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,9 @@ +2009-12-08 Phil Muldoon <pmuldoon@redhat.com> + + PR python/10804 + + * python/py-type.c (typy_range): New Function. + 2009-12-07 Doug Evans <dje@google.com> * charset.c: Include environ.h. diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog index 8e5eed6..a60e973 100644 --- a/gdb/doc/ChangeLog +++ b/gdb/doc/ChangeLog @@ -1,3 +1,7 @@ +2009-12-08 Phil Muldoon <pmuldoon@redhat.com> + + * gdb.texinfo (Types In Python): Describe range function. + 2009-12-03 Richard Ward <richard.j.ward1@googlemail.com> * gdb.texinfo (Types In Python): Describe "is_base_class". diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index b5862c1..e880838 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -19654,6 +19654,13 @@ variant of this type. That is, the result is neither @code{const} nor @code{volatile}. @end defmethod +@defmethod Type range +Return a Python @code{Tuple} object that contains two elements: the +low bound of the argument type and the high bound of that type. If +the type does not have a range, @value{GDBN} will raise a +@code{RuntimeError} exception. +@end defmethod + @defmethod Type reference Return a new @code{gdb.Type} object which represents a reference to this type. diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c index e73185e..c581307 100644 --- a/gdb/python/py-type.c +++ b/gdb/python/py-type.c @@ -273,6 +273,70 @@ typy_pointer (PyObject *self, PyObject *args) return type_to_type_object (type); } +/* Return the range of a type represented by SELF. The return type is + a tuple. The first element of the tuple contains the low bound, + while the second element of the tuple contains the high bound. */ +static PyObject * +typy_range (PyObject *self, PyObject *args) +{ + struct type *type = ((type_object *) self)->type; + PyObject *result; + PyObject *low_bound = NULL, *high_bound = NULL; + LONGEST low, high; + + if (TYPE_CODE (type) != TYPE_CODE_ARRAY + && TYPE_CODE (type) != TYPE_CODE_STRING + && TYPE_CODE (type) != TYPE_CODE_RANGE) + { + PyErr_SetString (PyExc_RuntimeError, + "This type does not have a range."); + return NULL; + } + + switch (TYPE_CODE (type)) + { + case TYPE_CODE_ARRAY: + case TYPE_CODE_STRING: + low = TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type)); + high = TYPE_HIGH_BOUND (TYPE_INDEX_TYPE (type)); + break; + case TYPE_CODE_RANGE: + low = TYPE_LOW_BOUND (type); + high = TYPE_HIGH_BOUND (type); + break; + } + + low_bound = PyLong_FromLong (low); + if (!low_bound) + goto failarg; + + high_bound = PyLong_FromLong (high); + if (!high_bound) + goto failarg; + + result = PyTuple_New (2); + if (!result) + goto failarg; + + if (PyTuple_SetItem (result, 0, low_bound) != 0) + { + Py_DECREF (result); + goto failarg; + } + if (PyTuple_SetItem (result, 1, high_bound) != 0) + { + Py_DECREF (high_bound); + Py_DECREF (result); + return NULL; + } + return result; + + failarg: + Py_XDECREF (high_bound); + Py_XDECREF (low_bound); + return NULL; +} + /* Return a Type object which represents a reference to SELF. */ static PyObject * typy_reference (PyObject *self, PyObject *args) @@ -699,6 +763,9 @@ Each field is a dictionary." }, { "pointer", typy_pointer, METH_NOARGS, "pointer () -> Type\n\ Return a type of pointer to this type." }, + { "range", typy_range, METH_NOARGS, + "range () -> tuple\n\ +Return a tuple containing the lower and upper range for this type."}, { "reference", typy_reference, METH_NOARGS, "reference () -> Type\n\ Return a type of reference to this type." }, diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 65d1ee6..069280c 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2009-12-08 Phil Muldoon <pmuldoon@redhat.com> + + * gdb.python/py-type.exp (test_range): New test. + 2009-12-03 Phil Muldoon <pmuldoon@redhat.com> PR python/10805 diff --git a/gdb/testsuite/gdb.python/py-type.exp b/gdb/testsuite/gdb.python/py-type.exp index fabda5b..5fa0877 100644 --- a/gdb/testsuite/gdb.python/py-type.exp +++ b/gdb/testsuite/gdb.python/py-type.exp @@ -102,6 +102,29 @@ proc test_base_class {} { gdb_test "python print fields\[1\].is_base_class" "False" "Check base class" } +proc test_range {} { + + # Test a valid range request. + gdb_py_test_silent_cmd "print ar" "print value" 1 + gdb_py_test_silent_cmd "python ar = gdb.history (0)" "get value from history" 1 + gdb_test "python print len(ar.type.range())" "2" "Check correct tuple length" + gdb_test "python print ar.type.range()\[0\]" "0" "Check low range" + gdb_test "python print ar.type.range()\[1\]" "1" "Check high range" + + # Test a range request on a ranged type. + gdb_py_test_silent_cmd "print ar" "print value" 1 + gdb_py_test_silent_cmd "python ar = gdb.history (0)" "get value from history" 1 + gdb_py_test_silent_cmd "python fields = ar.type.fields()" "get fields" 1 + gdb_test "python print fields\[0\].type.range()\[0\]" "0" "Check range type low bound" + gdb_test "python print fields\[0\].type.range()\[1\]" "1" "Check range type high bound" + + # Test where a range does not exist. + gdb_py_test_silent_cmd "print st" "print value" 1 + gdb_py_test_silent_cmd "python st = gdb.history (0)" "get value from history" 1 + gdb_test "python print st.type.range()" "RuntimeError: This type does not have a range.*" "Check range for non ranged type." +} + + # Perform C Tests. build_inferior "c" restart_gdb "break to inspect struct and array." @@ -112,3 +135,4 @@ build_inferior "c++" restart_gdb "break to inspect struct and array." test_fields "c++" test_base_class +test_range |