gdb/linux: remove ptrace support check for exec, fork, vfork, vforkdone, clone, sysgood
[binutils-gdb.git] / gdb / c-typeprint.c
index 107d200bd557b6767025698967ca4ce838570469..405ede8b9c88ae3aa0a30385c199f75de1e7743b 100644 (file)
@@ -1,5 +1,5 @@
 /* Support for printing C and C++ types for GDB, the GNU debugger.
-   Copyright (C) 1986-2021 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);
@@ -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)
@@ -309,7 +310,7 @@ cp_type_print_method_args (struct type *mtype, const char *prefix,
          else if (i < nargs)
            {
              fprintf_filtered (stream, ", ");
-             wrap_here ("        ");
+             stream->wrap_here (8);
            }
        }
     }
@@ -572,7 +573,7 @@ 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 (i).type ();
@@ -601,7 +602,7 @@ c_type_print_args (struct type *type, struct ui_file *stream,
       if (printed_any && type->has_varargs ())
        {
          fprintf_filtered (stream, ", ");
-         wrap_here ("    ");
+         stream->wrap_here (4);
          fprintf_filtered (stream, "...");
        }
     }
@@ -674,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++)
@@ -882,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)
@@ -1192,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
@@ -1257,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)
@@ -1311,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
@@ -1340,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.  */
@@ -1350,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");
@@ -1566,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
@@ -1601,14 +1594,14 @@ c_type_print_base_1 (struct type *type, struct ui_file *stream,
              QUIT;
              if (i)
                fprintf_filtered (stream, ", ");
-             wrap_here ("    ");
+             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++;
            }
@@ -1654,11 +1647,11 @@ c_type_print_base_1 (struct type *type, struct ui_file *stream,
                                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));
                  }