** New read-only attribute gdb.Type.is_scalar, which is True for
scalar types, and False for all other types.
+ ** New read-only attribute gdb.Type.is_signed. This attribute
+ should only be read when Type.is_scalar is True, and will be True
+ for signed types, and False for all other types. Attempting to
+ read this attribute for non-scalar types will raise a ValueError.
+
* New features in the GDB remote stub, GDBserver
** GDBserver is now supported on OpenRISC GNU/Linux.
structures, unions, and classes.
@end defvar
+@defvar Type.is_signed
+For scalar types (those for which @code{Type.is_scalar} is
+@code{True}), this property is @code{True} if the type is signed,
+otherwise this property is @code{False}.
+
+Attempting to read this property for a non-scalar type (a type for
+which @code{Type.is_scalar} is @code{False}), will raise a
+@code{ValueError}.
+@end defvar
+
The following methods are provided:
@defun Type.fields ()
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)
"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 }
};
}
foreach size {0 1 2 3 4 8 16} {
- foreach sign {"" ", True" ", False" ", None" ", \"blah\""} {
+ foreach sign_data {{"" True} \
+ {", True" True} \
+ {", False" False} \
+ {", None" False} \
+ {", \"blah\"" True}} {
+ set sign [lindex $sign_data 0]
+ # GDB's 0 bit type is always signed.
+ if { $size == 0 } {
+ set sign_result True
+ } else {
+ set sign_result [lindex $sign_data 1]
+ }
set fullsize [expr 8 * $size]
gdb_test_no_output "python t = arch.integer_type($fullsize$sign)" \
"get integer type for $size$sign"
gdb_test "python print(t.sizeof)" "$size" \
"print size of integer type for $size$sign"
+ gdb_test "python print(t.is_signed == ${sign_result})" "True" \
+ "check signedness of type for $size$sign"
}
}
gdb_test "python print (ttype.template_argument(2))" "&C::c"
}
+# Check the is_signed property of some types.
+proc test_is_signed {lang} {
+ if {$lang == "c++"} {
+ gdb_test "python print(gdb.parse_and_eval ('c').type.is_signed)" \
+ "ValueError: Type must be a scalar type.*"
+ gdb_test "python print(gdb.parse_and_eval ('&c').type.is_signed == False)" "True"
+ }
+
+ gdb_test "python print(gdb.parse_and_eval('global_unsigned_char').type.is_signed == False)" "True"
+ gdb_test "python print(gdb.parse_and_eval('global_char').type.is_signed)" "True|False"
+ gdb_test "python print(gdb.parse_and_eval('global_signed_char').type.is_signed == True)" "True"
+
+ gdb_test "python print(gdb.parse_and_eval ('ss.x').type.is_signed == True)" "True"
+ gdb_test "python print(gdb.parse_and_eval ('ss').type.is_signed)" \
+ "ValueError: Type must be a scalar type.*"
+ gdb_test "python print(gdb.parse_and_eval ('uu').type.is_signed)" \
+ "ValueError: Type must be a scalar type.*"
+ gdb_test "python print(gdb.parse_and_eval ('uu.i').type.is_signed == True)" "True"
+ gdb_test "python print(gdb.parse_and_eval ('uu.f').type.is_signed == True)" "True"
+ gdb_test "python print(gdb.parse_and_eval ('uu.a').type.is_signed)" \
+ "ValueError: Type must be a scalar type.*"
+
+ gdb_test "python print(gdb.parse_and_eval ('&ss.x').type.is_signed == False)" "True"
+ gdb_test "python print(gdb.parse_and_eval ('&uu').type.is_signed == False)" "True"
+}
+
# Test the gdb.Type.is_scalar property.
proc test_is_scalar { lang } {
if {$lang == "c++"} {
test_fields "c"
test_enums
test_is_scalar "c"
+ test_is_signed "c"
}
}
test_template
test_enums
test_is_scalar "c++"
+ test_is_signed "c++"
}
}