Enable -Wsuggest-override
[deliverable/binutils-gdb.git] / gdb / cp-valprint.c
index 143bb48db37c08877d11b07ea66b4f256a55104d..e019a60791eb6ef4de866b5d65ef6142372fe1cd 100644 (file)
@@ -1,6 +1,6 @@
 /* Support for printing C++ values for GDB, the GNU debugger.
 
-   Copyright (C) 1986-2017 Free Software Foundation, Inc.
+   Copyright (C) 1986-2018 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -35,6 +35,7 @@
 #include "language.h"
 #include "extension.h"
 #include "typeprint.h"
+#include "byte-vector.h"
 
 /* Controls printing of vtbl's.  */
 static void
@@ -73,8 +74,6 @@ static struct obstack dont_print_vb_obstack;
 static struct obstack dont_print_statmem_obstack;
 static struct obstack dont_print_stat_array_obstack;
 
-extern void _initialize_cp_valprint (void);
-
 static void cp_print_static_field (struct type *, struct value *,
                                   struct ui_file *, int,
                                   const struct value_print_options *);
@@ -372,13 +371,9 @@ cp_print_value_fields (struct type *type, struct type *real_type,
          if (obstack_final_size > statmem_obstack_initial_size)
            {
              /* In effect, a pop of the printed-statics stack.  */
-
-             void *free_to_ptr =
-               (char *) obstack_next_free (&dont_print_statmem_obstack) -
-               (obstack_final_size - statmem_obstack_initial_size);
-
-             obstack_free (&dont_print_statmem_obstack,
-                           free_to_ptr);
+             size_t shrink_bytes
+               = statmem_obstack_initial_size - obstack_final_size;
+             obstack_blank_fast (&dont_print_statmem_obstack, shrink_bytes);
            }
 
          if (last_set_recurse != recurse)
@@ -534,23 +529,18 @@ cp_print_value (struct type *type, struct type *real_type,
              if ((boffset + offset) < 0
                  || (boffset + offset) >= TYPE_LENGTH (real_type))
                {
-                 gdb_byte *buf;
-                 struct cleanup *back_to;
-
-                 buf = (gdb_byte *) xmalloc (TYPE_LENGTH (baseclass));
-                 back_to = make_cleanup (xfree, buf);
+                 gdb::byte_vector buf (TYPE_LENGTH (baseclass));
 
-                 if (target_read_memory (address + boffset, buf,
+                 if (target_read_memory (address + boffset, buf.data (),
                                          TYPE_LENGTH (baseclass)) != 0)
                    skip = 1;
                  base_val = value_from_contents_and_address (baseclass,
-                                                             buf,
+                                                             buf.data (),
                                                              address + boffset);
                  baseclass = value_type (base_val);
                  thisoffset = 0;
                  boffset = 0;
                  thistype = baseclass;
-                 do_cleanups (back_to);
                }
              else
                {
@@ -643,7 +633,8 @@ cp_print_static_field (struct type *type,
       return;
     }
 
-  if (TYPE_CODE (type) == TYPE_CODE_STRUCT)
+  struct type *real_type = check_typedef (type);
+  if (TYPE_CODE (real_type) == TYPE_CODE_STRUCT)
     {
       CORE_ADDR *first_dont_print;
       CORE_ADDR addr;
@@ -668,7 +659,6 @@ cp_print_static_field (struct type *type,
       addr = value_address (val);
       obstack_grow (&dont_print_statmem_obstack, (char *) &addr,
                    sizeof (CORE_ADDR));
-      type = check_typedef (type);
       cp_print_value_fields (type, value_enclosing_type (val),
                             value_embedded_offset (val), addr,
                             stream, recurse, val,
@@ -676,7 +666,7 @@ cp_print_static_field (struct type *type,
       return;
     }
 
-  if (TYPE_CODE (type) == TYPE_CODE_ARRAY)
+  if (TYPE_CODE (real_type) == TYPE_CODE_ARRAY)
     {
       struct type **first_dont_print;
       int i;
@@ -759,7 +749,7 @@ cp_find_class_member (struct type **self_p, int *fieldno,
 
 void
 cp_print_class_member (const gdb_byte *valaddr, struct type *type,
-                      struct ui_file *stream, char *prefix)
+                      struct ui_file *stream, const char *prefix)
 {
   enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type));
 
This page took 0.027235 seconds and 4 git commands to generate.