Add ptype support for DWARF-based fixed-point types
authorJoel Brobecker <brobecker@adacore.com>
Sun, 15 Nov 2020 08:16:01 +0000 (03:16 -0500)
committerJoel Brobecker <brobecker@adacore.com>
Sun, 15 Nov 2020 08:16:01 +0000 (03:16 -0500)
Note that the ptype information printed for types described
via pure DWARF debug info is slightly less informative as
the one printed when the information is encoded in the type's
name, via the GNAT encoding. As a result, the output in
the case of DWARF-described fixed point types is slightly
different. In pratice, this is no real loss because the information
not available in DWARF has no bearing on how the type is actually
stored in memory.

gdb/ChangeLog:

        * ada-typeprint.c (ada_print_type): Add handing of fixed-point
        range types.
        * c-typeprint.c (c_type_print_varspec_prefix)
        (c_type_print_varspec_suffix, c_type_print_base_1): Add
        TYPE_CODE_FIXED_POINT handling.
        * p-typeprint.c (pascal_type_print_varspec_prefix)
        (pascal_type_print_varspec_suffix): Likewise.
        * typeprint.c (print_type_fixed_point): New function.
        * typeprint.h (print_type_fixed_point): Add declaration.

gdb/testsuite/ChangeLog:

        * gdb.ada/fixed_points.exp: Add ptype tests.
        * gdb.dwarf2/dw2-fixed-point.exp: Likewise.

gdb/ChangeLog
gdb/ada-typeprint.c
gdb/c-typeprint.c
gdb/p-typeprint.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.ada/fixed_points.exp
gdb/testsuite/gdb.dwarf2/dw2-fixed-point.exp
gdb/typeprint.c
gdb/typeprint.h

index 0d322da69c505e7733de3f83e588543612d705a9..56e54d3efadb74afd60a0763072cdab9f9709930 100644 (file)
@@ -1,3 +1,15 @@
+2020-11-15  Joel Brobecker  <brobecker@adacore.com>
+
+       * ada-typeprint.c (ada_print_type): Add handing of fixed-point
+       range types.
+       * c-typeprint.c (c_type_print_varspec_prefix)
+       (c_type_print_varspec_suffix, c_type_print_base_1): Add
+       TYPE_CODE_FIXED_POINT handling.
+       * p-typeprint.c (pascal_type_print_varspec_prefix)
+       (pascal_type_print_varspec_suffix): Likewise.
+       * typeprint.c (print_type_fixed_point): New function.
+       * typeprint.h (print_type_fixed_point): Add declaration.
+
 2020-11-15  Joel Brobecker  <brobecker@adacore.com>
 
        * printcmd.c (print_scalar_formatted): Add fixed-point type
index 5388247957be8c269f5f3dff58673e086689d3f0..8abb65bc9e23bb1a0ab8fede178884bf1134caac 100644 (file)
@@ -1046,6 +1046,12 @@ ada_print_type (struct type *type0, const char *varstring,
       case TYPE_CODE_RANGE:
        if (ada_is_gnat_encoded_fixed_point_type (type))
          print_gnat_encoded_fixed_point_type (type, stream);
+       else if (is_fixed_point_type (type))
+         {
+           fprintf_filtered (stream, "<");
+           print_type_fixed_point (type, stream);
+           fprintf_filtered (stream, ">");
+         }
        else if (ada_is_modular_type (type))
          fprintf_filtered (stream, "mod %s", 
                            int_string (ada_modulus (type), 10, 0, 0, 1));
index e72fdaad30ae28956426ee0f9c0ab3718c3617b4..10631fff9a8006baf885dcd03720074d5f95f8b9 100644 (file)
@@ -465,6 +465,7 @@ c_type_print_varspec_prefix (struct type *type,
     case TYPE_CODE_COMPLEX:
     case TYPE_CODE_NAMESPACE:
     case TYPE_CODE_DECFLOAT:
+    case TYPE_CODE_FIXED_POINT:
       /* These types need no prefix.  They are listed here so that
         gcc -Wall will reveal any types that haven't been handled.  */
       break;
@@ -844,6 +845,7 @@ c_type_print_varspec_suffix (struct type *type,
     case TYPE_CODE_COMPLEX:
     case TYPE_CODE_NAMESPACE:
     case TYPE_CODE_DECFLOAT:
+    case TYPE_CODE_FIXED_POINT:
       /* These types do not need a suffix.  They are listed so that
         gcc -Wall will report types that may not have been
         considered.  */
@@ -1683,6 +1685,10 @@ c_type_print_base_1 (struct type *type, struct ui_file *stream,
       fprintf_styled (stream, metadata_style.style (), _("<range type>"));
       break;
 
+    case TYPE_CODE_FIXED_POINT:
+      print_type_fixed_point (type, stream);
+      break;
+
     case TYPE_CODE_NAMESPACE:
       fputs_filtered ("namespace ", stream);
       fputs_filtered (type->name (), stream);
index ef0f25486d1d58a2a0b0aef4c37086efab5e4312..c2c182a9ae9087ff8fa44e67deb6afa60b250412 100644 (file)
@@ -296,6 +296,7 @@ pascal_type_print_varspec_prefix (struct type *type, struct ui_file *stream,
     case TYPE_CODE_STRING:
     case TYPE_CODE_COMPLEX:
     case TYPE_CODE_TYPEDEF:
+    case TYPE_CODE_FIXED_POINT:
       /* These types need no prefix.  They are listed here so that
         gcc -Wall will reveal any types that haven't been handled.  */
       break;
@@ -429,6 +430,7 @@ pascal_type_print_varspec_suffix (struct type *type, struct ui_file *stream,
     case TYPE_CODE_STRING:
     case TYPE_CODE_COMPLEX:
     case TYPE_CODE_TYPEDEF:
+    case TYPE_CODE_FIXED_POINT:
       /* These types do not need a suffix.  They are listed so that
         gcc -Wall will report types that may not have been considered.  */
       break;
index 9b9ffe51133bb575a7e80d42ae41beecaa5b00a6..2c7b5c5a522da04243a04273764fe1de27f39ca9 100644 (file)
@@ -1,3 +1,8 @@
+2020-11-15  Joel Brobecker  <brobecker@adacore.com>
+
+       * gdb.ada/fixed_points.exp: Add ptype tests.
+       * gdb.dwarf2/dw2-fixed-point.exp: Likewise.
+
 2020-11-15  Joel Brobecker  <brobecker@adacore.com>
 
        * gdb.dwarf2/dw2-fixed-point.exp: Add "print /x" tests.
index 655ee955d3ef51f0cc3a799ba6fba58fc44c1b8e..1fe2eb203cbee46096a0c27926ece96a9cb58a7b 100644 (file)
@@ -55,8 +55,44 @@ gdb_test "ptype Overprecise_Object" \
 gdb_test "print fp1_var" \
          " = 0.25"
 
+gdb_test_multiple "ptype fp1_var" "" {
+    -re "type = <1-byte fixed point \\(small = 0\\.0625\\)>\r\n$gdb_prompt $" {
+        pass $gdb_test_name
+    }
+    -re "type = delta 0\\.1 <'small = 0\\.0625>\r\n$gdb_prompt $" {
+        # The (legacy) output we obtain when the compiler described
+        # our fixed point types using the GNAT encodings rather than
+        # standard DWARF.  OK as well.
+        pass $gdb_test_name
+    }
+}
+
 gdb_test "print fp2_var" \
          " = -0.01"
 
+gdb_test_multiple "ptype fp2_var" "" {
+    -re "type = <8-byte fixed point \\(small = 0\\.01\\)>\r\n$gdb_prompt $" {
+        pass $gdb_test_name
+    }
+    -re "type = delta 0\\.01\r\n$gdb_prompt $" {
+        # The (legacy) output we obtain when the compiler described
+        # our fixed point types using the GNAT encodings rather than
+        # standard DWARF.  OK as well.
+        pass $gdb_test_name
+    }
+}
+
 gdb_test "print fp3_var" \
          " = 0.1"
+
+gdb_test_multiple "ptype fp3_var" "" {
+    -re "type = <1-byte fixed point \\(small = 0\\.0333333\\)>\r\n$gdb_prompt $" {
+        pass $gdb_test_name
+    }
+    -re "type = delta 0\\.1 <'small = 0\\.0333333>\r\n$gdb_prompt $" {
+        # The (legacy) output we obtain when the compiler described
+        # our fixed point types using the GNAT encodings rather than
+        # standard DWARF.  OK as well.
+        pass $gdb_test_name
+    }
+}
index 27c549c602f481b073c5f8eb9cd1f4e2ae4d98c7..33a7e7485cb09787b3f18131ca8196586d87e9c5 100644 (file)
@@ -142,3 +142,47 @@ gdb_test "print pck.fp1_range_var" \
 
 gdb_test "print /x pck.fp1_range_var" \
          " = 0x1"
+
+# Set the language to LANG and do a ptype test on pck__fp1_var,
+# pck__fp2_var and pck__fp3_var, verifying that the output matches
+# FP1_RE, FP2_RE, FP2_RE (resp.).
+
+proc do_ptype_test {lang fp1_re fp2_re fp3_re fp1_range_re} {
+    with_test_prefix "lang=$lang" {
+        gdb_test_no_output "set language $lang" \
+            "set language to $lang for ptype test"
+
+        gdb_test "ptype pck__fp1_var" $fp1_re
+
+        gdb_test "ptype pck__fp2_var" $fp2_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
+    }
+}
+
+do_ptype_test "ada" \
+              " = <1-byte fixed point \\(small = 1/16\\)>" \
+              " = <1-byte fixed point \\(small = 1/100\\)>" \
+              " = <1-byte fixed point \\(small = 1/30\\)>" \
+              " = <1-byte fixed point \\(small = 1/16\\)>"
+
+foreach lang [list "c" "d" "go" "objective-c" "opencl" ] {
+    do_ptype_test $lang \
+                  " = 1-byte fixed point \\(small = 1/16\\)" \
+                  " = 1-byte fixed point \\(small = 1/100\\)" \
+                  " = 1-byte fixed point \\(small = 1/30\\)" \
+                  " = <range type>"
+}
+
+foreach lang [list "fortran" "modula-2" "pascal" ] {
+    do_ptype_test $lang \
+                  " = pck__fp1_type" \
+                  " = pck__fp2_type" \
+                  " = pck__fp3_type" \
+                  " = <range type>"
+}
index acaee449ab7fb9048ad4df3b94e4154850e69d0c..f947faf315f6566d74f1b0bb53b49f3ef7ba11e2 100644 (file)
@@ -662,6 +662,18 @@ print_type_scalar (struct type *type, LONGEST val, struct ui_file *stream)
     }
 }
 
+/* See typeprint.h.  */
+
+void
+print_type_fixed_point (struct type *type, struct ui_file *stream)
+{
+  gdb::unique_xmalloc_ptr<char> small_img
+    = fixed_point_scaling_factor (type).str ();
+
+  fprintf_filtered (stream, "%s-byte fixed point (small = %s)",
+                   pulongest (TYPE_LENGTH (type)), small_img.get ());
+}
+
 /* Dump details of a type specified either directly or indirectly.
    Uses the same sort of type lookup mechanism as ptype_command()
    and whatis_command().  */
index 8936b9adf53787b93093497e9c7f3a2f49f11581..d595cbe208cf3671cc9af76929734c64c407fa78 100644 (file)
@@ -151,6 +151,11 @@ private:
 
 void print_type_scalar (struct type * type, LONGEST, struct ui_file *);
 
+/* Assuming the TYPE is a fixed point type, print its type description
+   on STREAM.  */
+
+void print_type_fixed_point (struct type *type, struct ui_file *stream);
+
 void c_type_print_args (struct type *, struct ui_file *, int, enum language,
                        const struct type_print_options *);
 
This page took 0.045915 seconds and 4 git commands to generate.