diff options
Diffstat (limited to 'gdb/python')
-rw-r--r-- | gdb/python/py-type.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c index 5476123..7be3f32 100644 --- a/gdb/python/py-type.c +++ b/gdb/python/py-type.c @@ -446,6 +446,27 @@ typy_is_scalar (PyObject *self, void *closure) Py_RETURN_FALSE; } +/* Return true if this type is signed. Raises a ValueError if this type + is not a scalar type. */ + +static PyObject * +typy_is_signed (PyObject *self, void *closure) +{ + struct type *type = ((type_object *) self)->type; + + if (!is_scalar_type (type)) + { + PyErr_SetString (PyExc_ValueError, + _("Type must be a scalar type")); + return nullptr; + } + + if (type->is_unsigned ()) + Py_RETURN_FALSE; + else + Py_RETURN_TRUE; +} + /* Return the type, stripped of typedefs. */ static PyObject * typy_strip_typedefs (PyObject *self, PyObject *args) @@ -1502,6 +1523,8 @@ static gdb_PyGetSetDef type_object_getset[] = "The objfile this type was defined in, or None.", NULL }, { "is_scalar", typy_is_scalar, nullptr, "Is this a scalar type?", nullptr }, + { "is_signed", typy_is_signed, nullptr, + "Is this an signed type?", nullptr }, { NULL } }; |