Fix regresssion(internal-error) printing subprogram argument (PR gdb/22670)
[deliverable/binutils-gdb.git] / gdb / p-valprint.c
index a0b99f8350473793d485b43280afdc9359774170..933dbfb6c4d0b8a39c1d208183a82acc7c28a8a0 100644 (file)
@@ -1,6 +1,6 @@
 /* Support for printing Pascal values for GDB, the GNU debugger.
 
-   Copyright (C) 2000-2015 Free Software Foundation, Inc.
+   Copyright (C) 2000-2018 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -38,6 +38,7 @@
 #include "cp-abi.h"
 #include "cp-support.h"
 #include "objfiles.h"
+#include "common/byte-vector.h"
 \f
 
 /* Decorations for Pascal.  */
@@ -49,17 +50,19 @@ static const struct generic_val_print_decorations p_decorations =
   " * I",
   "true",
   "false",
-  "void"
+  "void",
+  "{",
+  "}"
 };
 
 /* See val_print for a description of the various parameters of this
    function; they are identical.  */
 
 void
-pascal_val_print (struct type *type, const gdb_byte *valaddr,
+pascal_val_print (struct type *type,
                  int embedded_offset, CORE_ADDR address,
                  struct ui_file *stream, int recurse,
-                 const struct value *original_value,
+                 struct value *original_value,
                  const struct value_print_options *options)
 {
   struct gdbarch *gdbarch = get_type_arch (type);
@@ -73,6 +76,7 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr,
   struct type *char_type;
   CORE_ADDR addr;
   int want_space = 0;
+  const gdb_byte *valaddr = value_contents_for_printing (original_value);
 
   type = check_typedef (type);
   switch (TYPE_CODE (type))
@@ -130,7 +134,7 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr,
                {
                  i = 0;
                }
-             val_print_array_elements (type, valaddr, embedded_offset,
+             val_print_array_elements (type, embedded_offset,
                                        address, stream, recurse,
                                        original_value, options, i);
              fprintf_filtered (stream, "}");
@@ -144,7 +148,7 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr,
     case TYPE_CODE_PTR:
       if (options->format && options->format != 's')
        {
-         val_print_scalar_formatted (type, valaddr, embedded_offset,
+         val_print_scalar_formatted (type, embedded_offset,
                                      original_value, options, 0, stream);
          break;
        }
@@ -203,11 +207,11 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr,
          && addr != 0)
        {
          ULONGEST string_length;
-         void *buffer;
+         gdb_byte *buffer;
 
          if (want_space)
            fputs_filtered (" ", stream);
-         buffer = xmalloc (length_size);
+         buffer = (gdb_byte *) xmalloc (length_size);
          read_memory (addr + length_pos, buffer, length_size);
          string_length = extract_unsigned_integer (buffer, length_size,
                                                    byte_order);
@@ -239,18 +243,20 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr,
          if (vt_address && options->vtblprint)
            {
              struct value *vt_val;
-             struct symbol *wsym = (struct symbol *) NULL;
+             struct symbol *wsym = NULL;
              struct type *wtype;
-             struct block *block = (struct block *) NULL;
-             struct field_of_this_result is_this_fld;
+             struct block *block = NULL;
 
              if (want_space)
                fputs_filtered (" ", stream);
 
              if (msymbol.minsym != NULL)
-               wsym = lookup_symbol (MSYMBOL_LINKAGE_NAME (msymbol.minsym),
-                                     block,
-                                     VAR_DOMAIN, &is_this_fld).symbol;
+               {
+                 const char *search_name
+                   = MSYMBOL_SEARCH_NAME (msymbol.minsym);
+                 wsym = lookup_symbol_search_name (search_name, block,
+                                                   VAR_DOMAIN).symbol;
+               }
 
              if (wsym)
                {
@@ -285,7 +291,7 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr,
     case TYPE_CODE_UNDEF:
     case TYPE_CODE_BOOL:
     case TYPE_CODE_CHAR:
-      generic_val_print (type, valaddr, embedded_offset, address,
+      generic_val_print (type, embedded_offset, address,
                         stream, recurse, original_value, options,
                         &p_decorations);
       break;
@@ -467,9 +473,9 @@ static void pascal_object_print_static_field (struct value *,
                                              const struct value_print_options *);
 
 static void pascal_object_print_value (struct type *, const gdb_byte *,
-                                      int,
+                                      LONGEST,
                                       CORE_ADDR, struct ui_file *, int,
-                                      const struct value *,
+                                      struct value *,
                                       const struct value_print_options *,
                                       struct type **);
 
@@ -526,16 +532,17 @@ pascal_object_is_vtbl_member (struct type *type)
 
 void
 pascal_object_print_value_fields (struct type *type, const gdb_byte *valaddr,
-                                 int offset,
+                                 LONGEST offset,
                                  CORE_ADDR address, struct ui_file *stream,
                                  int recurse,
-                                 const struct value *val,
+                                 struct value *val,
                                  const struct value_print_options *options,
                                  struct type **dont_print_vb,
                                  int dont_print_statmem)
 {
   int i, len, n_baseclasses;
-  char *last_dont_print = obstack_next_free (&dont_print_statmem_obstack);
+  char *last_dont_print
+    = (char *) obstack_next_free (&dont_print_statmem_obstack);
 
   type = check_typedef (type);
 
@@ -667,7 +674,7 @@ pascal_object_print_value_fields (struct type *type, const gdb_byte *valaddr,
                     address + TYPE_FIELD_BITPOS (type, i) / 8, 0,
                     stream, format, 0, recurse + 1, pretty); */
                  val_print (TYPE_FIELD_TYPE (type, i),
-                            valaddr, offset + TYPE_FIELD_BITPOS (type, i) / 8,
+                            offset + TYPE_FIELD_BITPOS (type, i) / 8,
                             address, stream, recurse + 1, val, &opts,
                             current_language);
                }
@@ -697,10 +704,10 @@ pascal_object_print_value_fields (struct type *type, const gdb_byte *valaddr,
 
 static void
 pascal_object_print_value (struct type *type, const gdb_byte *valaddr,
-                          int offset,
+                          LONGEST offset,
                           CORE_ADDR address, struct ui_file *stream,
                           int recurse,
-                          const struct value *val,
+                          struct value *val,
                           const struct value_print_options *options,
                           struct type **dont_print_vb)
 {
@@ -720,12 +727,13 @@ pascal_object_print_value (struct type *type, const gdb_byte *valaddr,
 
   for (i = 0; i < n_baseclasses; i++)
     {
-      int boffset = 0;
+      LONGEST boffset = 0;
       struct type *baseclass = check_typedef (TYPE_BASECLASS (type, i));
       const char *basename = type_name_no_tag (baseclass);
       const gdb_byte *base_valaddr = NULL;
-      int thisoffset;
+      LONGEST thisoffset;
       int skip = 0;
+      gdb::byte_vector buf;
 
       if (BASETYPE_VIA_VIRTUAL (type, i))
        {
@@ -765,20 +773,15 @@ pascal_object_print_value (struct type *type, const gdb_byte *valaddr,
 
          if (boffset < 0 || boffset >= TYPE_LENGTH (type))
            {
-             gdb_byte *buf;
-             struct cleanup *back_to;
+             buf.resize (TYPE_LENGTH (baseclass));
 
-             buf = xmalloc (TYPE_LENGTH (baseclass));
-             back_to = make_cleanup (xfree, buf);
-
-             base_valaddr = buf;
-             if (target_read_memory (address + boffset, buf,
+             base_valaddr = buf.data ();
+             if (target_read_memory (address + boffset, buf.data (),
                                      TYPE_LENGTH (baseclass)) != 0)
                skip = 1;
              address = address + boffset;
              thisoffset = 0;
              boffset = 0;
-             do_cleanups (back_to);
            }
          else
            base_valaddr = valaddr;
@@ -887,9 +890,6 @@ pascal_object_print_static_field (struct value *val,
   common_val_print (val, stream, recurse, &opts, current_language);
 }
 
-/* -Wmissing-prototypes */
-extern initialize_file_ftype _initialize_pascal_valprint;
-
 void
 _initialize_pascal_valprint (void)
 {
This page took 0.029837 seconds and 4 git commands to generate.