ubsan: xgate: left shift of negative value
[deliverable/binutils-gdb.git] / gdb / c-typeprint.c
index c167e212ded4ae12ef8110b95fc12ef98eada10c..a8c9705c031677969cbb215dace7ad7016099922 100644 (file)
@@ -1,5 +1,5 @@
 /* Support for printing C and C++ types for GDB, the GNU debugger.
-   Copyright (C) 1986-2018 Free Software Foundation, Inc.
+   Copyright (C) 1986-2020 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -28,6 +28,7 @@
 #include "language.h"
 #include "demangle.h"
 #include "c-lang.h"
+#include "cli/cli-style.h"
 #include "typeprint.h"
 #include "cp-abi.h"
 #include "cp-support.h"
@@ -115,6 +116,7 @@ c_print_type_1 (struct type *type,
     type = check_typedef (type);
 
   local_name = typedef_hash_table::find_typedef (flags, type);
+  code = TYPE_CODE (type);
   if (local_name != NULL)
     {
       fputs_filtered (local_name, stream);
@@ -124,7 +126,6 @@ c_print_type_1 (struct type *type,
   else
     {
       c_type_print_base_1 (type, stream, show, level, language, flags, podata);
-      code = TYPE_CODE (type);
       if ((varstring != NULL && *varstring != '\0')
          /* Need a space if going to print stars or brackets;
             but not if we will print just a type name.  */
@@ -144,7 +145,10 @@ c_print_type_1 (struct type *type,
 
   if (varstring != NULL)
     {
-      fputs_filtered (varstring, stream);
+      if (code == TYPE_CODE_FUNC || code == TYPE_CODE_METHOD)
+       fputs_styled (varstring, function_name_style.style (), stream);
+      else
+       fputs_filtered (varstring, stream);
 
       /* For demangled function names, we have the arglist as part of
          the name, so don't print an additional pair of ()'s.  */
@@ -201,13 +205,13 @@ c_print_typedef (struct type *type,
 {
   type = check_typedef (type);
   fprintf_filtered (stream, "typedef ");
-  type_print (type, "", stream, 0);
+  type_print (type, "", stream, -1);
   if (TYPE_NAME ((SYMBOL_TYPE (new_symbol))) == 0
       || strcmp (TYPE_NAME ((SYMBOL_TYPE (new_symbol))),
-                SYMBOL_LINKAGE_NAME (new_symbol)) != 0
+                new_symbol->linkage_name ()) != 0
       || TYPE_CODE (SYMBOL_TYPE (new_symbol)) == TYPE_CODE_TYPEDEF)
-    fprintf_filtered (stream, " %s", SYMBOL_PRINT_NAME (new_symbol));
-  fprintf_filtered (stream, ";\n");
+    fprintf_filtered (stream, " %s", new_symbol->print_name ());
+  fprintf_filtered (stream, ";");
 }
 
 /* If TYPE is a derived type, then print out derivation information.
@@ -876,15 +880,14 @@ c_type_print_template_args (const struct type_print_options *flags,
       if (first)
        {
          wrap_here ("    ");
-         fprintf_filtered (stream, _("[with %s = "),
-                           SYMBOL_LINKAGE_NAME (sym));
+         fprintf_filtered (stream, _("[with %s = "), sym->linkage_name ());
          first = 0;
        }
       else
        {
          fputs_filtered (", ", stream);
          wrap_here ("         ");
-         fprintf_filtered (stream, "%s = ", SYMBOL_LINKAGE_NAME (sym));
+         fprintf_filtered (stream, "%s = ", sym->linkage_name ());
        }
 
       c_print_type (SYMBOL_TYPE (sym), "", stream, -1, 0, flags);
@@ -1112,10 +1115,12 @@ c_type_print_base_struct_union (struct type *type, struct ui_file *stream,
        {
          if (TYPE_STUB (type))
            fprintfi_filtered (level + 4, stream,
-                              _("<incomplete type>\n"));
+                              _("%p[<incomplete type>%p]\n"),
+                              metadata_style.style ().ptr (), nullptr);
          else
            fprintfi_filtered (level + 4, stream,
-                              _("<no data fields>\n"));
+                              _("%p[<no data fields>%p]\n"),
+                              metadata_style.style ().ptr (), nullptr);
        }
 
       /* Start off with no specific section type, so we can print
@@ -1168,7 +1173,7 @@ c_type_print_base_struct_union (struct type *type, struct ui_file *stream,
 
          int newshow = show - 1;
 
-         if (flags->print_offsets
+         if (!is_static && flags->print_offsets
              && (TYPE_CODE (TYPE_FIELD_TYPE (type, i)) == TYPE_CODE_STRUCT
                  || TYPE_CODE (TYPE_FIELD_TYPE (type, i)) == TYPE_CODE_UNION))
            {
@@ -1273,7 +1278,8 @@ c_type_print_base_struct_union (struct type *type, struct ui_file *stream,
                {
                  /* Keep GDB from crashing here.  */
                  fprintf_filtered (stream,
-                                   _("<undefined type> %s;\n"),
+                                   _("%p[<undefined type>%p] %s;\n"),
+                                   metadata_style.style ().ptr (), nullptr,
                                    TYPE_FN_FIELD_PHYSNAME (f, j));
                  break;
                }
@@ -1321,9 +1327,9 @@ c_type_print_base_struct_union (struct type *type, struct ui_file *stream,
                                                 &local_flags);
                    }
                  else
-                   fprintf_filtered (stream,
-                                     _("<badly mangled name '%s'>"),
-                                     mangled_name);
+                   fprintf_styled (stream, metadata_style.style (),
+                                   _("<badly mangled name '%s'>"),
+                                   mangled_name);
                }
              else
                {
@@ -1461,7 +1467,7 @@ c_type_print_base_1 (struct type *type, struct ui_file *stream,
 
   if (type == NULL)
     {
-      fputs_filtered (_("<type unknown>"), stream);
+      fputs_styled (_("<type unknown>"), metadata_style.style (), stream);
       return;
     }
 
@@ -1507,7 +1513,8 @@ c_type_print_base_1 (struct type *type, struct ui_file *stream,
         couldn't resolve TYPE_TARGET_TYPE.  Not much we can do.  */
       gdb_assert (TYPE_NAME (type) == NULL);
       gdb_assert (TYPE_TARGET_TYPE (type) == NULL);
-      fprintf_filtered (stream, _("<unnamed typedef>"));
+      fprintf_styled (stream, metadata_style.style (),
+                     _("<unnamed typedef>"));
       break;
 
     case TYPE_CODE_FUNC:
@@ -1618,10 +1625,12 @@ c_type_print_base_1 (struct type *type, struct ui_file *stream,
              {
                if (TYPE_STUB (type))
                  fprintfi_filtered (level + 4, stream,
-                                    _("<incomplete type>\n"));
+                                    _("%p[<incomplete type>%p]\n"),
+                                    metadata_style.style ().ptr (), nullptr);
                else
                  fprintfi_filtered (level + 4, stream,
-                                    _("<no data fields>\n"));
+                                    _("%p[<no data fields>%p]\n"),
+                                    metadata_style.style ().ptr (), nullptr);
              }
            len = TYPE_NFIELDS (type);
            for (i = 0; i < len; i++)
@@ -1664,7 +1673,7 @@ c_type_print_base_1 (struct type *type, struct ui_file *stream,
 
     case TYPE_CODE_RANGE:
       /* This should not occur.  */
-      fprintf_filtered (stream, _("<range type>"));
+      fprintf_styled (stream, metadata_style.style (), _("<range type>"));
       break;
 
     case TYPE_CODE_NAMESPACE:
@@ -1686,8 +1695,8 @@ c_type_print_base_1 (struct type *type, struct ui_file *stream,
        {
          /* At least for dump_symtab, it is important that this not
             be an error ().  */
-         fprintf_filtered (stream, _("<invalid type code %d>"),
-                           TYPE_CODE (type));
+         fprintf_styled (stream, metadata_style.style (),
+                         _("<invalid type code %d>"), TYPE_CODE (type));
        }
       break;
     }
This page took 0.029308 seconds and 4 git commands to generate.