[gdb] Fix assert in remote_async_get_pending_events_handler
[deliverable/binutils-gdb.git] / gdb / ada-typeprint.c
index a58eabab06612decefa42d12d0193faaf3f38f6d..54bbe0f1a011ddc21b9332cedccd29a9b6bc0c54 100644 (file)
@@ -1,5 +1,5 @@
 /* Support for printing Ada types for GDB, the GNU debugger.
-   Copyright (C) 1986-2020 Free Software Foundation, Inc.
+   Copyright (C) 1986-2021 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -198,16 +198,16 @@ print_range_bound (struct type *type, const char *bounds, int *n,
   if (ada_scan_number (bounds, *n, &B, n))
     {
       /* STABS decodes all range types which bounds are 0 .. -1 as
-         unsigned integers (ie. the type code is TYPE_CODE_INT, not
-         TYPE_CODE_RANGE).  Unfortunately, ada_print_scalar() relies
-         on the unsigned flag to determine whether the bound should
-         be printed as a signed or an unsigned value.  This causes
-         the upper bound of the 0 .. -1 range types to be printed as
-         a very large unsigned number instead of -1.
-         To workaround this stabs deficiency, we replace the TYPE by NULL
-         to indicate default output when we detect that the bound is negative,
-         and the type is a TYPE_CODE_INT.  The bound is negative when
-         'm' is the last character of the number scanned in BOUNDS.  */
+        unsigned integers (ie. the type code is TYPE_CODE_INT, not
+        TYPE_CODE_RANGE).  Unfortunately, ada_print_scalar() relies
+        on the unsigned flag to determine whether the bound should
+        be printed as a signed or an unsigned value.  This causes
+        the upper bound of the 0 .. -1 range types to be printed as
+        a very large unsigned number instead of -1.
+        To workaround this stabs deficiency, we replace the TYPE by NULL
+        to indicate default output when we detect that the bound is negative,
+        and the type is a TYPE_CODE_INT.  The bound is negative when
+        'm' is the last character of the number scanned in BOUNDS.  */
       if (bounds[*n - 1] == 'm' && type->code () == TYPE_CODE_INT)
        type = NULL;
       ada_print_scalar (type, B, stream);
@@ -339,31 +339,6 @@ print_enum_type (struct type *type, struct ui_file *stream)
   fprintf_filtered (stream, ")");
 }
 
-/* Print representation of Ada fixed-point type TYPE on STREAM.  */
-
-static void
-print_gnat_encoded_fixed_point_type (struct type *type, struct ui_file *stream)
-{
-  struct value *delta = gnat_encoded_fixed_point_delta (type);
-  struct value *small = gnat_encoded_fixed_point_scaling_factor (type);
-
-  if (delta == nullptr)
-    fprintf_filtered (stream, "delta ??");
-  else
-    {
-      std::string str;
-      str = target_float_to_string (value_contents (delta),
-                                   value_type (delta), "%g");
-      fprintf_filtered (stream, "delta %s", str.c_str());
-      if (!value_equal (delta, small))
-       {
-         str = target_float_to_string (value_contents (small),
-                                       value_type (small), "%g");
-         fprintf_filtered (stream, " <'small = %s>", str.c_str());
-       }
-    }
-}
-
 /* Print simple (constrained) array type TYPE on STREAM.  LEVEL is the
    recursion (indentation) level, in case the element type itself has
    nested structure, and SHOW is the number of levels of internal
@@ -955,7 +930,20 @@ ada_print_type (struct type *type0, const char *varstring,
                const struct type_print_options *flags)
 {
   struct type *type = ada_check_typedef (ada_get_base_type (type0));
-  char *type_name = decoded_type_name (type0);
+  /* If we can decode the original type name, use it.  However, there
+     are cases where the original type is an internally-generated type
+     with a name that can't be decoded (and whose encoded name might
+     not actually bear any relation to the type actually declared in
+     the sources). In that case, try using the name of the base type
+     in its place.
+
+     Note that we looked at the possibility of always using the name
+     of the base type. This does not always work, unfortunately, as
+     there are situations where it's the base type which has an
+     internally-generated name.  */
+  const char *type_name = decoded_type_name (type0);
+  if (type_name == nullptr)
+    type_name = decoded_type_name (type);
   int is_var_decl = (varstring != NULL && varstring[0] != '\0');
 
   if (type == NULL)
@@ -993,7 +981,11 @@ ada_print_type (struct type *type0, const char *varstring,
        break;
       case TYPE_CODE_PTR:
       case TYPE_CODE_TYPEDEF:
-       fprintf_filtered (stream, "access ");
+       /* An __XVL field is not truly a pointer, so don't print
+          "access" in this case.  */
+       if (type->code () != TYPE_CODE_PTR
+           || strstr (varstring, "___XVL") == nullptr)
+         fprintf_filtered (stream, "access ");
        ada_print_type (TYPE_TARGET_TYPE (type), "", stream, show, level,
                        flags);
        break;
@@ -1009,26 +1001,27 @@ ada_print_type (struct type *type0, const char *varstring,
        fprintf_filtered (stream, "(false, true)");
        break;
       case TYPE_CODE_INT:
-       if (ada_is_gnat_encoded_fixed_point_type (type))
-         print_gnat_encoded_fixed_point_type (type, stream);
-       else
-         {
-           const char *name = ada_type_name (type);
-
-           if (!ada_is_range_type_name (name))
-             fprintf_styled (stream, metadata_style.style (),
-                             _("<%s-byte integer>"),
-                             pulongest (TYPE_LENGTH (type)));
-           else
-             {
-               fprintf_filtered (stream, "range ");
-               print_range_type (type, stream, 1 /* bounds_prefered_p */);
-             }
-         }
+       {
+         const char *name = ada_type_name (type);
+
+         if (!ada_is_range_type_name (name))
+           fprintf_styled (stream, metadata_style.style (),
+                           _("<%s-byte integer>"),
+                           pulongest (TYPE_LENGTH (type)));
+         else
+           {
+             fprintf_filtered (stream, "range ");
+             print_range_type (type, stream, 1 /* bounds_prefered_p */);
+           }
+       }
        break;
       case TYPE_CODE_RANGE:
-       if (ada_is_gnat_encoded_fixed_point_type (type))
-         print_gnat_encoded_fixed_point_type (type, stream);
+       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));
@@ -1071,7 +1064,7 @@ ada_print_type (struct type *type0, const char *varstring,
 
 void
 ada_print_typedef (struct type *type, struct symbol *new_symbol,
-                   struct ui_file *stream)
+                  struct ui_file *stream)
 {
   type = ada_check_typedef (type);
   ada_print_type (type, "", stream, 0, 0, &type_print_raw_options);
This page took 0.292364 seconds and 4 git commands to generate.