[RFA] Add TYPE_CODE_FIXED_POINT handling in print_type_scalar

Joel Brobecker
2020-11-22T13:13:04Z

Hello,

This commit enhances print_type_scalar to include support for
TYPE_CODE_FIXED_POINT. This way, any language falling back to
this function for printing the description of some types
also gets basic ptype support for fixed point types as well.

This fixes a couple of XFAILs in gdb.dwarf2/dw2-fixed-point.exp.

gdb/ChangeLog:

* typeprint.c (print_type_scalar): Add handling of
TYPE_CODE_FIXED_POINT.

gdb/testsuite/ChangeLog:

* gdb.dwarf2/dw2-fixed-point.exp: Fix the expected output of
the "ptype pck__fp1_range_var" test for the module-2 and pascal
languages. Remove the associated setup_xfail.

The ptype output for range types in modula-2 and pascal is a little
odd (the type info is repeated twice around the ".." operator), but
I guess that's how they present range types in those languages.

Tested on x86_64-linux, with the 2 XFAILs replaced by PASSes and
no regression.

OK to push to master?

Thanks,
--
Joel

---
gdb/testsuite/gdb.dwarf2/dw2-fixed-point.exp | 28 ++++++++++++++++++----------
gdb/typeprint.c | 4 ++++
2 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/gdb/testsuite/gdb.dwarf2/dw2-fixed-point.exp b/gdb/testsuite/gdb.dwarf2/dw2-fixed-point.exp
index a82a9af..67d1d34 100644
--- a/gdb/testsuite/gdb.dwarf2/dw2-fixed-point.exp
+++ b/gdb/testsuite/gdb.dwarf2/dw2-fixed-point.exp
@@ -278,9 +278,6 @@ proc do_ptype_test {lang fp1_re fp2_re fp3_re fp1_range_re} {

gdb_test "ptype pck__fp3_var" $fp3_re

- if { $lang == "modula-2" || $lang == "pascal" } {
- setup_xfail "*-*-*" "not supported by language"
- }
gdb_test "ptype pck__fp1_range_var" $fp1_range_re
}
}
@@ -299,10 +296,21 @@ foreach lang [list "c" "d" "go" "objective-c" "opencl" ] {
" = <range type>"
}

-foreach lang [list "fortran" "modula-2" "pascal" ] {
- do_ptype_test $lang \
- " = pck__fp1_type" \
- " = pck__fp2_type" \
- " = pck__fp3_type" \
- " = <range type>"
-}
+do_ptype_test "fortran" \
+ " = pck__fp1_type" \
+ " = pck__fp2_type" \
+ " = pck__fp3_type" \
+ " = <range type>"
+
+do_ptype_test "modula-2" \
+ " = pck__fp1_type" \
+ " = pck__fp2_type" \
+ " = pck__fp3_type" \
+ " = \\\[1-byte fixed point \\(small = 1/16\\)\\.\\.1-byte fixed point \\(small = 1/16\\)\\\]"
+
+do_ptype_test "pascal" \
+ " = pck__fp1_type" \
+ " = pck__fp2_type" \
+ " = pck__fp3_type" \
+ " = 1-byte fixed point \\(small = 1/16\\)\\.\\.1-byte fixed point \\(small = 1/16\\)"
+
diff --git a/gdb/typeprint.c b/gdb/typeprint.c
index a3fc9cc..47019a2 100644
--- a/gdb/typeprint.c
+++ b/gdb/typeprint.c
@@ -637,6 +637,10 @@ print_type_scalar (struct type *type, LONGEST val, struct ui_file *stream)
print_type_scalar (TYPE_TARGET_TYPE (type), val, stream);
return;

+ case TYPE_CODE_FIXED_POINT:
+ print_type_fixed_point (type, stream);
+ break;
+
case TYPE_CODE_UNDEF:
case TYPE_CODE_PTR:
case TYPE_CODE_ARRAY:
--
2.1.4