gdb/python: add Type.is_signed property
Add a new read-only property, Type.is_signed, which is True for signed types, and False otherwise. This property should only be read on types for which Type.is_scalar is true, attempting to read this property for non-scalar types will raise a ValueError. I chose 'is_signed' rather than 'is_unsigned' in order to match the existing Architecture.integer_type method, which takes a 'signed' parameter. As far as I could find, that was the only existing signed/unsigned selector in the Python API, so it seemed reasonable to stay consistent.
This commit is contained in:
parent
ee6a3d9e94
commit
551b380fbd
5 changed files with 80 additions and 1 deletions
|
@ -64,12 +64,25 @@ if { ![is_address_zero_readable] } {
|
|||
}
|
||||
|
||||
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"
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -270,6 +270,32 @@ proc test_template {} {
|
|||
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++"} {
|
||||
|
@ -320,6 +346,7 @@ if { [build_inferior "${binfile}" "c"] == 0 } {
|
|||
test_fields "c"
|
||||
test_enums
|
||||
test_is_scalar "c"
|
||||
test_is_signed "c"
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -334,5 +361,6 @@ if { [build_inferior "${binfile}-cxx" "c++"] == 0 } {
|
|||
test_template
|
||||
test_enums
|
||||
test_is_scalar "c++"
|
||||
test_is_signed "c++"
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue