gdb/linux: remove ptrace support check for exec, fork, vfork, vforkdone, clone, sysgood
[binutils-gdb.git] / gdb / c-typeprint.c
index 35cfd219edcae6f723d2aa8f01af9a6bcf6568aa..405ede8b9c88ae3aa0a30385c199f75de1e7743b 100644 (file)
@@ -1,5 +1,5 @@
 /* Support for printing C and C++ types for GDB, the GNU debugger.
-   Copyright (C) 1986-2020 Free Software Foundation, Inc.
+   Copyright (C) 1986-2022 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -17,7 +17,7 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include "defs.h"
-#include "gdb_obstack.h"
+#include "gdbsupport/gdb_obstack.h"
 #include "bfd.h"               /* Binary File Description.  */
 #include "symtab.h"
 #include "gdbtypes.h"
@@ -119,6 +119,7 @@ c_print_type_1 (struct type *type,
   code = type->code ();
   if (local_name != NULL)
     {
+      c_type_print_modifier (type, stream, 0, 1, language);
       fputs_filtered (local_name, stream);
       if (varstring != NULL && *varstring != '\0')
        fputs_filtered (" ", stream);
@@ -133,7 +134,7 @@ c_print_type_1 (struct type *type,
              && (code == TYPE_CODE_PTR || code == TYPE_CODE_FUNC
                  || code == TYPE_CODE_METHOD
                  || (code == TYPE_CODE_ARRAY
-                     && !TYPE_VECTOR (type))
+                     && !type->is_vector ())
                  || code == TYPE_CODE_MEMBERPTR
                  || code == TYPE_CODE_METHODPTR
                  || TYPE_IS_REFERENCE (type))))
@@ -151,7 +152,7 @@ c_print_type_1 (struct type *type,
        fputs_styled (varstring, variable_name_style.style (), stream);
 
       /* For demangled function names, we have the arglist as part of
-         the name, so don't print an additional pair of ()'s.  */
+        the name, so don't print an additional pair of ()'s.  */
       if (local_name == NULL)
        {
          demangled_args = strchr (varstring, '(') != NULL;
@@ -171,7 +172,7 @@ c_print_type (struct type *type,
              int show, int level,
              const struct type_print_options *flags)
 {
-  struct print_offset_data podata;
+  struct print_offset_data podata (flags);
 
   c_print_type_1 (type, varstring, stream, show, level,
                  current_language->la_language, flags, &podata);
@@ -188,7 +189,7 @@ c_print_type (struct type *type,
              enum language language,
              const struct type_print_options *flags)
 {
-  struct print_offset_data podata;
+  struct print_offset_data podata (flags);
 
   c_print_type_1 (type, varstring, stream, show, level, language, flags,
                  &podata);
@@ -206,10 +207,10 @@ c_print_typedef (struct type *type,
   type = check_typedef (type);
   fprintf_filtered (stream, "typedef ");
   type_print (type, "", stream, -1);
-  if ((SYMBOL_TYPE (new_symbol))->name () == 0
-      || strcmp ((SYMBOL_TYPE (new_symbol))->name (),
+  if ((new_symbol->type ())->name () == 0
+      || strcmp ((new_symbol->type ())->name (),
                 new_symbol->linkage_name ()) != 0
-      || SYMBOL_TYPE (new_symbol)->code () == TYPE_CODE_TYPEDEF)
+      || new_symbol->type ()->code () == TYPE_CODE_TYPEDEF)
     fprintf_filtered (stream, " %s", new_symbol->print_name ());
   fprintf_filtered (stream, ";");
 }
@@ -249,7 +250,7 @@ cp_type_print_derivation_info (struct ui_file *stream,
 
   for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
     {
-      wrap_here ("        ");
+      stream->wrap_here (8);
       fputs_filtered (i == 0 ? ": " : ", ", stream);
       fprintf_filtered (stream, "%s%s ",
                        BASETYPE_VIA_PUBLIC (type, i)
@@ -279,7 +280,7 @@ cp_type_print_method_args (struct type *mtype, const char *prefix,
 {
   struct field *args = mtype->fields ();
   int nargs = mtype->num_fields ();
-  int varargs = TYPE_VARARGS (mtype);
+  int varargs = mtype->has_varargs ();
   int i;
 
   fprintf_symbol_filtered (stream, prefix,
@@ -302,14 +303,14 @@ cp_type_print_method_args (struct type *mtype, const char *prefix,
          if (FIELD_ARTIFICIAL (arg))
            continue;
 
-         c_print_type (arg.type, "", stream, 0, 0, flags);
+         c_print_type (arg.type (), "", stream, 0, 0, flags);
 
          if (i == nargs && varargs)
            fprintf_filtered (stream, ", ...");
          else if (i < nargs)
            {
              fprintf_filtered (stream, ", ");
-             wrap_here ("        ");
+             stream->wrap_here (8);
            }
        }
     }
@@ -327,8 +328,8 @@ cp_type_print_method_args (struct type *mtype, const char *prefix,
       struct type *domain;
 
       gdb_assert (nargs > 0);
-      gdb_assert (args[0].type->code () == TYPE_CODE_PTR);
-      domain = TYPE_TARGET_TYPE (args[0].type);
+      gdb_assert (args[0].type ()->code () == TYPE_CODE_PTR);
+      domain = TYPE_TARGET_TYPE (args[0].type ());
 
       if (TYPE_CONST (domain))
        fprintf_filtered (stream, " const");
@@ -436,8 +437,8 @@ c_type_print_varspec_prefix (struct type *type,
 
     case TYPE_CODE_ARRAY:
       c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type),
-                                  stream, show, 0, 0, language, flags,
-                                  podata);
+                                  stream, show, 0, need_post_space,
+                                  language, flags, podata);
       if (passed_a_ptr)
        fprintf_filtered (stream, "(");
       break;
@@ -465,8 +466,9 @@ 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.  */
+        gcc -Wall will reveal any types that haven't been handled.  */
       break;
     default:
       error (_("type not handled in c_type_print_varspec_prefix()"));
@@ -526,8 +528,9 @@ c_type_print_modifier (struct type *type, struct ui_file *stream,
       did_print_modifier = 1;
     }
 
-  address_space_id = address_space_int_to_name (get_type_arch (type),
-                                               TYPE_INSTANCE_FLAGS (type));
+  address_space_id
+    = address_space_type_instance_flags_to_name (type->arch (),
+                                                type->instance_flags ());
   if (address_space_id)
     {
       if (did_print_modifier || need_pre_space)
@@ -570,10 +573,10 @@ c_type_print_args (struct type *type, struct ui_file *stream,
       if (printed_any)
        {
          fprintf_filtered (stream, ", ");
-         wrap_here ("    ");
+         stream->wrap_here (4);
        }
 
-      param_type = TYPE_FIELD_TYPE (type, i);
+      param_type = type->field (i).type ();
 
       if (language == language_cplus && linkage_name)
        {
@@ -591,20 +594,20 @@ c_type_print_args (struct type *type, struct ui_file *stream,
       printed_any = 1;
     }
 
-  if (printed_any && TYPE_VARARGS (type))
+  if (printed_any && type->has_varargs ())
     {
       /* Print out a trailing ellipsis for varargs functions.  Ignore
         TYPE_VARARGS if the function has no named arguments; that
         represents unprototyped (K&R style) C functions.  */
-      if (printed_any && TYPE_VARARGS (type))
+      if (printed_any && type->has_varargs ())
        {
          fprintf_filtered (stream, ", ");
-         wrap_here ("    ");
+         stream->wrap_here (4);
          fprintf_filtered (stream, "...");
        }
     }
   else if (!printed_any
-          && (TYPE_PROTOTYPED (type) || language == language_cplus))
+          && (type->is_prototyped () || language == language_cplus))
     fprintf_filtered (stream, "void");
 
   fprintf_filtered (stream, ")");
@@ -672,16 +675,16 @@ is_type_conversion_operator (struct type *type, int i, int j)
    form.  Even the author of this function feels that writing little
    parsers like this everywhere is stupid.  */
 
-static char *
-remove_qualifiers (char *qid)
+static const char *
+remove_qualifiers (const char *qid)
 {
   int quoted = 0;      /* Zero if we're not in quotes;
                           '"' if we're in a double-quoted string;
                           '\'' if we're in a single-quoted string.  */
   int depth = 0;       /* Number of unclosed parens we've seen.  */
   char *parenstack = (char *) alloca (strlen (qid));
-  char *scan;
-  char *last = 0;      /* The character after the rightmost
+  const char *scan;
+  const char *last = 0;        /* The character after the rightmost
                           `::' token we've seen so far.  */
 
   for (scan = qid; *scan; scan++)
@@ -772,7 +775,7 @@ c_type_print_varspec_suffix (struct type *type,
     case TYPE_CODE_ARRAY:
       {
        LONGEST low_bound, high_bound;
-       int is_vector = TYPE_VECTOR (type);
+       int is_vector = type->is_vector ();
 
        if (passed_a_ptr)
          fprintf_filtered (stream, ")");
@@ -780,8 +783,8 @@ c_type_print_varspec_suffix (struct type *type,
        fprintf_filtered (stream, (is_vector ?
                                   " __attribute__ ((vector_size(" : "["));
        /* Bounds are not yet resolved, print a bounds placeholder instead.  */
-       if (TYPE_HIGH_BOUND_KIND (type->index_type ()) == PROP_LOCEXPR
-           || TYPE_HIGH_BOUND_KIND (type->index_type ()) == PROP_LOCLIST)
+       if (type->bounds ()->high.kind () == PROP_LOCEXPR
+           || type->bounds ()->high.kind () == PROP_LOCLIST)
          fprintf_filtered (stream, "variable length");
        else if (get_array_bounds (type, &low_bound, &high_bound))
          fprintf_filtered (stream, "%s", 
@@ -843,9 +846,10 @@ 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.  */
+        gcc -Wall will report types that may not have been
+        considered.  */
       break;
     default:
       error (_("type not handled in c_type_print_varspec_suffix()"));
@@ -879,23 +883,23 @@ c_type_print_template_args (const struct type_print_options *flags,
     {
       struct symbol *sym = TYPE_TEMPLATE_ARGUMENT (type, i);
 
-      if (SYMBOL_CLASS (sym) != LOC_TYPEDEF)
+      if (sym->aclass () != LOC_TYPEDEF)
        continue;
 
       if (first)
        {
-         wrap_here ("    ");
+         stream->wrap_here (4);
          fprintf_filtered (stream, _("[with %s = "), sym->linkage_name ());
          first = 0;
        }
       else
        {
          fputs_filtered (", ", stream);
-         wrap_here ("         ");
+         stream->wrap_here (9);
          fprintf_filtered (stream, "%s = ", sym->linkage_name ());
        }
 
-      c_print_type (SYMBOL_TYPE (sym), "", stream, -1, 0, flags);
+      c_print_type (sym->type (), "", stream, -1, 0, flags);
     }
 
   if (!first)
@@ -962,7 +966,7 @@ output_access_specifier (struct ui_file *stream,
 static bool
 need_access_label_p (struct type *type)
 {
-  if (TYPE_DECLARED_CLASS (type))
+  if (type->is_declared_class ())
     {
       QUIT;
       for (int i = TYPE_N_BASECLASSES (type); i < type->num_fields (); i++)
@@ -1058,7 +1062,7 @@ c_type_print_base_struct_union (struct type *type, struct ui_file *stream,
   c_type_print_modifier (type, stream, 0, 1, language);
   if (type->code () == TYPE_CODE_UNION)
     fprintf_filtered (stream, "union ");
-  else if (TYPE_DECLARED_CLASS (type))
+  else if (type->is_declared_class ())
     fprintf_filtered (stream, "class ");
   else
     fprintf_filtered (stream, "struct ");
@@ -1118,14 +1122,13 @@ c_type_print_base_struct_union (struct type *type, struct ui_file *stream,
       if (type->num_fields () == 0 && TYPE_NFN_FIELDS (type) == 0
          && TYPE_TYPEDEF_FIELD_COUNT (type) == 0)
        {
-         if (TYPE_STUB (type))
-           fprintfi_filtered (level + 4, stream,
-                              _("%p[<incomplete type>%p]\n"),
-                              metadata_style.style ().ptr (), nullptr);
+         print_spaces_filtered_with_print_options (level + 4, stream, flags);
+         if (type->is_stub ())
+           fprintf_filtered (stream, _("%p[<incomplete type>%p]\n"),
+                             metadata_style.style ().ptr (), nullptr);
          else
-           fprintfi_filtered (level + 4, stream,
-                              _("%p[<no data fields>%p]\n"),
-                              metadata_style.style ().ptr (), nullptr);
+           fprintf_filtered (stream, _("%p[<no data fields>%p]\n"),
+                             metadata_style.style ().ptr (), nullptr);
        }
 
       /* Start off with no specific section type, so we can print
@@ -1146,7 +1149,7 @@ c_type_print_base_struct_union (struct type *type, struct ui_file *stream,
       int len = type->num_fields ();
       vptr_fieldno = get_vptr_fieldno (type, &basetype);
 
-      struct print_offset_data local_podata;
+      struct print_offset_data local_podata (flags);
 
       for (int i = TYPE_N_BASECLASSES (type); i < len; i++)
        {
@@ -1179,8 +1182,8 @@ c_type_print_base_struct_union (struct type *type, struct ui_file *stream,
          int newshow = show - 1;
 
          if (!is_static && flags->print_offsets
-             && (TYPE_FIELD_TYPE (type, i)->code () == TYPE_CODE_STRUCT
-                 || TYPE_FIELD_TYPE (type, i)->code () == TYPE_CODE_UNION))
+             && (type->field (i).type ()->code () == TYPE_CODE_STRUCT
+                 || type->field (i).type ()->code () == TYPE_CODE_UNION))
            {
              /* If we're printing offsets and this field's type is
                 either a struct or an union, then we're interested in
@@ -1190,7 +1193,7 @@ c_type_print_base_struct_union (struct type *type, struct ui_file *stream,
              /* Make sure we carry our offset when we expand the
                 struct/union.  */
              local_podata.offset_bitpos
-               = podata->offset_bitpos + TYPE_FIELD_BITPOS (type, i);
+               = podata->offset_bitpos + type->field (i).loc_bitpos ();
              /* We're entering a struct/union.  Right now,
                 PODATA->END_BITPOS points right *after* the
                 struct/union.  However, when printing the first field
@@ -1200,11 +1203,11 @@ c_type_print_base_struct_union (struct type *type, struct ui_file *stream,
                 the whole struct/union.  */
              local_podata.end_bitpos
                = podata->end_bitpos
-                 - TYPE_LENGTH (TYPE_FIELD_TYPE (type, i)) * TARGET_CHAR_BIT;
+                 - TYPE_LENGTH (type->field (i).type ()) * TARGET_CHAR_BIT;
            }
 
-         c_print_type_1 (TYPE_FIELD_TYPE (type, i),
-                         TYPE_FIELD_NAME (type, i),
+         c_print_type_1 (type->field (i).type (),
+                         type->field (i).name (),
                          stream, newshow, level + 4,
                          language, &local_flags, &local_podata);
 
@@ -1255,7 +1258,6 @@ c_type_print_base_struct_union (struct type *type, struct ui_file *stream,
            {
              const char *mangled_name;
              gdb::unique_xmalloc_ptr<char> mangled_name_holder;
-             char *demangled_name;
              const char *physname = TYPE_FN_FIELD_PHYSNAME (f, j);
              int is_full_physname_constructor =
                TYPE_FN_FIELD_CONSTRUCTOR (f, j)
@@ -1309,9 +1311,9 @@ c_type_print_base_struct_union (struct type *type, struct ui_file *stream,
              else
                mangled_name = TYPE_FN_FIELD_PHYSNAME (f, j);
 
-             demangled_name =
-               gdb_demangle (mangled_name,
-                             DMGL_ANSI | DMGL_PARAMS);
+             gdb::unique_xmalloc_ptr<char> demangled_name
+               gdb_demangle (mangled_name,
+                               DMGL_ANSI | DMGL_PARAMS);
              if (demangled_name == NULL)
                {
                  /* In some cases (for instance with the HP
@@ -1338,9 +1340,9 @@ c_type_print_base_struct_union (struct type *type, struct ui_file *stream,
                }
              else
                {
-                 char *p;
-                 char *demangled_no_class
-                   = remove_qualifiers (demangled_name);
+                 const char *p;
+                 const char *demangled_no_class
+                   = remove_qualifiers (demangled_name.get ());
 
                  /* Get rid of the `static' appended by the
                     demangler.  */
@@ -1348,19 +1350,12 @@ c_type_print_base_struct_union (struct type *type, struct ui_file *stream,
                  if (p != NULL)
                    {
                      int length = p - demangled_no_class;
-                     char *demangled_no_static;
-
-                     demangled_no_static
-                       = (char *) xmalloc (length + 1);
-                     strncpy (demangled_no_static,
-                              demangled_no_class, length);
-                     *(demangled_no_static + length) = '\0';
-                     fputs_filtered (demangled_no_static, stream);
-                     xfree (demangled_no_static);
+                     std::string demangled_no_static (demangled_no_class,
+                                                      length);
+                     fputs_filtered (demangled_no_static.c_str (), stream);
                    }
                  else
                    fputs_filtered (demangled_no_class, stream);
-                 xfree (demangled_name);
                }
 
              fprintf_filtered (stream, ";\n");
@@ -1436,7 +1431,7 @@ c_type_print_base_struct_union (struct type *type, struct ui_file *stream,
            print_spaces_filtered (2, stream);
        }
 
-      fprintfi_filtered (level, stream, "}");
+      fprintf_filtered (stream, "%*s}", level, "");
     }
 }
 
@@ -1496,7 +1491,7 @@ c_type_print_base_1 (struct type *type, struct ui_file *stream,
            fprintf_filtered (stream, "union ");
          else if (type->code () == TYPE_CODE_STRUCT)
            {
-             if (TYPE_DECLARED_CLASS (type))
+             if (type->is_declared_class ())
                fprintf_filtered (stream, "class ");
              else
                fprintf_filtered (stream, "struct ");
@@ -1549,13 +1544,13 @@ c_type_print_base_1 (struct type *type, struct ui_file *stream,
     case TYPE_CODE_ENUM:
       c_type_print_modifier (type, stream, 0, 1, language);
       fprintf_filtered (stream, "enum ");
-      if (TYPE_DECLARED_CLASS (type))
+      if (type->is_declared_class ())
        fprintf_filtered (stream, "class ");
       /* Print the tag name if it exists.
-         The aCC compiler emits a spurious 
-         "{unnamed struct}"/"{unnamed union}"/"{unnamed enum}"
-         tag for unnamed struct/union/enum's, which we don't
-         want to print.  */
+        The aCC compiler emits a spurious 
+        "{unnamed struct}"/"{unnamed union}"/"{unnamed enum}"
+        tag for unnamed struct/union/enum's, which we don't
+        want to print.  */
       if (type->name () != NULL
          && !startswith (type->name (), "{unnamed"))
        {
@@ -1564,7 +1559,7 @@ c_type_print_base_1 (struct type *type, struct ui_file *stream,
            fputs_filtered (" ", stream);
        }
 
-      wrap_here ("    ");
+      stream->wrap_here (4);
       if (show < 0)
        {
          /* If we just printed a tag name, no need to print anything
@@ -1599,14 +1594,14 @@ c_type_print_base_1 (struct type *type, struct ui_file *stream,
              QUIT;
              if (i)
                fprintf_filtered (stream, ", ");
-             wrap_here ("    ");
-             fputs_styled (TYPE_FIELD_NAME (type, i),
+             stream->wrap_here (4);
+             fputs_styled (type->field (i).name (),
                            variable_name_style.style (), stream);
-             if (lastval != TYPE_FIELD_ENUMVAL (type, i))
+             if (lastval != type->field (i).loc_enumval ())
                {
                  fprintf_filtered (stream, " = %s",
-                                   plongest (TYPE_FIELD_ENUMVAL (type, i)));
-                 lastval = TYPE_FIELD_ENUMVAL (type, i);
+                                   plongest (type->field (i).loc_enumval ()));
+                 lastval = type->field (i).loc_enumval ();
                }
              lastval++;
            }
@@ -1629,14 +1624,16 @@ c_type_print_base_1 (struct type *type, struct ui_file *stream,
            fprintf_filtered (stream, "{\n");
            if (type->num_fields () == 0)
              {
-               if (TYPE_STUB (type))
-                 fprintfi_filtered (level + 4, stream,
-                                    _("%p[<incomplete type>%p]\n"),
-                                    metadata_style.style ().ptr (), nullptr);
+               if (type->is_stub ())
+                 fprintf_filtered (stream,
+                                   _("%*s%p[<incomplete type>%p]\n"),
+                                   level + 4, "",
+                                   metadata_style.style ().ptr (), nullptr);
                else
-                 fprintfi_filtered (level + 4, stream,
-                                    _("%p[<no data fields>%p]\n"),
-                                    metadata_style.style ().ptr (), nullptr);
+                 fprintf_filtered (stream,
+                                   _("%*s%p[<no data fields>%p]\n"),
+                                   level + 4, "",
+                                   metadata_style.style ().ptr (), nullptr);
              }
            len = type->num_fields ();
            for (i = 0; i < len; i++)
@@ -1645,22 +1642,22 @@ c_type_print_base_1 (struct type *type, struct ui_file *stream,
                print_spaces_filtered (level + 4, stream);
                /* We pass "show" here and not "show - 1" to get enum types
                   printed.  There's no other way to see them.  */
-               c_print_type_1 (TYPE_FIELD_TYPE (type, i),
-                               TYPE_FIELD_NAME (type, i),
+               c_print_type_1 (type->field (i).type (),
+                               type->field (i).name (),
                                stream, show, level + 4,
                                language, &local_flags, podata);
                fprintf_filtered (stream, " @%s",
-                                 plongest (TYPE_FIELD_BITPOS (type, i)));
+                                 plongest (type->field (i).loc_bitpos ()));
                if (TYPE_FIELD_BITSIZE (type, i) > 1)
                  {
                    fprintf_filtered (stream, "-%s",
-                                     plongest (TYPE_FIELD_BITPOS (type, i)
+                                     plongest (type->field (i).loc_bitpos ()
                                                + TYPE_FIELD_BITSIZE (type, i)
                                                - 1));
                  }
                fprintf_filtered (stream, ";\n");
              }
-           fprintfi_filtered (level, stream, "}");
+           fprintf_filtered (stream, "%*s}", level, "");
          }
       }
       break;
@@ -1682,6 +1679,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);
@@ -1689,9 +1690,9 @@ c_type_print_base_1 (struct type *type, struct ui_file *stream,
 
     default:
       /* Handle types not explicitly handled by the other cases, such
-         as fundamental types.  For these, just print whatever the
-         type name is, as recorded in the type itself.  If there is no
-         type name, then complain.  */
+        as fundamental types.  For these, just print whatever the
+        type name is, as recorded in the type itself.  If there is no
+        type name, then complain.  */
       if (type->name () != NULL)
        {
          c_type_print_modifier (type, stream, 0, 1, language);
@@ -1715,7 +1716,7 @@ c_type_print_base (struct type *type, struct ui_file *stream,
                   int show, int level,
                   const struct type_print_options *flags)
 {
-  struct print_offset_data podata;
+  struct print_offset_data podata (flags);
 
   c_type_print_base_1 (type, stream, show, level,
                       current_language->la_language, flags, &podata);